Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 16 | |
Mathieu Chartier | c645f1d | 2014-03-06 18:11:53 -0800 | [diff] [blame] | 17 | #include "method_verifier-inl.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 18 | |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 19 | #include <iostream> |
| 20 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 21 | #include "art_field-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 22 | #include "art_method-inl.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 23 | #include "base/logging.h" |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 24 | #include "base/mutex-inl.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 25 | #include "base/time_utils.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 26 | #include "class_linker.h" |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 27 | #include "compiler_callbacks.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 28 | #include "dex_file-inl.h" |
Ian Rogers | d058380 | 2013-06-01 10:51:46 -0700 | [diff] [blame] | 29 | #include "dex_instruction-inl.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 30 | #include "dex_instruction_utils.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 31 | #include "dex_instruction_visitor.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 32 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 33 | #include "indenter.h" |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 34 | #include "intern_table.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 35 | #include "leb128.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | #include "mirror/class.h" |
| 37 | #include "mirror/class-inl.h" |
Ian Rogers | 39ebcb8 | 2013-05-30 16:57:23 -0700 | [diff] [blame] | 38 | #include "mirror/dex_cache-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | #include "mirror/object-inl.h" |
| 40 | #include "mirror/object_array-inl.h" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 41 | #include "reg_type-inl.h" |
Ian Rogers | 39ebcb8 | 2013-05-30 16:57:23 -0700 | [diff] [blame] | 42 | #include "register_line-inl.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 43 | #include "runtime.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 44 | #include "scoped_thread_state_change.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 45 | #include "utils.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 46 | #include "handle_scope-inl.h" |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 47 | #include "verifier/dex_gc_map.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 48 | |
| 49 | namespace art { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 50 | namespace verifier { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 51 | |
Mathieu Chartier | 8e219ae | 2014-08-19 14:29:46 -0700 | [diff] [blame] | 52 | static constexpr bool kTimeVerifyMethod = !kIsDebugBuild; |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 53 | static constexpr bool gDebugVerify = false; |
Anwar Ghuloum | 75a43f1 | 2013-08-13 17:22:14 -0700 | [diff] [blame] | 54 | // TODO: Add a constant to method_verifier to turn on verbose logging? |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 55 | |
Andreas Gampe | ebf850c | 2015-08-14 15:37:35 -0700 | [diff] [blame] | 56 | // On VLOG(verifier), should we dump the whole state when we run into a hard failure? |
| 57 | static constexpr bool kDumpRegLinesOnHardFailureIfVLOG = true; |
| 58 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 59 | void PcToRegisterLineTable::Init(RegisterTrackingMode mode, InstructionFlags* flags, |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 60 | uint32_t insns_size, uint16_t registers_size, |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 61 | MethodVerifier* verifier) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 62 | DCHECK_GT(insns_size, 0U); |
Ian Rogers | d0fbd85 | 2013-09-24 18:17:04 -0700 | [diff] [blame] | 63 | register_lines_.reset(new RegisterLine*[insns_size]()); |
| 64 | size_ = insns_size; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 65 | for (uint32_t i = 0; i < insns_size; i++) { |
| 66 | bool interesting = false; |
| 67 | switch (mode) { |
| 68 | case kTrackRegsAll: |
| 69 | interesting = flags[i].IsOpcode(); |
| 70 | break; |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 71 | case kTrackCompilerInterestPoints: |
Brian Carlstrom | 02c8cc6 | 2013-07-18 15:54:44 -0700 | [diff] [blame] | 72 | interesting = flags[i].IsCompileTimeInfoPoint() || flags[i].IsBranchTarget(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 73 | break; |
| 74 | case kTrackRegsBranches: |
| 75 | interesting = flags[i].IsBranchTarget(); |
| 76 | break; |
| 77 | default: |
| 78 | break; |
| 79 | } |
| 80 | if (interesting) { |
Ian Rogers | d0fbd85 | 2013-09-24 18:17:04 -0700 | [diff] [blame] | 81 | register_lines_[i] = RegisterLine::Create(registers_size, verifier); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | PcToRegisterLineTable::~PcToRegisterLineTable() { |
| 87 | for (size_t i = 0; i < size_; i++) { |
| 88 | delete register_lines_[i]; |
| 89 | if (kIsDebugBuild) { |
| 90 | register_lines_[i] = nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 95 | // Note: returns true on failure. |
| 96 | ALWAYS_INLINE static inline bool FailOrAbort(MethodVerifier* verifier, bool condition, |
| 97 | const char* error_msg, uint32_t work_insn_idx) { |
| 98 | if (kIsDebugBuild) { |
| 99 | // In a debug build, abort if the error condition is wrong. |
| 100 | DCHECK(condition) << error_msg << work_insn_idx; |
| 101 | } else { |
| 102 | // In a non-debug build, just fail the class. |
| 103 | if (!condition) { |
| 104 | verifier->Fail(VERIFY_ERROR_BAD_CLASS_HARD) << error_msg << work_insn_idx; |
| 105 | return true; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return false; |
| 110 | } |
| 111 | |
Stephen Kyle | 7e541c9 | 2014-12-17 17:10:02 +0000 | [diff] [blame] | 112 | static void SafelyMarkAllRegistersAsConflicts(MethodVerifier* verifier, RegisterLine* reg_line) { |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 113 | if (verifier->IsInstanceConstructor()) { |
Stephen Kyle | 7e541c9 | 2014-12-17 17:10:02 +0000 | [diff] [blame] | 114 | // Before we mark all regs as conflicts, check that we don't have an uninitialized this. |
| 115 | reg_line->CheckConstructorReturn(verifier); |
| 116 | } |
| 117 | reg_line->MarkAllRegistersAsConflicts(verifier); |
| 118 | } |
| 119 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 120 | MethodVerifier::FailureKind MethodVerifier::VerifyMethod( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 121 | ArtMethod* method, bool allow_soft_failures, std::string* error ATTRIBUTE_UNUSED) { |
| 122 | StackHandleScope<2> hs(Thread::Current()); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 123 | mirror::Class* klass = method->GetDeclaringClass(); |
| 124 | auto h_dex_cache(hs.NewHandle(klass->GetDexCache())); |
| 125 | auto h_class_loader(hs.NewHandle(klass->GetClassLoader())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 126 | return VerifyMethod(hs.Self(), method->GetDexMethodIndex(), method->GetDexFile(), h_dex_cache, |
| 127 | h_class_loader, klass->GetClassDef(), method->GetCodeItem(), method, |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 128 | method->GetAccessFlags(), allow_soft_failures, false); |
| 129 | } |
| 130 | |
| 131 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 132 | MethodVerifier::FailureKind MethodVerifier::VerifyClass(Thread* self, |
| 133 | mirror::Class* klass, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 134 | bool allow_soft_failures, |
| 135 | std::string* error) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 136 | if (klass->IsVerified()) { |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 137 | return kNoFailure; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 138 | } |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 139 | bool early_failure = false; |
| 140 | std::string failure_message; |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 141 | const DexFile& dex_file = klass->GetDexFile(); |
| 142 | const DexFile::ClassDef* class_def = klass->GetClassDef(); |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 143 | mirror::Class* super = klass->GetSuperClass(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 144 | std::string temp; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 145 | if (super == nullptr && strcmp("Ljava/lang/Object;", klass->GetDescriptor(&temp)) != 0) { |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 146 | early_failure = true; |
| 147 | failure_message = " that has no super class"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 148 | } else if (super != nullptr && super->IsFinal()) { |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 149 | early_failure = true; |
| 150 | failure_message = " that attempts to sub-class final class " + PrettyDescriptor(super); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 151 | } else if (class_def == nullptr) { |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 152 | early_failure = true; |
| 153 | failure_message = " that isn't present in dex file " + dex_file.GetLocation(); |
| 154 | } |
| 155 | if (early_failure) { |
| 156 | *error = "Verifier rejected class " + PrettyDescriptor(klass) + failure_message; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 157 | if (Runtime::Current()->IsAotCompiler()) { |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 158 | ClassReference ref(&dex_file, klass->GetDexClassDefIndex()); |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 159 | Runtime::Current()->GetCompilerCallbacks()->ClassRejected(ref); |
Jeff Hao | 2d7e5aa | 2013-12-13 17:39:59 -0800 | [diff] [blame] | 160 | } |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 161 | return kHardFailure; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 162 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 163 | StackHandleScope<2> hs(self); |
Mathieu Chartier | f832284 | 2014-05-16 10:59:25 -0700 | [diff] [blame] | 164 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache())); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 165 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 166 | return VerifyClass( |
| 167 | self, &dex_file, dex_cache, class_loader, class_def, allow_soft_failures, error); |
Shih-wei Liao | 371814f | 2011-10-27 16:52:10 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 170 | MethodVerifier::FailureKind MethodVerifier::VerifyClass(Thread* self, |
| 171 | const DexFile* dex_file, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 172 | Handle<mirror::DexCache> dex_cache, |
| 173 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 174 | const DexFile::ClassDef* class_def, |
| 175 | bool allow_soft_failures, |
| 176 | std::string* error) { |
| 177 | DCHECK(class_def != nullptr); |
Andreas Gampe | 507cc6f | 2015-06-19 22:58:47 -0700 | [diff] [blame] | 178 | |
| 179 | // A class must not be abstract and final. |
| 180 | if ((class_def->access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) { |
| 181 | *error = "Verifier rejected class "; |
| 182 | *error += PrettyDescriptor(dex_file->GetClassDescriptor(*class_def)); |
| 183 | *error += ": class is abstract and final."; |
| 184 | return kHardFailure; |
| 185 | } |
| 186 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 187 | const uint8_t* class_data = dex_file->GetClassData(*class_def); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 188 | if (class_data == nullptr) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 189 | // empty class, probably a marker interface |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 190 | return kNoFailure; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 191 | } |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 192 | ClassDataItemIterator it(*dex_file, class_data); |
| 193 | while (it.HasNextStaticField() || it.HasNextInstanceField()) { |
| 194 | it.Next(); |
| 195 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 196 | size_t error_count = 0; |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 197 | bool hard_fail = false; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 198 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
jeffhao | 9b0b188 | 2012-10-01 16:51:22 -0700 | [diff] [blame] | 199 | int64_t previous_direct_method_idx = -1; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 200 | while (it.HasNextDirectMethod()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 201 | self->AllowThreadSuspension(); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 202 | uint32_t method_idx = it.GetMemberIndex(); |
jeffhao | 9b0b188 | 2012-10-01 16:51:22 -0700 | [diff] [blame] | 203 | if (method_idx == previous_direct_method_idx) { |
| 204 | // smali can create dex files with two encoded_methods sharing the same method_idx |
| 205 | // http://code.google.com/p/smali/issues/detail?id=119 |
| 206 | it.Next(); |
| 207 | continue; |
| 208 | } |
| 209 | previous_direct_method_idx = method_idx; |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 210 | InvokeType type = it.GetMethodInvokeType(*class_def); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 211 | ArtMethod* method = linker->ResolveMethod( |
| 212 | *dex_file, method_idx, dex_cache, class_loader, nullptr, type); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 213 | if (method == nullptr) { |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 214 | DCHECK(self->IsExceptionPending()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 215 | // We couldn't resolve the method, but continue regardless. |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 216 | self->ClearException(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 217 | } else { |
| 218 | DCHECK(method->GetDeclaringClassUnchecked() != nullptr) << type; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 219 | } |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 220 | StackHandleScope<1> hs(self); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 221 | MethodVerifier::FailureKind result = VerifyMethod(self, |
| 222 | method_idx, |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 223 | dex_file, |
| 224 | dex_cache, |
| 225 | class_loader, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 226 | class_def, |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 227 | it.GetMethodCodeItem(), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 228 | method, it.GetMethodAccessFlags(), allow_soft_failures, false); |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 229 | if (result != kNoFailure) { |
| 230 | if (result == kHardFailure) { |
| 231 | hard_fail = true; |
| 232 | if (error_count > 0) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 233 | *error += "\n"; |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 234 | } |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 235 | *error = "Verifier rejected class "; |
| 236 | *error += PrettyDescriptor(dex_file->GetClassDescriptor(*class_def)); |
| 237 | *error += " due to bad method "; |
| 238 | *error += PrettyMethod(method_idx, *dex_file); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 239 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 240 | ++error_count; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 241 | } |
| 242 | it.Next(); |
| 243 | } |
jeffhao | 9b0b188 | 2012-10-01 16:51:22 -0700 | [diff] [blame] | 244 | int64_t previous_virtual_method_idx = -1; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 245 | while (it.HasNextVirtualMethod()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 246 | self->AllowThreadSuspension(); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 247 | uint32_t method_idx = it.GetMemberIndex(); |
jeffhao | 9b0b188 | 2012-10-01 16:51:22 -0700 | [diff] [blame] | 248 | if (method_idx == previous_virtual_method_idx) { |
| 249 | // smali can create dex files with two encoded_methods sharing the same method_idx |
| 250 | // http://code.google.com/p/smali/issues/detail?id=119 |
| 251 | it.Next(); |
| 252 | continue; |
| 253 | } |
| 254 | previous_virtual_method_idx = method_idx; |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 255 | InvokeType type = it.GetMethodInvokeType(*class_def); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 256 | ArtMethod* method = linker->ResolveMethod( |
| 257 | *dex_file, method_idx, dex_cache, class_loader, nullptr, type); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 258 | if (method == nullptr) { |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 259 | DCHECK(self->IsExceptionPending()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 260 | // We couldn't resolve the method, but continue regardless. |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 261 | self->ClearException(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 262 | } |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 263 | StackHandleScope<1> hs(self); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 264 | MethodVerifier::FailureKind result = VerifyMethod(self, |
| 265 | method_idx, |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 266 | dex_file, |
| 267 | dex_cache, |
| 268 | class_loader, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 269 | class_def, |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 270 | it.GetMethodCodeItem(), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 271 | method, it.GetMethodAccessFlags(), allow_soft_failures, false); |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 272 | if (result != kNoFailure) { |
| 273 | if (result == kHardFailure) { |
| 274 | hard_fail = true; |
| 275 | if (error_count > 0) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 276 | *error += "\n"; |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 277 | } |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 278 | *error = "Verifier rejected class "; |
| 279 | *error += PrettyDescriptor(dex_file->GetClassDescriptor(*class_def)); |
| 280 | *error += " due to bad method "; |
| 281 | *error += PrettyMethod(method_idx, *dex_file); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 282 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 283 | ++error_count; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 284 | } |
| 285 | it.Next(); |
| 286 | } |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 287 | if (error_count == 0) { |
| 288 | return kNoFailure; |
| 289 | } else { |
| 290 | return hard_fail ? kHardFailure : kSoftFailure; |
| 291 | } |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Andreas Gampe | a4f5bf6 | 2015-05-18 20:50:12 -0700 | [diff] [blame] | 294 | static bool IsLargeMethod(const DexFile::CodeItem* const code_item) { |
Andreas Gampe | 3c651fc | 2015-05-21 14:06:46 -0700 | [diff] [blame] | 295 | if (code_item == nullptr) { |
| 296 | return false; |
| 297 | } |
| 298 | |
Andreas Gampe | a4f5bf6 | 2015-05-18 20:50:12 -0700 | [diff] [blame] | 299 | uint16_t registers_size = code_item->registers_size_; |
| 300 | uint32_t insns_size = code_item->insns_size_in_code_units_; |
| 301 | |
| 302 | return registers_size * insns_size > 4*1024*1024; |
| 303 | } |
| 304 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 305 | MethodVerifier::FailureKind MethodVerifier::VerifyMethod(Thread* self, uint32_t method_idx, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 306 | const DexFile* dex_file, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 307 | Handle<mirror::DexCache> dex_cache, |
| 308 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 309 | const DexFile::ClassDef* class_def, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 310 | const DexFile::CodeItem* code_item, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 311 | ArtMethod* method, |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 312 | uint32_t method_access_flags, |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 313 | bool allow_soft_failures, |
| 314 | bool need_precise_constants) { |
Ian Rogers | c898258 | 2012-09-07 16:53:25 -0700 | [diff] [blame] | 315 | MethodVerifier::FailureKind result = kNoFailure; |
Mathieu Chartier | 8e219ae | 2014-08-19 14:29:46 -0700 | [diff] [blame] | 316 | uint64_t start_ns = kTimeVerifyMethod ? NanoTime() : 0; |
Ian Rogers | c898258 | 2012-09-07 16:53:25 -0700 | [diff] [blame] | 317 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 318 | MethodVerifier verifier(self, dex_file, dex_cache, class_loader, class_def, code_item, |
Hiroshi Yamauchi | dc37617 | 2014-08-22 11:13:12 -0700 | [diff] [blame] | 319 | method_idx, method, method_access_flags, true, allow_soft_failures, |
Mathieu Chartier | 4306ef8 | 2014-12-19 18:41:47 -0800 | [diff] [blame] | 320 | need_precise_constants, true); |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 321 | if (verifier.Verify()) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 322 | // Verification completed, however failures may be pending that didn't cause the verification |
| 323 | // to hard fail. |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 324 | CHECK(!verifier.have_pending_hard_failure_); |
| 325 | if (verifier.failures_.size() != 0) { |
Anwar Ghuloum | 75a43f1 | 2013-08-13 17:22:14 -0700 | [diff] [blame] | 326 | if (VLOG_IS_ON(verifier)) { |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 327 | verifier.DumpFailures(VLOG_STREAM(verifier) << "Soft verification failures in " |
Anwar Ghuloum | 75a43f1 | 2013-08-13 17:22:14 -0700 | [diff] [blame] | 328 | << PrettyMethod(method_idx, *dex_file) << "\n"); |
| 329 | } |
Ian Rogers | c898258 | 2012-09-07 16:53:25 -0700 | [diff] [blame] | 330 | result = kSoftFailure; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 331 | } |
| 332 | } else { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 333 | // Bad method data. |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 334 | CHECK_NE(verifier.failures_.size(), 0U); |
Igor Murashkin | 4d7b75f | 2015-07-21 17:03:36 -0700 | [diff] [blame] | 335 | |
| 336 | if (UNLIKELY(verifier.have_pending_experimental_failure_)) { |
| 337 | // Failed due to being forced into interpreter. This is ok because |
| 338 | // we just want to skip verification. |
| 339 | result = kSoftFailure; |
| 340 | } else { |
| 341 | CHECK(verifier.have_pending_hard_failure_); |
| 342 | verifier.DumpFailures(LOG(INFO) << "Verification error in " |
| 343 | << PrettyMethod(method_idx, *dex_file) << "\n"); |
| 344 | result = kHardFailure; |
| 345 | } |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 346 | if (gDebugVerify) { |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 347 | std::cout << "\n" << verifier.info_messages_.str(); |
| 348 | verifier.Dump(std::cout); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 349 | } |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 350 | } |
Mathieu Chartier | 8e219ae | 2014-08-19 14:29:46 -0700 | [diff] [blame] | 351 | if (kTimeVerifyMethod) { |
| 352 | uint64_t duration_ns = NanoTime() - start_ns; |
| 353 | if (duration_ns > MsToNs(100)) { |
| 354 | LOG(WARNING) << "Verification of " << PrettyMethod(method_idx, *dex_file) |
Andreas Gampe | a4f5bf6 | 2015-05-18 20:50:12 -0700 | [diff] [blame] | 355 | << " took " << PrettyDuration(duration_ns) |
| 356 | << (IsLargeMethod(code_item) ? " (large method)" : ""); |
Mathieu Chartier | 8e219ae | 2014-08-19 14:29:46 -0700 | [diff] [blame] | 357 | } |
Ian Rogers | c898258 | 2012-09-07 16:53:25 -0700 | [diff] [blame] | 358 | } |
| 359 | return result; |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 362 | MethodVerifier* MethodVerifier::VerifyMethodAndDump(Thread* self, |
| 363 | VariableIndentationOutputStream* vios, |
| 364 | uint32_t dex_method_idx, |
| 365 | const DexFile* dex_file, |
| 366 | Handle<mirror::DexCache> dex_cache, |
| 367 | Handle<mirror::ClassLoader> class_loader, |
| 368 | const DexFile::ClassDef* class_def, |
| 369 | const DexFile::CodeItem* code_item, |
| 370 | ArtMethod* method, |
| 371 | uint32_t method_access_flags) { |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 372 | MethodVerifier* verifier = new MethodVerifier(self, dex_file, dex_cache, class_loader, |
| 373 | class_def, code_item, dex_method_idx, method, |
| 374 | method_access_flags, true, true, true, true); |
| 375 | verifier->Verify(); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 376 | verifier->DumpFailures(vios->Stream()); |
| 377 | vios->Stream() << verifier->info_messages_.str(); |
Andreas Gampe | 5cbcde2 | 2014-09-16 14:59:49 -0700 | [diff] [blame] | 378 | // Only dump and return if no hard failures. Otherwise the verifier may be not fully initialized |
| 379 | // and querying any info is dangerous/can abort. |
| 380 | if (verifier->have_pending_hard_failure_) { |
| 381 | delete verifier; |
| 382 | return nullptr; |
| 383 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 384 | verifier->Dump(vios); |
Andreas Gampe | 5cbcde2 | 2014-09-16 14:59:49 -0700 | [diff] [blame] | 385 | return verifier; |
| 386 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 389 | MethodVerifier::MethodVerifier(Thread* self, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 390 | const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, |
| 391 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 392 | const DexFile::ClassDef* class_def, |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 393 | const DexFile::CodeItem* code_item, uint32_t dex_method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 394 | ArtMethod* method, uint32_t method_access_flags, |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 395 | bool can_load_classes, bool allow_soft_failures, |
Mathieu Chartier | 4306ef8 | 2014-12-19 18:41:47 -0800 | [diff] [blame] | 396 | bool need_precise_constants, bool verify_to_dump, |
| 397 | bool allow_thread_suspension) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 398 | : self_(self), |
| 399 | reg_types_(can_load_classes), |
Andreas Gampe | d5ad72f | 2015-06-26 17:33:47 -0700 | [diff] [blame] | 400 | work_insn_idx_(DexFile::kDexNoIndex), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 401 | dex_method_idx_(dex_method_idx), |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 402 | mirror_method_(method), |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 403 | method_access_flags_(method_access_flags), |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 404 | return_type_(nullptr), |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 405 | dex_file_(dex_file), |
| 406 | dex_cache_(dex_cache), |
| 407 | class_loader_(class_loader), |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 408 | class_def_(class_def), |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 409 | code_item_(code_item), |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 410 | declaring_class_(nullptr), |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 411 | interesting_dex_pc_(-1), |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 412 | monitor_enter_dex_pcs_(nullptr), |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 413 | have_pending_hard_failure_(false), |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 414 | have_pending_runtime_throw_failure_(false), |
Igor Murashkin | 4d7b75f | 2015-07-21 17:03:36 -0700 | [diff] [blame] | 415 | have_pending_experimental_failure_(false), |
Andreas Gampe | d12e782 | 2015-06-25 10:26:40 -0700 | [diff] [blame] | 416 | have_any_pending_runtime_throw_failure_(false), |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 417 | new_instance_count_(0), |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 418 | monitor_enter_count_(0), |
Andreas Gampe | 0760a81 | 2015-08-26 17:12:51 -0700 | [diff] [blame] | 419 | encountered_failure_types_(0), |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 420 | can_load_classes_(can_load_classes), |
Sebastien Hertz | 4d4adb1 | 2013-07-24 16:14:19 +0200 | [diff] [blame] | 421 | allow_soft_failures_(allow_soft_failures), |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 422 | need_precise_constants_(need_precise_constants), |
Sebastien Hertz | 4d4adb1 | 2013-07-24 16:14:19 +0200 | [diff] [blame] | 423 | has_check_casts_(false), |
Andreas Gampe | 2ed8def | 2014-08-28 14:41:02 -0700 | [diff] [blame] | 424 | has_virtual_or_interface_invokes_(false), |
Mathieu Chartier | 4306ef8 | 2014-12-19 18:41:47 -0800 | [diff] [blame] | 425 | verify_to_dump_(verify_to_dump), |
Andreas Gampe | d5ad72f | 2015-06-26 17:33:47 -0700 | [diff] [blame] | 426 | allow_thread_suspension_(allow_thread_suspension), |
| 427 | link_(nullptr) { |
Mathieu Chartier | d0ad2ee | 2015-03-31 14:59:59 -0700 | [diff] [blame] | 428 | self->PushVerifier(this); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 429 | DCHECK(class_def != nullptr); |
jeffhao | f56197c | 2012-03-05 18:01:54 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 432 | MethodVerifier::~MethodVerifier() { |
Mathieu Chartier | d0ad2ee | 2015-03-31 14:59:59 -0700 | [diff] [blame] | 433 | Thread::Current()->PopVerifier(this); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 434 | STLDeleteElements(&failure_messages_); |
| 435 | } |
| 436 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 437 | void MethodVerifier::FindLocksAtDexPc(ArtMethod* m, uint32_t dex_pc, |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 438 | std::vector<uint32_t>* monitor_enter_dex_pcs) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 439 | StackHandleScope<2> hs(Thread::Current()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 440 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(m->GetDexCache())); |
| 441 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(m->GetClassLoader())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 442 | MethodVerifier verifier(hs.Self(), m->GetDexFile(), dex_cache, class_loader, &m->GetClassDef(), |
| 443 | m->GetCodeItem(), m->GetDexMethodIndex(), m, m->GetAccessFlags(), |
Mathieu Chartier | 4306ef8 | 2014-12-19 18:41:47 -0800 | [diff] [blame] | 444 | false, true, false, false); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 445 | verifier.interesting_dex_pc_ = dex_pc; |
Ian Rogers | 46960fe | 2014-05-23 10:43:43 -0700 | [diff] [blame] | 446 | verifier.monitor_enter_dex_pcs_ = monitor_enter_dex_pcs; |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 447 | verifier.FindLocksAtDexPc(); |
| 448 | } |
| 449 | |
Andreas Gampe | cb3c08f | 2014-09-18 13:16:38 -0700 | [diff] [blame] | 450 | static bool HasMonitorEnterInstructions(const DexFile::CodeItem* const code_item) { |
| 451 | const Instruction* inst = Instruction::At(code_item->insns_); |
| 452 | |
| 453 | uint32_t insns_size = code_item->insns_size_in_code_units_; |
| 454 | for (uint32_t dex_pc = 0; dex_pc < insns_size;) { |
| 455 | if (inst->Opcode() == Instruction::MONITOR_ENTER) { |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | dex_pc += inst->SizeInCodeUnits(); |
| 460 | inst = inst->Next(); |
| 461 | } |
| 462 | |
| 463 | return false; |
| 464 | } |
| 465 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 466 | void MethodVerifier::FindLocksAtDexPc() { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 467 | CHECK(monitor_enter_dex_pcs_ != nullptr); |
| 468 | CHECK(code_item_ != nullptr); // This only makes sense for methods with code. |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 469 | |
Andreas Gampe | cb3c08f | 2014-09-18 13:16:38 -0700 | [diff] [blame] | 470 | // Quick check whether there are any monitor_enter instructions at all. |
| 471 | if (!HasMonitorEnterInstructions(code_item_)) { |
| 472 | return; |
| 473 | } |
| 474 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 475 | // Strictly speaking, we ought to be able to get away with doing a subset of the full method |
| 476 | // verification. In practice, the phase we want relies on data structures set up by all the |
| 477 | // earlier passes, so we just run the full method verification and bail out early when we've |
| 478 | // got what we wanted. |
| 479 | Verify(); |
| 480 | } |
| 481 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 482 | ArtField* MethodVerifier::FindAccessedFieldAtDexPc(ArtMethod* m, uint32_t dex_pc) { |
| 483 | StackHandleScope<2> hs(Thread::Current()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 484 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(m->GetDexCache())); |
| 485 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(m->GetClassLoader())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 486 | MethodVerifier verifier(hs.Self(), m->GetDexFile(), dex_cache, class_loader, &m->GetClassDef(), |
| 487 | m->GetCodeItem(), m->GetDexMethodIndex(), m, m->GetAccessFlags(), true, |
| 488 | true, false, true); |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 489 | return verifier.FindAccessedFieldAtDexPc(dex_pc); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 492 | ArtField* MethodVerifier::FindAccessedFieldAtDexPc(uint32_t dex_pc) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 493 | CHECK(code_item_ != nullptr); // This only makes sense for methods with code. |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 494 | |
| 495 | // Strictly speaking, we ought to be able to get away with doing a subset of the full method |
| 496 | // verification. In practice, the phase we want relies on data structures set up by all the |
| 497 | // earlier passes, so we just run the full method verification and bail out early when we've |
| 498 | // got what we wanted. |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 499 | bool success = Verify(); |
| 500 | if (!success) { |
Ian Rogers | 9bc5440 | 2014-04-17 16:40:01 -0700 | [diff] [blame] | 501 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 502 | } |
| 503 | RegisterLine* register_line = reg_table_.GetLine(dex_pc); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 504 | if (register_line == nullptr) { |
Ian Rogers | 9bc5440 | 2014-04-17 16:40:01 -0700 | [diff] [blame] | 505 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 506 | } |
| 507 | const Instruction* inst = Instruction::At(code_item_->insns_ + dex_pc); |
| 508 | return GetQuickFieldAccess(inst, register_line); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 511 | ArtMethod* MethodVerifier::FindInvokedMethodAtDexPc(ArtMethod* m, uint32_t dex_pc) { |
| 512 | StackHandleScope<2> hs(Thread::Current()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 513 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(m->GetDexCache())); |
| 514 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(m->GetClassLoader())); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 515 | MethodVerifier verifier(hs.Self(), m->GetDexFile(), dex_cache, class_loader, &m->GetClassDef(), |
| 516 | m->GetCodeItem(), m->GetDexMethodIndex(), m, m->GetAccessFlags(), true, |
| 517 | true, false, true); |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 518 | return verifier.FindInvokedMethodAtDexPc(dex_pc); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 521 | ArtMethod* MethodVerifier::FindInvokedMethodAtDexPc(uint32_t dex_pc) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 522 | CHECK(code_item_ != nullptr); // This only makes sense for methods with code. |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 523 | |
| 524 | // Strictly speaking, we ought to be able to get away with doing a subset of the full method |
| 525 | // verification. In practice, the phase we want relies on data structures set up by all the |
| 526 | // earlier passes, so we just run the full method verification and bail out early when we've |
| 527 | // got what we wanted. |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 528 | bool success = Verify(); |
| 529 | if (!success) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 530 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 531 | } |
| 532 | RegisterLine* register_line = reg_table_.GetLine(dex_pc); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 533 | if (register_line == nullptr) { |
| 534 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 535 | } |
| 536 | const Instruction* inst = Instruction::At(code_item_->insns_ + dex_pc); |
| 537 | const bool is_range = (inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK); |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 538 | return GetQuickInvokedMethod(inst, register_line, is_range, false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 541 | SafeMap<uint32_t, std::set<uint32_t>> MethodVerifier::FindStringInitMap(ArtMethod* m) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 542 | Thread* self = Thread::Current(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 543 | StackHandleScope<2> hs(self); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 544 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(m->GetDexCache())); |
| 545 | Handle<mirror::ClassLoader> class_loader(hs.NewHandle(m->GetClassLoader())); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 546 | MethodVerifier verifier(self, m->GetDexFile(), dex_cache, class_loader, &m->GetClassDef(), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 547 | m->GetCodeItem(), m->GetDexMethodIndex(), m, m->GetAccessFlags(), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 548 | true, true, false, true); |
| 549 | return verifier.FindStringInitMap(); |
| 550 | } |
| 551 | |
| 552 | SafeMap<uint32_t, std::set<uint32_t>>& MethodVerifier::FindStringInitMap() { |
| 553 | Verify(); |
| 554 | return GetStringInitPcRegMap(); |
| 555 | } |
| 556 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 557 | bool MethodVerifier::Verify() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 558 | // If there aren't any instructions, make sure that's expected, then exit successfully. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 559 | if (code_item_ == nullptr) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 560 | if ((method_access_flags_ & (kAccNative | kAccAbstract)) == 0) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 561 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "zero-length code in concrete non-native method"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 562 | return false; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 563 | } else { |
| 564 | return true; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 565 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 566 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 567 | // Sanity-check the register counts. ins + locals = registers, so make sure that ins <= registers. |
| 568 | if (code_item_->ins_size_ > code_item_->registers_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 569 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad register counts (ins=" << code_item_->ins_size_ |
| 570 | << " regs=" << code_item_->registers_size_; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 571 | return false; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 572 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 573 | // Allocate and initialize an array to hold instruction data. |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 574 | insn_flags_.reset(new InstructionFlags[code_item_->insns_size_in_code_units_]()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 575 | // Run through the instructions and see if the width checks out. |
| 576 | bool result = ComputeWidthsAndCountOps(); |
| 577 | // Flag instructions guarded by a "try" block and check exception handlers. |
| 578 | result = result && ScanTryCatchBlocks(); |
| 579 | // Perform static instruction verification. |
| 580 | result = result && VerifyInstructions(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 581 | // Perform code-flow analysis and return. |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 582 | result = result && VerifyCodeFlow(); |
| 583 | // Compute information for compiler. |
| 584 | if (result && Runtime::Current()->IsCompiler()) { |
| 585 | result = Runtime::Current()->GetCompilerCallbacks()->MethodVerified(this); |
| 586 | } |
| 587 | return result; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 590 | std::ostream& MethodVerifier::Fail(VerifyError error) { |
Andreas Gampe | 0760a81 | 2015-08-26 17:12:51 -0700 | [diff] [blame] | 591 | // Mark the error type as encountered. |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 592 | encountered_failure_types_ |= static_cast<uint32_t>(error); |
Andreas Gampe | 0760a81 | 2015-08-26 17:12:51 -0700 | [diff] [blame] | 593 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 594 | switch (error) { |
| 595 | case VERIFY_ERROR_NO_CLASS: |
| 596 | case VERIFY_ERROR_NO_FIELD: |
| 597 | case VERIFY_ERROR_NO_METHOD: |
| 598 | case VERIFY_ERROR_ACCESS_CLASS: |
| 599 | case VERIFY_ERROR_ACCESS_FIELD: |
| 600 | case VERIFY_ERROR_ACCESS_METHOD: |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 601 | case VERIFY_ERROR_INSTANTIATION: |
| 602 | case VERIFY_ERROR_CLASS_CHANGE: |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 603 | case VERIFY_ERROR_FORCE_INTERPRETER: |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 604 | case VERIFY_ERROR_LOCKING: |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 605 | if (Runtime::Current()->IsAotCompiler() || !can_load_classes_) { |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 606 | // If we're optimistically running verification at compile time, turn NO_xxx, ACCESS_xxx, |
| 607 | // class change and instantiation errors into soft verification errors so that we re-verify |
| 608 | // at runtime. We may fail to find or to agree on access because of not yet available class |
| 609 | // loaders, or class loaders that will differ at runtime. In these cases, we don't want to |
| 610 | // affect the soundness of the code being compiled. Instead, the generated code runs "slow |
| 611 | // paths" that dynamically perform the verification and cause the behavior to be that akin |
| 612 | // to an interpreter. |
| 613 | error = VERIFY_ERROR_BAD_CLASS_SOFT; |
| 614 | } else { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 615 | // If we fail again at runtime, mark that this instruction would throw and force this |
| 616 | // method to be executed using the interpreter with checks. |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 617 | have_pending_runtime_throw_failure_ = true; |
Andreas Gampe | d7f8d05 | 2015-03-12 11:05:47 -0700 | [diff] [blame] | 618 | |
| 619 | // We need to save the work_line if the instruction wasn't throwing before. Otherwise we'll |
| 620 | // try to merge garbage. |
| 621 | // Note: this assumes that Fail is called before we do any work_line modifications. |
Andreas Gampe | d5ad72f | 2015-06-26 17:33:47 -0700 | [diff] [blame] | 622 | // Note: this can fail before we touch any instruction, for the signature of a method. So |
| 623 | // add a check. |
| 624 | if (work_insn_idx_ < DexFile::kDexNoIndex) { |
| 625 | const uint16_t* insns = code_item_->insns_ + work_insn_idx_; |
| 626 | const Instruction* inst = Instruction::At(insns); |
| 627 | int opcode_flags = Instruction::FlagsOf(inst->Opcode()); |
Andreas Gampe | d7f8d05 | 2015-03-12 11:05:47 -0700 | [diff] [blame] | 628 | |
Andreas Gampe | d5ad72f | 2015-06-26 17:33:47 -0700 | [diff] [blame] | 629 | if ((opcode_flags & Instruction::kThrow) == 0 && CurrentInsnFlags()->IsInTry()) { |
| 630 | saved_line_->CopyFromLine(work_line_.get()); |
| 631 | } |
Andreas Gampe | d7f8d05 | 2015-03-12 11:05:47 -0700 | [diff] [blame] | 632 | } |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 633 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 634 | break; |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 635 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 636 | // Indication that verification should be retried at runtime. |
| 637 | case VERIFY_ERROR_BAD_CLASS_SOFT: |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 638 | if (!allow_soft_failures_) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 639 | have_pending_hard_failure_ = true; |
| 640 | } |
| 641 | break; |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 642 | |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 643 | // Hard verification failures at compile time will still fail at runtime, so the class is |
| 644 | // marked as rejected to prevent it from being compiled. |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 645 | case VERIFY_ERROR_BAD_CLASS_HARD: { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 646 | if (Runtime::Current()->IsAotCompiler()) { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 647 | ClassReference ref(dex_file_, dex_file_->GetIndexForClassDef(*class_def_)); |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 648 | Runtime::Current()->GetCompilerCallbacks()->ClassRejected(ref); |
jeffhao | d1224c7 | 2012-02-29 13:43:08 -0800 | [diff] [blame] | 649 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 650 | have_pending_hard_failure_ = true; |
Andreas Gampe | ebf850c | 2015-08-14 15:37:35 -0700 | [diff] [blame] | 651 | if (VLOG_IS_ON(verifier) && kDumpRegLinesOnHardFailureIfVLOG) { |
| 652 | ScopedObjectAccess soa(Thread::Current()); |
| 653 | std::ostringstream oss; |
| 654 | Dump(oss); |
| 655 | LOG(ERROR) << oss.str(); |
| 656 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 657 | break; |
Ian Rogers | 47a0588 | 2012-02-03 12:23:33 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 660 | failures_.push_back(error); |
Elena Sayapina | 78480ec | 2014-08-15 15:52:42 +0700 | [diff] [blame] | 661 | std::string location(StringPrintf("%s: [0x%X] ", PrettyMethod(dex_method_idx_, *dex_file_).c_str(), |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 662 | work_insn_idx_)); |
Elena Sayapina | 78480ec | 2014-08-15 15:52:42 +0700 | [diff] [blame] | 663 | std::ostringstream* failure_message = new std::ostringstream(location, std::ostringstream::ate); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 664 | failure_messages_.push_back(failure_message); |
| 665 | return *failure_message; |
| 666 | } |
| 667 | |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 668 | std::ostream& MethodVerifier::LogVerifyInfo() { |
| 669 | return info_messages_ << "VFY: " << PrettyMethod(dex_method_idx_, *dex_file_) |
| 670 | << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : "; |
| 671 | } |
| 672 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 673 | void MethodVerifier::PrependToLastFailMessage(std::string prepend) { |
| 674 | size_t failure_num = failure_messages_.size(); |
| 675 | DCHECK_NE(failure_num, 0U); |
| 676 | std::ostringstream* last_fail_message = failure_messages_[failure_num - 1]; |
| 677 | prepend += last_fail_message->str(); |
Elena Sayapina | 78480ec | 2014-08-15 15:52:42 +0700 | [diff] [blame] | 678 | failure_messages_[failure_num - 1] = new std::ostringstream(prepend, std::ostringstream::ate); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 679 | delete last_fail_message; |
| 680 | } |
| 681 | |
| 682 | void MethodVerifier::AppendToLastFailMessage(std::string append) { |
| 683 | size_t failure_num = failure_messages_.size(); |
| 684 | DCHECK_NE(failure_num, 0U); |
| 685 | std::ostringstream* last_fail_message = failure_messages_[failure_num - 1]; |
| 686 | (*last_fail_message) << append; |
Ian Rogers | 47a0588 | 2012-02-03 12:23:33 -0800 | [diff] [blame] | 687 | } |
| 688 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 689 | bool MethodVerifier::ComputeWidthsAndCountOps() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 690 | const uint16_t* insns = code_item_->insns_; |
| 691 | size_t insns_size = code_item_->insns_size_in_code_units_; |
| 692 | const Instruction* inst = Instruction::At(insns); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 693 | size_t new_instance_count = 0; |
| 694 | size_t monitor_enter_count = 0; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 695 | size_t dex_pc = 0; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 696 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 697 | while (dex_pc < insns_size) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 698 | Instruction::Code opcode = inst->Opcode(); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 699 | switch (opcode) { |
| 700 | case Instruction::APUT_OBJECT: |
| 701 | case Instruction::CHECK_CAST: |
| 702 | has_check_casts_ = true; |
| 703 | break; |
| 704 | case Instruction::INVOKE_VIRTUAL: |
| 705 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 706 | case Instruction::INVOKE_INTERFACE: |
| 707 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 708 | has_virtual_or_interface_invokes_ = true; |
| 709 | break; |
| 710 | case Instruction::MONITOR_ENTER: |
| 711 | monitor_enter_count++; |
| 712 | break; |
| 713 | case Instruction::NEW_INSTANCE: |
| 714 | new_instance_count++; |
| 715 | break; |
| 716 | default: |
| 717 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 718 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 719 | size_t inst_size = inst->SizeInCodeUnits(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 720 | insn_flags_[dex_pc].SetIsOpcode(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 721 | dex_pc += inst_size; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 722 | inst = inst->RelativeAt(inst_size); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 725 | if (dex_pc != insns_size) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 726 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "code did not end where expected (" |
| 727 | << dex_pc << " vs. " << insns_size << ")"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 728 | return false; |
| 729 | } |
| 730 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 731 | new_instance_count_ = new_instance_count; |
| 732 | monitor_enter_count_ = monitor_enter_count; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 733 | return true; |
| 734 | } |
| 735 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 736 | bool MethodVerifier::ScanTryCatchBlocks() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 737 | uint32_t tries_size = code_item_->tries_size_; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 738 | if (tries_size == 0) { |
| 739 | return true; |
| 740 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 741 | uint32_t insns_size = code_item_->insns_size_in_code_units_; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 742 | const DexFile::TryItem* tries = DexFile::GetTryItems(*code_item_, 0); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 743 | |
| 744 | for (uint32_t idx = 0; idx < tries_size; idx++) { |
| 745 | const DexFile::TryItem* try_item = &tries[idx]; |
| 746 | uint32_t start = try_item->start_addr_; |
| 747 | uint32_t end = start + try_item->insn_count_; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 748 | if ((start >= end) || (start >= insns_size) || (end > insns_size)) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 749 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad exception entry: startAddr=" << start |
| 750 | << " endAddr=" << end << " (size=" << insns_size << ")"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 751 | return false; |
| 752 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 753 | if (!insn_flags_[start].IsOpcode()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 754 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 755 | << "'try' block starts inside an instruction (" << start << ")"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 756 | return false; |
| 757 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 758 | uint32_t dex_pc = start; |
| 759 | const Instruction* inst = Instruction::At(code_item_->insns_ + dex_pc); |
| 760 | while (dex_pc < end) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 761 | insn_flags_[dex_pc].SetInTry(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 762 | size_t insn_size = inst->SizeInCodeUnits(); |
| 763 | dex_pc += insn_size; |
| 764 | inst = inst->RelativeAt(insn_size); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 767 | // Iterate over each of the handlers to verify target addresses. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 768 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(*code_item_, 0); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 769 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 770 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 771 | for (uint32_t idx = 0; idx < handlers_size; idx++) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 772 | CatchHandlerIterator iterator(handlers_ptr); |
| 773 | for (; iterator.HasNext(); iterator.Next()) { |
| 774 | uint32_t dex_pc= iterator.GetHandlerAddress(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 775 | if (!insn_flags_[dex_pc].IsOpcode()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 776 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 777 | << "exception handler starts at bad address (" << dex_pc << ")"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 778 | return false; |
| 779 | } |
Stephen Kyle | 9bc6199 | 2014-09-22 13:53:15 +0100 | [diff] [blame] | 780 | if (!CheckNotMoveResult(code_item_->insns_, dex_pc)) { |
| 781 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 782 | << "exception handler begins with move-result* (" << dex_pc << ")"; |
| 783 | return false; |
| 784 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 785 | insn_flags_[dex_pc].SetBranchTarget(); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 786 | // Ensure exception types are resolved so that they don't need resolution to be delivered, |
| 787 | // unresolved exception types will be ignored by exception delivery |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 788 | if (iterator.GetHandlerTypeIndex() != DexFile::kDexNoIndex16) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 789 | mirror::Class* exception_type = linker->ResolveType(*dex_file_, |
| 790 | iterator.GetHandlerTypeIndex(), |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 791 | dex_cache_, class_loader_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 792 | if (exception_type == nullptr) { |
| 793 | DCHECK(self_->IsExceptionPending()); |
| 794 | self_->ClearException(); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 795 | } |
| 796 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 797 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 798 | handlers_ptr = iterator.EndDataPointer(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 799 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 800 | return true; |
| 801 | } |
| 802 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 803 | bool MethodVerifier::VerifyInstructions() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 804 | const Instruction* inst = Instruction::At(code_item_->insns_); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 805 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 806 | /* Flag the start of the method as a branch target, and a GC point due to stack overflow errors */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 807 | insn_flags_[0].SetBranchTarget(); |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 808 | insn_flags_[0].SetCompileTimeInfoPoint(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 809 | |
| 810 | uint32_t insns_size = code_item_->insns_size_in_code_units_; |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 811 | for (uint32_t dex_pc = 0; dex_pc < insns_size;) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 812 | if (!VerifyInstruction(inst, dex_pc)) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 813 | DCHECK_NE(failures_.size(), 0U); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 814 | return false; |
| 815 | } |
| 816 | /* Flag instructions that are garbage collection points */ |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 817 | // All invoke points are marked as "Throw" points already. |
| 818 | // We are relying on this to also count all the invokes as interesting. |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 819 | if (inst->IsBranch()) { |
| 820 | insn_flags_[dex_pc].SetCompileTimeInfoPoint(); |
| 821 | // The compiler also needs safepoints for fall-through to loop heads. |
| 822 | // Such a loop head must be a target of a branch. |
| 823 | int32_t offset = 0; |
| 824 | bool cond, self_ok; |
| 825 | bool target_ok = GetBranchOffset(dex_pc, &offset, &cond, &self_ok); |
| 826 | DCHECK(target_ok); |
| 827 | insn_flags_[dex_pc + offset].SetCompileTimeInfoPoint(); |
| 828 | } else if (inst->IsSwitch() || inst->IsThrow()) { |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 829 | insn_flags_[dex_pc].SetCompileTimeInfoPoint(); |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 830 | } else if (inst->IsReturn()) { |
| 831 | insn_flags_[dex_pc].SetCompileTimeInfoPointAndReturn(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 832 | } |
| 833 | dex_pc += inst->SizeInCodeUnits(); |
| 834 | inst = inst->Next(); |
| 835 | } |
| 836 | return true; |
| 837 | } |
| 838 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 839 | bool MethodVerifier::VerifyInstruction(const Instruction* inst, uint32_t code_offset) { |
Igor Murashkin | 4d7b75f | 2015-07-21 17:03:36 -0700 | [diff] [blame] | 840 | if (UNLIKELY(inst->IsExperimental())) { |
| 841 | // Experimental instructions don't yet have verifier support implementation. |
| 842 | // While it is possible to use them by themselves, when we try to use stable instructions |
| 843 | // with a virtual register that was created by an experimental instruction, |
| 844 | // the data flow analysis will fail. |
| 845 | Fail(VERIFY_ERROR_FORCE_INTERPRETER) |
| 846 | << "experimental instruction is not supported by verifier; skipping verification"; |
| 847 | have_pending_experimental_failure_ = true; |
| 848 | return false; |
| 849 | } |
| 850 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 851 | bool result = true; |
| 852 | switch (inst->GetVerifyTypeArgumentA()) { |
| 853 | case Instruction::kVerifyRegA: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 854 | result = result && CheckRegisterIndex(inst->VRegA()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 855 | break; |
| 856 | case Instruction::kVerifyRegAWide: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 857 | result = result && CheckWideRegisterIndex(inst->VRegA()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | switch (inst->GetVerifyTypeArgumentB()) { |
| 861 | case Instruction::kVerifyRegB: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 862 | result = result && CheckRegisterIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 863 | break; |
| 864 | case Instruction::kVerifyRegBField: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 865 | result = result && CheckFieldIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 866 | break; |
| 867 | case Instruction::kVerifyRegBMethod: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 868 | result = result && CheckMethodIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 869 | break; |
| 870 | case Instruction::kVerifyRegBNewInstance: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 871 | result = result && CheckNewInstance(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 872 | break; |
| 873 | case Instruction::kVerifyRegBString: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 874 | result = result && CheckStringIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 875 | break; |
| 876 | case Instruction::kVerifyRegBType: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 877 | result = result && CheckTypeIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 878 | break; |
| 879 | case Instruction::kVerifyRegBWide: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 880 | result = result && CheckWideRegisterIndex(inst->VRegB()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | switch (inst->GetVerifyTypeArgumentC()) { |
| 884 | case Instruction::kVerifyRegC: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 885 | result = result && CheckRegisterIndex(inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 886 | break; |
| 887 | case Instruction::kVerifyRegCField: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 888 | result = result && CheckFieldIndex(inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 889 | break; |
| 890 | case Instruction::kVerifyRegCNewArray: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 891 | result = result && CheckNewArray(inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 892 | break; |
| 893 | case Instruction::kVerifyRegCType: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 894 | result = result && CheckTypeIndex(inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 895 | break; |
| 896 | case Instruction::kVerifyRegCWide: |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 897 | result = result && CheckWideRegisterIndex(inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 898 | break; |
| 899 | } |
| 900 | switch (inst->GetVerifyExtraFlags()) { |
| 901 | case Instruction::kVerifyArrayData: |
| 902 | result = result && CheckArrayData(code_offset); |
| 903 | break; |
| 904 | case Instruction::kVerifyBranchTarget: |
| 905 | result = result && CheckBranchTarget(code_offset); |
| 906 | break; |
| 907 | case Instruction::kVerifySwitchTargets: |
| 908 | result = result && CheckSwitchTargets(code_offset); |
| 909 | break; |
Andreas Gampe | c331431 | 2014-06-19 18:13:29 -0700 | [diff] [blame] | 910 | case Instruction::kVerifyVarArgNonZero: |
| 911 | // Fall-through. |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 912 | case Instruction::kVerifyVarArg: { |
Taiju Tsuiki | 29498a2 | 2015-04-13 14:21:00 +0900 | [diff] [blame] | 913 | // Instructions that can actually return a negative value shouldn't have this flag. |
| 914 | uint32_t v_a = dchecked_integral_cast<uint32_t>(inst->VRegA()); |
| 915 | if ((inst->GetVerifyExtraFlags() == Instruction::kVerifyVarArgNonZero && v_a == 0) || |
| 916 | v_a > Instruction::kMaxVarArgRegs) { |
| 917 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid arg count (" << v_a << ") in " |
Andreas Gampe | c331431 | 2014-06-19 18:13:29 -0700 | [diff] [blame] | 918 | "non-range invoke"; |
| 919 | return false; |
| 920 | } |
Taiju Tsuiki | 29498a2 | 2015-04-13 14:21:00 +0900 | [diff] [blame] | 921 | |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 922 | uint32_t args[Instruction::kMaxVarArgRegs]; |
| 923 | inst->GetVarArgs(args); |
Taiju Tsuiki | 29498a2 | 2015-04-13 14:21:00 +0900 | [diff] [blame] | 924 | result = result && CheckVarArgRegs(v_a, args); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 925 | break; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 926 | } |
Andreas Gampe | c331431 | 2014-06-19 18:13:29 -0700 | [diff] [blame] | 927 | case Instruction::kVerifyVarArgRangeNonZero: |
| 928 | // Fall-through. |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 929 | case Instruction::kVerifyVarArgRange: |
Andreas Gampe | c331431 | 2014-06-19 18:13:29 -0700 | [diff] [blame] | 930 | if (inst->GetVerifyExtraFlags() == Instruction::kVerifyVarArgRangeNonZero && |
| 931 | inst->VRegA() <= 0) { |
| 932 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid arg count (" << inst->VRegA() << ") in " |
| 933 | "range invoke"; |
| 934 | return false; |
| 935 | } |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 936 | result = result && CheckVarArgRangeRegs(inst->VRegA(), inst->VRegC()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 937 | break; |
| 938 | case Instruction::kVerifyError: |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 939 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected opcode " << inst->Name(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 940 | result = false; |
| 941 | break; |
| 942 | } |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 943 | if (inst->GetVerifyIsRuntimeOnly() && Runtime::Current()->IsAotCompiler() && !verify_to_dump_) { |
Ian Rogers | 5fb22a9 | 2014-06-13 10:31:28 -0700 | [diff] [blame] | 944 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "opcode only expected at runtime " << inst->Name(); |
| 945 | result = false; |
| 946 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 947 | return result; |
| 948 | } |
| 949 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 950 | inline bool MethodVerifier::CheckRegisterIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 951 | if (idx >= code_item_->registers_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 952 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "register index out of range (" << idx << " >= " |
| 953 | << code_item_->registers_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 954 | return false; |
| 955 | } |
| 956 | return true; |
| 957 | } |
| 958 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 959 | inline bool MethodVerifier::CheckWideRegisterIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 960 | if (idx + 1 >= code_item_->registers_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 961 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "wide register index out of range (" << idx |
| 962 | << "+1 >= " << code_item_->registers_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 963 | return false; |
| 964 | } |
| 965 | return true; |
| 966 | } |
| 967 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 968 | inline bool MethodVerifier::CheckFieldIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 969 | if (idx >= dex_file_->GetHeader().field_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 970 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad field index " << idx << " (max " |
| 971 | << dex_file_->GetHeader().field_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 972 | return false; |
| 973 | } |
| 974 | return true; |
| 975 | } |
| 976 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 977 | inline bool MethodVerifier::CheckMethodIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 978 | if (idx >= dex_file_->GetHeader().method_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 979 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad method index " << idx << " (max " |
| 980 | << dex_file_->GetHeader().method_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 981 | return false; |
| 982 | } |
| 983 | return true; |
| 984 | } |
| 985 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 986 | inline bool MethodVerifier::CheckNewInstance(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 987 | if (idx >= dex_file_->GetHeader().type_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 988 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad type index " << idx << " (max " |
| 989 | << dex_file_->GetHeader().type_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 990 | return false; |
| 991 | } |
| 992 | // We don't need the actual class, just a pointer to the class name. |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 993 | const char* descriptor = dex_file_->StringByTypeIdx(idx); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 994 | if (descriptor[0] != 'L') { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 995 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "can't call new-instance on type '" << descriptor << "'"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 996 | return false; |
| 997 | } |
| 998 | return true; |
| 999 | } |
| 1000 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1001 | inline bool MethodVerifier::CheckStringIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1002 | if (idx >= dex_file_->GetHeader().string_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1003 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad string index " << idx << " (max " |
| 1004 | << dex_file_->GetHeader().string_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1005 | return false; |
| 1006 | } |
| 1007 | return true; |
| 1008 | } |
| 1009 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1010 | inline bool MethodVerifier::CheckTypeIndex(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1011 | if (idx >= dex_file_->GetHeader().type_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1012 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad type index " << idx << " (max " |
| 1013 | << dex_file_->GetHeader().type_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1014 | return false; |
| 1015 | } |
| 1016 | return true; |
| 1017 | } |
| 1018 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1019 | bool MethodVerifier::CheckNewArray(uint32_t idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1020 | if (idx >= dex_file_->GetHeader().type_ids_size_) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1021 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad type index " << idx << " (max " |
| 1022 | << dex_file_->GetHeader().type_ids_size_ << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1023 | return false; |
| 1024 | } |
| 1025 | int bracket_count = 0; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1026 | const char* descriptor = dex_file_->StringByTypeIdx(idx); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1027 | const char* cp = descriptor; |
| 1028 | while (*cp++ == '[') { |
| 1029 | bracket_count++; |
| 1030 | } |
| 1031 | if (bracket_count == 0) { |
| 1032 | /* The given class must be an array type. */ |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1033 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 1034 | << "can't new-array class '" << descriptor << "' (not an array)"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1035 | return false; |
| 1036 | } else if (bracket_count > 255) { |
| 1037 | /* It is illegal to create an array of more than 255 dimensions. */ |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1038 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 1039 | << "can't new-array class '" << descriptor << "' (exceeds limit)"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1040 | return false; |
| 1041 | } |
| 1042 | return true; |
| 1043 | } |
| 1044 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1045 | bool MethodVerifier::CheckArrayData(uint32_t cur_offset) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1046 | const uint32_t insn_count = code_item_->insns_size_in_code_units_; |
| 1047 | const uint16_t* insns = code_item_->insns_ + cur_offset; |
| 1048 | const uint16_t* array_data; |
| 1049 | int32_t array_data_offset; |
| 1050 | |
| 1051 | DCHECK_LT(cur_offset, insn_count); |
| 1052 | /* make sure the start of the array data table is in range */ |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 1053 | array_data_offset = insns[1] | (static_cast<int32_t>(insns[2]) << 16); |
| 1054 | if (static_cast<int32_t>(cur_offset) + array_data_offset < 0 || |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1055 | cur_offset + array_data_offset + 2 >= insn_count) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1056 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid array data start: at " << cur_offset |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1057 | << ", data offset " << array_data_offset |
| 1058 | << ", count " << insn_count; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1059 | return false; |
| 1060 | } |
| 1061 | /* offset to array data table is a relative branch-style offset */ |
| 1062 | array_data = insns + array_data_offset; |
Andreas Gampe | 57c4758 | 2015-07-01 22:05:59 -0700 | [diff] [blame] | 1063 | // Make sure the table is at an even dex pc, that is, 32-bit aligned. |
| 1064 | if (!IsAligned<4>(array_data)) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1065 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unaligned array data table: at " << cur_offset |
| 1066 | << ", data offset " << array_data_offset; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1067 | return false; |
| 1068 | } |
Andreas Gampe | 57c4758 | 2015-07-01 22:05:59 -0700 | [diff] [blame] | 1069 | // Make sure the array-data is marked as an opcode. This ensures that it was reached when |
| 1070 | // traversing the code item linearly. It is an approximation for a by-spec padding value. |
| 1071 | if (!insn_flags_[cur_offset + array_data_offset].IsOpcode()) { |
| 1072 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "array data table at " << cur_offset |
| 1073 | << ", data offset " << array_data_offset |
| 1074 | << " not correctly visited, probably bad padding."; |
| 1075 | return false; |
| 1076 | } |
| 1077 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1078 | uint32_t value_width = array_data[1]; |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 1079 | uint32_t value_count = *reinterpret_cast<const uint32_t*>(&array_data[2]); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1080 | uint32_t table_size = 4 + (value_width * value_count + 1) / 2; |
| 1081 | /* make sure the end of the switch is in range */ |
| 1082 | if (cur_offset + array_data_offset + table_size > insn_count) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1083 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid array data end: at " << cur_offset |
| 1084 | << ", data offset " << array_data_offset << ", end " |
| 1085 | << cur_offset + array_data_offset + table_size |
| 1086 | << ", count " << insn_count; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1087 | return false; |
| 1088 | } |
| 1089 | return true; |
| 1090 | } |
| 1091 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1092 | bool MethodVerifier::CheckBranchTarget(uint32_t cur_offset) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1093 | int32_t offset; |
| 1094 | bool isConditional, selfOkay; |
| 1095 | if (!GetBranchOffset(cur_offset, &offset, &isConditional, &selfOkay)) { |
| 1096 | return false; |
| 1097 | } |
| 1098 | if (!selfOkay && offset == 0) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1099 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "branch offset of zero not allowed at" |
| 1100 | << reinterpret_cast<void*>(cur_offset); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1101 | return false; |
| 1102 | } |
Elliott Hughes | 81ff318 | 2012-03-23 20:35:56 -0700 | [diff] [blame] | 1103 | // Check for 32-bit overflow. This isn't strictly necessary if we can depend on the runtime |
| 1104 | // to have identical "wrap-around" behavior, but it's unwise to depend on that. |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1105 | if (((int64_t) cur_offset + (int64_t) offset) != (int64_t) (cur_offset + offset)) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1106 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "branch target overflow " |
| 1107 | << reinterpret_cast<void*>(cur_offset) << " +" << offset; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1108 | return false; |
| 1109 | } |
| 1110 | const uint32_t insn_count = code_item_->insns_size_in_code_units_; |
| 1111 | int32_t abs_offset = cur_offset + offset; |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1112 | if (abs_offset < 0 || |
| 1113 | (uint32_t) abs_offset >= insn_count || |
| 1114 | !insn_flags_[abs_offset].IsOpcode()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1115 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid branch target " << offset << " (-> " |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 1116 | << reinterpret_cast<void*>(abs_offset) << ") at " |
| 1117 | << reinterpret_cast<void*>(cur_offset); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1118 | return false; |
| 1119 | } |
| 1120 | insn_flags_[abs_offset].SetBranchTarget(); |
| 1121 | return true; |
| 1122 | } |
| 1123 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1124 | bool MethodVerifier::GetBranchOffset(uint32_t cur_offset, int32_t* pOffset, bool* pConditional, |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1125 | bool* selfOkay) { |
| 1126 | const uint16_t* insns = code_item_->insns_ + cur_offset; |
| 1127 | *pConditional = false; |
| 1128 | *selfOkay = false; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1129 | switch (*insns & 0xff) { |
| 1130 | case Instruction::GOTO: |
| 1131 | *pOffset = ((int16_t) *insns) >> 8; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1132 | break; |
| 1133 | case Instruction::GOTO_32: |
| 1134 | *pOffset = insns[1] | (((uint32_t) insns[2]) << 16); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1135 | *selfOkay = true; |
| 1136 | break; |
| 1137 | case Instruction::GOTO_16: |
| 1138 | *pOffset = (int16_t) insns[1]; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1139 | break; |
| 1140 | case Instruction::IF_EQ: |
| 1141 | case Instruction::IF_NE: |
| 1142 | case Instruction::IF_LT: |
| 1143 | case Instruction::IF_GE: |
| 1144 | case Instruction::IF_GT: |
| 1145 | case Instruction::IF_LE: |
| 1146 | case Instruction::IF_EQZ: |
| 1147 | case Instruction::IF_NEZ: |
| 1148 | case Instruction::IF_LTZ: |
| 1149 | case Instruction::IF_GEZ: |
| 1150 | case Instruction::IF_GTZ: |
| 1151 | case Instruction::IF_LEZ: |
| 1152 | *pOffset = (int16_t) insns[1]; |
| 1153 | *pConditional = true; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1154 | break; |
| 1155 | default: |
| 1156 | return false; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1157 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1158 | return true; |
| 1159 | } |
| 1160 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1161 | bool MethodVerifier::CheckSwitchTargets(uint32_t cur_offset) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1162 | const uint32_t insn_count = code_item_->insns_size_in_code_units_; |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 1163 | DCHECK_LT(cur_offset, insn_count); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1164 | const uint16_t* insns = code_item_->insns_ + cur_offset; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1165 | /* make sure the start of the switch is in range */ |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 1166 | int32_t switch_offset = insns[1] | (static_cast<int32_t>(insns[2]) << 16); |
| 1167 | if (static_cast<int32_t>(cur_offset) + switch_offset < 0 || |
| 1168 | cur_offset + switch_offset + 2 > insn_count) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1169 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid switch start: at " << cur_offset |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1170 | << ", switch offset " << switch_offset |
| 1171 | << ", count " << insn_count; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1172 | return false; |
| 1173 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1174 | /* offset to switch table is a relative branch-style offset */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1175 | const uint16_t* switch_insns = insns + switch_offset; |
Andreas Gampe | 57c4758 | 2015-07-01 22:05:59 -0700 | [diff] [blame] | 1176 | // Make sure the table is at an even dex pc, that is, 32-bit aligned. |
| 1177 | if (!IsAligned<4>(switch_insns)) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1178 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unaligned switch table: at " << cur_offset |
| 1179 | << ", switch offset " << switch_offset; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1180 | return false; |
| 1181 | } |
Andreas Gampe | 57c4758 | 2015-07-01 22:05:59 -0700 | [diff] [blame] | 1182 | // Make sure the switch data is marked as an opcode. This ensures that it was reached when |
| 1183 | // traversing the code item linearly. It is an approximation for a by-spec padding value. |
| 1184 | if (!insn_flags_[cur_offset + switch_offset].IsOpcode()) { |
| 1185 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "switch table at " << cur_offset |
| 1186 | << ", switch offset " << switch_offset |
| 1187 | << " not correctly visited, probably bad padding."; |
| 1188 | return false; |
| 1189 | } |
| 1190 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1191 | uint32_t switch_count = switch_insns[1]; |
| 1192 | int32_t keys_offset, targets_offset; |
| 1193 | uint16_t expected_signature; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1194 | if ((*insns & 0xff) == Instruction::PACKED_SWITCH) { |
| 1195 | /* 0=sig, 1=count, 2/3=firstKey */ |
| 1196 | targets_offset = 4; |
| 1197 | keys_offset = -1; |
| 1198 | expected_signature = Instruction::kPackedSwitchSignature; |
| 1199 | } else { |
| 1200 | /* 0=sig, 1=count, 2..count*2 = keys */ |
| 1201 | keys_offset = 2; |
| 1202 | targets_offset = 2 + 2 * switch_count; |
| 1203 | expected_signature = Instruction::kSparseSwitchSignature; |
| 1204 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1205 | uint32_t table_size = targets_offset + switch_count * 2; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1206 | if (switch_insns[0] != expected_signature) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1207 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
| 1208 | << StringPrintf("wrong signature for switch table (%x, wanted %x)", |
| 1209 | switch_insns[0], expected_signature); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1210 | return false; |
| 1211 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1212 | /* make sure the end of the switch is in range */ |
| 1213 | if (cur_offset + switch_offset + table_size > (uint32_t) insn_count) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1214 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid switch end: at " << cur_offset |
| 1215 | << ", switch offset " << switch_offset |
| 1216 | << ", end " << (cur_offset + switch_offset + table_size) |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1217 | << ", count " << insn_count; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1218 | return false; |
| 1219 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1220 | /* for a sparse switch, verify the keys are in ascending order */ |
| 1221 | if (keys_offset > 0 && switch_count > 1) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1222 | int32_t last_key = switch_insns[keys_offset] | (switch_insns[keys_offset + 1] << 16); |
| 1223 | for (uint32_t targ = 1; targ < switch_count; targ++) { |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 1224 | int32_t key = |
| 1225 | static_cast<int32_t>(switch_insns[keys_offset + targ * 2]) | |
| 1226 | static_cast<int32_t>(switch_insns[keys_offset + targ * 2 + 1] << 16); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1227 | if (key <= last_key) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1228 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid packed switch: last key=" << last_key |
| 1229 | << ", this=" << key; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1230 | return false; |
| 1231 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1232 | last_key = key; |
| 1233 | } |
| 1234 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1235 | /* verify each switch target */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1236 | for (uint32_t targ = 0; targ < switch_count; targ++) { |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 1237 | int32_t offset = static_cast<int32_t>(switch_insns[targets_offset + targ * 2]) | |
| 1238 | static_cast<int32_t>(switch_insns[targets_offset + targ * 2 + 1] << 16); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1239 | int32_t abs_offset = cur_offset + offset; |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1240 | if (abs_offset < 0 || |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 1241 | abs_offset >= static_cast<int32_t>(insn_count) || |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1242 | !insn_flags_[abs_offset].IsOpcode()) { |
| 1243 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid switch target " << offset |
| 1244 | << " (-> " << reinterpret_cast<void*>(abs_offset) << ") at " |
| 1245 | << reinterpret_cast<void*>(cur_offset) |
| 1246 | << "[" << targ << "]"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1247 | return false; |
| 1248 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1249 | insn_flags_[abs_offset].SetBranchTarget(); |
| 1250 | } |
| 1251 | return true; |
| 1252 | } |
| 1253 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1254 | bool MethodVerifier::CheckVarArgRegs(uint32_t vA, uint32_t arg[]) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1255 | uint16_t registers_size = code_item_->registers_size_; |
| 1256 | for (uint32_t idx = 0; idx < vA; idx++) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 1257 | if (arg[idx] >= registers_size) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1258 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid reg index (" << arg[idx] |
| 1259 | << ") in non-range invoke (>= " << registers_size << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1260 | return false; |
| 1261 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | return true; |
| 1265 | } |
| 1266 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1267 | bool MethodVerifier::CheckVarArgRangeRegs(uint32_t vA, uint32_t vC) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1268 | uint16_t registers_size = code_item_->registers_size_; |
| 1269 | // vA/vC are unsigned 8-bit/16-bit quantities for /range instructions, so there's no risk of |
| 1270 | // integer overflow when adding them here. |
| 1271 | if (vA + vC > registers_size) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1272 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid reg index " << vA << "+" << vC |
| 1273 | << " in range invoke (> " << registers_size << ")"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1274 | return false; |
| 1275 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1276 | return true; |
| 1277 | } |
| 1278 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1279 | bool MethodVerifier::VerifyCodeFlow() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1280 | uint16_t registers_size = code_item_->registers_size_; |
| 1281 | uint32_t insns_size = code_item_->insns_size_in_code_units_; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1282 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1283 | /* Create and initialize table holding register status */ |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1284 | reg_table_.Init(kTrackCompilerInterestPoints, |
| 1285 | insn_flags_.get(), |
| 1286 | insns_size, |
| 1287 | registers_size, |
| 1288 | this); |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 1289 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1290 | |
Ian Rogers | d0fbd85 | 2013-09-24 18:17:04 -0700 | [diff] [blame] | 1291 | work_line_.reset(RegisterLine::Create(registers_size, this)); |
| 1292 | saved_line_.reset(RegisterLine::Create(registers_size, this)); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1293 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1294 | /* Initialize register types of method arguments. */ |
| 1295 | if (!SetTypesFromSignature()) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1296 | DCHECK_NE(failures_.size(), 0U); |
| 1297 | std::string prepend("Bad signature in "); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1298 | prepend += PrettyMethod(dex_method_idx_, *dex_file_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1299 | PrependToLastFailMessage(prepend); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1300 | return false; |
| 1301 | } |
Andreas Gampe | d5ad72f | 2015-06-26 17:33:47 -0700 | [diff] [blame] | 1302 | // We may have a runtime failure here, clear. |
| 1303 | have_pending_runtime_throw_failure_ = false; |
| 1304 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1305 | /* Perform code flow verification. */ |
| 1306 | if (!CodeFlowVerifyMethod()) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1307 | DCHECK_NE(failures_.size(), 0U); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1308 | return false; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1309 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1310 | return true; |
| 1311 | } |
| 1312 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1313 | std::ostream& MethodVerifier::DumpFailures(std::ostream& os) { |
| 1314 | DCHECK_EQ(failures_.size(), failure_messages_.size()); |
Jeff Hao | 4137f48 | 2013-11-22 11:44:57 -0800 | [diff] [blame] | 1315 | for (size_t i = 0; i < failures_.size(); ++i) { |
| 1316 | os << failure_messages_[i]->str() << "\n"; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1317 | } |
| 1318 | return os; |
| 1319 | } |
| 1320 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1321 | void MethodVerifier::Dump(std::ostream& os) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1322 | VariableIndentationOutputStream vios(&os); |
| 1323 | Dump(&vios); |
| 1324 | } |
| 1325 | |
| 1326 | void MethodVerifier::Dump(VariableIndentationOutputStream* vios) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1327 | if (code_item_ == nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1328 | vios->Stream() << "Native method\n"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1329 | return; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1330 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1331 | { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1332 | vios->Stream() << "Register Types:\n"; |
| 1333 | ScopedIndentation indent1(vios); |
| 1334 | reg_types_.Dump(vios->Stream()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1335 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1336 | vios->Stream() << "Dumping instructions and register lines:\n"; |
| 1337 | ScopedIndentation indent1(vios); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1338 | const Instruction* inst = Instruction::At(code_item_->insns_); |
| 1339 | for (size_t dex_pc = 0; dex_pc < code_item_->insns_size_in_code_units_; |
Andreas Gampe | ebf850c | 2015-08-14 15:37:35 -0700 | [diff] [blame] | 1340 | dex_pc += inst->SizeInCodeUnits(), inst = inst->Next()) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1341 | RegisterLine* reg_line = reg_table_.GetLine(dex_pc); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1342 | if (reg_line != nullptr) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1343 | vios->Stream() << reg_line->Dump(this) << "\n"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1344 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1345 | vios->Stream() |
| 1346 | << StringPrintf("0x%04zx", dex_pc) << ": " << insn_flags_[dex_pc].ToString() << " "; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1347 | const bool kDumpHexOfInstruction = false; |
| 1348 | if (kDumpHexOfInstruction) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1349 | vios->Stream() << inst->DumpHex(5) << " "; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1350 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1351 | vios->Stream() << inst->DumpString(dex_file_) << "\n"; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1352 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1355 | static bool IsPrimitiveDescriptor(char descriptor) { |
| 1356 | switch (descriptor) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1357 | case 'I': |
| 1358 | case 'C': |
| 1359 | case 'S': |
| 1360 | case 'B': |
| 1361 | case 'Z': |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1362 | case 'F': |
| 1363 | case 'D': |
| 1364 | case 'J': |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1365 | return true; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1366 | default: |
| 1367 | return false; |
| 1368 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1371 | bool MethodVerifier::SetTypesFromSignature() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1372 | RegisterLine* reg_line = reg_table_.GetLine(0); |
Andreas Gampe | ef0b1a1 | 2015-06-19 20:37:46 -0700 | [diff] [blame] | 1373 | |
| 1374 | // Should have been verified earlier. |
| 1375 | DCHECK_GE(code_item_->registers_size_, code_item_->ins_size_); |
| 1376 | |
| 1377 | uint32_t arg_start = code_item_->registers_size_ - code_item_->ins_size_; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1378 | size_t expected_args = code_item_->ins_size_; /* long/double count as two */ |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1379 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1380 | // Include the "this" pointer. |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1381 | size_t cur_arg = 0; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1382 | if (!IsStatic()) { |
Andreas Gampe | ef0b1a1 | 2015-06-19 20:37:46 -0700 | [diff] [blame] | 1383 | if (expected_args == 0) { |
| 1384 | // Expect at least a receiver. |
| 1385 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected 0 args, but method is not static"; |
| 1386 | return false; |
| 1387 | } |
| 1388 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1389 | // If this is a constructor for a class other than java.lang.Object, mark the first ("this") |
| 1390 | // argument as uninitialized. This restricts field access until the superclass constructor is |
| 1391 | // called. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1392 | const RegType& declaring_class = GetDeclaringClass(); |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1393 | if (IsConstructor()) { |
| 1394 | if (declaring_class.IsJavaLangObject()) { |
| 1395 | // "this" is implicitly initialized. |
| 1396 | reg_line->SetThisInitialized(); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1397 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, declaring_class); |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1398 | } else { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1399 | reg_line->SetRegisterType<LockOp::kClear>( |
| 1400 | this, |
| 1401 | arg_start + cur_arg, |
| 1402 | reg_types_.UninitializedThisArgument(declaring_class)); |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1403 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1404 | } else { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1405 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, declaring_class); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1406 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1407 | cur_arg++; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1410 | const DexFile::ProtoId& proto_id = |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1411 | dex_file_->GetMethodPrototype(dex_file_->GetMethodId(dex_method_idx_)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1412 | DexFileParameterIterator iterator(*dex_file_, proto_id); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1413 | |
| 1414 | for (; iterator.HasNext(); iterator.Next()) { |
| 1415 | const char* descriptor = iterator.GetDescriptor(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1416 | if (descriptor == nullptr) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1417 | LOG(FATAL) << "Null descriptor"; |
| 1418 | } |
| 1419 | if (cur_arg >= expected_args) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1420 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected " << expected_args |
| 1421 | << " args, found more (" << descriptor << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
| 1424 | switch (descriptor[0]) { |
| 1425 | case 'L': |
| 1426 | case '[': |
| 1427 | // We assume that reference arguments are initialized. The only way it could be otherwise |
| 1428 | // (assuming the caller was verified) is if the current method is <init>, but in that case |
| 1429 | // it's effectively considered initialized the instant we reach here (in the sense that we |
| 1430 | // can return without doing anything or call virtual methods). |
| 1431 | { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1432 | const RegType& reg_type = ResolveClassAndCheckAccess(iterator.GetTypeIdx()); |
Sebastien Hertz | 2ed76f9 | 2014-04-22 17:11:08 +0200 | [diff] [blame] | 1433 | if (!reg_type.IsNonZeroReferenceTypes()) { |
| 1434 | DCHECK(HasFailures()); |
| 1435 | return false; |
| 1436 | } |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1437 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_type); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1438 | } |
| 1439 | break; |
| 1440 | case 'Z': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1441 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Boolean()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1442 | break; |
| 1443 | case 'C': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1444 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Char()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | case 'B': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1447 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Byte()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | case 'I': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1450 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Integer()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | case 'S': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1453 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Short()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1454 | break; |
| 1455 | case 'F': |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1456 | reg_line->SetRegisterType<LockOp::kClear>(this, arg_start + cur_arg, reg_types_.Float()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1457 | break; |
| 1458 | case 'J': |
| 1459 | case 'D': { |
Andreas Gampe | 77cd4d6 | 2014-06-19 17:29:48 -0700 | [diff] [blame] | 1460 | if (cur_arg + 1 >= expected_args) { |
| 1461 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected " << expected_args |
| 1462 | << " args, found more (" << descriptor << ")"; |
| 1463 | return false; |
| 1464 | } |
| 1465 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1466 | const RegType* lo_half; |
| 1467 | const RegType* hi_half; |
| 1468 | if (descriptor[0] == 'J') { |
| 1469 | lo_half = ®_types_.LongLo(); |
| 1470 | hi_half = ®_types_.LongHi(); |
| 1471 | } else { |
| 1472 | lo_half = ®_types_.DoubleLo(); |
| 1473 | hi_half = ®_types_.DoubleHi(); |
| 1474 | } |
| 1475 | reg_line->SetRegisterTypeWide(this, arg_start + cur_arg, *lo_half, *hi_half); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1476 | cur_arg++; |
| 1477 | break; |
| 1478 | } |
| 1479 | default: |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1480 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected signature type char '" |
| 1481 | << descriptor << "'"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1482 | return false; |
| 1483 | } |
| 1484 | cur_arg++; |
| 1485 | } |
| 1486 | if (cur_arg != expected_args) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1487 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected " << expected_args |
| 1488 | << " arguments, found " << cur_arg; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1489 | return false; |
| 1490 | } |
| 1491 | const char* descriptor = dex_file_->GetReturnTypeDescriptor(proto_id); |
| 1492 | // Validate return type. We don't do the type lookup; just want to make sure that it has the right |
| 1493 | // format. Only major difference from the method argument format is that 'V' is supported. |
| 1494 | bool result; |
| 1495 | if (IsPrimitiveDescriptor(descriptor[0]) || descriptor[0] == 'V') { |
| 1496 | result = descriptor[1] == '\0'; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1497 | } else if (descriptor[0] == '[') { // single/multi-dimensional array of object/primitive |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1498 | size_t i = 0; |
| 1499 | do { |
| 1500 | i++; |
| 1501 | } while (descriptor[i] == '['); // process leading [ |
| 1502 | if (descriptor[i] == 'L') { // object array |
| 1503 | do { |
| 1504 | i++; // find closing ; |
| 1505 | } while (descriptor[i] != ';' && descriptor[i] != '\0'); |
| 1506 | result = descriptor[i] == ';'; |
| 1507 | } else { // primitive array |
| 1508 | result = IsPrimitiveDescriptor(descriptor[i]) && descriptor[i + 1] == '\0'; |
| 1509 | } |
| 1510 | } else if (descriptor[0] == 'L') { |
| 1511 | // could be more thorough here, but shouldn't be required |
| 1512 | size_t i = 0; |
| 1513 | do { |
| 1514 | i++; |
| 1515 | } while (descriptor[i] != ';' && descriptor[i] != '\0'); |
| 1516 | result = descriptor[i] == ';'; |
| 1517 | } else { |
| 1518 | result = false; |
| 1519 | } |
| 1520 | if (!result) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1521 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected char in return type descriptor '" |
| 1522 | << descriptor << "'"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1523 | } |
| 1524 | return result; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1527 | bool MethodVerifier::CodeFlowVerifyMethod() { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1528 | const uint16_t* insns = code_item_->insns_; |
| 1529 | const uint32_t insns_size = code_item_->insns_size_in_code_units_; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1530 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1531 | /* Begin by marking the first instruction as "changed". */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1532 | insn_flags_[0].SetChanged(); |
| 1533 | uint32_t start_guess = 0; |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1534 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1535 | /* Continue until no instructions are marked "changed". */ |
| 1536 | while (true) { |
Mathieu Chartier | 4306ef8 | 2014-12-19 18:41:47 -0800 | [diff] [blame] | 1537 | if (allow_thread_suspension_) { |
| 1538 | self_->AllowThreadSuspension(); |
| 1539 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1540 | // Find the first marked one. Use "start_guess" as a way to find one quickly. |
| 1541 | uint32_t insn_idx = start_guess; |
| 1542 | for (; insn_idx < insns_size; insn_idx++) { |
| 1543 | if (insn_flags_[insn_idx].IsChanged()) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1544 | break; |
| 1545 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1546 | if (insn_idx == insns_size) { |
| 1547 | if (start_guess != 0) { |
| 1548 | /* try again, starting from the top */ |
| 1549 | start_guess = 0; |
| 1550 | continue; |
| 1551 | } else { |
| 1552 | /* all flags are clear */ |
| 1553 | break; |
| 1554 | } |
| 1555 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1556 | // We carry the working set of registers from instruction to instruction. If this address can |
| 1557 | // be the target of a branch (or throw) instruction, or if we're skipping around chasing |
| 1558 | // "changed" flags, we need to load the set of registers from the table. |
| 1559 | // Because we always prefer to continue on to the next instruction, we should never have a |
| 1560 | // situation where we have a stray "changed" flag set on an instruction that isn't a branch |
| 1561 | // target. |
| 1562 | work_insn_idx_ = insn_idx; |
| 1563 | if (insn_flags_[insn_idx].IsBranchTarget()) { |
| 1564 | work_line_->CopyFromLine(reg_table_.GetLine(insn_idx)); |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 1565 | } else if (kIsDebugBuild) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1566 | /* |
| 1567 | * Sanity check: retrieve the stored register line (assuming |
| 1568 | * a full table) and make sure it actually matches. |
| 1569 | */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1570 | RegisterLine* register_line = reg_table_.GetLine(insn_idx); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1571 | if (register_line != nullptr) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1572 | if (work_line_->CompareLine(register_line) != 0) { |
| 1573 | Dump(std::cout); |
| 1574 | std::cout << info_messages_.str(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1575 | LOG(FATAL) << "work_line diverged in " << PrettyMethod(dex_method_idx_, *dex_file_) |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 1576 | << "@" << reinterpret_cast<void*>(work_insn_idx_) << "\n" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1577 | << " work_line=" << work_line_->Dump(this) << "\n" |
| 1578 | << " expected=" << register_line->Dump(this); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1579 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1580 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1581 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1582 | if (!CodeFlowVerifyInstruction(&start_guess)) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1583 | std::string prepend(PrettyMethod(dex_method_idx_, *dex_file_)); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1584 | prepend += " failed to verify: "; |
| 1585 | PrependToLastFailMessage(prepend); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1588 | /* Clear "changed" and mark as visited. */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1589 | insn_flags_[insn_idx].SetVisited(); |
| 1590 | insn_flags_[insn_idx].ClearChanged(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1591 | } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1592 | |
Ian Rogers | 1c849e5 | 2012-06-28 14:00:33 -0700 | [diff] [blame] | 1593 | if (gDebugVerify) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1594 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1595 | * Scan for dead code. There's nothing "evil" about dead code |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1596 | * (besides the wasted space), but it indicates a flaw somewhere |
| 1597 | * down the line, possibly in the verifier. |
| 1598 | * |
| 1599 | * If we've substituted "always throw" instructions into the stream, |
| 1600 | * we are almost certainly going to have some dead code. |
| 1601 | */ |
| 1602 | int dead_start = -1; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1603 | uint32_t insn_idx = 0; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1604 | for (; insn_idx < insns_size; |
| 1605 | insn_idx += Instruction::At(code_item_->insns_ + insn_idx)->SizeInCodeUnits()) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1606 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1607 | * Switch-statement data doesn't get "visited" by scanner. It |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1608 | * may or may not be preceded by a padding NOP (for alignment). |
| 1609 | */ |
| 1610 | if (insns[insn_idx] == Instruction::kPackedSwitchSignature || |
| 1611 | insns[insn_idx] == Instruction::kSparseSwitchSignature || |
| 1612 | insns[insn_idx] == Instruction::kArrayDataSignature || |
Elliott Hughes | 380aaa7 | 2012-07-09 14:33:15 -0700 | [diff] [blame] | 1613 | (insns[insn_idx] == Instruction::NOP && (insn_idx + 1 < insns_size) && |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1614 | (insns[insn_idx + 1] == Instruction::kPackedSwitchSignature || |
| 1615 | insns[insn_idx + 1] == Instruction::kSparseSwitchSignature || |
| 1616 | insns[insn_idx + 1] == Instruction::kArrayDataSignature))) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1617 | insn_flags_[insn_idx].SetVisited(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1620 | if (!insn_flags_[insn_idx].IsVisited()) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1621 | if (dead_start < 0) |
| 1622 | dead_start = insn_idx; |
| 1623 | } else if (dead_start >= 0) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1624 | LogVerifyInfo() << "dead code " << reinterpret_cast<void*>(dead_start) |
| 1625 | << "-" << reinterpret_cast<void*>(insn_idx - 1); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1626 | dead_start = -1; |
| 1627 | } |
| 1628 | } |
| 1629 | if (dead_start >= 0) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1630 | LogVerifyInfo() << "dead code " << reinterpret_cast<void*>(dead_start) |
| 1631 | << "-" << reinterpret_cast<void*>(insn_idx - 1); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1632 | } |
Ian Rogers | c9e463c | 2013-06-05 16:52:26 -0700 | [diff] [blame] | 1633 | // To dump the state of the verify after a method, do something like: |
| 1634 | // if (PrettyMethod(dex_method_idx_, *dex_file_) == |
| 1635 | // "boolean java.lang.String.equals(java.lang.Object)") { |
| 1636 | // LOG(INFO) << info_messages_.str(); |
| 1637 | // } |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1638 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1639 | return true; |
| 1640 | } |
| 1641 | |
Andreas Gampe | 68df320 | 2015-06-22 11:35:46 -0700 | [diff] [blame] | 1642 | // Returns the index of the first final instance field of the given class, or kDexNoIndex if there |
| 1643 | // is no such field. |
| 1644 | static uint32_t GetFirstFinalInstanceFieldIndex(const DexFile& dex_file, uint16_t type_idx) { |
| 1645 | const DexFile::ClassDef* class_def = dex_file.FindClassDef(type_idx); |
| 1646 | DCHECK(class_def != nullptr); |
| 1647 | const uint8_t* class_data = dex_file.GetClassData(*class_def); |
| 1648 | DCHECK(class_data != nullptr); |
| 1649 | ClassDataItemIterator it(dex_file, class_data); |
| 1650 | // Skip static fields. |
| 1651 | while (it.HasNextStaticField()) { |
| 1652 | it.Next(); |
| 1653 | } |
| 1654 | while (it.HasNextInstanceField()) { |
| 1655 | if ((it.GetFieldAccessFlags() & kAccFinal) != 0) { |
| 1656 | return it.GetMemberIndex(); |
| 1657 | } |
| 1658 | it.Next(); |
| 1659 | } |
| 1660 | return DexFile::kDexNoIndex; |
| 1661 | } |
| 1662 | |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 1663 | // Setup a register line for the given return instruction. |
| 1664 | static void AdjustReturnLine(MethodVerifier* verifier, |
| 1665 | const Instruction* ret_inst, |
| 1666 | RegisterLine* line) { |
| 1667 | Instruction::Code opcode = ret_inst->Opcode(); |
| 1668 | |
| 1669 | switch (opcode) { |
| 1670 | case Instruction::RETURN_VOID: |
| 1671 | case Instruction::RETURN_VOID_NO_BARRIER: |
| 1672 | SafelyMarkAllRegistersAsConflicts(verifier, line); |
| 1673 | break; |
| 1674 | |
| 1675 | case Instruction::RETURN: |
| 1676 | case Instruction::RETURN_OBJECT: |
| 1677 | line->MarkAllRegistersAsConflictsExcept(verifier, ret_inst->VRegA_11x()); |
| 1678 | break; |
| 1679 | |
| 1680 | case Instruction::RETURN_WIDE: |
| 1681 | line->MarkAllRegistersAsConflictsExceptWide(verifier, ret_inst->VRegA_11x()); |
| 1682 | break; |
| 1683 | |
| 1684 | default: |
| 1685 | LOG(FATAL) << "Unknown return opcode " << opcode; |
| 1686 | UNREACHABLE(); |
| 1687 | } |
| 1688 | } |
| 1689 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1690 | bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 1691 | // If we're doing FindLocksAtDexPc, check whether we're at the dex pc we care about. |
| 1692 | // We want the state _before_ the instruction, for the case where the dex pc we're |
| 1693 | // interested in is itself a monitor-enter instruction (which is a likely place |
| 1694 | // for a thread to be suspended). |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1695 | if (monitor_enter_dex_pcs_ != nullptr && work_insn_idx_ == interesting_dex_pc_) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1696 | monitor_enter_dex_pcs_->clear(); // The new work line is more accurate than the previous one. |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 1697 | for (size_t i = 0; i < work_line_->GetMonitorEnterCount(); ++i) { |
| 1698 | monitor_enter_dex_pcs_->push_back(work_line_->GetMonitorEnterDexPc(i)); |
| 1699 | } |
| 1700 | } |
| 1701 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1702 | /* |
| 1703 | * Once we finish decoding the instruction, we need to figure out where |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1704 | * we can go from here. There are three possible ways to transfer |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1705 | * control to another statement: |
| 1706 | * |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1707 | * (1) Continue to the next instruction. Applies to all but |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1708 | * unconditional branches, method returns, and exception throws. |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1709 | * (2) Branch to one or more possible locations. Applies to branches |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1710 | * and switch statements. |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1711 | * (3) Exception handlers. Applies to any instruction that can |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1712 | * throw an exception that is handled by an encompassing "try" |
| 1713 | * block. |
| 1714 | * |
| 1715 | * We can also return, in which case there is no successor instruction |
| 1716 | * from this point. |
| 1717 | * |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1718 | * The behavior can be determined from the opcode flags. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1719 | */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1720 | const uint16_t* insns = code_item_->insns_ + work_insn_idx_; |
| 1721 | const Instruction* inst = Instruction::At(insns); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 1722 | int opcode_flags = Instruction::FlagsOf(inst->Opcode()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1723 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1724 | int32_t branch_target = 0; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1725 | bool just_set_result = false; |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 1726 | if (gDebugVerify) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1727 | // Generate processing back trace to debug verifier |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 1728 | LogVerifyInfo() << "Processing " << inst->DumpString(dex_file_) << "\n" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1729 | << work_line_->Dump(this) << "\n"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1730 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1731 | |
| 1732 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1733 | * Make a copy of the previous register state. If the instruction |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1734 | * can throw an exception, we will copy/merge this into the "catch" |
| 1735 | * address rather than work_line, because we don't want the result |
| 1736 | * from the "successful" code path (e.g. a check-cast that "improves" |
| 1737 | * a type) to be visible to the exception handler. |
| 1738 | */ |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1739 | if ((opcode_flags & Instruction::kThrow) != 0 && CurrentInsnFlags()->IsInTry()) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1740 | saved_line_->CopyFromLine(work_line_.get()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 1741 | } else if (kIsDebugBuild) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1742 | saved_line_->FillWithGarbage(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1743 | } |
Andreas Gampe | d12e782 | 2015-06-25 10:26:40 -0700 | [diff] [blame] | 1744 | DCHECK(!have_pending_runtime_throw_failure_); // Per-instruction flag, should not be set here. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1745 | |
Dragos Sbirlea | 980d16b | 2013-06-04 15:01:40 -0700 | [diff] [blame] | 1746 | |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 1747 | // We need to ensure the work line is consistent while performing validation. When we spot a |
| 1748 | // peephole pattern we compute a new line for either the fallthrough instruction or the |
| 1749 | // branch target. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1750 | std::unique_ptr<RegisterLine> branch_line; |
| 1751 | std::unique_ptr<RegisterLine> fallthrough_line; |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 1752 | |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1753 | switch (inst->Opcode()) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1754 | case Instruction::NOP: |
| 1755 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1756 | * A "pure" NOP has no effect on anything. Data tables start with |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1757 | * a signature that looks like a NOP; if we see one of these in |
| 1758 | * the course of executing code then we have a problem. |
| 1759 | */ |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1760 | if (inst->VRegA_10x() != 0) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1761 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "encountered data table in instruction stream"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1762 | } |
| 1763 | break; |
| 1764 | |
| 1765 | case Instruction::MOVE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1766 | work_line_->CopyRegister1(this, inst->VRegA_12x(), inst->VRegB_12x(), kTypeCategory1nr); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1767 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1768 | case Instruction::MOVE_FROM16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1769 | work_line_->CopyRegister1(this, inst->VRegA_22x(), inst->VRegB_22x(), kTypeCategory1nr); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1770 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1771 | case Instruction::MOVE_16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1772 | work_line_->CopyRegister1(this, inst->VRegA_32x(), inst->VRegB_32x(), kTypeCategory1nr); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1773 | break; |
| 1774 | case Instruction::MOVE_WIDE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1775 | work_line_->CopyRegister2(this, inst->VRegA_12x(), inst->VRegB_12x()); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1776 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1777 | case Instruction::MOVE_WIDE_FROM16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1778 | work_line_->CopyRegister2(this, inst->VRegA_22x(), inst->VRegB_22x()); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1779 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1780 | case Instruction::MOVE_WIDE_16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1781 | work_line_->CopyRegister2(this, inst->VRegA_32x(), inst->VRegB_32x()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1782 | break; |
| 1783 | case Instruction::MOVE_OBJECT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1784 | work_line_->CopyRegister1(this, inst->VRegA_12x(), inst->VRegB_12x(), kTypeCategoryRef); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1785 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1786 | case Instruction::MOVE_OBJECT_FROM16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1787 | work_line_->CopyRegister1(this, inst->VRegA_22x(), inst->VRegB_22x(), kTypeCategoryRef); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1788 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1789 | case Instruction::MOVE_OBJECT_16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1790 | work_line_->CopyRegister1(this, inst->VRegA_32x(), inst->VRegB_32x(), kTypeCategoryRef); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1791 | break; |
| 1792 | |
| 1793 | /* |
| 1794 | * The move-result instructions copy data out of a "pseudo-register" |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1795 | * with the results from the last method invocation. In practice we |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1796 | * might want to hold the result in an actual CPU register, so the |
| 1797 | * Dalvik spec requires that these only appear immediately after an |
| 1798 | * invoke or filled-new-array. |
| 1799 | * |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 1800 | * These calls invalidate the "result" register. (This is now |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1801 | * redundant with the reset done below, but it can make the debug info |
| 1802 | * easier to read in some cases.) |
| 1803 | */ |
| 1804 | case Instruction::MOVE_RESULT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1805 | work_line_->CopyResultRegister1(this, inst->VRegA_11x(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1806 | break; |
| 1807 | case Instruction::MOVE_RESULT_WIDE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1808 | work_line_->CopyResultRegister2(this, inst->VRegA_11x()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1809 | break; |
| 1810 | case Instruction::MOVE_RESULT_OBJECT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1811 | work_line_->CopyResultRegister1(this, inst->VRegA_11x(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1812 | break; |
| 1813 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1814 | case Instruction::MOVE_EXCEPTION: { |
Sebastien Hertz | 270a0e1 | 2015-01-16 19:49:09 +0100 | [diff] [blame] | 1815 | // We do not allow MOVE_EXCEPTION as the first instruction in a method. This is a simple case |
| 1816 | // where one entrypoint to the catch block is not actually an exception path. |
| 1817 | if (work_insn_idx_ == 0) { |
| 1818 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "move-exception at pc 0x0"; |
| 1819 | break; |
| 1820 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1821 | /* |
jeffhao | 60f83e3 | 2012-02-13 17:16:30 -0800 | [diff] [blame] | 1822 | * This statement can only appear as the first instruction in an exception handler. We verify |
| 1823 | * that as part of extracting the exception type from the catch block list. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1824 | */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1825 | const RegType& res_type = GetCaughtExceptionType(); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1826 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_11x(), res_type); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1827 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1828 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1829 | case Instruction::RETURN_VOID: |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1830 | if (!IsInstanceConstructor() || work_line_->CheckConstructorReturn(this)) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1831 | if (!GetMethodReturnType().IsConflict()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1832 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-void not expected"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1833 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1834 | } |
| 1835 | break; |
| 1836 | case Instruction::RETURN: |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1837 | if (!IsInstanceConstructor() || work_line_->CheckConstructorReturn(this)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1838 | /* check the method signature */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1839 | const RegType& return_type = GetMethodReturnType(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1840 | if (!return_type.IsCategory1Types()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1841 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected non-category 1 return type " |
| 1842 | << return_type; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1843 | } else { |
| 1844 | // Compilers may generate synthetic functions that write byte values into boolean fields. |
| 1845 | // Also, it may use integer values for boolean, byte, short, and character return types. |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1846 | const uint32_t vregA = inst->VRegA_11x(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1847 | const RegType& src_type = work_line_->GetRegisterType(this, vregA); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1848 | bool use_src = ((return_type.IsBoolean() && src_type.IsByte()) || |
| 1849 | ((return_type.IsBoolean() || return_type.IsByte() || |
| 1850 | return_type.IsShort() || return_type.IsChar()) && |
| 1851 | src_type.IsInteger())); |
| 1852 | /* check the register contents */ |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1853 | bool success = |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1854 | work_line_->VerifyRegisterType(this, vregA, use_src ? src_type : return_type); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1855 | if (!success) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1856 | AppendToLastFailMessage(StringPrintf(" return-1nr on invalid register v%d", vregA)); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1857 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | break; |
| 1861 | case Instruction::RETURN_WIDE: |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1862 | if (!IsInstanceConstructor() || work_line_->CheckConstructorReturn(this)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1863 | /* check the method signature */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1864 | const RegType& return_type = GetMethodReturnType(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1865 | if (!return_type.IsCategory2Types()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1866 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-wide not expected"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1867 | } else { |
| 1868 | /* check the register contents */ |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1869 | const uint32_t vregA = inst->VRegA_11x(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1870 | bool success = work_line_->VerifyRegisterType(this, vregA, return_type); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1871 | if (!success) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1872 | AppendToLastFailMessage(StringPrintf(" return-wide on invalid register v%d", vregA)); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1873 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1874 | } |
| 1875 | } |
| 1876 | break; |
| 1877 | case Instruction::RETURN_OBJECT: |
Andreas Gampe | f10b6e1 | 2015-08-12 10:48:12 -0700 | [diff] [blame] | 1878 | if (!IsInstanceConstructor() || work_line_->CheckConstructorReturn(this)) { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1879 | const RegType& return_type = GetMethodReturnType(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1880 | if (!return_type.IsReferenceTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 1881 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-object not expected"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1882 | } else { |
| 1883 | /* return_type is the *expected* return type, not register value */ |
| 1884 | DCHECK(!return_type.IsZero()); |
| 1885 | DCHECK(!return_type.IsUninitializedReference()); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1886 | const uint32_t vregA = inst->VRegA_11x(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1887 | const RegType& reg_type = work_line_->GetRegisterType(this, vregA); |
Andreas Gampe | a32210c | 2015-06-24 10:26:13 -0700 | [diff] [blame] | 1888 | // Disallow returning undefined, conflict & uninitialized values and verify that the |
| 1889 | // reference in vAA is an instance of the "return_type." |
| 1890 | if (reg_type.IsUndefined()) { |
| 1891 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "returning undefined register"; |
| 1892 | } else if (reg_type.IsConflict()) { |
| 1893 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "returning register with conflict"; |
| 1894 | } else if (reg_type.IsUninitializedTypes()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 1895 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "returning uninitialized object '" |
| 1896 | << reg_type << "'"; |
Ian Rogers | 9074b99 | 2011-10-26 17:41:55 -0700 | [diff] [blame] | 1897 | } else if (!return_type.IsAssignableFrom(reg_type)) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1898 | if (reg_type.IsUnresolvedTypes() || return_type.IsUnresolvedTypes()) { |
| 1899 | Fail(VERIFY_ERROR_NO_CLASS) << " can't resolve returned type '" << return_type |
| 1900 | << "' or '" << reg_type << "'"; |
| 1901 | } else { |
Andreas Gampe | 16f149c | 2015-03-23 10:10:20 -0700 | [diff] [blame] | 1902 | bool soft_error = false; |
| 1903 | // Check whether arrays are involved. They will show a valid class status, even |
| 1904 | // if their components are erroneous. |
| 1905 | if (reg_type.IsArrayTypes() && return_type.IsArrayTypes()) { |
| 1906 | return_type.CanAssignArray(reg_type, reg_types_, class_loader_, &soft_error); |
| 1907 | if (soft_error) { |
| 1908 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "array with erroneous component type: " |
| 1909 | << reg_type << " vs " << return_type; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | if (!soft_error) { |
| 1914 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "returning '" << reg_type |
| 1915 | << "', but expected from declaration '" << return_type << "'"; |
| 1916 | } |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 1917 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | break; |
| 1922 | |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1923 | /* could be boolean, int, float, or a null reference */ |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1924 | case Instruction::CONST_4: { |
| 1925 | int32_t val = static_cast<int32_t>(inst->VRegB_11n() << 28) >> 28; |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1926 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1927 | this, inst->VRegA_11n(), DetermineCat1Constant(val, need_precise_constants_)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1928 | break; |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1929 | } |
| 1930 | case Instruction::CONST_16: { |
| 1931 | int16_t val = static_cast<int16_t>(inst->VRegB_21s()); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1932 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1933 | this, inst->VRegA_21s(), DetermineCat1Constant(val, need_precise_constants_)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 1934 | break; |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1935 | } |
Sebastien Hertz | 849600b | 2013-12-20 10:28:08 +0100 | [diff] [blame] | 1936 | case Instruction::CONST: { |
| 1937 | int32_t val = inst->VRegB_31i(); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1938 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1939 | this, inst->VRegA_31i(), DetermineCat1Constant(val, need_precise_constants_)); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1940 | break; |
Sebastien Hertz | 849600b | 2013-12-20 10:28:08 +0100 | [diff] [blame] | 1941 | } |
| 1942 | case Instruction::CONST_HIGH16: { |
| 1943 | int32_t val = static_cast<int32_t>(inst->VRegB_21h() << 16); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1944 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1945 | this, inst->VRegA_21h(), DetermineCat1Constant(val, need_precise_constants_)); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1946 | break; |
Sebastien Hertz | 849600b | 2013-12-20 10:28:08 +0100 | [diff] [blame] | 1947 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1948 | /* could be long or double; resolved upon use */ |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1949 | case Instruction::CONST_WIDE_16: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1950 | int64_t val = static_cast<int16_t>(inst->VRegB_21s()); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1951 | const RegType& lo = reg_types_.FromCat2ConstLo(static_cast<int32_t>(val), true); |
| 1952 | const RegType& hi = reg_types_.FromCat2ConstHi(static_cast<int32_t>(val >> 32), true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1953 | work_line_->SetRegisterTypeWide(this, inst->VRegA_21s(), lo, hi); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1954 | break; |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1955 | } |
| 1956 | case Instruction::CONST_WIDE_32: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1957 | int64_t val = static_cast<int32_t>(inst->VRegB_31i()); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1958 | const RegType& lo = reg_types_.FromCat2ConstLo(static_cast<int32_t>(val), true); |
| 1959 | const RegType& hi = reg_types_.FromCat2ConstHi(static_cast<int32_t>(val >> 32), true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1960 | work_line_->SetRegisterTypeWide(this, inst->VRegA_31i(), lo, hi); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | case Instruction::CONST_WIDE: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1964 | int64_t val = inst->VRegB_51l(); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1965 | const RegType& lo = reg_types_.FromCat2ConstLo(static_cast<int32_t>(val), true); |
| 1966 | const RegType& hi = reg_types_.FromCat2ConstHi(static_cast<int32_t>(val >> 32), true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1967 | work_line_->SetRegisterTypeWide(this, inst->VRegA_51l(), lo, hi); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1968 | break; |
| 1969 | } |
| 1970 | case Instruction::CONST_WIDE_HIGH16: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1971 | int64_t val = static_cast<uint64_t>(inst->VRegB_21h()) << 48; |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1972 | const RegType& lo = reg_types_.FromCat2ConstLo(static_cast<int32_t>(val), true); |
| 1973 | const RegType& hi = reg_types_.FromCat2ConstHi(static_cast<int32_t>(val >> 32), true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1974 | work_line_->SetRegisterTypeWide(this, inst->VRegA_21h(), lo, hi); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 1975 | break; |
| 1976 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1977 | case Instruction::CONST_STRING: |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1978 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1979 | this, inst->VRegA_21c(), reg_types_.JavaLangString()); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 1980 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1981 | case Instruction::CONST_STRING_JUMBO: |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1982 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1983 | this, inst->VRegA_31c(), reg_types_.JavaLangString()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1984 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1985 | case Instruction::CONST_CLASS: { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 1986 | // Get type from instruction if unresolved then we need an access check |
| 1987 | // TODO: check Compiler::CanAccessTypeWithoutChecks returns false when res_type is unresolved |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 1988 | const RegType& res_type = ResolveClassAndCheckAccess(inst->VRegB_21c()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 1989 | // Register holds class, ie its type is class, on error it will hold Conflict. |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 1990 | work_line_->SetRegisterType<LockOp::kClear>( |
| 1991 | this, inst->VRegA_21c(), res_type.IsConflict() ? res_type |
| 1992 | : reg_types_.JavaLangClass()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1993 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 1994 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 1995 | case Instruction::MONITOR_ENTER: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1996 | work_line_->PushMonitor(this, inst->VRegA_11x(), work_insn_idx_); |
Andreas Gampe | c147410 | 2015-08-18 08:57:44 -0700 | [diff] [blame] | 1997 | // Check whether the previous instruction is a move-object with vAA as a source, creating |
| 1998 | // untracked lock aliasing. |
| 1999 | if (0 != work_insn_idx_ && !insn_flags_[work_insn_idx_].IsBranchTarget()) { |
| 2000 | uint32_t prev_idx = work_insn_idx_ - 1; |
| 2001 | while (0 != prev_idx && !insn_flags_[prev_idx].IsOpcode()) { |
| 2002 | prev_idx--; |
| 2003 | } |
| 2004 | const Instruction* prev_inst = Instruction::At(code_item_->insns_ + prev_idx); |
| 2005 | switch (prev_inst->Opcode()) { |
| 2006 | case Instruction::MOVE_OBJECT: |
| 2007 | case Instruction::MOVE_OBJECT_16: |
| 2008 | case Instruction::MOVE_OBJECT_FROM16: |
| 2009 | if (prev_inst->VRegB() == inst->VRegA_11x()) { |
| 2010 | // Redo the copy. This won't change the register types, but update the lock status |
| 2011 | // for the aliased register. |
| 2012 | work_line_->CopyRegister1(this, |
| 2013 | prev_inst->VRegA(), |
| 2014 | prev_inst->VRegB(), |
| 2015 | kTypeCategoryRef); |
| 2016 | } |
| 2017 | break; |
| 2018 | |
| 2019 | default: // Other instruction types ignored. |
| 2020 | break; |
| 2021 | } |
| 2022 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2023 | break; |
| 2024 | case Instruction::MONITOR_EXIT: |
| 2025 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 2026 | * monitor-exit instructions are odd. They can throw exceptions, |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2027 | * but when they do they act as if they succeeded and the PC is |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 2028 | * pointing to the following instruction. (This behavior goes back |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2029 | * to the need to handle asynchronous exceptions, a now-deprecated |
| 2030 | * feature that Dalvik doesn't support.) |
| 2031 | * |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 2032 | * In practice we don't need to worry about this. The only |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2033 | * exceptions that can be thrown from monitor-exit are for a |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 2034 | * null reference and -exit without a matching -enter. If the |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2035 | * structured locking checks are working, the former would have |
| 2036 | * failed on the -enter instruction, and the latter is impossible. |
| 2037 | * |
| 2038 | * This is fortunate, because issue 3221411 prevents us from |
| 2039 | * chasing the "can throw" path when monitor verification is |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 2040 | * enabled. If we can fully verify the locking we can ignore |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2041 | * some catch blocks (which will show up as "dead" code when |
| 2042 | * we skip them here); if we can't, then the code path could be |
| 2043 | * "live" so we still need to check it. |
| 2044 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2045 | opcode_flags &= ~Instruction::kThrow; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2046 | work_line_->PopMonitor(this, inst->VRegA_11x()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2047 | break; |
| 2048 | |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2049 | case Instruction::CHECK_CAST: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2050 | case Instruction::INSTANCE_OF: { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2051 | /* |
| 2052 | * If this instruction succeeds, we will "downcast" register vA to the type in vB. (This |
| 2053 | * could be a "upcast" -- not expected, so we don't try to address it.) |
| 2054 | * |
| 2055 | * If it fails, an exception is thrown, which we deal with later by ignoring the update to |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2056 | * dec_insn.vA when branching to a handler. |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2057 | */ |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2058 | const bool is_checkcast = (inst->Opcode() == Instruction::CHECK_CAST); |
| 2059 | const uint32_t type_idx = (is_checkcast) ? inst->VRegB_21c() : inst->VRegC_22c(); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2060 | const RegType& res_type = ResolveClassAndCheckAccess(type_idx); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2061 | if (res_type.IsConflict()) { |
Andreas Gampe | 00633eb | 2014-07-17 16:13:35 -0700 | [diff] [blame] | 2062 | // If this is a primitive type, fail HARD. |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 2063 | mirror::Class* klass = dex_cache_->GetResolvedType(type_idx); |
Andreas Gampe | 00633eb | 2014-07-17 16:13:35 -0700 | [diff] [blame] | 2064 | if (klass != nullptr && klass->IsPrimitive()) { |
| 2065 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "using primitive type " |
| 2066 | << dex_file_->StringByTypeIdx(type_idx) << " in instanceof in " |
| 2067 | << GetDeclaringClass(); |
| 2068 | break; |
| 2069 | } |
| 2070 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2071 | DCHECK_NE(failures_.size(), 0U); |
| 2072 | if (!is_checkcast) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2073 | work_line_->SetRegisterType<LockOp::kClear>(this, |
| 2074 | inst->VRegA_22c(), |
| 2075 | reg_types_.Boolean()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2076 | } |
| 2077 | break; // bad class |
Ian Rogers | 9f1ab12 | 2011-12-12 08:52:43 -0800 | [diff] [blame] | 2078 | } |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2079 | // TODO: check Compiler::CanAccessTypeWithoutChecks returns false when res_type is unresolved |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2080 | uint32_t orig_type_reg = (is_checkcast) ? inst->VRegA_21c() : inst->VRegB_22c(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2081 | const RegType& orig_type = work_line_->GetRegisterType(this, orig_type_reg); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2082 | if (!res_type.IsNonZeroReferenceTypes()) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2083 | if (is_checkcast) { |
| 2084 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "check-cast on unexpected class " << res_type; |
| 2085 | } else { |
| 2086 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "instance-of on unexpected class " << res_type; |
| 2087 | } |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2088 | } else if (!orig_type.IsReferenceTypes()) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2089 | if (is_checkcast) { |
| 2090 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "check-cast on non-reference in v" << orig_type_reg; |
| 2091 | } else { |
| 2092 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "instance-of on non-reference in v" << orig_type_reg; |
| 2093 | } |
jeffhao | 2a8a90e | 2011-09-26 14:25:31 -0700 | [diff] [blame] | 2094 | } else { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2095 | if (is_checkcast) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2096 | work_line_->SetRegisterType<LockOp::kKeep>(this, inst->VRegA_21c(), res_type); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2097 | } else { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2098 | work_line_->SetRegisterType<LockOp::kClear>(this, |
| 2099 | inst->VRegA_22c(), |
| 2100 | reg_types_.Boolean()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2101 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2102 | } |
jeffhao | 2a8a90e | 2011-09-26 14:25:31 -0700 | [diff] [blame] | 2103 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2104 | } |
| 2105 | case Instruction::ARRAY_LENGTH: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2106 | const RegType& res_type = work_line_->GetRegisterType(this, inst->VRegB_12x()); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2107 | if (res_type.IsReferenceTypes()) { |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 2108 | if (!res_type.IsArrayTypes() && !res_type.IsZero()) { // ie not an array or null |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2109 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "array-length on non-array " << res_type; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2110 | } else { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2111 | work_line_->SetRegisterType<LockOp::kClear>(this, |
| 2112 | inst->VRegA_12x(), |
| 2113 | reg_types_.Integer()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2114 | } |
Andreas Gampe | 65c9db8 | 2014-07-28 13:14:34 -0700 | [diff] [blame] | 2115 | } else { |
| 2116 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "array-length on non-array " << res_type; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2117 | } |
| 2118 | break; |
| 2119 | } |
| 2120 | case Instruction::NEW_INSTANCE: { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2121 | const RegType& res_type = ResolveClassAndCheckAccess(inst->VRegB_21c()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2122 | if (res_type.IsConflict()) { |
| 2123 | DCHECK_NE(failures_.size(), 0U); |
| 2124 | break; // bad class |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 2125 | } |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2126 | // TODO: check Compiler::CanAccessTypeWithoutChecks returns false when res_type is unresolved |
| 2127 | // can't create an instance of an interface or abstract class */ |
| 2128 | if (!res_type.IsInstantiableTypes()) { |
| 2129 | Fail(VERIFY_ERROR_INSTANTIATION) |
| 2130 | << "new-instance on primitive, interface or abstract class" << res_type; |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 2131 | // Soft failure so carry on to set register type. |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2132 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2133 | const RegType& uninit_type = reg_types_.Uninitialized(res_type, work_insn_idx_); |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 2134 | // Any registers holding previous allocations from this address that have not yet been |
| 2135 | // initialized must be marked invalid. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2136 | work_line_->MarkUninitRefsAsInvalid(this, uninit_type); |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 2137 | // add the new uninitialized reference to the register state |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2138 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_21c(), uninit_type); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2139 | break; |
| 2140 | } |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 2141 | case Instruction::NEW_ARRAY: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2142 | VerifyNewArray(inst, false, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2143 | break; |
| 2144 | case Instruction::FILLED_NEW_ARRAY: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2145 | VerifyNewArray(inst, true, false); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 2146 | just_set_result = true; // Filled new array sets result register |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2147 | break; |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 2148 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2149 | VerifyNewArray(inst, true, true); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 2150 | just_set_result = true; // Filled new array range sets result register |
| 2151 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2152 | case Instruction::CMPL_FLOAT: |
| 2153 | case Instruction::CMPG_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2154 | if (!work_line_->VerifyRegisterType(this, inst->VRegB_23x(), reg_types_.Float())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2155 | break; |
| 2156 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2157 | if (!work_line_->VerifyRegisterType(this, inst->VRegC_23x(), reg_types_.Float())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2158 | break; |
| 2159 | } |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2160 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_23x(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2161 | break; |
| 2162 | case Instruction::CMPL_DOUBLE: |
| 2163 | case Instruction::CMPG_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2164 | if (!work_line_->VerifyRegisterTypeWide(this, inst->VRegB_23x(), reg_types_.DoubleLo(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2165 | reg_types_.DoubleHi())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2166 | break; |
| 2167 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2168 | if (!work_line_->VerifyRegisterTypeWide(this, inst->VRegC_23x(), reg_types_.DoubleLo(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2169 | reg_types_.DoubleHi())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2170 | break; |
| 2171 | } |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2172 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_23x(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2173 | break; |
| 2174 | case Instruction::CMP_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2175 | if (!work_line_->VerifyRegisterTypeWide(this, inst->VRegB_23x(), reg_types_.LongLo(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2176 | reg_types_.LongHi())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2177 | break; |
| 2178 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2179 | if (!work_line_->VerifyRegisterTypeWide(this, inst->VRegC_23x(), reg_types_.LongLo(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2180 | reg_types_.LongHi())) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2181 | break; |
| 2182 | } |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2183 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_23x(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2184 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2185 | case Instruction::THROW: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2186 | const RegType& res_type = work_line_->GetRegisterType(this, inst->VRegA_11x()); |
Ian Rogers | b490357 | 2012-10-11 11:52:56 -0700 | [diff] [blame] | 2187 | if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(res_type)) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 2188 | Fail(res_type.IsUnresolvedTypes() ? VERIFY_ERROR_NO_CLASS : VERIFY_ERROR_BAD_CLASS_SOFT) |
| 2189 | << "thrown class " << res_type << " not instanceof Throwable"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2190 | } |
| 2191 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2192 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2193 | case Instruction::GOTO: |
| 2194 | case Instruction::GOTO_16: |
| 2195 | case Instruction::GOTO_32: |
| 2196 | /* no effect on or use of registers */ |
| 2197 | break; |
| 2198 | |
| 2199 | case Instruction::PACKED_SWITCH: |
| 2200 | case Instruction::SPARSE_SWITCH: |
| 2201 | /* verify that vAA is an integer, or can be converted to one */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2202 | work_line_->VerifyRegisterType(this, inst->VRegA_31t(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2203 | break; |
| 2204 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2205 | case Instruction::FILL_ARRAY_DATA: { |
| 2206 | /* Similar to the verification done for APUT */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2207 | const RegType& array_type = work_line_->GetRegisterType(this, inst->VRegA_31t()); |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 2208 | /* array_type can be null if the reg type is Zero */ |
| 2209 | if (!array_type.IsZero()) { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2210 | if (!array_type.IsArrayTypes()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 2211 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid fill-array-data with array type " |
| 2212 | << array_type; |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 2213 | } else { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2214 | const RegType& component_type = reg_types_.GetComponentType(array_type, GetClassLoader()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2215 | DCHECK(!component_type.IsConflict()); |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2216 | if (component_type.IsNonZeroReferenceTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2217 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid fill-array-data with component type " |
| 2218 | << component_type; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2219 | } else { |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2220 | // Now verify if the element width in the table matches the element width declared in |
| 2221 | // the array |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 2222 | const uint16_t* array_data = |
| 2223 | insns + (insns[1] | (static_cast<int32_t>(insns[2]) << 16)); |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2224 | if (array_data[0] != Instruction::kArrayDataSignature) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2225 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid magic for array-data"; |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2226 | } else { |
| 2227 | size_t elem_width = Primitive::ComponentSize(component_type.GetPrimitiveType()); |
| 2228 | // Since we don't compress the data in Dex, expect to see equal width of data stored |
| 2229 | // in the table and expected from the array class. |
| 2230 | if (array_data[1] != elem_width) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2231 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "array-data size mismatch (" << array_data[1] |
| 2232 | << " vs " << elem_width << ")"; |
jeffhao | 457cc51 | 2012-02-02 16:55:13 -0800 | [diff] [blame] | 2233 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2234 | } |
| 2235 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2239 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2240 | case Instruction::IF_EQ: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2241 | case Instruction::IF_NE: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2242 | const RegType& reg_type1 = work_line_->GetRegisterType(this, inst->VRegA_22t()); |
| 2243 | const RegType& reg_type2 = work_line_->GetRegisterType(this, inst->VRegB_22t()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2244 | bool mismatch = false; |
| 2245 | if (reg_type1.IsZero()) { // zero then integral or reference expected |
| 2246 | mismatch = !reg_type2.IsReferenceTypes() && !reg_type2.IsIntegralTypes(); |
| 2247 | } else if (reg_type1.IsReferenceTypes()) { // both references? |
| 2248 | mismatch = !reg_type2.IsReferenceTypes(); |
| 2249 | } else { // both integral? |
| 2250 | mismatch = !reg_type1.IsIntegralTypes() || !reg_type2.IsIntegralTypes(); |
| 2251 | } |
| 2252 | if (mismatch) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 2253 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "args to if-eq/if-ne (" << reg_type1 << "," |
| 2254 | << reg_type2 << ") must both be references or integral"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2255 | } |
| 2256 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2257 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2258 | case Instruction::IF_LT: |
| 2259 | case Instruction::IF_GE: |
| 2260 | case Instruction::IF_GT: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2261 | case Instruction::IF_LE: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2262 | const RegType& reg_type1 = work_line_->GetRegisterType(this, inst->VRegA_22t()); |
| 2263 | const RegType& reg_type2 = work_line_->GetRegisterType(this, inst->VRegB_22t()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2264 | if (!reg_type1.IsIntegralTypes() || !reg_type2.IsIntegralTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2265 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "args to 'if' (" << reg_type1 << "," |
| 2266 | << reg_type2 << ") must be integral"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2267 | } |
| 2268 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2269 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2270 | case Instruction::IF_EQZ: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2271 | case Instruction::IF_NEZ: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2272 | const RegType& reg_type = work_line_->GetRegisterType(this, inst->VRegA_21t()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2273 | if (!reg_type.IsReferenceTypes() && !reg_type.IsIntegralTypes()) { |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 2274 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "type " << reg_type |
| 2275 | << " unexpected as arg to if-eqz/if-nez"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2276 | } |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2277 | |
| 2278 | // Find previous instruction - its existence is a precondition to peephole optimization. |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2279 | uint32_t instance_of_idx = 0; |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2280 | if (0 != work_insn_idx_) { |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2281 | instance_of_idx = work_insn_idx_ - 1; |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 2282 | while (0 != instance_of_idx && !insn_flags_[instance_of_idx].IsOpcode()) { |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2283 | instance_of_idx--; |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2284 | } |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 2285 | if (FailOrAbort(this, insn_flags_[instance_of_idx].IsOpcode(), |
| 2286 | "Unable to get previous instruction of if-eqz/if-nez for work index ", |
| 2287 | work_insn_idx_)) { |
| 2288 | break; |
| 2289 | } |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2290 | } else { |
| 2291 | break; |
| 2292 | } |
| 2293 | |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2294 | const Instruction* instance_of_inst = Instruction::At(code_item_->insns_ + instance_of_idx); |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2295 | |
| 2296 | /* Check for peep-hole pattern of: |
| 2297 | * ...; |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2298 | * instance-of vX, vY, T; |
| 2299 | * ifXXX vX, label ; |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2300 | * ...; |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2301 | * label: |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2302 | * ...; |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2303 | * and sharpen the type of vY to be type T. |
| 2304 | * Note, this pattern can't be if: |
| 2305 | * - if there are other branches to this branch, |
| 2306 | * - when vX == vY. |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2307 | */ |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2308 | if (!CurrentInsnFlags()->IsBranchTarget() && |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2309 | (Instruction::INSTANCE_OF == instance_of_inst->Opcode()) && |
| 2310 | (inst->VRegA_21t() == instance_of_inst->VRegA_22c()) && |
| 2311 | (instance_of_inst->VRegA_22c() != instance_of_inst->VRegB_22c())) { |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 2312 | // Check the type of the instance-of is different than that of registers type, as if they |
| 2313 | // are the same there is no work to be done here. Check that the conversion is not to or |
| 2314 | // from an unresolved type as type information is imprecise. If the instance-of is to an |
| 2315 | // interface then ignore the type information as interfaces can only be treated as Objects |
| 2316 | // and we don't want to disallow field and other operations on the object. If the value |
| 2317 | // being instance-of checked against is known null (zero) then allow the optimization as |
| 2318 | // we didn't have type information. If the merge of the instance-of type with the original |
| 2319 | // type is assignable to the original then allow optimization. This check is performed to |
| 2320 | // ensure that subsequent merges don't lose type information - such as becoming an |
| 2321 | // interface from a class that would lose information relevant to field checks. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2322 | const RegType& orig_type = work_line_->GetRegisterType(this, instance_of_inst->VRegB_22c()); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2323 | const RegType& cast_type = ResolveClassAndCheckAccess(instance_of_inst->VRegC_22c()); |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2324 | |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 2325 | if (!orig_type.Equals(cast_type) && |
| 2326 | !cast_type.IsUnresolvedTypes() && !orig_type.IsUnresolvedTypes() && |
Andreas Gampe | 00633eb | 2014-07-17 16:13:35 -0700 | [diff] [blame] | 2327 | cast_type.HasClass() && // Could be conflict type, make sure it has a class. |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 2328 | !cast_type.GetClass()->IsInterface() && |
| 2329 | (orig_type.IsZero() || |
| 2330 | orig_type.IsStrictlyAssignableFrom(cast_type.Merge(orig_type, ®_types_)))) { |
Ian Rogers | d0fbd85 | 2013-09-24 18:17:04 -0700 | [diff] [blame] | 2331 | RegisterLine* update_line = RegisterLine::Create(code_item_->registers_size_, this); |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2332 | if (inst->Opcode() == Instruction::IF_EQZ) { |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2333 | fallthrough_line.reset(update_line); |
Ian Rogers | fae370a | 2013-06-05 08:33:27 -0700 | [diff] [blame] | 2334 | } else { |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2335 | branch_line.reset(update_line); |
| 2336 | } |
| 2337 | update_line->CopyFromLine(work_line_.get()); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2338 | update_line->SetRegisterType<LockOp::kKeep>(this, |
| 2339 | instance_of_inst->VRegB_22c(), |
| 2340 | cast_type); |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2341 | if (!insn_flags_[instance_of_idx].IsBranchTarget() && 0 != instance_of_idx) { |
| 2342 | // See if instance-of was preceded by a move-object operation, common due to the small |
| 2343 | // register encoding space of instance-of, and propagate type information to the source |
| 2344 | // of the move-object. |
| 2345 | uint32_t move_idx = instance_of_idx - 1; |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 2346 | while (0 != move_idx && !insn_flags_[move_idx].IsOpcode()) { |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2347 | move_idx--; |
| 2348 | } |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 2349 | if (FailOrAbort(this, insn_flags_[move_idx].IsOpcode(), |
| 2350 | "Unable to get previous instruction of if-eqz/if-nez for work index ", |
| 2351 | work_insn_idx_)) { |
| 2352 | break; |
| 2353 | } |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2354 | const Instruction* move_inst = Instruction::At(code_item_->insns_ + move_idx); |
| 2355 | switch (move_inst->Opcode()) { |
| 2356 | case Instruction::MOVE_OBJECT: |
| 2357 | if (move_inst->VRegA_12x() == instance_of_inst->VRegB_22c()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2358 | update_line->SetRegisterType<LockOp::kKeep>(this, |
| 2359 | move_inst->VRegB_12x(), |
| 2360 | cast_type); |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2361 | } |
| 2362 | break; |
| 2363 | case Instruction::MOVE_OBJECT_FROM16: |
| 2364 | if (move_inst->VRegA_22x() == instance_of_inst->VRegB_22c()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2365 | update_line->SetRegisterType<LockOp::kKeep>(this, |
| 2366 | move_inst->VRegB_22x(), |
| 2367 | cast_type); |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2368 | } |
| 2369 | break; |
| 2370 | case Instruction::MOVE_OBJECT_16: |
| 2371 | if (move_inst->VRegA_32x() == instance_of_inst->VRegB_22c()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 2372 | update_line->SetRegisterType<LockOp::kKeep>(this, |
| 2373 | move_inst->VRegB_32x(), |
| 2374 | cast_type); |
Ian Rogers | 9b36039 | 2013-06-06 14:45:07 -0700 | [diff] [blame] | 2375 | } |
| 2376 | break; |
| 2377 | default: |
| 2378 | break; |
| 2379 | } |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2384 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2385 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2386 | case Instruction::IF_LTZ: |
| 2387 | case Instruction::IF_GEZ: |
| 2388 | case Instruction::IF_GTZ: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2389 | case Instruction::IF_LEZ: { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2390 | const RegType& reg_type = work_line_->GetRegisterType(this, inst->VRegA_21t()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2391 | if (!reg_type.IsIntegralTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 2392 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "type " << reg_type |
| 2393 | << " unexpected as arg to if-ltz/if-gez/if-gtz/if-lez"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2394 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2395 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2396 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2397 | case Instruction::AGET_BOOLEAN: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2398 | VerifyAGet(inst, reg_types_.Boolean(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2399 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2400 | case Instruction::AGET_BYTE: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2401 | VerifyAGet(inst, reg_types_.Byte(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2402 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2403 | case Instruction::AGET_CHAR: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2404 | VerifyAGet(inst, reg_types_.Char(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2405 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2406 | case Instruction::AGET_SHORT: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2407 | VerifyAGet(inst, reg_types_.Short(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2408 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2409 | case Instruction::AGET: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2410 | VerifyAGet(inst, reg_types_.Integer(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2411 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2412 | case Instruction::AGET_WIDE: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2413 | VerifyAGet(inst, reg_types_.LongLo(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2414 | break; |
| 2415 | case Instruction::AGET_OBJECT: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2416 | VerifyAGet(inst, reg_types_.JavaLangObject(false), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2417 | break; |
| 2418 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2419 | case Instruction::APUT_BOOLEAN: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2420 | VerifyAPut(inst, reg_types_.Boolean(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2421 | break; |
| 2422 | case Instruction::APUT_BYTE: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2423 | VerifyAPut(inst, reg_types_.Byte(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2424 | break; |
| 2425 | case Instruction::APUT_CHAR: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2426 | VerifyAPut(inst, reg_types_.Char(), true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2427 | break; |
| 2428 | case Instruction::APUT_SHORT: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2429 | VerifyAPut(inst, reg_types_.Short(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2430 | break; |
| 2431 | case Instruction::APUT: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2432 | VerifyAPut(inst, reg_types_.Integer(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2433 | break; |
| 2434 | case Instruction::APUT_WIDE: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2435 | VerifyAPut(inst, reg_types_.LongLo(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2436 | break; |
| 2437 | case Instruction::APUT_OBJECT: |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2438 | VerifyAPut(inst, reg_types_.JavaLangObject(false), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2439 | break; |
| 2440 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2441 | case Instruction::IGET_BOOLEAN: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2442 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Boolean(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2443 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2444 | case Instruction::IGET_BYTE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2445 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Byte(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2446 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2447 | case Instruction::IGET_CHAR: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2448 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Char(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2449 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2450 | case Instruction::IGET_SHORT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2451 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Short(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2452 | break; |
| 2453 | case Instruction::IGET: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2454 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Integer(), true, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2455 | break; |
| 2456 | case Instruction::IGET_WIDE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2457 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.LongLo(), true, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2458 | break; |
| 2459 | case Instruction::IGET_OBJECT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2460 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.JavaLangObject(false), false, |
| 2461 | false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2462 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2463 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2464 | case Instruction::IPUT_BOOLEAN: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2465 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Boolean(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2466 | break; |
| 2467 | case Instruction::IPUT_BYTE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2468 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Byte(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2469 | break; |
| 2470 | case Instruction::IPUT_CHAR: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2471 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Char(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2472 | break; |
| 2473 | case Instruction::IPUT_SHORT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2474 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Short(), true, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2475 | break; |
| 2476 | case Instruction::IPUT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2477 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Integer(), true, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2478 | break; |
| 2479 | case Instruction::IPUT_WIDE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2480 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.LongLo(), true, false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2481 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2482 | case Instruction::IPUT_OBJECT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2483 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.JavaLangObject(false), false, |
| 2484 | false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2485 | break; |
| 2486 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2487 | case Instruction::SGET_BOOLEAN: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2488 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Boolean(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2489 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2490 | case Instruction::SGET_BYTE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2491 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Byte(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2492 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2493 | case Instruction::SGET_CHAR: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2494 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Char(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2495 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2496 | case Instruction::SGET_SHORT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2497 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Short(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2498 | break; |
| 2499 | case Instruction::SGET: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2500 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Integer(), true, true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2501 | break; |
| 2502 | case Instruction::SGET_WIDE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2503 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.LongLo(), true, true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2504 | break; |
| 2505 | case Instruction::SGET_OBJECT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2506 | VerifyISFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.JavaLangObject(false), false, |
| 2507 | true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2508 | break; |
| 2509 | |
| 2510 | case Instruction::SPUT_BOOLEAN: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2511 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Boolean(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2512 | break; |
| 2513 | case Instruction::SPUT_BYTE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2514 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Byte(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2515 | break; |
| 2516 | case Instruction::SPUT_CHAR: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2517 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Char(), true, true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2518 | break; |
| 2519 | case Instruction::SPUT_SHORT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2520 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Short(), true, true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2521 | break; |
| 2522 | case Instruction::SPUT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2523 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Integer(), true, true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2524 | break; |
| 2525 | case Instruction::SPUT_WIDE: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2526 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.LongLo(), true, true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2527 | break; |
| 2528 | case Instruction::SPUT_OBJECT: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2529 | VerifyISFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.JavaLangObject(false), false, |
| 2530 | true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2531 | break; |
| 2532 | |
| 2533 | case Instruction::INVOKE_VIRTUAL: |
| 2534 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 2535 | case Instruction::INVOKE_SUPER: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2536 | case Instruction::INVOKE_SUPER_RANGE: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2537 | bool is_range = (inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE || |
| 2538 | inst->Opcode() == Instruction::INVOKE_SUPER_RANGE); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 2539 | bool is_super = (inst->Opcode() == Instruction::INVOKE_SUPER || |
| 2540 | inst->Opcode() == Instruction::INVOKE_SUPER_RANGE); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2541 | ArtMethod* called_method = VerifyInvocationArgs(inst, METHOD_VIRTUAL, is_range, is_super); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2542 | const RegType* return_type = nullptr; |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2543 | if (called_method != nullptr) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2544 | size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
| 2545 | mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_, |
| 2546 | pointer_size); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2547 | if (return_type_class != nullptr) { |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 2548 | return_type = &FromClass(called_method->GetReturnTypeDescriptor(), |
| 2549 | return_type_class, |
| 2550 | return_type_class->CannotBeAssignedFromOtherTypes()); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2551 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2552 | DCHECK(!can_load_classes_ || self_->IsExceptionPending()); |
| 2553 | self_->ClearException(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2554 | } |
| 2555 | } |
| 2556 | if (return_type == nullptr) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2557 | uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2558 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 2559 | uint32_t return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2560 | const char* descriptor = dex_file_->StringByTypeIdx(return_type_idx); |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 2561 | return_type = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2562 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2563 | if (!return_type->IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2564 | work_line_->SetResultRegisterType(this, *return_type); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2565 | } else { |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 2566 | work_line_->SetResultRegisterTypeWide(*return_type, return_type->HighHalf(®_types_)); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2567 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2568 | just_set_result = true; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2569 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2570 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2571 | case Instruction::INVOKE_DIRECT: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2572 | case Instruction::INVOKE_DIRECT_RANGE: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2573 | bool is_range = (inst->Opcode() == Instruction::INVOKE_DIRECT_RANGE); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2574 | ArtMethod* called_method = VerifyInvocationArgs(inst, METHOD_DIRECT, is_range, false); |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2575 | const char* return_type_descriptor; |
| 2576 | bool is_constructor; |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2577 | const RegType* return_type = nullptr; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2578 | if (called_method == nullptr) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2579 | uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2580 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
Ian Rogers | dfb325e | 2013-10-30 01:00:44 -0700 | [diff] [blame] | 2581 | is_constructor = strcmp("<init>", dex_file_->StringDataByIdx(method_id.name_idx_)) == 0; |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2582 | uint32_t return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; |
| 2583 | return_type_descriptor = dex_file_->StringByTypeIdx(return_type_idx); |
| 2584 | } else { |
| 2585 | is_constructor = called_method->IsConstructor(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 2586 | return_type_descriptor = called_method->GetReturnTypeDescriptor(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 2587 | size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
| 2588 | mirror::Class* return_type_class = called_method->GetReturnType(can_load_classes_, |
| 2589 | pointer_size); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2590 | if (return_type_class != nullptr) { |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 2591 | return_type = &FromClass(return_type_descriptor, |
| 2592 | return_type_class, |
| 2593 | return_type_class->CannotBeAssignedFromOtherTypes()); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2594 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2595 | DCHECK(!can_load_classes_ || self_->IsExceptionPending()); |
| 2596 | self_->ClearException(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2597 | } |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2598 | } |
| 2599 | if (is_constructor) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2600 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2601 | * Some additional checks when calling a constructor. We know from the invocation arg check |
| 2602 | * that the "this" argument is an instance of called_method->klass. Now we further restrict |
| 2603 | * that to require that called_method->klass is the same as this->klass or this->super, |
| 2604 | * allowing the latter only if the "this" argument is the same as the "this" argument to |
| 2605 | * this method (which implies that we're in a constructor ourselves). |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2606 | */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2607 | const RegType& this_type = work_line_->GetInvocationThis(this, inst, is_range); |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 2608 | if (this_type.IsConflict()) // failure. |
| 2609 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2610 | |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 2611 | /* no null refs allowed (?) */ |
| 2612 | if (this_type.IsZero()) { |
| 2613 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unable to initialize null ref"; |
| 2614 | break; |
jeffhao | 2a8a90e | 2011-09-26 14:25:31 -0700 | [diff] [blame] | 2615 | } |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 2616 | |
| 2617 | /* must be in same class or in superclass */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2618 | // const RegType& this_super_klass = this_type.GetSuperClass(®_types_); |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2619 | // TODO: re-enable constructor type verification |
| 2620 | // if (this_super_klass.IsConflict()) { |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 2621 | // Unknown super class, fail so we re-check at runtime. |
Ian Rogers | 4668543 | 2012-06-03 22:26:43 -0700 | [diff] [blame] | 2622 | // Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "super class unknown for '" << this_type << "'"; |
| 2623 | // break; |
| 2624 | // } |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 2625 | |
| 2626 | /* arg must be an uninitialized reference */ |
| 2627 | if (!this_type.IsUninitializedTypes()) { |
| 2628 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Expected initialization on uninitialized reference " |
| 2629 | << this_type; |
| 2630 | break; |
| 2631 | } |
| 2632 | |
| 2633 | /* |
| 2634 | * Replace the uninitialized reference with an initialized one. We need to do this for all |
| 2635 | * registers that have the same object instance in them, not just the "this" register. |
| 2636 | */ |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2637 | const uint32_t this_reg = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c(); |
| 2638 | work_line_->MarkRefsAsInitialized(this, this_type, this_reg, work_insn_idx_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2639 | } |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2640 | if (return_type == nullptr) { |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 2641 | return_type = ®_types_.FromDescriptor(GetClassLoader(), return_type_descriptor, |
| 2642 | false); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2643 | } |
| 2644 | if (!return_type->IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2645 | work_line_->SetResultRegisterType(this, *return_type); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2646 | } else { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 2647 | work_line_->SetResultRegisterTypeWide(*return_type, return_type->HighHalf(®_types_)); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2648 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2649 | just_set_result = true; |
| 2650 | break; |
| 2651 | } |
| 2652 | case Instruction::INVOKE_STATIC: |
| 2653 | case Instruction::INVOKE_STATIC_RANGE: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2654 | bool is_range = (inst->Opcode() == Instruction::INVOKE_STATIC_RANGE); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2655 | ArtMethod* called_method = VerifyInvocationArgs(inst, METHOD_STATIC, is_range, false); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2656 | const char* descriptor; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2657 | if (called_method == nullptr) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2658 | uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2659 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 2660 | uint32_t return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 2661 | descriptor = dex_file_->StringByTypeIdx(return_type_idx); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2662 | } else { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 2663 | descriptor = called_method->GetReturnTypeDescriptor(); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2664 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2665 | const RegType& return_type = reg_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2666 | if (!return_type.IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2667 | work_line_->SetResultRegisterType(this, return_type); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2668 | } else { |
| 2669 | work_line_->SetResultRegisterTypeWide(return_type, return_type.HighHalf(®_types_)); |
| 2670 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2671 | just_set_result = true; |
| 2672 | } |
| 2673 | break; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2674 | case Instruction::INVOKE_INTERFACE: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2675 | case Instruction::INVOKE_INTERFACE_RANGE: { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2676 | bool is_range = (inst->Opcode() == Instruction::INVOKE_INTERFACE_RANGE); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2677 | ArtMethod* abs_method = VerifyInvocationArgs(inst, METHOD_INTERFACE, is_range, false); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2678 | if (abs_method != nullptr) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2679 | mirror::Class* called_interface = abs_method->GetDeclaringClass(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2680 | if (!called_interface->IsInterface() && !called_interface->IsObjectClass()) { |
| 2681 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "expected interface class in invoke-interface '" |
| 2682 | << PrettyMethod(abs_method) << "'"; |
| 2683 | break; |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 2684 | } |
Ian Rogers | 0d60484 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2685 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2686 | /* Get the type of the "this" arg, which should either be a sub-interface of called |
| 2687 | * interface or Object (see comments in RegType::JoinClass). |
| 2688 | */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2689 | const RegType& this_type = work_line_->GetInvocationThis(this, inst, is_range); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2690 | if (this_type.IsZero()) { |
| 2691 | /* null pointer always passes (and always fails at runtime) */ |
| 2692 | } else { |
| 2693 | if (this_type.IsUninitializedTypes()) { |
| 2694 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "interface call on uninitialized object " |
| 2695 | << this_type; |
| 2696 | break; |
| 2697 | } |
| 2698 | // In the past we have tried to assert that "called_interface" is assignable |
| 2699 | // from "this_type.GetClass()", however, as we do an imprecise Join |
| 2700 | // (RegType::JoinClass) we don't have full information on what interfaces are |
| 2701 | // implemented by "this_type". For example, two classes may implement the same |
| 2702 | // interfaces and have a common parent that doesn't implement the interface. The |
| 2703 | // join will set "this_type" to the parent class and a test that this implements |
| 2704 | // the interface will incorrectly fail. |
| 2705 | } |
| 2706 | /* |
| 2707 | * We don't have an object instance, so we can't find the concrete method. However, all of |
| 2708 | * the type information is in the abstract method, so we're good. |
| 2709 | */ |
| 2710 | const char* descriptor; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2711 | if (abs_method == nullptr) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 2712 | uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2713 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); |
| 2714 | uint32_t return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; |
| 2715 | descriptor = dex_file_->StringByTypeIdx(return_type_idx); |
| 2716 | } else { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 2717 | descriptor = abs_method->GetReturnTypeDescriptor(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2718 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 2719 | const RegType& return_type = reg_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2720 | if (!return_type.IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2721 | work_line_->SetResultRegisterType(this, return_type); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2722 | } else { |
| 2723 | work_line_->SetResultRegisterTypeWide(return_type, return_type.HighHalf(®_types_)); |
| 2724 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 2725 | just_set_result = true; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2726 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2727 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2728 | case Instruction::NEG_INT: |
| 2729 | case Instruction::NOT_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2730 | work_line_->CheckUnaryOp(this, inst, reg_types_.Integer(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2731 | break; |
| 2732 | case Instruction::NEG_LONG: |
| 2733 | case Instruction::NOT_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2734 | work_line_->CheckUnaryOpWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2735 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2736 | break; |
| 2737 | case Instruction::NEG_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2738 | work_line_->CheckUnaryOp(this, inst, reg_types_.Float(), reg_types_.Float()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2739 | break; |
| 2740 | case Instruction::NEG_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2741 | work_line_->CheckUnaryOpWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2742 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2743 | break; |
| 2744 | case Instruction::INT_TO_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2745 | work_line_->CheckUnaryOpToWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2746 | reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2747 | break; |
| 2748 | case Instruction::INT_TO_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2749 | work_line_->CheckUnaryOp(this, inst, reg_types_.Float(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2750 | break; |
| 2751 | case Instruction::INT_TO_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2752 | work_line_->CheckUnaryOpToWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2753 | reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2754 | break; |
| 2755 | case Instruction::LONG_TO_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2756 | work_line_->CheckUnaryOpFromWide(this, inst, reg_types_.Integer(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2757 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2758 | break; |
| 2759 | case Instruction::LONG_TO_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2760 | work_line_->CheckUnaryOpFromWide(this, inst, reg_types_.Float(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2761 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2762 | break; |
| 2763 | case Instruction::LONG_TO_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2764 | work_line_->CheckUnaryOpWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2765 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2766 | break; |
| 2767 | case Instruction::FLOAT_TO_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2768 | work_line_->CheckUnaryOp(this, inst, reg_types_.Integer(), reg_types_.Float()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2769 | break; |
| 2770 | case Instruction::FLOAT_TO_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2771 | work_line_->CheckUnaryOpToWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2772 | reg_types_.Float()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2773 | break; |
| 2774 | case Instruction::FLOAT_TO_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2775 | work_line_->CheckUnaryOpToWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2776 | reg_types_.Float()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2777 | break; |
| 2778 | case Instruction::DOUBLE_TO_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2779 | work_line_->CheckUnaryOpFromWide(this, inst, reg_types_.Integer(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2780 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2781 | break; |
| 2782 | case Instruction::DOUBLE_TO_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2783 | work_line_->CheckUnaryOpWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2784 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2785 | break; |
| 2786 | case Instruction::DOUBLE_TO_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2787 | work_line_->CheckUnaryOpFromWide(this, inst, reg_types_.Float(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2788 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2789 | break; |
| 2790 | case Instruction::INT_TO_BYTE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2791 | work_line_->CheckUnaryOp(this, inst, reg_types_.Byte(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2792 | break; |
| 2793 | case Instruction::INT_TO_CHAR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2794 | work_line_->CheckUnaryOp(this, inst, reg_types_.Char(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2795 | break; |
| 2796 | case Instruction::INT_TO_SHORT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2797 | work_line_->CheckUnaryOp(this, inst, reg_types_.Short(), reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2798 | break; |
| 2799 | |
| 2800 | case Instruction::ADD_INT: |
| 2801 | case Instruction::SUB_INT: |
| 2802 | case Instruction::MUL_INT: |
| 2803 | case Instruction::REM_INT: |
| 2804 | case Instruction::DIV_INT: |
| 2805 | case Instruction::SHL_INT: |
| 2806 | case Instruction::SHR_INT: |
| 2807 | case Instruction::USHR_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2808 | work_line_->CheckBinaryOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2809 | reg_types_.Integer(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2810 | break; |
| 2811 | case Instruction::AND_INT: |
| 2812 | case Instruction::OR_INT: |
| 2813 | case Instruction::XOR_INT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2814 | work_line_->CheckBinaryOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2815 | reg_types_.Integer(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2816 | break; |
| 2817 | case Instruction::ADD_LONG: |
| 2818 | case Instruction::SUB_LONG: |
| 2819 | case Instruction::MUL_LONG: |
| 2820 | case Instruction::DIV_LONG: |
| 2821 | case Instruction::REM_LONG: |
| 2822 | case Instruction::AND_LONG: |
| 2823 | case Instruction::OR_LONG: |
| 2824 | case Instruction::XOR_LONG: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2825 | work_line_->CheckBinaryOpWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2826 | reg_types_.LongLo(), reg_types_.LongHi(), |
| 2827 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2828 | break; |
| 2829 | case Instruction::SHL_LONG: |
| 2830 | case Instruction::SHR_LONG: |
| 2831 | case Instruction::USHR_LONG: |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 2832 | /* shift distance is Int, making these different from other binary operations */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2833 | work_line_->CheckBinaryOpWideShift(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2834 | reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2835 | break; |
| 2836 | case Instruction::ADD_FLOAT: |
| 2837 | case Instruction::SUB_FLOAT: |
| 2838 | case Instruction::MUL_FLOAT: |
| 2839 | case Instruction::DIV_FLOAT: |
| 2840 | case Instruction::REM_FLOAT: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2841 | work_line_->CheckBinaryOp(this, inst, reg_types_.Float(), reg_types_.Float(), |
| 2842 | reg_types_.Float(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2843 | break; |
| 2844 | case Instruction::ADD_DOUBLE: |
| 2845 | case Instruction::SUB_DOUBLE: |
| 2846 | case Instruction::MUL_DOUBLE: |
| 2847 | case Instruction::DIV_DOUBLE: |
| 2848 | case Instruction::REM_DOUBLE: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2849 | work_line_->CheckBinaryOpWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2850 | reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
| 2851 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2852 | break; |
| 2853 | case Instruction::ADD_INT_2ADDR: |
| 2854 | case Instruction::SUB_INT_2ADDR: |
| 2855 | case Instruction::MUL_INT_2ADDR: |
| 2856 | case Instruction::REM_INT_2ADDR: |
| 2857 | case Instruction::SHL_INT_2ADDR: |
| 2858 | case Instruction::SHR_INT_2ADDR: |
| 2859 | case Instruction::USHR_INT_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2860 | work_line_->CheckBinaryOp2addr(this, inst, reg_types_.Integer(), reg_types_.Integer(), |
| 2861 | reg_types_.Integer(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2862 | break; |
| 2863 | case Instruction::AND_INT_2ADDR: |
| 2864 | case Instruction::OR_INT_2ADDR: |
| 2865 | case Instruction::XOR_INT_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2866 | work_line_->CheckBinaryOp2addr(this, inst, reg_types_.Integer(), reg_types_.Integer(), |
| 2867 | reg_types_.Integer(), true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2868 | break; |
| 2869 | case Instruction::DIV_INT_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2870 | work_line_->CheckBinaryOp2addr(this, inst, reg_types_.Integer(), reg_types_.Integer(), |
| 2871 | reg_types_.Integer(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2872 | break; |
| 2873 | case Instruction::ADD_LONG_2ADDR: |
| 2874 | case Instruction::SUB_LONG_2ADDR: |
| 2875 | case Instruction::MUL_LONG_2ADDR: |
| 2876 | case Instruction::DIV_LONG_2ADDR: |
| 2877 | case Instruction::REM_LONG_2ADDR: |
| 2878 | case Instruction::AND_LONG_2ADDR: |
| 2879 | case Instruction::OR_LONG_2ADDR: |
| 2880 | case Instruction::XOR_LONG_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2881 | work_line_->CheckBinaryOp2addrWide(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2882 | reg_types_.LongLo(), reg_types_.LongHi(), |
| 2883 | reg_types_.LongLo(), reg_types_.LongHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2884 | break; |
| 2885 | case Instruction::SHL_LONG_2ADDR: |
| 2886 | case Instruction::SHR_LONG_2ADDR: |
| 2887 | case Instruction::USHR_LONG_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2888 | work_line_->CheckBinaryOp2addrWideShift(this, inst, reg_types_.LongLo(), reg_types_.LongHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2889 | reg_types_.Integer()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2890 | break; |
| 2891 | case Instruction::ADD_FLOAT_2ADDR: |
| 2892 | case Instruction::SUB_FLOAT_2ADDR: |
| 2893 | case Instruction::MUL_FLOAT_2ADDR: |
| 2894 | case Instruction::DIV_FLOAT_2ADDR: |
| 2895 | case Instruction::REM_FLOAT_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2896 | work_line_->CheckBinaryOp2addr(this, inst, reg_types_.Float(), reg_types_.Float(), |
| 2897 | reg_types_.Float(), false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2898 | break; |
| 2899 | case Instruction::ADD_DOUBLE_2ADDR: |
| 2900 | case Instruction::SUB_DOUBLE_2ADDR: |
| 2901 | case Instruction::MUL_DOUBLE_2ADDR: |
| 2902 | case Instruction::DIV_DOUBLE_2ADDR: |
| 2903 | case Instruction::REM_DOUBLE_2ADDR: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2904 | work_line_->CheckBinaryOp2addrWide(this, inst, reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 2905 | reg_types_.DoubleLo(), reg_types_.DoubleHi(), |
| 2906 | reg_types_.DoubleLo(), reg_types_.DoubleHi()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2907 | break; |
| 2908 | case Instruction::ADD_INT_LIT16: |
Ian Rogers | f72a11d | 2014-10-30 15:41:08 -0700 | [diff] [blame] | 2909 | case Instruction::RSUB_INT_LIT16: |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2910 | case Instruction::MUL_INT_LIT16: |
| 2911 | case Instruction::DIV_INT_LIT16: |
| 2912 | case Instruction::REM_INT_LIT16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2913 | work_line_->CheckLiteralOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), false, |
| 2914 | true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2915 | break; |
| 2916 | case Instruction::AND_INT_LIT16: |
| 2917 | case Instruction::OR_INT_LIT16: |
| 2918 | case Instruction::XOR_INT_LIT16: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2919 | work_line_->CheckLiteralOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), true, |
| 2920 | true); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2921 | break; |
| 2922 | case Instruction::ADD_INT_LIT8: |
| 2923 | case Instruction::RSUB_INT_LIT8: |
| 2924 | case Instruction::MUL_INT_LIT8: |
| 2925 | case Instruction::DIV_INT_LIT8: |
| 2926 | case Instruction::REM_INT_LIT8: |
| 2927 | case Instruction::SHL_INT_LIT8: |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2928 | case Instruction::SHR_INT_LIT8: |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2929 | case Instruction::USHR_INT_LIT8: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2930 | work_line_->CheckLiteralOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), false, |
| 2931 | false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2932 | break; |
| 2933 | case Instruction::AND_INT_LIT8: |
| 2934 | case Instruction::OR_INT_LIT8: |
| 2935 | case Instruction::XOR_INT_LIT8: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 2936 | work_line_->CheckLiteralOp(this, inst, reg_types_.Integer(), reg_types_.Integer(), true, |
| 2937 | false); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 2938 | break; |
| 2939 | |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2940 | // Special instructions. |
Mathieu Chartier | d7cbf8a | 2015-03-19 12:43:20 -0700 | [diff] [blame] | 2941 | case Instruction::RETURN_VOID_NO_BARRIER: |
| 2942 | if (IsConstructor() && !IsStatic()) { |
| 2943 | auto& declaring_class = GetDeclaringClass(); |
Andreas Gampe | 68df320 | 2015-06-22 11:35:46 -0700 | [diff] [blame] | 2944 | if (declaring_class.IsUnresolvedReference()) { |
| 2945 | // We must iterate over the fields, even if we cannot use mirror classes to do so. Do it |
| 2946 | // manually over the underlying dex file. |
| 2947 | uint32_t first_index = GetFirstFinalInstanceFieldIndex(*dex_file_, |
| 2948 | dex_file_->GetMethodId(dex_method_idx_).class_idx_); |
| 2949 | if (first_index != DexFile::kDexNoIndex) { |
| 2950 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-void-no-barrier not expected for field " |
| 2951 | << first_index; |
| 2952 | } |
| 2953 | break; |
| 2954 | } |
Mathieu Chartier | d7cbf8a | 2015-03-19 12:43:20 -0700 | [diff] [blame] | 2955 | auto* klass = declaring_class.GetClass(); |
| 2956 | for (uint32_t i = 0, num_fields = klass->NumInstanceFields(); i < num_fields; ++i) { |
| 2957 | if (klass->GetInstanceField(i)->IsFinal()) { |
Mathieu Chartier | e86deef | 2015-03-19 13:43:37 -0700 | [diff] [blame] | 2958 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-void-no-barrier not expected for " |
| 2959 | << PrettyField(klass->GetInstanceField(i)); |
Mathieu Chartier | d7cbf8a | 2015-03-19 12:43:20 -0700 | [diff] [blame] | 2960 | break; |
| 2961 | } |
| 2962 | } |
Sebastien Hertz | cc10e0e | 2013-06-28 14:24:48 +0200 | [diff] [blame] | 2963 | } |
Andreas Gampe | b291796 | 2015-07-31 13:36:10 -0700 | [diff] [blame] | 2964 | // Handle this like a RETURN_VOID now. Code is duplicated to separate standard from |
| 2965 | // quickened opcodes (otherwise this could be a fall-through). |
| 2966 | if (!IsConstructor()) { |
| 2967 | if (!GetMethodReturnType().IsConflict()) { |
| 2968 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "return-void not expected"; |
| 2969 | } |
| 2970 | } |
Sebastien Hertz | cc10e0e | 2013-06-28 14:24:48 +0200 | [diff] [blame] | 2971 | break; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2972 | // Note: the following instructions encode offsets derived from class linking. |
| 2973 | // As such they use Class*/Field*/AbstractMethod* as these offsets only have |
| 2974 | // meaning if the class linking and resolution were successful. |
| 2975 | case Instruction::IGET_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2976 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Integer(), true); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2977 | break; |
| 2978 | case Instruction::IGET_WIDE_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2979 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.LongLo(), true); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2980 | break; |
| 2981 | case Instruction::IGET_OBJECT_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2982 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.JavaLangObject(false), false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2983 | break; |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 2984 | case Instruction::IGET_BOOLEAN_QUICK: |
| 2985 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Boolean(), true); |
| 2986 | break; |
| 2987 | case Instruction::IGET_BYTE_QUICK: |
| 2988 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Byte(), true); |
| 2989 | break; |
| 2990 | case Instruction::IGET_CHAR_QUICK: |
| 2991 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Char(), true); |
| 2992 | break; |
| 2993 | case Instruction::IGET_SHORT_QUICK: |
| 2994 | VerifyQuickFieldAccess<FieldAccessType::kAccGet>(inst, reg_types_.Short(), true); |
| 2995 | break; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2996 | case Instruction::IPUT_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 2997 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Integer(), true); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 2998 | break; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 2999 | case Instruction::IPUT_BOOLEAN_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3000 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Boolean(), true); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 3001 | break; |
| 3002 | case Instruction::IPUT_BYTE_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3003 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Byte(), true); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 3004 | break; |
| 3005 | case Instruction::IPUT_CHAR_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3006 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Char(), true); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 3007 | break; |
| 3008 | case Instruction::IPUT_SHORT_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3009 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.Short(), true); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 3010 | break; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3011 | case Instruction::IPUT_WIDE_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3012 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.LongLo(), true); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3013 | break; |
| 3014 | case Instruction::IPUT_OBJECT_QUICK: |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 3015 | VerifyQuickFieldAccess<FieldAccessType::kAccPut>(inst, reg_types_.JavaLangObject(false), false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3016 | break; |
| 3017 | case Instruction::INVOKE_VIRTUAL_QUICK: |
| 3018 | case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: { |
| 3019 | bool is_range = (inst->Opcode() == Instruction::INVOKE_VIRTUAL_RANGE_QUICK); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3020 | ArtMethod* called_method = VerifyInvokeVirtualQuickArgs(inst, is_range); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3021 | if (called_method != nullptr) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 3022 | const char* descriptor = called_method->GetReturnTypeDescriptor(); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3023 | const RegType& return_type = reg_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3024 | if (!return_type.IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3025 | work_line_->SetResultRegisterType(this, return_type); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3026 | } else { |
| 3027 | work_line_->SetResultRegisterTypeWide(return_type, return_type.HighHalf(®_types_)); |
| 3028 | } |
| 3029 | just_set_result = true; |
| 3030 | } |
| 3031 | break; |
| 3032 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 3033 | case Instruction::INVOKE_LAMBDA: { |
| 3034 | // Don't bother verifying, instead the interpreter will take the slow path with access checks. |
| 3035 | // If the code would've normally hard-failed, then the interpreter will throw the |
| 3036 | // appropriate verification errors at runtime. |
| 3037 | Fail(VERIFY_ERROR_FORCE_INTERPRETER); // TODO(iam): implement invoke-lambda verification |
| 3038 | break; |
| 3039 | } |
| 3040 | case Instruction::CREATE_LAMBDA: { |
| 3041 | // Don't bother verifying, instead the interpreter will take the slow path with access checks. |
| 3042 | // If the code would've normally hard-failed, then the interpreter will throw the |
| 3043 | // appropriate verification errors at runtime. |
| 3044 | Fail(VERIFY_ERROR_FORCE_INTERPRETER); // TODO(iam): implement create-lambda verification |
| 3045 | break; |
| 3046 | } |
| 3047 | |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 3048 | case Instruction::UNUSED_F4: |
| 3049 | case Instruction::UNUSED_F5: |
| 3050 | case Instruction::UNUSED_F7: { |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 3051 | DCHECK(false); // TODO(iam): Implement opcodes for lambdas |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 3052 | // Conservatively fail verification on release builds. |
| 3053 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Unexpected opcode " << inst->DumpString(dex_file_); |
| 3054 | break; |
| 3055 | } |
| 3056 | |
| 3057 | case Instruction::BOX_LAMBDA: { |
| 3058 | // Don't bother verifying, instead the interpreter will take the slow path with access checks. |
| 3059 | // If the code would've normally hard-failed, then the interpreter will throw the |
| 3060 | // appropriate verification errors at runtime. |
| 3061 | Fail(VERIFY_ERROR_FORCE_INTERPRETER); // TODO(iam): implement box-lambda verification |
Igor Murashkin | e2facc5 | 2015-07-10 13:49:08 -0700 | [diff] [blame] | 3062 | |
| 3063 | // Partial verification. Sets the resulting type to always be an object, which |
| 3064 | // is good enough for some other verification to occur without hard-failing. |
| 3065 | const uint32_t vreg_target_object = inst->VRegA_22x(); // box-lambda vA, vB |
| 3066 | const RegType& reg_type = reg_types_.JavaLangObject(need_precise_constants_); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 3067 | work_line_->SetRegisterType<LockOp::kClear>(this, vreg_target_object, reg_type); |
Igor Murashkin | 2ee54e2 | 2015-06-18 10:05:11 -0700 | [diff] [blame] | 3068 | break; |
| 3069 | } |
| 3070 | |
| 3071 | case Instruction::UNBOX_LAMBDA: { |
| 3072 | // Don't bother verifying, instead the interpreter will take the slow path with access checks. |
| 3073 | // If the code would've normally hard-failed, then the interpreter will throw the |
| 3074 | // appropriate verification errors at runtime. |
| 3075 | Fail(VERIFY_ERROR_FORCE_INTERPRETER); // TODO(iam): implement unbox-lambda verification |
| 3076 | break; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 3077 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3078 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3079 | /* These should never appear during verification. */ |
Mathieu Chartier | ffc605c | 2014-12-10 10:35:44 -0800 | [diff] [blame] | 3080 | case Instruction::UNUSED_3E ... Instruction::UNUSED_43: |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 3081 | case Instruction::UNUSED_FA ... Instruction::UNUSED_FF: |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3082 | case Instruction::UNUSED_79: |
| 3083 | case Instruction::UNUSED_7A: |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3084 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Unexpected opcode " << inst->DumpString(dex_file_); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3085 | break; |
| 3086 | |
| 3087 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3088 | * DO NOT add a "default" clause here. Without it the compiler will |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3089 | * complain if an instruction is missing (which is desirable). |
| 3090 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3091 | } // end - switch (dec_insn.opcode) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3092 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3093 | if (have_pending_hard_failure_) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 3094 | if (Runtime::Current()->IsAotCompiler()) { |
| 3095 | /* When AOT compiling, check that the last failure is a hard failure */ |
Andreas Gampe | b588f4c | 2015-05-26 13:35:39 -0700 | [diff] [blame] | 3096 | if (failures_[failures_.size() - 1] != VERIFY_ERROR_BAD_CLASS_HARD) { |
| 3097 | LOG(ERROR) << "Pending failures:"; |
| 3098 | for (auto& error : failures_) { |
| 3099 | LOG(ERROR) << error; |
| 3100 | } |
| 3101 | for (auto& error_msg : failure_messages_) { |
| 3102 | LOG(ERROR) << error_msg->str(); |
| 3103 | } |
| 3104 | LOG(FATAL) << "Pending hard failure, but last failure not hard."; |
| 3105 | } |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 3106 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3107 | /* immediate failure, reject class */ |
| 3108 | info_messages_ << "Rejecting opcode " << inst->DumpString(dex_file_); |
| 3109 | return false; |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 3110 | } else if (have_pending_runtime_throw_failure_) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 3111 | /* checking interpreter will throw, mark following code as unreachable */ |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 3112 | opcode_flags = Instruction::kThrow; |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 3113 | // Note: the flag must be reset as it is only global to decouple Fail and is semantically per |
| 3114 | // instruction. However, RETURN checking may throw LOCKING errors, so we clear at the |
| 3115 | // very end. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3116 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3117 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3118 | * If we didn't just set the result register, clear it out. This ensures that you can only use |
| 3119 | * "move-result" immediately after the result is set. (We could check this statically, but it's |
| 3120 | * not expensive and it makes our debugging output cleaner.) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3121 | */ |
| 3122 | if (!just_set_result) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3123 | work_line_->SetResultTypeToUnknown(this); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3126 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3127 | |
| 3128 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3129 | * Handle "branch". Tag the branch target. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3130 | * |
| 3131 | * NOTE: instructions like Instruction::EQZ provide information about the |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3132 | * state of the register when the branch is taken or not taken. For example, |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3133 | * somebody could get a reference field, check it for zero, and if the |
| 3134 | * branch is taken immediately store that register in a boolean field |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3135 | * since the value is known to be zero. We do not currently account for |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3136 | * that, and will reject the code. |
| 3137 | * |
| 3138 | * TODO: avoid re-fetching the branch target |
| 3139 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3140 | if ((opcode_flags & Instruction::kBranch) != 0) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3141 | bool isConditional, selfOkay; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3142 | if (!GetBranchOffset(work_insn_idx_, &branch_target, &isConditional, &selfOkay)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3143 | /* should never happen after static verification */ |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3144 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "bad branch"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3145 | return false; |
| 3146 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3147 | DCHECK_EQ(isConditional, (opcode_flags & Instruction::kContinue) != 0); |
Stephen Kyle | 9bc6199 | 2014-09-22 13:53:15 +0100 | [diff] [blame] | 3148 | if (!CheckNotMoveExceptionOrMoveResult(code_item_->insns_, work_insn_idx_ + branch_target)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3149 | return false; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3150 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3151 | /* update branch target, set "changed" if appropriate */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3152 | if (nullptr != branch_line.get()) { |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3153 | if (!UpdateRegisters(work_insn_idx_ + branch_target, branch_line.get(), false)) { |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3154 | return false; |
| 3155 | } |
| 3156 | } else { |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3157 | if (!UpdateRegisters(work_insn_idx_ + branch_target, work_line_.get(), false)) { |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3158 | return false; |
| 3159 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3160 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3164 | * Handle "switch". Tag all possible branch targets. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3165 | * |
| 3166 | * We've already verified that the table is structurally sound, so we |
| 3167 | * just need to walk through and tag the targets. |
| 3168 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3169 | if ((opcode_flags & Instruction::kSwitch) != 0) { |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 3170 | int offset_to_switch = insns[1] | (static_cast<int32_t>(insns[2]) << 16); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3171 | const uint16_t* switch_insns = insns + offset_to_switch; |
| 3172 | int switch_count = switch_insns[1]; |
| 3173 | int offset_to_targets, targ; |
| 3174 | |
| 3175 | if ((*insns & 0xff) == Instruction::PACKED_SWITCH) { |
| 3176 | /* 0 = sig, 1 = count, 2/3 = first key */ |
| 3177 | offset_to_targets = 4; |
| 3178 | } else { |
| 3179 | /* 0 = sig, 1 = count, 2..count * 2 = keys */ |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 3180 | DCHECK((*insns & 0xff) == Instruction::SPARSE_SWITCH); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3181 | offset_to_targets = 2 + 2 * switch_count; |
| 3182 | } |
| 3183 | |
| 3184 | /* verify each switch target */ |
| 3185 | for (targ = 0; targ < switch_count; targ++) { |
| 3186 | int offset; |
| 3187 | uint32_t abs_offset; |
| 3188 | |
| 3189 | /* offsets are 32-bit, and only partly endian-swapped */ |
| 3190 | offset = switch_insns[offset_to_targets + targ * 2] | |
Andreas Gampe | 53de99c | 2015-08-17 13:43:55 -0700 | [diff] [blame] | 3191 | (static_cast<int32_t>(switch_insns[offset_to_targets + targ * 2 + 1]) << 16); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3192 | abs_offset = work_insn_idx_ + offset; |
| 3193 | DCHECK_LT(abs_offset, code_item_->insns_size_in_code_units_); |
Stephen Kyle | 9bc6199 | 2014-09-22 13:53:15 +0100 | [diff] [blame] | 3194 | if (!CheckNotMoveExceptionOrMoveResult(code_item_->insns_, abs_offset)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3195 | return false; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3196 | } |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3197 | if (!UpdateRegisters(abs_offset, work_line_.get(), false)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3198 | return false; |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3199 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3204 | * Handle instructions that can throw and that are sitting in a "try" block. (If they're not in a |
| 3205 | * "try" block when they throw, control transfers out of the method.) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3206 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3207 | if ((opcode_flags & Instruction::kThrow) != 0 && insn_flags_[work_insn_idx_].IsInTry()) { |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3208 | bool has_catch_all_handler = false; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 3209 | CatchHandlerIterator iterator(*code_item_, work_insn_idx_); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3210 | |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3211 | // Need the linker to try and resolve the handled class to check if it's Throwable. |
| 3212 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
| 3213 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 3214 | for (; iterator.HasNext(); iterator.Next()) { |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3215 | uint16_t handler_type_idx = iterator.GetHandlerTypeIndex(); |
| 3216 | if (handler_type_idx == DexFile::kDexNoIndex16) { |
| 3217 | has_catch_all_handler = true; |
| 3218 | } else { |
| 3219 | // It is also a catch-all if it is java.lang.Throwable. |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 3220 | mirror::Class* klass = linker->ResolveType(*dex_file_, handler_type_idx, dex_cache_, |
| 3221 | class_loader_); |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3222 | if (klass != nullptr) { |
| 3223 | if (klass == mirror::Throwable::GetJavaLangThrowable()) { |
| 3224 | has_catch_all_handler = true; |
| 3225 | } |
| 3226 | } else { |
| 3227 | // Clear exception. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3228 | DCHECK(self_->IsExceptionPending()); |
| 3229 | self_->ClearException(); |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3230 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3231 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3232 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3233 | * Merge registers into the "catch" block. We want to use the "savedRegs" rather than |
| 3234 | * "work_regs", because at runtime the exception will be thrown before the instruction |
| 3235 | * modifies any registers. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3236 | */ |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3237 | if (!UpdateRegisters(iterator.GetHandlerAddress(), saved_line_.get(), false)) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3238 | return false; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3239 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3243 | * If the monitor stack depth is nonzero, there must be a "catch all" handler for this |
| 3244 | * instruction. This does apply to monitor-exit because of async exception handling. |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3245 | */ |
Andreas Gampe | f91baf1 | 2014-07-18 15:41:00 -0700 | [diff] [blame] | 3246 | if (work_line_->MonitorStackDepth() > 0 && !has_catch_all_handler) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3247 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3248 | * The state in work_line reflects the post-execution state. If the current instruction is a |
| 3249 | * monitor-enter and the monitor stack was empty, we don't need a catch-all (if it throws, |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3250 | * it will do so before grabbing the lock). |
| 3251 | */ |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3252 | if (inst->Opcode() != Instruction::MONITOR_ENTER || work_line_->MonitorStackDepth() != 1) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3253 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3254 | << "expected to be within a catch-all for an instruction where a monitor is held"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3255 | return false; |
| 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3260 | /* Handle "continue". Tag the next consecutive instruction. |
| 3261 | * Note: Keep the code handling "continue" case below the "branch" and "switch" cases, |
| 3262 | * because it changes work_line_ when performing peephole optimization |
| 3263 | * and this change should not be used in those cases. |
| 3264 | */ |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3265 | if ((opcode_flags & Instruction::kContinue) != 0) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3266 | DCHECK_EQ(Instruction::At(code_item_->insns_ + work_insn_idx_), inst); |
| 3267 | uint32_t next_insn_idx = work_insn_idx_ + inst->SizeInCodeUnits(); |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3268 | if (next_insn_idx >= code_item_->insns_size_in_code_units_) { |
| 3269 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Execution can walk off end of code area"; |
| 3270 | return false; |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3271 | } |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3272 | // The only way to get to a move-exception instruction is to get thrown there. Make sure the |
| 3273 | // next instruction isn't one. |
| 3274 | if (!CheckNotMoveException(code_item_->insns_, next_insn_idx)) { |
| 3275 | return false; |
| 3276 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3277 | if (nullptr != fallthrough_line.get()) { |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3278 | // Make workline consistent with fallthrough computed from peephole optimization. |
| 3279 | work_line_->CopyFromLine(fallthrough_line.get()); |
| 3280 | } |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 3281 | if (insn_flags_[next_insn_idx].IsReturn()) { |
| 3282 | // For returns we only care about the operand to the return, all other registers are dead. |
| 3283 | const Instruction* ret_inst = Instruction::At(code_item_->insns_ + next_insn_idx); |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 3284 | AdjustReturnLine(this, ret_inst, work_line_.get()); |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 3285 | } |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3286 | RegisterLine* next_line = reg_table_.GetLine(next_insn_idx); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3287 | if (next_line != nullptr) { |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 3288 | // Merge registers into what we have for the next instruction, and set the "changed" flag if |
| 3289 | // needed. If the merge changes the state of the registers then the work line will be |
| 3290 | // updated. |
| 3291 | if (!UpdateRegisters(next_insn_idx, work_line_.get(), true)) { |
Ian Rogers | 6d376ae | 2013-07-23 15:12:40 -0700 | [diff] [blame] | 3292 | return false; |
| 3293 | } |
| 3294 | } else { |
| 3295 | /* |
| 3296 | * We're not recording register data for the next instruction, so we don't know what the |
| 3297 | * prior state was. We have to assume that something has changed and re-evaluate it. |
| 3298 | */ |
| 3299 | insn_flags_[next_insn_idx].SetChanged(); |
| 3300 | } |
| 3301 | } |
Dragos Sbirlea | 2b87ddf | 2013-05-28 14:14:12 -0700 | [diff] [blame] | 3302 | |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3303 | /* If we're returning from the method, make sure monitor stack is empty. */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3304 | if ((opcode_flags & Instruction::kReturn) != 0) { |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 3305 | work_line_->VerifyMonitorStackEmpty(this); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | /* |
jeffhao | d1f0fde | 2011-09-08 17:25:33 -0700 | [diff] [blame] | 3309 | * Update start_guess. Advance to the next instruction of that's |
| 3310 | * possible, otherwise use the branch target if one was found. If |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3311 | * neither of those exists we're in a return or throw; leave start_guess |
| 3312 | * alone and let the caller sort it out. |
| 3313 | */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3314 | if ((opcode_flags & Instruction::kContinue) != 0) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3315 | DCHECK_EQ(Instruction::At(code_item_->insns_ + work_insn_idx_), inst); |
| 3316 | *start_guess = work_insn_idx_ + inst->SizeInCodeUnits(); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3317 | } else if ((opcode_flags & Instruction::kBranch) != 0) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3318 | /* we're still okay if branch_target is zero */ |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3319 | *start_guess = work_insn_idx_ + branch_target; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3322 | DCHECK_LT(*start_guess, code_item_->insns_size_in_code_units_); |
| 3323 | DCHECK(insn_flags_[*start_guess].IsOpcode()); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3324 | |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 3325 | if (have_pending_runtime_throw_failure_) { |
| 3326 | have_any_pending_runtime_throw_failure_ = true; |
| 3327 | // Reset the pending_runtime_throw flag now. |
| 3328 | have_pending_runtime_throw_failure_ = false; |
| 3329 | } |
| 3330 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3331 | return true; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 3332 | } // NOLINT(readability/fn_size) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 3333 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3334 | const RegType& MethodVerifier::ResolveClassAndCheckAccess(uint32_t class_idx) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 3335 | const char* descriptor = dex_file_->StringByTypeIdx(class_idx); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3336 | const RegType& referrer = GetDeclaringClass(); |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 3337 | mirror::Class* klass = dex_cache_->GetResolvedType(class_idx); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3338 | const RegType& result = klass != nullptr ? |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 3339 | FromClass(descriptor, klass, klass->CannotBeAssignedFromOtherTypes()) : |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 3340 | reg_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3341 | if (result.IsConflict()) { |
| 3342 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "accessing broken descriptor '" << descriptor |
| 3343 | << "' in " << referrer; |
| 3344 | return result; |
| 3345 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3346 | if (klass == nullptr && !result.IsUnresolvedTypes()) { |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 3347 | dex_cache_->SetResolvedType(class_idx, result.GetClass()); |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 3348 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3349 | // Check if access is allowed. Unresolved types use xxxWithAccessCheck to |
Jeff Hao | b24b4a7 | 2013-07-31 13:47:31 -0700 | [diff] [blame] | 3350 | // check at runtime if access is allowed and so pass here. If result is |
| 3351 | // primitive, skip the access check. |
| 3352 | if (result.IsNonZeroReferenceTypes() && !result.IsUnresolvedTypes() && |
| 3353 | !referrer.IsUnresolvedTypes() && !referrer.CanAccess(result)) { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 3354 | Fail(VERIFY_ERROR_ACCESS_CLASS) << "illegal class access: '" |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3355 | << referrer << "' -> '" << result << "'"; |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 3356 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3357 | return result; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3360 | const RegType& MethodVerifier::GetCaughtExceptionType() { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3361 | const RegType* common_super = nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3362 | if (code_item_->tries_size_ != 0) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 3363 | const uint8_t* handlers_ptr = DexFile::GetCatchHandlerData(*code_item_, 0); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3364 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 3365 | for (uint32_t i = 0; i < handlers_size; i++) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 3366 | CatchHandlerIterator iterator(handlers_ptr); |
| 3367 | for (; iterator.HasNext(); iterator.Next()) { |
| 3368 | if (iterator.GetHandlerAddress() == (uint32_t) work_insn_idx_) { |
| 3369 | if (iterator.GetHandlerTypeIndex() == DexFile::kDexNoIndex16) { |
Ian Rogers | b490357 | 2012-10-11 11:52:56 -0700 | [diff] [blame] | 3370 | common_super = ®_types_.JavaLangThrowable(false); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3371 | } else { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3372 | const RegType& exception = ResolveClassAndCheckAccess(iterator.GetHandlerTypeIndex()); |
Jeff Hao | b878f21 | 2014-04-24 16:25:36 -0700 | [diff] [blame] | 3373 | if (!reg_types_.JavaLangThrowable(false).IsAssignableFrom(exception)) { |
Jeff Hao | c26a56c | 2013-11-04 12:00:47 -0800 | [diff] [blame] | 3374 | if (exception.IsUnresolvedTypes()) { |
| 3375 | // We don't know enough about the type. Fail here and let runtime handle it. |
| 3376 | Fail(VERIFY_ERROR_NO_CLASS) << "unresolved exception class " << exception; |
| 3377 | return exception; |
| 3378 | } else { |
| 3379 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "unexpected non-exception class " << exception; |
| 3380 | return reg_types_.Conflict(); |
| 3381 | } |
Jeff Hao | b878f21 | 2014-04-24 16:25:36 -0700 | [diff] [blame] | 3382 | } else if (common_super == nullptr) { |
| 3383 | common_super = &exception; |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 3384 | } else if (common_super->Equals(exception)) { |
Ian Rogers | c476227 | 2012-02-01 15:55:55 -0800 | [diff] [blame] | 3385 | // odd case, but nothing to do |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3386 | } else { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 3387 | common_super = &common_super->Merge(exception, ®_types_); |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3388 | if (FailOrAbort(this, |
| 3389 | reg_types_.JavaLangThrowable(false).IsAssignableFrom(*common_super), |
| 3390 | "java.lang.Throwable is not assignable-from common_super at ", |
| 3391 | work_insn_idx_)) { |
| 3392 | break; |
| 3393 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | } |
| 3397 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 3398 | handlers_ptr = iterator.EndDataPointer(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3399 | } |
| 3400 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3401 | if (common_super == nullptr) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3402 | /* no catch blocks, or no catches with classes we can find */ |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3403 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "unable to find exception handler"; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3404 | return reg_types_.Conflict(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3405 | } |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 3406 | return *common_super; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3409 | ArtMethod* MethodVerifier::ResolveMethodAndCheckAccess( |
| 3410 | uint32_t dex_method_idx, MethodType method_type) { |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3411 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3412 | const RegType& klass_type = ResolveClassAndCheckAccess(method_id.class_idx_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3413 | if (klass_type.IsConflict()) { |
| 3414 | std::string append(" in attempt to access method "); |
| 3415 | append += dex_file_->GetMethodName(method_id); |
| 3416 | AppendToLastFailMessage(append); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3417 | return nullptr; |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 3418 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3419 | if (klass_type.IsUnresolvedTypes()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3420 | return nullptr; // Can't resolve Class so no more to do here |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 3421 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 3422 | mirror::Class* klass = klass_type.GetClass(); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3423 | const RegType& referrer = GetDeclaringClass(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3424 | auto* cl = Runtime::Current()->GetClassLinker(); |
| 3425 | auto pointer_size = cl->GetImagePointerSize(); |
| 3426 | ArtMethod* res_method = dex_cache_->GetResolvedMethod(dex_method_idx, pointer_size); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3427 | if (res_method == nullptr) { |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 3428 | const char* name = dex_file_->GetMethodName(method_id); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 3429 | const Signature signature = dex_file_->GetMethodSignature(method_id); |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3430 | |
| 3431 | if (method_type == METHOD_DIRECT || method_type == METHOD_STATIC) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3432 | res_method = klass->FindDirectMethod(name, signature, pointer_size); |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3433 | } else if (method_type == METHOD_INTERFACE) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3434 | res_method = klass->FindInterfaceMethod(name, signature, pointer_size); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3435 | } else { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3436 | res_method = klass->FindVirtualMethod(name, signature, pointer_size); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3437 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3438 | if (res_method != nullptr) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3439 | dex_cache_->SetResolvedMethod(dex_method_idx, res_method, pointer_size); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3440 | } else { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3441 | // If a virtual or interface method wasn't found with the expected type, look in |
| 3442 | // the direct methods. This can happen when the wrong invoke type is used or when |
| 3443 | // a class has changed, and will be flagged as an error in later checks. |
| 3444 | if (method_type == METHOD_INTERFACE || method_type == METHOD_VIRTUAL) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3445 | res_method = klass->FindDirectMethod(name, signature, pointer_size); |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3446 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3447 | if (res_method == nullptr) { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3448 | Fail(VERIFY_ERROR_NO_METHOD) << "couldn't find method " |
| 3449 | << PrettyDescriptor(klass) << "." << name |
| 3450 | << " " << signature; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3451 | return nullptr; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3452 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3453 | } |
| 3454 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3455 | // Make sure calls to constructors are "direct". There are additional restrictions but we don't |
| 3456 | // enforce them here. |
| 3457 | if (res_method->IsConstructor() && method_type != METHOD_DIRECT) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3458 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "rejecting non-direct call to constructor " |
| 3459 | << PrettyMethod(res_method); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3460 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3461 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3462 | // Disallow any calls to class initializers. |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 3463 | if (res_method->IsClassInitializer()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3464 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "rejecting call to class initializer " |
| 3465 | << PrettyMethod(res_method); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3466 | return nullptr; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3467 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3468 | // Check if access is allowed. |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3469 | if (!referrer.CanAccessMember(res_method->GetDeclaringClass(), res_method->GetAccessFlags())) { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3470 | Fail(VERIFY_ERROR_ACCESS_METHOD) << "illegal method access (call " << PrettyMethod(res_method) |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3471 | << " from " << referrer << ")"; |
jeffhao | b57e952 | 2012-04-26 18:08:21 -0700 | [diff] [blame] | 3472 | return res_method; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3473 | } |
jeffhao | de0d9c9 | 2012-02-27 13:58:13 -0800 | [diff] [blame] | 3474 | // Check that invoke-virtual and invoke-super are not used on private methods of the same class. |
| 3475 | if (res_method->IsPrivate() && method_type == METHOD_VIRTUAL) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3476 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invoke-super/virtual can't be used on private method " |
| 3477 | << PrettyMethod(res_method); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3478 | return nullptr; |
jeffhao | de0d9c9 | 2012-02-27 13:58:13 -0800 | [diff] [blame] | 3479 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3480 | // Check that interface methods match interface classes. |
| 3481 | if (klass->IsInterface() && method_type != METHOD_INTERFACE) { |
| 3482 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "non-interface method " << PrettyMethod(res_method) |
| 3483 | << " is in an interface class " << PrettyClass(klass); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3484 | return nullptr; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3485 | } else if (!klass->IsInterface() && method_type == METHOD_INTERFACE) { |
| 3486 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "interface method " << PrettyMethod(res_method) |
| 3487 | << " is in a non-interface class " << PrettyClass(klass); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3488 | return nullptr; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3489 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3490 | // See if the method type implied by the invoke instruction matches the access flags for the |
| 3491 | // target method. |
Brian Carlstrom | be6fa5e | 2014-12-09 20:15:42 -0800 | [diff] [blame] | 3492 | if ((method_type == METHOD_DIRECT && (!res_method->IsDirect() || res_method->IsStatic())) || |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3493 | (method_type == METHOD_STATIC && !res_method->IsStatic()) || |
| 3494 | ((method_type == METHOD_VIRTUAL || method_type == METHOD_INTERFACE) && res_method->IsDirect()) |
| 3495 | ) { |
Ian Rogers | 2fc1427 | 2012-08-30 10:56:57 -0700 | [diff] [blame] | 3496 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "invoke type (" << method_type << ") does not match method " |
| 3497 | " type of " << PrettyMethod(res_method); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3498 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3499 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3500 | return res_method; |
| 3501 | } |
| 3502 | |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3503 | template <class T> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3504 | ArtMethod* MethodVerifier::VerifyInvocationArgsFromIterator( |
| 3505 | T* it, const Instruction* inst, MethodType method_type, bool is_range, ArtMethod* res_method) { |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3506 | // We use vAA as our expected arg count, rather than res_method->insSize, because we need to |
| 3507 | // match the call to the signature. Also, we might be calling through an abstract method |
| 3508 | // definition (which doesn't have register count values). |
| 3509 | const size_t expected_args = (is_range) ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 3510 | /* caught by static verifier */ |
| 3511 | DCHECK(is_range || expected_args <= 5); |
| 3512 | if (expected_args > code_item_->outs_size_) { |
| 3513 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid argument count (" << expected_args |
| 3514 | << ") exceeds outsSize (" << code_item_->outs_size_ << ")"; |
| 3515 | return nullptr; |
| 3516 | } |
| 3517 | |
| 3518 | uint32_t arg[5]; |
| 3519 | if (!is_range) { |
| 3520 | inst->GetVarArgs(arg); |
| 3521 | } |
| 3522 | uint32_t sig_registers = 0; |
| 3523 | |
| 3524 | /* |
| 3525 | * Check the "this" argument, which must be an instance of the class that declared the method. |
| 3526 | * For an interface class, we don't do the full interface merge (see JoinClass), so we can't do a |
| 3527 | * rigorous check here (which is okay since we have to do it at runtime). |
| 3528 | */ |
| 3529 | if (method_type != METHOD_STATIC) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3530 | const RegType& actual_arg_type = work_line_->GetInvocationThis(this, inst, is_range); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3531 | if (actual_arg_type.IsConflict()) { // GetInvocationThis failed. |
| 3532 | CHECK(have_pending_hard_failure_); |
| 3533 | return nullptr; |
| 3534 | } |
| 3535 | if (actual_arg_type.IsUninitializedReference()) { |
| 3536 | if (res_method) { |
| 3537 | if (!res_method->IsConstructor()) { |
| 3538 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "'this' arg must be initialized"; |
| 3539 | return nullptr; |
| 3540 | } |
| 3541 | } else { |
| 3542 | // Check whether the name of the called method is "<init>" |
| 3543 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Jeff Hao | 0d08727 | 2014-08-04 14:47:17 -0700 | [diff] [blame] | 3544 | if (strcmp(dex_file_->GetMethodName(dex_file_->GetMethodId(method_idx)), "<init>") != 0) { |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3545 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "'this' arg must be initialized"; |
| 3546 | return nullptr; |
| 3547 | } |
| 3548 | } |
| 3549 | } |
| 3550 | if (method_type != METHOD_INTERFACE && !actual_arg_type.IsZero()) { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3551 | const RegType* res_method_class; |
Andreas Gampe | d9e2301 | 2015-06-04 22:19:58 -0700 | [diff] [blame] | 3552 | // Miranda methods have the declaring interface as their declaring class, not the abstract |
| 3553 | // class. It would be wrong to use this for the type check (interface type checks are |
| 3554 | // postponed to runtime). |
| 3555 | if (res_method != nullptr && !res_method->IsMiranda()) { |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3556 | mirror::Class* klass = res_method->GetDeclaringClass(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 3557 | std::string temp; |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 3558 | res_method_class = &FromClass(klass->GetDescriptor(&temp), klass, |
| 3559 | klass->CannotBeAssignedFromOtherTypes()); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3560 | } else { |
| 3561 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 3562 | const uint16_t class_idx = dex_file_->GetMethodId(method_idx).class_idx_; |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 3563 | res_method_class = ®_types_.FromDescriptor(GetClassLoader(), |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3564 | dex_file_->StringByTypeIdx(class_idx), |
| 3565 | false); |
| 3566 | } |
| 3567 | if (!res_method_class->IsAssignableFrom(actual_arg_type)) { |
| 3568 | Fail(actual_arg_type.IsUnresolvedTypes() ? VERIFY_ERROR_NO_CLASS: |
| 3569 | VERIFY_ERROR_BAD_CLASS_SOFT) << "'this' argument '" << actual_arg_type |
| 3570 | << "' not instance of '" << *res_method_class << "'"; |
| 3571 | // Continue on soft failures. We need to find possible hard failures to avoid problems in |
| 3572 | // the compiler. |
| 3573 | if (have_pending_hard_failure_) { |
| 3574 | return nullptr; |
| 3575 | } |
| 3576 | } |
| 3577 | } |
| 3578 | sig_registers = 1; |
| 3579 | } |
| 3580 | |
| 3581 | for ( ; it->HasNext(); it->Next()) { |
| 3582 | if (sig_registers >= expected_args) { |
| 3583 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation, expected " << inst->VRegA() << |
| 3584 | " arguments, found " << sig_registers << " or more."; |
| 3585 | return nullptr; |
| 3586 | } |
| 3587 | |
| 3588 | const char* param_descriptor = it->GetDescriptor(); |
| 3589 | |
| 3590 | if (param_descriptor == nullptr) { |
| 3591 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation because of missing signature " |
| 3592 | "component"; |
| 3593 | return nullptr; |
| 3594 | } |
| 3595 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3596 | const RegType& reg_type = reg_types_.FromDescriptor(GetClassLoader(), param_descriptor, false); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3597 | uint32_t get_reg = is_range ? inst->VRegC_3rc() + static_cast<uint32_t>(sig_registers) : |
| 3598 | arg[sig_registers]; |
| 3599 | if (reg_type.IsIntegralTypes()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3600 | const RegType& src_type = work_line_->GetRegisterType(this, get_reg); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3601 | if (!src_type.IsIntegralTypes()) { |
| 3602 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "register v" << get_reg << " has type " << src_type |
| 3603 | << " but expected " << reg_type; |
Andreas Gampe | b588f4c | 2015-05-26 13:35:39 -0700 | [diff] [blame] | 3604 | return nullptr; |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3605 | } |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 3606 | } else { |
| 3607 | if (!work_line_->VerifyRegisterType(this, get_reg, reg_type)) { |
| 3608 | // Continue on soft failures. We need to find possible hard failures to avoid problems in |
| 3609 | // the compiler. |
| 3610 | if (have_pending_hard_failure_) { |
| 3611 | return nullptr; |
| 3612 | } |
| 3613 | } else if (reg_type.IsLongOrDoubleTypes()) { |
| 3614 | // Check that registers are consecutive (for non-range invokes). Invokes are the only |
| 3615 | // instructions not specifying register pairs by the first component, but require them |
| 3616 | // nonetheless. Only check when there's an actual register in the parameters. If there's |
| 3617 | // none, this will fail below. |
| 3618 | if (!is_range && sig_registers + 1 < expected_args) { |
| 3619 | uint32_t second_reg = arg[sig_registers + 1]; |
| 3620 | if (second_reg != get_reg + 1) { |
| 3621 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation, long or double parameter " |
| 3622 | "at index " << sig_registers << " is not a pair: " << get_reg << " + " |
| 3623 | << second_reg << "."; |
| 3624 | return nullptr; |
| 3625 | } |
| 3626 | } |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3627 | } |
| 3628 | } |
| 3629 | sig_registers += reg_type.IsLongOrDoubleTypes() ? 2 : 1; |
| 3630 | } |
| 3631 | if (expected_args != sig_registers) { |
| 3632 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation, expected " << expected_args << |
| 3633 | " arguments, found " << sig_registers; |
| 3634 | return nullptr; |
| 3635 | } |
| 3636 | return res_method; |
| 3637 | } |
| 3638 | |
| 3639 | void MethodVerifier::VerifyInvocationArgsUnresolvedMethod(const Instruction* inst, |
| 3640 | MethodType method_type, |
| 3641 | bool is_range) { |
| 3642 | // As the method may not have been resolved, make this static check against what we expect. |
| 3643 | // The main reason for this code block is to fail hard when we find an illegal use, e.g., |
| 3644 | // wrong number of arguments or wrong primitive types, even if the method could not be resolved. |
| 3645 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
| 3646 | DexFileParameterIterator it(*dex_file_, |
| 3647 | dex_file_->GetProtoId(dex_file_->GetMethodId(method_idx).proto_idx_)); |
| 3648 | VerifyInvocationArgsFromIterator<DexFileParameterIterator>(&it, inst, method_type, is_range, |
| 3649 | nullptr); |
| 3650 | } |
| 3651 | |
| 3652 | class MethodParamListDescriptorIterator { |
| 3653 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3654 | explicit MethodParamListDescriptorIterator(ArtMethod* res_method) : |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3655 | res_method_(res_method), pos_(0), params_(res_method->GetParameterTypeList()), |
| 3656 | params_size_(params_ == nullptr ? 0 : params_->Size()) { |
| 3657 | } |
| 3658 | |
| 3659 | bool HasNext() { |
| 3660 | return pos_ < params_size_; |
| 3661 | } |
| 3662 | |
| 3663 | void Next() { |
| 3664 | ++pos_; |
| 3665 | } |
| 3666 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 3667 | const char* GetDescriptor() SHARED_REQUIRES(Locks::mutator_lock_) { |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3668 | return res_method_->GetTypeDescriptorFromTypeIdx(params_->GetTypeItem(pos_).type_idx_); |
| 3669 | } |
| 3670 | |
| 3671 | private: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3672 | ArtMethod* res_method_; |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3673 | size_t pos_; |
| 3674 | const DexFile::TypeList* params_; |
| 3675 | const size_t params_size_; |
| 3676 | }; |
| 3677 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3678 | ArtMethod* MethodVerifier::VerifyInvocationArgs( |
| 3679 | const Instruction* inst, MethodType method_type, bool is_range, bool is_super) { |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3680 | // Resolve the method. This could be an abstract or concrete method depending on what sort of call |
| 3681 | // we're making. |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3682 | const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Andreas Gampe | acc4d2f | 2014-06-12 19:35:05 -0700 | [diff] [blame] | 3683 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3684 | ArtMethod* res_method = ResolveMethodAndCheckAccess(method_idx, method_type); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3685 | if (res_method == nullptr) { // error or class is unresolved |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3686 | // Check what we can statically. |
| 3687 | if (!have_pending_hard_failure_) { |
| 3688 | VerifyInvocationArgsUnresolvedMethod(inst, method_type, is_range); |
| 3689 | } |
| 3690 | return nullptr; |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 3691 | } |
| 3692 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3693 | // If we're using invoke-super(method), make sure that the executing method's class' superclass |
| 3694 | // has a vtable entry for the target method. |
| 3695 | if (is_super) { |
| 3696 | DCHECK(method_type == METHOD_VIRTUAL); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3697 | const RegType& super = GetDeclaringClass().GetSuperClass(®_types_); |
Ian Rogers | 529781d | 2012-07-23 17:24:29 -0700 | [diff] [blame] | 3698 | if (super.IsUnresolvedTypes()) { |
jeffhao | 4d8df82 | 2012-04-24 17:09:36 -0700 | [diff] [blame] | 3699 | Fail(VERIFY_ERROR_NO_METHOD) << "unknown super class in invoke-super from " |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3700 | << PrettyMethod(dex_method_idx_, *dex_file_) |
jeffhao | 4d8df82 | 2012-04-24 17:09:36 -0700 | [diff] [blame] | 3701 | << " to super " << PrettyMethod(res_method); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3702 | return nullptr; |
jeffhao | 4d8df82 | 2012-04-24 17:09:36 -0700 | [diff] [blame] | 3703 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 3704 | mirror::Class* super_klass = super.GetClass(); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 3705 | if (res_method->GetMethodIndex() >= super_klass->GetVTableLength()) { |
jeffhao | 4d8df82 | 2012-04-24 17:09:36 -0700 | [diff] [blame] | 3706 | Fail(VERIFY_ERROR_NO_METHOD) << "invalid invoke-super from " |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3707 | << PrettyMethod(dex_method_idx_, *dex_file_) |
jeffhao | 4d8df82 | 2012-04-24 17:09:36 -0700 | [diff] [blame] | 3708 | << " to super " << super |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 3709 | << "." << res_method->GetName() |
| 3710 | << res_method->GetSignature(); |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3711 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3712 | } |
| 3713 | } |
Ian Rogers | 7b0c5b4 | 2012-02-16 15:29:07 -0800 | [diff] [blame] | 3714 | |
Andreas Gampe | 95c0bf8 | 2014-06-16 14:06:52 -0700 | [diff] [blame] | 3715 | // Process the target method's signature. This signature may or may not |
| 3716 | MethodParamListDescriptorIterator it(res_method); |
| 3717 | return VerifyInvocationArgsFromIterator<MethodParamListDescriptorIterator>(&it, inst, method_type, |
| 3718 | is_range, res_method); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3719 | } |
| 3720 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3721 | ArtMethod* MethodVerifier::GetQuickInvokedMethod(const Instruction* inst, RegisterLine* reg_line, |
| 3722 | bool is_range, bool allow_failure) { |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 3723 | if (is_range) { |
| 3724 | DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_VIRTUAL_RANGE_QUICK); |
| 3725 | } else { |
| 3726 | DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_VIRTUAL_QUICK); |
| 3727 | } |
| 3728 | const RegType& actual_arg_type = reg_line->GetInvocationThis(this, inst, is_range, allow_failure); |
Ian Rogers | 9bc5440 | 2014-04-17 16:40:01 -0700 | [diff] [blame] | 3729 | if (!actual_arg_type.HasClass()) { |
| 3730 | VLOG(verifier) << "Failed to get mirror::Class* from '" << actual_arg_type << "'"; |
Andreas Gampe | 6398156 | 2014-04-17 12:28:43 -0700 | [diff] [blame] | 3731 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3732 | } |
Ian Rogers | a4cf1df | 2014-05-07 19:47:17 -0700 | [diff] [blame] | 3733 | mirror::Class* klass = actual_arg_type.GetClass(); |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 3734 | mirror::Class* dispatch_class; |
Ian Rogers | a4cf1df | 2014-05-07 19:47:17 -0700 | [diff] [blame] | 3735 | if (klass->IsInterface()) { |
| 3736 | // Derive Object.class from Class.class.getSuperclass(). |
| 3737 | mirror::Class* object_klass = klass->GetClass()->GetSuperClass(); |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3738 | if (FailOrAbort(this, object_klass->IsObjectClass(), |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 3739 | "Failed to find Object class in quickened invoke receiver", work_insn_idx_)) { |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3740 | return nullptr; |
| 3741 | } |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 3742 | dispatch_class = object_klass; |
Ian Rogers | a4cf1df | 2014-05-07 19:47:17 -0700 | [diff] [blame] | 3743 | } else { |
Mingyao Yang | 2cdbad7 | 2014-07-16 10:44:41 -0700 | [diff] [blame] | 3744 | dispatch_class = klass; |
Ian Rogers | a4cf1df | 2014-05-07 19:47:17 -0700 | [diff] [blame] | 3745 | } |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 3746 | if (!dispatch_class->HasVTable()) { |
| 3747 | FailOrAbort(this, allow_failure, "Receiver class has no vtable for quickened invoke at ", |
| 3748 | work_insn_idx_); |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3749 | return nullptr; |
| 3750 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3751 | uint16_t vtable_index = is_range ? inst->VRegB_3rc() : inst->VRegB_35c(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3752 | auto* cl = Runtime::Current()->GetClassLinker(); |
| 3753 | auto pointer_size = cl->GetImagePointerSize(); |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 3754 | if (static_cast<int32_t>(vtable_index) >= dispatch_class->GetVTableLength()) { |
| 3755 | FailOrAbort(this, allow_failure, |
| 3756 | "Receiver class has not enough vtable slots for quickened invoke at ", |
| 3757 | work_insn_idx_); |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3758 | return nullptr; |
| 3759 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3760 | ArtMethod* res_method = dispatch_class->GetVTableEntry(vtable_index, pointer_size); |
Mathieu Chartier | 091d238 | 2015-03-06 10:59:06 -0800 | [diff] [blame] | 3761 | if (self_->IsExceptionPending()) { |
| 3762 | FailOrAbort(this, allow_failure, "Unexpected exception pending for quickened invoke at ", |
| 3763 | work_insn_idx_); |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3764 | return nullptr; |
| 3765 | } |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 3766 | return res_method; |
| 3767 | } |
| 3768 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3769 | ArtMethod* MethodVerifier::VerifyInvokeVirtualQuickArgs(const Instruction* inst, bool is_range) { |
Andreas Gampe | 76bd880 | 2014-12-10 16:43:58 -0800 | [diff] [blame] | 3770 | DCHECK(Runtime::Current()->IsStarted() || verify_to_dump_) |
| 3771 | << PrettyMethod(dex_method_idx_, *dex_file_, true) << "@" << work_insn_idx_; |
| 3772 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 3773 | ArtMethod* res_method = GetQuickInvokedMethod(inst, work_line_.get(), is_range, false); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3774 | if (res_method == nullptr) { |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 3775 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Cannot infer method from " << inst->Name(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3776 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3777 | } |
Andreas Gampe | 7c03810 | 2014-10-27 20:08:46 -0700 | [diff] [blame] | 3778 | if (FailOrAbort(this, !res_method->IsDirect(), "Quick-invoked method is direct at ", |
| 3779 | work_insn_idx_)) { |
| 3780 | return nullptr; |
| 3781 | } |
| 3782 | if (FailOrAbort(this, !res_method->IsStatic(), "Quick-invoked method is static at ", |
| 3783 | work_insn_idx_)) { |
| 3784 | return nullptr; |
| 3785 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3786 | |
| 3787 | // We use vAA as our expected arg count, rather than res_method->insSize, because we need to |
| 3788 | // match the call to the signature. Also, we might be calling through an abstract method |
| 3789 | // definition (which doesn't have register count values). |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3790 | const RegType& actual_arg_type = work_line_->GetInvocationThis(this, inst, is_range); |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 3791 | if (actual_arg_type.IsConflict()) { // GetInvocationThis failed. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3792 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 3793 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3794 | const size_t expected_args = (is_range) ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 3795 | /* caught by static verifier */ |
| 3796 | DCHECK(is_range || expected_args <= 5); |
| 3797 | if (expected_args > code_item_->outs_size_) { |
| 3798 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid argument count (" << expected_args |
| 3799 | << ") exceeds outsSize (" << code_item_->outs_size_ << ")"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3800 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | /* |
| 3804 | * Check the "this" argument, which must be an instance of the class that declared the method. |
| 3805 | * For an interface class, we don't do the full interface merge (see JoinClass), so we can't do a |
| 3806 | * rigorous check here (which is okay since we have to do it at runtime). |
| 3807 | */ |
| 3808 | if (actual_arg_type.IsUninitializedReference() && !res_method->IsConstructor()) { |
| 3809 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "'this' arg must be initialized"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3810 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3811 | } |
| 3812 | if (!actual_arg_type.IsZero()) { |
| 3813 | mirror::Class* klass = res_method->GetDeclaringClass(); |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 3814 | std::string temp; |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3815 | const RegType& res_method_class = |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 3816 | FromClass(klass->GetDescriptor(&temp), klass, klass->CannotBeAssignedFromOtherTypes()); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3817 | if (!res_method_class.IsAssignableFrom(actual_arg_type)) { |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 3818 | Fail(actual_arg_type.IsUnresolvedTypes() ? VERIFY_ERROR_NO_CLASS : |
| 3819 | VERIFY_ERROR_BAD_CLASS_SOFT) << "'this' argument '" << actual_arg_type |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3820 | << "' not instance of '" << res_method_class << "'"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3821 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | /* |
| 3825 | * Process the target method's signature. This signature may or may not |
| 3826 | * have been verified, so we can't assume it's properly formed. |
| 3827 | */ |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 3828 | const DexFile::TypeList* params = res_method->GetParameterTypeList(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3829 | size_t params_size = params == nullptr ? 0 : params->Size(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3830 | uint32_t arg[5]; |
| 3831 | if (!is_range) { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 3832 | inst->GetVarArgs(arg); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3833 | } |
| 3834 | size_t actual_args = 1; |
| 3835 | for (size_t param_index = 0; param_index < params_size; param_index++) { |
| 3836 | if (actual_args >= expected_args) { |
| 3837 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invalid call to '" << PrettyMethod(res_method) |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 3838 | << "'. Expected " << expected_args |
| 3839 | << " arguments, processing argument " << actual_args |
| 3840 | << " (where longs/doubles count twice)."; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3841 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3842 | } |
| 3843 | const char* descriptor = |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 3844 | res_method->GetTypeDescriptorFromTypeIdx(params->GetTypeItem(param_index).type_idx_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3845 | if (descriptor == nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3846 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation of " << PrettyMethod(res_method) |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 3847 | << " missing signature component"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3848 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3849 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3850 | const RegType& reg_type = reg_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3851 | uint32_t get_reg = is_range ? inst->VRegC_3rc() + actual_args : arg[actual_args]; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3852 | if (!work_line_->VerifyRegisterType(this, get_reg, reg_type)) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3853 | return res_method; |
| 3854 | } |
| 3855 | actual_args = reg_type.IsLongOrDoubleTypes() ? actual_args + 2 : actual_args + 1; |
| 3856 | } |
| 3857 | if (actual_args != expected_args) { |
| 3858 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Rejecting invocation of " << PrettyMethod(res_method) |
| 3859 | << " expected " << expected_args << " arguments, found " << actual_args; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3860 | return nullptr; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 3861 | } else { |
| 3862 | return res_method; |
| 3863 | } |
| 3864 | } |
| 3865 | |
Ian Rogers | 62342ec | 2013-06-11 10:26:37 -0700 | [diff] [blame] | 3866 | void MethodVerifier::VerifyNewArray(const Instruction* inst, bool is_filled, bool is_range) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3867 | uint32_t type_idx; |
| 3868 | if (!is_filled) { |
| 3869 | DCHECK_EQ(inst->Opcode(), Instruction::NEW_ARRAY); |
| 3870 | type_idx = inst->VRegC_22c(); |
| 3871 | } else if (!is_range) { |
| 3872 | DCHECK_EQ(inst->Opcode(), Instruction::FILLED_NEW_ARRAY); |
| 3873 | type_idx = inst->VRegB_35c(); |
| 3874 | } else { |
| 3875 | DCHECK_EQ(inst->Opcode(), Instruction::FILLED_NEW_ARRAY_RANGE); |
| 3876 | type_idx = inst->VRegB_3rc(); |
| 3877 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3878 | const RegType& res_type = ResolveClassAndCheckAccess(type_idx); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 3879 | if (res_type.IsConflict()) { // bad class |
| 3880 | DCHECK_NE(failures_.size(), 0U); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3881 | } else { |
| 3882 | // TODO: check Compiler::CanAccessTypeWithoutChecks returns false when res_type is unresolved |
| 3883 | if (!res_type.IsArrayTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3884 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "new-array on non-array class " << res_type; |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3885 | } else if (!is_filled) { |
| 3886 | /* make sure "size" register is valid type */ |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3887 | work_line_->VerifyRegisterType(this, inst->VRegB_22c(), reg_types_.Integer()); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3888 | /* set register type to array class */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3889 | const RegType& precise_type = reg_types_.FromUninitialized(res_type); |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 3890 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_22c(), precise_type); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3891 | } else { |
| 3892 | // Verify each register. If "arg_count" is bad, VerifyRegisterType() will run off the end of |
| 3893 | // the list and fail. It's legal, if silly, for arg_count to be zero. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3894 | const RegType& expected_type = reg_types_.GetComponentType(res_type, GetClassLoader()); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3895 | uint32_t arg_count = (is_range) ? inst->VRegA_3rc() : inst->VRegA_35c(); |
| 3896 | uint32_t arg[5]; |
| 3897 | if (!is_range) { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 3898 | inst->GetVarArgs(arg); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3899 | } |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3900 | for (size_t ui = 0; ui < arg_count; ui++) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3901 | uint32_t get_reg = is_range ? inst->VRegC_3rc() + ui : arg[ui]; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3902 | if (!work_line_->VerifyRegisterType(this, get_reg, expected_type)) { |
| 3903 | work_line_->SetResultRegisterType(this, reg_types_.Conflict()); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3904 | return; |
| 3905 | } |
| 3906 | } |
| 3907 | // filled-array result goes into "result" register |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3908 | const RegType& precise_type = reg_types_.FromUninitialized(res_type); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3909 | work_line_->SetResultRegisterType(this, precise_type); |
Ian Rogers | 0c4a506 | 2012-02-03 15:18:59 -0800 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | } |
| 3913 | |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 3914 | void MethodVerifier::VerifyAGet(const Instruction* inst, |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3915 | const RegType& insn_type, bool is_primitive) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3916 | const RegType& index_type = work_line_->GetRegisterType(this, inst->VRegC_23x()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3917 | if (!index_type.IsArrayIndexTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3918 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Invalid reg type for array index (" << index_type << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3919 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3920 | const RegType& array_type = work_line_->GetRegisterType(this, inst->VRegB_23x()); |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3921 | if (array_type.IsZero()) { |
Nicolas Geoffray | 4824c27 | 2015-06-24 15:53:03 +0100 | [diff] [blame] | 3922 | have_pending_runtime_throw_failure_ = true; |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3923 | // Null array class; this code path will fail at runtime. Infer a merge-able type from the |
| 3924 | // instruction type. TODO: have a proper notion of bottom here. |
| 3925 | if (!is_primitive || insn_type.IsCategory1Types()) { |
| 3926 | // Reference or category 1 |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 3927 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_23x(), reg_types_.Zero()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3928 | } else { |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3929 | // Category 2 |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3930 | work_line_->SetRegisterTypeWide(this, inst->VRegA_23x(), |
| 3931 | reg_types_.FromCat2ConstLo(0, false), |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3932 | reg_types_.FromCat2ConstHi(0, false)); |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3933 | } |
jeffhao | fc3144e | 2012-02-01 17:21:15 -0800 | [diff] [blame] | 3934 | } else if (!array_type.IsArrayTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3935 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "not array type " << array_type << " with aget"; |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3936 | } else { |
| 3937 | /* verify the class */ |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3938 | const RegType& component_type = reg_types_.GetComponentType(array_type, GetClassLoader()); |
jeffhao | fc3144e | 2012-02-01 17:21:15 -0800 | [diff] [blame] | 3939 | if (!component_type.IsReferenceTypes() && !is_primitive) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3940 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "primitive array type " << array_type |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3941 | << " source for aget-object"; |
| 3942 | } else if (component_type.IsNonZeroReferenceTypes() && is_primitive) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 3943 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "reference array type " << array_type |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3944 | << " source for category 1 aget"; |
| 3945 | } else if (is_primitive && !insn_type.Equals(component_type) && |
| 3946 | !((insn_type.IsInteger() && component_type.IsFloat()) || |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3947 | (insn_type.IsLong() && component_type.IsDouble()))) { |
| 3948 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "array type " << array_type |
| 3949 | << " incompatible with aget of type " << insn_type; |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 3950 | } else { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3951 | // Use knowledge of the field type which is stronger than the type inferred from the |
| 3952 | // instruction, which can't differentiate object types and ints from floats, longs from |
| 3953 | // doubles. |
| 3954 | if (!component_type.IsLowHalf()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 3955 | work_line_->SetRegisterType<LockOp::kClear>(this, inst->VRegA_23x(), component_type); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3956 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3957 | work_line_->SetRegisterTypeWide(this, inst->VRegA_23x(), component_type, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 3958 | component_type.HighHalf(®_types_)); |
| 3959 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | } |
| 3963 | } |
| 3964 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 3965 | void MethodVerifier::VerifyPrimitivePut(const RegType& target_type, const RegType& insn_type, |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 3966 | const uint32_t vregA) { |
| 3967 | // Primitive assignability rules are weaker than regular assignability rules. |
| 3968 | bool instruction_compatible; |
| 3969 | bool value_compatible; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3970 | const RegType& value_type = work_line_->GetRegisterType(this, vregA); |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 3971 | if (target_type.IsIntegralTypes()) { |
Jeff Hao | a464748 | 2013-08-06 15:35:47 -0700 | [diff] [blame] | 3972 | instruction_compatible = target_type.Equals(insn_type); |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 3973 | value_compatible = value_type.IsIntegralTypes(); |
| 3974 | } else if (target_type.IsFloat()) { |
| 3975 | instruction_compatible = insn_type.IsInteger(); // no put-float, so expect put-int |
| 3976 | value_compatible = value_type.IsFloatTypes(); |
| 3977 | } else if (target_type.IsLong()) { |
| 3978 | instruction_compatible = insn_type.IsLong(); |
Andreas Gampe | 376fa68 | 2014-09-07 13:06:12 -0700 | [diff] [blame] | 3979 | // Additional register check: this is not checked statically (as part of VerifyInstructions), |
| 3980 | // as target_type depends on the resolved type of the field. |
| 3981 | if (instruction_compatible && work_line_->NumRegs() > vregA + 1) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3982 | const RegType& value_type_hi = work_line_->GetRegisterType(this, vregA + 1); |
Andreas Gampe | 376fa68 | 2014-09-07 13:06:12 -0700 | [diff] [blame] | 3983 | value_compatible = value_type.IsLongTypes() && value_type.CheckWidePair(value_type_hi); |
| 3984 | } else { |
| 3985 | value_compatible = false; |
| 3986 | } |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 3987 | } else if (target_type.IsDouble()) { |
| 3988 | instruction_compatible = insn_type.IsLong(); // no put-double, so expect put-long |
Andreas Gampe | 376fa68 | 2014-09-07 13:06:12 -0700 | [diff] [blame] | 3989 | // Additional register check: this is not checked statically (as part of VerifyInstructions), |
| 3990 | // as target_type depends on the resolved type of the field. |
| 3991 | if (instruction_compatible && work_line_->NumRegs() > vregA + 1) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 3992 | const RegType& value_type_hi = work_line_->GetRegisterType(this, vregA + 1); |
Andreas Gampe | 376fa68 | 2014-09-07 13:06:12 -0700 | [diff] [blame] | 3993 | value_compatible = value_type.IsDoubleTypes() && value_type.CheckWidePair(value_type_hi); |
| 3994 | } else { |
| 3995 | value_compatible = false; |
| 3996 | } |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 3997 | } else { |
| 3998 | instruction_compatible = false; // reference with primitive store |
| 3999 | value_compatible = false; // unused |
| 4000 | } |
| 4001 | if (!instruction_compatible) { |
| 4002 | // This is a global failure rather than a class change failure as the instructions and |
| 4003 | // the descriptors for the type should have been consistent within the same file at |
| 4004 | // compile time. |
| 4005 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "put insn has type '" << insn_type |
| 4006 | << "' but expected type '" << target_type << "'"; |
| 4007 | return; |
| 4008 | } |
| 4009 | if (!value_compatible) { |
| 4010 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected value in v" << vregA |
| 4011 | << " of type " << value_type << " but expected " << target_type << " for put"; |
| 4012 | return; |
| 4013 | } |
| 4014 | } |
| 4015 | |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 4016 | void MethodVerifier::VerifyAPut(const Instruction* inst, |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4017 | const RegType& insn_type, bool is_primitive) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4018 | const RegType& index_type = work_line_->GetRegisterType(this, inst->VRegC_23x()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4019 | if (!index_type.IsArrayIndexTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 4020 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Invalid reg type for array index (" << index_type << ")"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4021 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4022 | const RegType& array_type = work_line_->GetRegisterType(this, inst->VRegB_23x()); |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 4023 | if (array_type.IsZero()) { |
Nicolas Geoffray | 66389fb | 2015-06-19 10:35:42 +0100 | [diff] [blame] | 4024 | // Null array type; this code path will fail at runtime. |
| 4025 | // Still check that the given value matches the instruction's type. |
Andreas Gampe | 4bf4c78 | 2015-08-14 14:07:43 -0700 | [diff] [blame] | 4026 | // Note: this is, as usual, complicated by the fact the the instruction isn't fully typed |
| 4027 | // and fits multiple register types. |
| 4028 | const RegType* modified_reg_type = &insn_type; |
| 4029 | if ((modified_reg_type == ®_types_.Integer()) || |
| 4030 | (modified_reg_type == ®_types_.LongLo())) { |
| 4031 | // May be integer or float | long or double. Overwrite insn_type accordingly. |
| 4032 | const RegType& value_type = work_line_->GetRegisterType(this, inst->VRegA_23x()); |
| 4033 | if (modified_reg_type == ®_types_.Integer()) { |
| 4034 | if (&value_type == ®_types_.Float()) { |
| 4035 | modified_reg_type = &value_type; |
| 4036 | } |
| 4037 | } else { |
| 4038 | if (&value_type == ®_types_.DoubleLo()) { |
| 4039 | modified_reg_type = &value_type; |
| 4040 | } |
| 4041 | } |
| 4042 | } |
| 4043 | work_line_->VerifyRegisterType(this, inst->VRegA_23x(), *modified_reg_type); |
jeffhao | fc3144e | 2012-02-01 17:21:15 -0800 | [diff] [blame] | 4044 | } else if (!array_type.IsArrayTypes()) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 4045 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "not array type " << array_type << " with aput"; |
Ian Rogers | 89310de | 2012-02-01 13:47:30 -0800 | [diff] [blame] | 4046 | } else { |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4047 | const RegType& component_type = reg_types_.GetComponentType(array_type, GetClassLoader()); |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 4048 | const uint32_t vregA = inst->VRegA_23x(); |
Jeff Hao | b24b4a7 | 2013-07-31 13:47:31 -0700 | [diff] [blame] | 4049 | if (is_primitive) { |
Jeff Hao | fe1f7c8 | 2013-08-01 14:50:24 -0700 | [diff] [blame] | 4050 | VerifyPrimitivePut(component_type, insn_type, vregA); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4051 | } else { |
Jeff Hao | b24b4a7 | 2013-07-31 13:47:31 -0700 | [diff] [blame] | 4052 | if (!component_type.IsReferenceTypes()) { |
| 4053 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "primitive array type " << array_type |
| 4054 | << " source for aput-object"; |
| 4055 | } else { |
| 4056 | // The instruction agrees with the type of array, confirm the value to be stored does too |
| 4057 | // Note: we use the instruction type (rather than the component type) for aput-object as |
| 4058 | // incompatible classes will be caught at runtime as an array store exception |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4059 | work_line_->VerifyRegisterType(this, vregA, insn_type); |
Jeff Hao | b24b4a7 | 2013-07-31 13:47:31 -0700 | [diff] [blame] | 4060 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | } |
| 4064 | } |
| 4065 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4066 | ArtField* MethodVerifier::GetStaticField(int field_idx) { |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4067 | const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); |
| 4068 | // Check access to class |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4069 | const RegType& klass_type = ResolveClassAndCheckAccess(field_id.class_idx_); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 4070 | if (klass_type.IsConflict()) { // bad class |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4071 | AppendToLastFailMessage(StringPrintf(" in attempt to access static field %d (%s) in %s", |
| 4072 | field_idx, dex_file_->GetFieldName(field_id), |
| 4073 | dex_file_->GetFieldDeclaringClassDescriptor(field_id))); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4074 | return nullptr; |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4075 | } |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 4076 | if (klass_type.IsUnresolvedTypes()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4077 | return nullptr; // Can't resolve Class so no more to do here, will do checking at runtime. |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4078 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 4079 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4080 | ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, |
| 4081 | class_loader_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4082 | if (field == nullptr) { |
Anwar Ghuloum | 75a43f1 | 2013-08-13 17:22:14 -0700 | [diff] [blame] | 4083 | VLOG(verifier) << "Unable to resolve static field " << field_idx << " (" |
Ian Rogers | f4028cc | 2011-11-02 14:56:39 -0700 | [diff] [blame] | 4084 | << dex_file_->GetFieldName(field_id) << ") in " |
| 4085 | << dex_file_->GetFieldDeclaringClassDescriptor(field_id); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4086 | DCHECK(self_->IsExceptionPending()); |
| 4087 | self_->ClearException(); |
| 4088 | return nullptr; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4089 | } else if (!GetDeclaringClass().CanAccessMember(field->GetDeclaringClass(), |
| 4090 | field->GetAccessFlags())) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4091 | Fail(VERIFY_ERROR_ACCESS_FIELD) << "cannot access static field " << PrettyField(field) |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4092 | << " from " << GetDeclaringClass(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4093 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4094 | } else if (!field->IsStatic()) { |
| 4095 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "expected field " << PrettyField(field) << " to be static"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4096 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4097 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 4098 | return field; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4099 | } |
| 4100 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4101 | ArtField* MethodVerifier::GetInstanceField(const RegType& obj_type, int field_idx) { |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4102 | const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); |
| 4103 | // Check access to class |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4104 | const RegType& klass_type = ResolveClassAndCheckAccess(field_id.class_idx_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4105 | if (klass_type.IsConflict()) { |
| 4106 | AppendToLastFailMessage(StringPrintf(" in attempt to access instance field %d (%s) in %s", |
| 4107 | field_idx, dex_file_->GetFieldName(field_id), |
| 4108 | dex_file_->GetFieldDeclaringClassDescriptor(field_id))); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4109 | return nullptr; |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4110 | } |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 4111 | if (klass_type.IsUnresolvedTypes()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4112 | return nullptr; // Can't resolve Class so no more to do here |
Ian Rogers | 9004019 | 2011-12-16 08:54:29 -0800 | [diff] [blame] | 4113 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 4114 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4115 | ArtField* field = class_linker->ResolveFieldJLS(*dex_file_, field_idx, dex_cache_, |
| 4116 | class_loader_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4117 | if (field == nullptr) { |
Anwar Ghuloum | 75a43f1 | 2013-08-13 17:22:14 -0700 | [diff] [blame] | 4118 | VLOG(verifier) << "Unable to resolve instance field " << field_idx << " (" |
Ian Rogers | f4028cc | 2011-11-02 14:56:39 -0700 | [diff] [blame] | 4119 | << dex_file_->GetFieldName(field_id) << ") in " |
| 4120 | << dex_file_->GetFieldDeclaringClassDescriptor(field_id); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4121 | DCHECK(self_->IsExceptionPending()); |
| 4122 | self_->ClearException(); |
| 4123 | return nullptr; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4124 | } else if (!GetDeclaringClass().CanAccessMember(field->GetDeclaringClass(), |
| 4125 | field->GetAccessFlags())) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4126 | Fail(VERIFY_ERROR_ACCESS_FIELD) << "cannot access instance field " << PrettyField(field) |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4127 | << " from " << GetDeclaringClass(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4128 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4129 | } else if (field->IsStatic()) { |
| 4130 | Fail(VERIFY_ERROR_CLASS_CHANGE) << "expected field " << PrettyField(field) |
| 4131 | << " to not be static"; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4132 | return nullptr; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4133 | } else if (obj_type.IsZero()) { |
| 4134 | // Cannot infer and check type, however, access will cause null pointer exception |
| 4135 | return field; |
Stephen Kyle | 695c598 | 2014-08-22 15:03:07 +0100 | [diff] [blame] | 4136 | } else if (!obj_type.IsReferenceTypes()) { |
| 4137 | // Trying to read a field from something that isn't a reference |
| 4138 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "instance field access on object that has " |
| 4139 | << "non-reference type " << obj_type; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4140 | return nullptr; |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 4141 | } else { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 4142 | mirror::Class* klass = field->GetDeclaringClass(); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4143 | const RegType& field_klass = |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4144 | FromClass(dex_file_->GetFieldDeclaringClassDescriptor(field_id), |
| 4145 | klass, klass->CannotBeAssignedFromOtherTypes()); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4146 | if (obj_type.IsUninitializedTypes() && |
| 4147 | (!IsConstructor() || GetDeclaringClass().Equals(obj_type) || |
| 4148 | !field_klass.Equals(GetDeclaringClass()))) { |
| 4149 | // Field accesses through uninitialized references are only allowable for constructors where |
| 4150 | // the field is declared in this class |
| 4151 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "cannot access instance field " << PrettyField(field) |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 4152 | << " of a not fully initialized object within the context" |
| 4153 | << " of " << PrettyMethod(dex_method_idx_, *dex_file_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4154 | return nullptr; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4155 | } else if (!field_klass.IsAssignableFrom(obj_type)) { |
| 4156 | // Trying to access C1.field1 using reference of type C2, which is neither C1 or a sub-class |
| 4157 | // of C1. For resolution to occur the declared class of the field must be compatible with |
| 4158 | // obj_type, we've discovered this wasn't so, so report the field didn't exist. |
| 4159 | Fail(VERIFY_ERROR_NO_FIELD) << "cannot access instance field " << PrettyField(field) |
| 4160 | << " from object of type " << obj_type; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4161 | return nullptr; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4162 | } else { |
| 4163 | return field; |
| 4164 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4168 | template <MethodVerifier::FieldAccessType kAccType> |
| 4169 | void MethodVerifier::VerifyISFieldAccess(const Instruction* inst, const RegType& insn_type, |
| 4170 | bool is_primitive, bool is_static) { |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 4171 | uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4172 | ArtField* field; |
Ian Rogers | b94a27b | 2011-10-26 00:33:41 -0700 | [diff] [blame] | 4173 | if (is_static) { |
Ian Rogers | f4028cc | 2011-11-02 14:56:39 -0700 | [diff] [blame] | 4174 | field = GetStaticField(field_idx); |
Ian Rogers | b94a27b | 2011-10-26 00:33:41 -0700 | [diff] [blame] | 4175 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4176 | const RegType& object_type = work_line_->GetRegisterType(this, inst->VRegB_22c()); |
Ian Rogers | f4028cc | 2011-11-02 14:56:39 -0700 | [diff] [blame] | 4177 | field = GetInstanceField(object_type, field_idx); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4178 | if (UNLIKELY(have_pending_hard_failure_)) { |
| 4179 | return; |
| 4180 | } |
Ian Rogers | b94a27b | 2011-10-26 00:33:41 -0700 | [diff] [blame] | 4181 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4182 | const RegType* field_type = nullptr; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4183 | if (field != nullptr) { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4184 | if (kAccType == FieldAccessType::kAccPut) { |
| 4185 | if (field->IsFinal() && field->GetDeclaringClass() != GetDeclaringClass().GetClass()) { |
| 4186 | Fail(VERIFY_ERROR_ACCESS_FIELD) << "cannot modify final field " << PrettyField(field) |
| 4187 | << " from other class " << GetDeclaringClass(); |
| 4188 | return; |
| 4189 | } |
| 4190 | } |
| 4191 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4192 | mirror::Class* field_type_class = |
| 4193 | can_load_classes_ ? field->GetType<true>() : field->GetType<false>(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4194 | if (field_type_class != nullptr) { |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4195 | field_type = &FromClass(field->GetTypeDescriptor(), field_type_class, |
| 4196 | field_type_class->CannotBeAssignedFromOtherTypes()); |
Mathieu Chartier | eae2fb2 | 2014-01-14 14:31:25 -0800 | [diff] [blame] | 4197 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4198 | DCHECK(!can_load_classes_ || self_->IsExceptionPending()); |
| 4199 | self_->ClearException(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4200 | } |
Ian Rogers | 0d60484 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4201 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4202 | if (field_type == nullptr) { |
| 4203 | const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); |
| 4204 | const char* descriptor = dex_file_->GetFieldTypeDescriptor(field_id); |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 4205 | field_type = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4206 | } |
Sebastien Hertz | 757b304 | 2014-03-28 14:34:28 +0100 | [diff] [blame] | 4207 | DCHECK(field_type != nullptr); |
Sebastien Hertz | 5243e91 | 2013-05-21 10:55:07 +0200 | [diff] [blame] | 4208 | const uint32_t vregA = (is_static) ? inst->VRegA_21c() : inst->VRegA_22c(); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4209 | static_assert(kAccType == FieldAccessType::kAccPut || kAccType == FieldAccessType::kAccGet, |
| 4210 | "Unexpected third access type"); |
| 4211 | if (kAccType == FieldAccessType::kAccPut) { |
| 4212 | // sput or iput. |
| 4213 | if (is_primitive) { |
| 4214 | VerifyPrimitivePut(*field_type, insn_type, vregA); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4215 | } else { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4216 | if (!insn_type.IsAssignableFrom(*field_type)) { |
Vladimir Marko | 414000e | 2015-06-23 17:45:21 +0100 | [diff] [blame] | 4217 | // If the field type is not a reference, this is a global failure rather than |
| 4218 | // a class change failure as the instructions and the descriptors for the type |
| 4219 | // should have been consistent within the same file at compile time. |
| 4220 | VerifyError error = field_type->IsReferenceTypes() ? VERIFY_ERROR_BAD_CLASS_SOFT |
| 4221 | : VERIFY_ERROR_BAD_CLASS_HARD; |
| 4222 | Fail(error) << "expected field " << PrettyField(field) |
| 4223 | << " to be compatible with type '" << insn_type |
| 4224 | << "' but found type '" << *field_type |
| 4225 | << "' in put-object"; |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4226 | return; |
| 4227 | } |
| 4228 | work_line_->VerifyRegisterType(this, vregA, *field_type); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4229 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4230 | } else if (kAccType == FieldAccessType::kAccGet) { |
| 4231 | // sget or iget. |
| 4232 | if (is_primitive) { |
| 4233 | if (field_type->Equals(insn_type) || |
| 4234 | (field_type->IsFloat() && insn_type.IsInteger()) || |
| 4235 | (field_type->IsDouble() && insn_type.IsLong())) { |
| 4236 | // expected that read is of the correct primitive type or that int reads are reading |
| 4237 | // floats or long reads are reading doubles |
| 4238 | } else { |
| 4239 | // This is a global failure rather than a class change failure as the instructions and |
| 4240 | // the descriptors for the type should have been consistent within the same file at |
| 4241 | // compile time |
| 4242 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected field " << PrettyField(field) |
| 4243 | << " to be of type '" << insn_type |
| 4244 | << "' but found type '" << *field_type << "' in get"; |
| 4245 | return; |
| 4246 | } |
Mathieu Chartier | eae2fb2 | 2014-01-14 14:31:25 -0800 | [diff] [blame] | 4247 | } else { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4248 | if (!insn_type.IsAssignableFrom(*field_type)) { |
Vladimir Marko | 414000e | 2015-06-23 17:45:21 +0100 | [diff] [blame] | 4249 | // If the field type is not a reference, this is a global failure rather than |
| 4250 | // a class change failure as the instructions and the descriptors for the type |
| 4251 | // should have been consistent within the same file at compile time. |
| 4252 | VerifyError error = field_type->IsReferenceTypes() ? VERIFY_ERROR_BAD_CLASS_SOFT |
| 4253 | : VERIFY_ERROR_BAD_CLASS_HARD; |
| 4254 | Fail(error) << "expected field " << PrettyField(field) |
| 4255 | << " to be compatible with type '" << insn_type |
| 4256 | << "' but found type '" << *field_type |
| 4257 | << "' in get-object"; |
Andreas Gampe | 890da29 | 2015-07-06 17:20:18 -0700 | [diff] [blame] | 4258 | if (error != VERIFY_ERROR_BAD_CLASS_HARD) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 4259 | work_line_->SetRegisterType<LockOp::kClear>(this, vregA, reg_types_.Conflict()); |
Andreas Gampe | 890da29 | 2015-07-06 17:20:18 -0700 | [diff] [blame] | 4260 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4261 | return; |
| 4262 | } |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4263 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4264 | if (!field_type->IsLowHalf()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 4265 | work_line_->SetRegisterType<LockOp::kClear>(this, vregA, *field_type); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4266 | } else { |
| 4267 | work_line_->SetRegisterTypeWide(this, vregA, *field_type, field_type->HighHalf(®_types_)); |
| 4268 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4269 | } else { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4270 | LOG(FATAL) << "Unexpected case."; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4271 | } |
| 4272 | } |
| 4273 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4274 | ArtField* MethodVerifier::GetQuickFieldAccess(const Instruction* inst, |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 4275 | RegisterLine* reg_line) { |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 4276 | DCHECK(IsInstructionIGetQuickOrIPutQuick(inst->Opcode())) << inst->Opcode(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4277 | const RegType& object_type = reg_line->GetRegisterType(this, inst->VRegB_22c()); |
Ian Rogers | 9bc5440 | 2014-04-17 16:40:01 -0700 | [diff] [blame] | 4278 | if (!object_type.HasClass()) { |
| 4279 | VLOG(verifier) << "Failed to get mirror::Class* from '" << object_type << "'"; |
| 4280 | return nullptr; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 4281 | } |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4282 | uint32_t field_offset = static_cast<uint32_t>(inst->VRegC_22c()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4283 | ArtField* const f = ArtField::FindInstanceFieldWithOffset(object_type.GetClass(), field_offset); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 4284 | DCHECK_EQ(f->GetOffset().Uint32Value(), field_offset); |
Sebastien Hertz | 479fc1e | 2014-04-04 17:51:34 +0200 | [diff] [blame] | 4285 | if (f == nullptr) { |
| 4286 | VLOG(verifier) << "Failed to find instance field at offset '" << field_offset |
| 4287 | << "' from '" << PrettyDescriptor(object_type.GetClass()) << "'"; |
| 4288 | } |
| 4289 | return f; |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 4290 | } |
| 4291 | |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4292 | template <MethodVerifier::FieldAccessType kAccType> |
| 4293 | void MethodVerifier::VerifyQuickFieldAccess(const Instruction* inst, const RegType& insn_type, |
| 4294 | bool is_primitive) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 4295 | DCHECK(Runtime::Current()->IsStarted() || verify_to_dump_); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4296 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4297 | ArtField* field = GetQuickFieldAccess(inst, work_line_.get()); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4298 | if (field == nullptr) { |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 4299 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Cannot infer field from " << inst->Name(); |
| 4300 | return; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4301 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4302 | |
| 4303 | // For an IPUT_QUICK, we now test for final flag of the field. |
| 4304 | if (kAccType == FieldAccessType::kAccPut) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4305 | if (field->IsFinal() && field->GetDeclaringClass() != GetDeclaringClass().GetClass()) { |
| 4306 | Fail(VERIFY_ERROR_ACCESS_FIELD) << "cannot modify final field " << PrettyField(field) |
Sebastien Hertz | c15853b | 2013-06-25 17:36:27 +0200 | [diff] [blame] | 4307 | << " from other class " << GetDeclaringClass(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4308 | return; |
| 4309 | } |
| 4310 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4311 | |
| 4312 | // Get the field type. |
| 4313 | const RegType* field_type; |
| 4314 | { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 4315 | mirror::Class* field_type_class = can_load_classes_ ? field->GetType<true>() : |
| 4316 | field->GetType<false>(); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4317 | |
| 4318 | if (field_type_class != nullptr) { |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4319 | field_type = &FromClass(field->GetTypeDescriptor(), field_type_class, |
| 4320 | field_type_class->CannotBeAssignedFromOtherTypes()); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4321 | } else { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4322 | Thread* self = Thread::Current(); |
| 4323 | DCHECK(!can_load_classes_ || self->IsExceptionPending()); |
| 4324 | self->ClearException(); |
| 4325 | field_type = ®_types_.FromDescriptor(field->GetDeclaringClass()->GetClassLoader(), |
| 4326 | field->GetTypeDescriptor(), false); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4327 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4328 | if (field_type == nullptr) { |
| 4329 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Cannot infer field type from " << inst->Name(); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4330 | return; |
| 4331 | } |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | const uint32_t vregA = inst->VRegA_22c(); |
| 4335 | static_assert(kAccType == FieldAccessType::kAccPut || kAccType == FieldAccessType::kAccGet, |
| 4336 | "Unexpected third access type"); |
| 4337 | if (kAccType == FieldAccessType::kAccPut) { |
| 4338 | if (is_primitive) { |
| 4339 | // Primitive field assignability rules are weaker than regular assignability rules |
| 4340 | bool instruction_compatible; |
| 4341 | bool value_compatible; |
| 4342 | const RegType& value_type = work_line_->GetRegisterType(this, vregA); |
| 4343 | if (field_type->IsIntegralTypes()) { |
| 4344 | instruction_compatible = insn_type.IsIntegralTypes(); |
| 4345 | value_compatible = value_type.IsIntegralTypes(); |
| 4346 | } else if (field_type->IsFloat()) { |
| 4347 | instruction_compatible = insn_type.IsInteger(); // no [is]put-float, so expect [is]put-int |
| 4348 | value_compatible = value_type.IsFloatTypes(); |
| 4349 | } else if (field_type->IsLong()) { |
| 4350 | instruction_compatible = insn_type.IsLong(); |
| 4351 | value_compatible = value_type.IsLongTypes(); |
| 4352 | } else if (field_type->IsDouble()) { |
| 4353 | instruction_compatible = insn_type.IsLong(); // no [is]put-double, so expect [is]put-long |
| 4354 | value_compatible = value_type.IsDoubleTypes(); |
| 4355 | } else { |
| 4356 | instruction_compatible = false; // reference field with primitive store |
| 4357 | value_compatible = false; // unused |
| 4358 | } |
| 4359 | if (!instruction_compatible) { |
| 4360 | // This is a global failure rather than a class change failure as the instructions and |
| 4361 | // the descriptors for the type should have been consistent within the same file at |
| 4362 | // compile time |
| 4363 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected field " << PrettyField(field) |
| 4364 | << " to be of type '" << insn_type |
| 4365 | << "' but found type '" << *field_type |
| 4366 | << "' in put"; |
| 4367 | return; |
| 4368 | } |
| 4369 | if (!value_compatible) { |
| 4370 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "unexpected value in v" << vregA |
| 4371 | << " of type " << value_type |
| 4372 | << " but expected " << *field_type |
| 4373 | << " for store to " << PrettyField(field) << " in put"; |
| 4374 | return; |
| 4375 | } |
| 4376 | } else { |
| 4377 | if (!insn_type.IsAssignableFrom(*field_type)) { |
| 4378 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "expected field " << PrettyField(field) |
| 4379 | << " to be compatible with type '" << insn_type |
| 4380 | << "' but found type '" << *field_type |
| 4381 | << "' in put-object"; |
| 4382 | return; |
| 4383 | } |
| 4384 | work_line_->VerifyRegisterType(this, vregA, *field_type); |
| 4385 | } |
| 4386 | } else if (kAccType == FieldAccessType::kAccGet) { |
| 4387 | if (is_primitive) { |
| 4388 | if (field_type->Equals(insn_type) || |
| 4389 | (field_type->IsFloat() && insn_type.IsIntegralTypes()) || |
| 4390 | (field_type->IsDouble() && insn_type.IsLongTypes())) { |
| 4391 | // expected that read is of the correct primitive type or that int reads are reading |
| 4392 | // floats or long reads are reading doubles |
| 4393 | } else { |
| 4394 | // This is a global failure rather than a class change failure as the instructions and |
| 4395 | // the descriptors for the type should have been consistent within the same file at |
| 4396 | // compile time |
| 4397 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "expected field " << PrettyField(field) |
| 4398 | << " to be of type '" << insn_type |
| 4399 | << "' but found type '" << *field_type << "' in Get"; |
| 4400 | return; |
| 4401 | } |
| 4402 | } else { |
| 4403 | if (!insn_type.IsAssignableFrom(*field_type)) { |
| 4404 | Fail(VERIFY_ERROR_BAD_CLASS_SOFT) << "expected field " << PrettyField(field) |
| 4405 | << " to be compatible with type '" << insn_type |
| 4406 | << "' but found type '" << *field_type |
| 4407 | << "' in get-object"; |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 4408 | work_line_->SetRegisterType<LockOp::kClear>(this, vregA, reg_types_.Conflict()); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4409 | return; |
| 4410 | } |
| 4411 | } |
| 4412 | if (!field_type->IsLowHalf()) { |
Andreas Gampe | ad238ce | 2015-08-24 21:13:08 -0700 | [diff] [blame] | 4413 | work_line_->SetRegisterType<LockOp::kClear>(this, vregA, *field_type); |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4414 | } else { |
| 4415 | work_line_->SetRegisterTypeWide(this, vregA, *field_type, field_type->HighHalf(®_types_)); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4416 | } |
| 4417 | } else { |
Andreas Gampe | 896df40 | 2014-10-20 22:25:29 -0700 | [diff] [blame] | 4418 | LOG(FATAL) << "Unexpected case."; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 4422 | bool MethodVerifier::CheckNotMoveException(const uint16_t* insns, int insn_idx) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4423 | if ((insns[insn_idx] & 0xff) == Instruction::MOVE_EXCEPTION) { |
jeffhao | d5347e0 | 2012-03-22 17:25:05 -0700 | [diff] [blame] | 4424 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid use of move-exception"; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4425 | return false; |
| 4426 | } |
| 4427 | return true; |
| 4428 | } |
| 4429 | |
Stephen Kyle | 9bc6199 | 2014-09-22 13:53:15 +0100 | [diff] [blame] | 4430 | bool MethodVerifier::CheckNotMoveResult(const uint16_t* insns, int insn_idx) { |
| 4431 | if (((insns[insn_idx] & 0xff) >= Instruction::MOVE_RESULT) && |
| 4432 | ((insns[insn_idx] & 0xff) <= Instruction::MOVE_RESULT_OBJECT)) { |
| 4433 | Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "invalid use of move-result*"; |
| 4434 | return false; |
| 4435 | } |
| 4436 | return true; |
| 4437 | } |
| 4438 | |
| 4439 | bool MethodVerifier::CheckNotMoveExceptionOrMoveResult(const uint16_t* insns, int insn_idx) { |
| 4440 | return (CheckNotMoveException(insns, insn_idx) && CheckNotMoveResult(insns, insn_idx)); |
| 4441 | } |
| 4442 | |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 4443 | bool MethodVerifier::UpdateRegisters(uint32_t next_insn, RegisterLine* merge_line, |
| 4444 | bool update_merge_line) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4445 | bool changed = true; |
| 4446 | RegisterLine* target_line = reg_table_.GetLine(next_insn); |
| 4447 | if (!insn_flags_[next_insn].IsVisitedOrChanged()) { |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4448 | /* |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4449 | * We haven't processed this instruction before, and we haven't touched the registers here, so |
| 4450 | * there's nothing to "merge". Copy the registers over and mark it as changed. (This is the |
| 4451 | * only way a register can transition out of "unknown", so this is not just an optimization.) |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4452 | */ |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 4453 | target_line->CopyFromLine(merge_line); |
| 4454 | if (insn_flags_[next_insn].IsReturn()) { |
Jeff Hao | b24b4a7 | 2013-07-31 13:47:31 -0700 | [diff] [blame] | 4455 | // Verify that the monitor stack is empty on return. |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 4456 | merge_line->VerifyMonitorStackEmpty(this); |
| 4457 | |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 4458 | // For returns we only care about the operand to the return, all other registers are dead. |
| 4459 | // Initialize them as conflicts so they don't add to GC and deoptimization information. |
| 4460 | const Instruction* ret_inst = Instruction::At(code_item_->insns_ + next_insn); |
Andreas Gampe | a727e37 | 2015-08-25 09:22:37 -0700 | [diff] [blame] | 4461 | AdjustReturnLine(this, ret_inst, target_line); |
Ian Rogers | b8c7859 | 2013-07-25 23:52:52 +0000 | [diff] [blame] | 4462 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4463 | } else { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 4464 | std::unique_ptr<RegisterLine> copy(gDebugVerify ? |
Ian Rogers | d0fbd85 | 2013-09-24 18:17:04 -0700 | [diff] [blame] | 4465 | RegisterLine::Create(target_line->NumRegs(), this) : |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4466 | nullptr); |
Ian Rogers | 7b0c5b4 | 2012-02-16 15:29:07 -0800 | [diff] [blame] | 4467 | if (gDebugVerify) { |
| 4468 | copy->CopyFromLine(target_line); |
| 4469 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4470 | changed = target_line->MergeRegisters(this, merge_line); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4471 | if (have_pending_hard_failure_) { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4472 | return false; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4473 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 4474 | if (gDebugVerify && changed) { |
Elliott Hughes | 398f64b | 2012-03-26 18:05:48 -0700 | [diff] [blame] | 4475 | LogVerifyInfo() << "Merging at [" << reinterpret_cast<void*>(work_insn_idx_) << "]" |
Elliott Hughes | c073b07 | 2012-05-24 19:29:17 -0700 | [diff] [blame] | 4476 | << " to [" << reinterpret_cast<void*>(next_insn) << "]: " << "\n" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4477 | << copy->Dump(this) << " MERGE\n" |
| 4478 | << merge_line->Dump(this) << " ==\n" |
| 4479 | << target_line->Dump(this) << "\n"; |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4480 | } |
Ian Rogers | ebbdd87 | 2014-07-07 23:53:08 -0700 | [diff] [blame] | 4481 | if (update_merge_line && changed) { |
| 4482 | merge_line->CopyFromLine(target_line); |
| 4483 | } |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4484 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4485 | if (changed) { |
| 4486 | insn_flags_[next_insn].SetChanged(); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 4487 | } |
| 4488 | return true; |
| 4489 | } |
| 4490 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 4491 | InstructionFlags* MethodVerifier::CurrentInsnFlags() { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 4492 | return &insn_flags_[work_insn_idx_]; |
| 4493 | } |
| 4494 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4495 | const RegType& MethodVerifier::GetMethodReturnType() { |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4496 | if (return_type_ == nullptr) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4497 | if (mirror_method_ != nullptr) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4498 | size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); |
| 4499 | mirror::Class* return_type_class = mirror_method_->GetReturnType(can_load_classes_, |
| 4500 | pointer_size); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4501 | if (return_type_class != nullptr) { |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4502 | return_type_ = &FromClass(mirror_method_->GetReturnTypeDescriptor(), |
| 4503 | return_type_class, |
| 4504 | return_type_class->CannotBeAssignedFromOtherTypes()); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4505 | } else { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4506 | DCHECK(!can_load_classes_ || self_->IsExceptionPending()); |
| 4507 | self_->ClearException(); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4508 | } |
| 4509 | } |
| 4510 | if (return_type_ == nullptr) { |
| 4511 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); |
| 4512 | const DexFile::ProtoId& proto_id = dex_file_->GetMethodPrototype(method_id); |
| 4513 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 4514 | const char* descriptor = dex_file_->GetTypeDescriptor(dex_file_->GetTypeId(return_type_idx)); |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 4515 | return_type_ = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 4516 | } |
| 4517 | } |
| 4518 | return *return_type_; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4519 | } |
| 4520 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4521 | const RegType& MethodVerifier::GetDeclaringClass() { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4522 | if (declaring_class_ == nullptr) { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4523 | const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); |
Brian Carlstrom | 93c3396 | 2013-07-26 10:37:43 -0700 | [diff] [blame] | 4524 | const char* descriptor |
| 4525 | = dex_file_->GetTypeDescriptor(dex_file_->GetTypeId(method_id.class_idx_)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4526 | if (mirror_method_ != nullptr) { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 4527 | mirror::Class* klass = mirror_method_->GetDeclaringClass(); |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4528 | declaring_class_ = &FromClass(descriptor, klass, |
| 4529 | klass->CannotBeAssignedFromOtherTypes()); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 4530 | } else { |
Mathieu Chartier | bf99f77 | 2014-08-23 16:37:27 -0700 | [diff] [blame] | 4531 | declaring_class_ = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 4532 | } |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4533 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 4534 | return *declaring_class_; |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4537 | std::vector<int32_t> MethodVerifier::DescribeVRegs(uint32_t dex_pc) { |
| 4538 | RegisterLine* line = reg_table_.GetLine(dex_pc); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 4539 | DCHECK(line != nullptr) << "No register line at DEX pc " << StringPrintf("0x%x", dex_pc); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4540 | std::vector<int32_t> result; |
| 4541 | for (size_t i = 0; i < line->NumRegs(); ++i) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4542 | const RegType& type = line->GetRegisterType(this, i); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4543 | if (type.IsConstant()) { |
| 4544 | result.push_back(type.IsPreciseConstant() ? kConstant : kImpreciseConstant); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4545 | const ConstantType* const_val = down_cast<const ConstantType*>(&type); |
| 4546 | result.push_back(const_val->ConstantValue()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4547 | } else if (type.IsConstantLo()) { |
| 4548 | result.push_back(type.IsPreciseConstantLo() ? kConstant : kImpreciseConstant); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4549 | const ConstantType* const_val = down_cast<const ConstantType*>(&type); |
| 4550 | result.push_back(const_val->ConstantValueLo()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4551 | } else if (type.IsConstantHi()) { |
| 4552 | result.push_back(type.IsPreciseConstantHi() ? kConstant : kImpreciseConstant); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 4553 | const ConstantType* const_val = down_cast<const ConstantType*>(&type); |
| 4554 | result.push_back(const_val->ConstantValueHi()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4555 | } else if (type.IsIntegralTypes()) { |
| 4556 | result.push_back(kIntVReg); |
| 4557 | result.push_back(0); |
| 4558 | } else if (type.IsFloat()) { |
| 4559 | result.push_back(kFloatVReg); |
| 4560 | result.push_back(0); |
| 4561 | } else if (type.IsLong()) { |
| 4562 | result.push_back(kLongLoVReg); |
| 4563 | result.push_back(0); |
| 4564 | result.push_back(kLongHiVReg); |
| 4565 | result.push_back(0); |
| 4566 | ++i; |
| 4567 | } else if (type.IsDouble()) { |
| 4568 | result.push_back(kDoubleLoVReg); |
| 4569 | result.push_back(0); |
| 4570 | result.push_back(kDoubleHiVReg); |
| 4571 | result.push_back(0); |
| 4572 | ++i; |
| 4573 | } else if (type.IsUndefined() || type.IsConflict() || type.IsHighHalf()) { |
| 4574 | result.push_back(kUndefined); |
| 4575 | result.push_back(0); |
| 4576 | } else { |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 4577 | CHECK(type.IsNonZeroReferenceTypes()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 4578 | result.push_back(kReferenceVReg); |
| 4579 | result.push_back(0); |
| 4580 | } |
| 4581 | } |
| 4582 | return result; |
| 4583 | } |
| 4584 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 4585 | const RegType& MethodVerifier::DetermineCat1Constant(int32_t value, bool precise) { |
Sebastien Hertz | 849600b | 2013-12-20 10:28:08 +0100 | [diff] [blame] | 4586 | if (precise) { |
| 4587 | // Precise constant type. |
| 4588 | return reg_types_.FromCat1Const(value, true); |
| 4589 | } else { |
| 4590 | // Imprecise constant type. |
| 4591 | if (value < -32768) { |
| 4592 | return reg_types_.IntConstant(); |
| 4593 | } else if (value < -128) { |
| 4594 | return reg_types_.ShortConstant(); |
| 4595 | } else if (value < 0) { |
| 4596 | return reg_types_.ByteConstant(); |
| 4597 | } else if (value == 0) { |
| 4598 | return reg_types_.Zero(); |
| 4599 | } else if (value == 1) { |
| 4600 | return reg_types_.One(); |
| 4601 | } else if (value < 128) { |
| 4602 | return reg_types_.PosByteConstant(); |
| 4603 | } else if (value < 32768) { |
| 4604 | return reg_types_.PosShortConstant(); |
| 4605 | } else if (value < 65536) { |
| 4606 | return reg_types_.CharConstant(); |
| 4607 | } else { |
| 4608 | return reg_types_.IntConstant(); |
| 4609 | } |
| 4610 | } |
| 4611 | } |
| 4612 | |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 4613 | void MethodVerifier::Init() { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 4614 | art::verifier::RegTypeCache::Init(); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 4615 | } |
| 4616 | |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 4617 | void MethodVerifier::Shutdown() { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 4618 | verifier::RegTypeCache::ShutDown(); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 4619 | } |
jeffhao | d1224c7 | 2012-02-29 13:43:08 -0800 | [diff] [blame] | 4620 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 4621 | void MethodVerifier::VisitStaticRoots(RootVisitor* visitor) { |
| 4622 | RegTypeCache::VisitStaticRoots(visitor); |
Mathieu Chartier | 7c438b1 | 2014-09-12 17:01:24 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 4625 | void MethodVerifier::VisitRoots(RootVisitor* visitor, const RootInfo& root_info) { |
| 4626 | reg_types_.VisitRoots(visitor, root_info); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 4627 | } |
| 4628 | |
Andreas Gampe | f23f33d | 2015-06-23 14:18:17 -0700 | [diff] [blame] | 4629 | const RegType& MethodVerifier::FromClass(const char* descriptor, |
| 4630 | mirror::Class* klass, |
| 4631 | bool precise) { |
| 4632 | DCHECK(klass != nullptr); |
| 4633 | if (precise && !klass->IsInstantiable() && !klass->IsPrimitive()) { |
| 4634 | Fail(VerifyError::VERIFY_ERROR_NO_CLASS) << "Could not create precise reference for " |
| 4635 | << "non-instantiable klass " << descriptor; |
| 4636 | precise = false; |
| 4637 | } |
| 4638 | return reg_types_.FromClass(descriptor, klass, precise); |
| 4639 | } |
| 4640 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 4641 | } // namespace verifier |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 4642 | } // namespace art |