Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [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 | */ |
| 16 | |
| 17 | #ifndef ART_SRC_VERIFIER_METHOD_VERIFIER_H_ |
| 18 | #define ART_SRC_VERIFIER_METHOD_VERIFIER_H_ |
| 19 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 20 | #include <set> |
| 21 | #include <vector> |
| 22 | |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 23 | #include "base/casts.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 25 | #include "base/stl_util.h" |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 26 | #include "compiler/driver/compiler_driver.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 27 | #include "dex_file.h" |
| 28 | #include "dex_instruction.h" |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 29 | #include "instruction_flags.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "mirror/object.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 31 | #include "reg_type.h" |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 32 | #include "reg_type_cache-inl.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 33 | #include "register_line.h" |
| 34 | #include "safe_map.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 35 | #include "UniquePtr.h" |
| 36 | |
| 37 | namespace art { |
| 38 | |
| 39 | struct ReferenceMap2Visitor; |
| 40 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 41 | namespace verifier { |
| 42 | |
| 43 | class MethodVerifier; |
Ian Rogers | 46c6bb2 | 2012-09-18 13:47:36 -0700 | [diff] [blame] | 44 | class DexPcToReferenceMap; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 47 | * "Direct" and "virtual" methods are stored independently. The type of call used to invoke the |
| 48 | * method determines which list we search, and whether we travel up into superclasses. |
| 49 | * |
| 50 | * (<clinit>, <init>, and methods declared "private" or "static" are stored in the "direct" list. |
| 51 | * All others are stored in the "virtual" list.) |
| 52 | */ |
| 53 | enum MethodType { |
| 54 | METHOD_UNKNOWN = 0, |
| 55 | METHOD_DIRECT, // <init>, private |
| 56 | METHOD_STATIC, // static |
| 57 | METHOD_VIRTUAL, // virtual, super |
| 58 | METHOD_INTERFACE // interface |
| 59 | }; |
Ian Rogers | 2fc1427 | 2012-08-30 10:56:57 -0700 | [diff] [blame] | 60 | std::ostream& operator<<(std::ostream& os, const MethodType& rhs); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * An enumeration of problems that can turn up during verification. |
| 64 | * Both VERIFY_ERROR_BAD_CLASS_SOFT and VERIFY_ERROR_BAD_CLASS_HARD denote failures that cause |
| 65 | * the entire class to be rejected. However, VERIFY_ERROR_BAD_CLASS_SOFT denotes a soft failure |
| 66 | * that can potentially be corrected, and the verifier will try again at runtime. |
| 67 | * VERIFY_ERROR_BAD_CLASS_HARD denotes a hard failure that can't be corrected, and will cause |
| 68 | * the class to remain uncompiled. Other errors denote verification errors that cause bytecode |
| 69 | * to be rewritten to fail at runtime. |
| 70 | */ |
| 71 | enum VerifyError { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 72 | VERIFY_ERROR_BAD_CLASS_HARD, // VerifyError; hard error that skips compilation. |
| 73 | VERIFY_ERROR_BAD_CLASS_SOFT, // VerifyError; soft error that verifies again at runtime. |
| 74 | |
| 75 | VERIFY_ERROR_NO_CLASS, // NoClassDefFoundError. |
| 76 | VERIFY_ERROR_NO_FIELD, // NoSuchFieldError. |
| 77 | VERIFY_ERROR_NO_METHOD, // NoSuchMethodError. |
| 78 | VERIFY_ERROR_ACCESS_CLASS, // IllegalAccessError. |
| 79 | VERIFY_ERROR_ACCESS_FIELD, // IllegalAccessError. |
| 80 | VERIFY_ERROR_ACCESS_METHOD, // IllegalAccessError. |
| 81 | VERIFY_ERROR_CLASS_CHANGE, // IncompatibleClassChangeError. |
| 82 | VERIFY_ERROR_INSTANTIATION, // InstantiationError. |
| 83 | }; |
| 84 | std::ostream& operator<<(std::ostream& os, const VerifyError& rhs); |
| 85 | |
| 86 | /* |
| 87 | * Identifies the type of reference in the instruction that generated the verify error |
| 88 | * (e.g. VERIFY_ERROR_ACCESS_CLASS could come from a method, field, or class reference). |
| 89 | * |
| 90 | * This must fit in two bits. |
| 91 | */ |
| 92 | enum VerifyErrorRefType { |
| 93 | VERIFY_ERROR_REF_CLASS = 0, |
| 94 | VERIFY_ERROR_REF_FIELD = 1, |
| 95 | VERIFY_ERROR_REF_METHOD = 2, |
| 96 | }; |
| 97 | const int kVerifyErrorRefTypeShift = 6; |
| 98 | |
| 99 | // We don't need to store the register data for many instructions, because we either only need |
| 100 | // it at branch points (for verification) or GC points and branches (for verification + |
| 101 | // type-precise register analysis). |
| 102 | enum RegisterTrackingMode { |
| 103 | kTrackRegsBranches, |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 104 | kTrackCompilerInterestPoints, |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 105 | kTrackRegsAll, |
| 106 | }; |
| 107 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 108 | // A mapping from a dex pc to the register line statuses as they are immediately prior to the |
| 109 | // execution of that instruction. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 110 | class PcToRegisterLineTable { |
| 111 | public: |
| 112 | PcToRegisterLineTable() {} |
| 113 | ~PcToRegisterLineTable() { |
| 114 | STLDeleteValues(&pc_to_register_line_); |
| 115 | } |
| 116 | |
| 117 | // Initialize the RegisterTable. Every instruction address can have a different set of information |
| 118 | // about what's in which register, but for verification purposes we only need to store it at |
| 119 | // branch target addresses (because we merge into that). |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 120 | void Init(RegisterTrackingMode mode, InstructionFlags* flags, uint32_t insns_size, |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 121 | uint16_t registers_size, MethodVerifier* verifier); |
| 122 | |
| 123 | RegisterLine* GetLine(size_t idx) { |
| 124 | Table::iterator result = pc_to_register_line_.find(idx); // TODO: C++0x auto |
| 125 | if (result == pc_to_register_line_.end()) { |
| 126 | return NULL; |
| 127 | } else { |
| 128 | return result->second; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | private: |
| 133 | typedef SafeMap<int32_t, RegisterLine*> Table; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 134 | Table pc_to_register_line_; |
| 135 | }; |
| 136 | |
| 137 | // The verifier |
| 138 | class MethodVerifier { |
| 139 | public: |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 140 | enum FailureKind { |
| 141 | kNoFailure, |
| 142 | kSoftFailure, |
| 143 | kHardFailure, |
| 144 | }; |
| 145 | |
| 146 | /* Verify a class. Returns "kNoFailure" on success. */ |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 147 | static FailureKind VerifyClass(const mirror::Class* klass, std::string& error, |
| 148 | bool allow_soft_failures) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 149 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 150 | static FailureKind VerifyClass(const DexFile* dex_file, mirror::DexCache* dex_cache, |
| 151 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 152 | std::string& error, bool allow_soft_failures) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 153 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 154 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 155 | static void VerifyMethodAndDump(std::ostream& os, uint32_t method_idx, const DexFile* dex_file, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 156 | mirror::DexCache* dex_cache, mirror::ClassLoader* class_loader, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 157 | uint32_t class_def_idx, const DexFile::CodeItem* code_item, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 158 | mirror::AbstractMethod* method, uint32_t method_access_flags) |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 159 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 160 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 161 | uint8_t EncodePcToReferenceMapData() const; |
| 162 | |
| 163 | uint32_t DexFileVersion() const { |
| 164 | return dex_file_->GetVersion(); |
| 165 | } |
| 166 | |
| 167 | RegTypeCache* GetRegTypeCache() { |
| 168 | return ®_types_; |
| 169 | } |
| 170 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 171 | // Log a verification failure. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 172 | std::ostream& Fail(VerifyError error); |
| 173 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 174 | // Log for verification information. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 175 | std::ostream& LogVerifyInfo() { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 176 | return info_messages_ << "VFY: " << PrettyMethod(dex_method_idx_, *dex_file_) |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 177 | << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : "; |
| 178 | } |
| 179 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 180 | // Dump the failures encountered by the verifier. |
| 181 | std::ostream& DumpFailures(std::ostream& os); |
| 182 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 183 | // Dump the state of the verifier, namely each instruction, what flags are set on it, register |
| 184 | // information |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 185 | void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 186 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 187 | static const std::vector<uint8_t>* GetDexGcMap(CompilerDriver::MethodReference ref) |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 188 | LOCKS_EXCLUDED(dex_gc_maps_lock_); |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 189 | |
Ian Rogers | e3cd2f0 | 2013-05-24 15:32:56 -0700 | [diff] [blame] | 190 | static const CompilerDriver::MethodReference* GetDevirtMap(const CompilerDriver::MethodReference& ref, |
| 191 | uint32_t dex_pc) |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 192 | LOCKS_EXCLUDED(devirt_maps_lock_); |
| 193 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 194 | // Fills 'monitor_enter_dex_pcs' with the dex pcs of the monitor-enter instructions corresponding |
| 195 | // to the locks held at 'dex_pc' in 'm'. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 196 | static void FindLocksAtDexPc(mirror::AbstractMethod* m, uint32_t dex_pc, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 197 | std::vector<uint32_t>& monitor_enter_dex_pcs) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 198 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 199 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 200 | static void Init() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 201 | static void Shutdown(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 202 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 203 | static bool IsClassRejected(CompilerDriver::ClassReference ref) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 204 | LOCKS_EXCLUDED(rejected_classes_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 205 | |
Elliott Hughes | 4993bbc | 2013-01-10 15:41:25 -0800 | [diff] [blame] | 206 | bool CanLoadClasses() const { |
| 207 | return can_load_classes_; |
| 208 | } |
| 209 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 210 | MethodVerifier(const DexFile* dex_file, mirror::DexCache* dex_cache, |
| 211 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
| 212 | const DexFile::CodeItem* code_item, |
| 213 | uint32_t method_idx, mirror::AbstractMethod* method, |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 214 | uint32_t access_flags, bool can_load_classes, bool allow_soft_failures) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 215 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 216 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 217 | // Run verification on the method. Returns true if verification completes and false if the input |
| 218 | // has an irrecoverable corruption. |
| 219 | bool Verify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 220 | |
| 221 | // Describe VRegs at the given dex pc. |
| 222 | std::vector<int32_t> DescribeVRegs(uint32_t dex_pc); |
| 223 | |
| 224 | private: |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 225 | // Adds the given string to the beginning of the last failure message. |
| 226 | void PrependToLastFailMessage(std::string); |
| 227 | |
| 228 | // Adds the given string to the end of the last failure message. |
| 229 | void AppendToLastFailMessage(std::string); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * Perform verification on a single method. |
| 233 | * |
| 234 | * We do this in three passes: |
| 235 | * (1) Walk through all code units, determining instruction locations, |
| 236 | * widths, and other characteristics. |
| 237 | * (2) Walk through all code units, performing static checks on |
| 238 | * operands. |
| 239 | * (3) Iterate through the method, checking type safety and looking |
| 240 | * for code flow problems. |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 241 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 242 | static FailureKind VerifyMethod(uint32_t method_idx, const DexFile* dex_file, |
| 243 | mirror::DexCache* dex_cache, |
| 244 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
| 245 | const DexFile::CodeItem* code_item, |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 246 | mirror::AbstractMethod* method, uint32_t method_access_flags, |
| 247 | bool allow_soft_failures) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 248 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 249 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 250 | void FindLocksAtDexPc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 251 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Compute the width of the instruction at each address in the instruction stream, and store it in |
| 254 | * insn_flags_. Addresses that are in the middle of an instruction, or that are part of switch |
| 255 | * table data, are not touched (so the caller should probably initialize "insn_flags" to zero). |
| 256 | * |
| 257 | * The "new_instance_count_" and "monitor_enter_count_" fields in vdata are also set. |
| 258 | * |
| 259 | * Performs some static checks, notably: |
| 260 | * - opcode of first instruction begins at index 0 |
| 261 | * - only documented instructions may appear |
| 262 | * - each instruction follows the last |
| 263 | * - last byte of last instruction is at (code_length-1) |
| 264 | * |
| 265 | * Logs an error and returns "false" on failure. |
| 266 | */ |
| 267 | bool ComputeWidthsAndCountOps(); |
| 268 | |
| 269 | /* |
| 270 | * Set the "in try" flags for all instructions protected by "try" statements. Also sets the |
| 271 | * "branch target" flags for exception handlers. |
| 272 | * |
| 273 | * Call this after widths have been set in "insn_flags". |
| 274 | * |
| 275 | * Returns "false" if something in the exception table looks fishy, but we're expecting the |
| 276 | * exception table to be somewhat sane. |
| 277 | */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 278 | bool ScanTryCatchBlocks() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Perform static verification on all instructions in a method. |
| 282 | * |
| 283 | * Walks through instructions in a method calling VerifyInstruction on each. |
| 284 | */ |
| 285 | bool VerifyInstructions(); |
| 286 | |
| 287 | /* |
| 288 | * Perform static verification on an instruction. |
| 289 | * |
| 290 | * As a side effect, this sets the "branch target" flags in InsnFlags. |
| 291 | * |
| 292 | * "(CF)" items are handled during code-flow analysis. |
| 293 | * |
| 294 | * v3 4.10.1 |
| 295 | * - target of each jump and branch instruction must be valid |
| 296 | * - targets of switch statements must be valid |
| 297 | * - operands referencing constant pool entries must be valid |
| 298 | * - (CF) operands of getfield, putfield, getstatic, putstatic must be valid |
| 299 | * - (CF) operands of method invocation instructions must be valid |
| 300 | * - (CF) only invoke-direct can call a method starting with '<' |
| 301 | * - (CF) <clinit> must never be called explicitly |
| 302 | * - operands of instanceof, checkcast, new (and variants) must be valid |
| 303 | * - new-array[-type] limited to 255 dimensions |
| 304 | * - can't use "new" on an array class |
| 305 | * - (?) limit dimensions in multi-array creation |
| 306 | * - local variable load/store register values must be in valid range |
| 307 | * |
| 308 | * v3 4.11.1.2 |
| 309 | * - branches must be within the bounds of the code array |
| 310 | * - targets of all control-flow instructions are the start of an instruction |
| 311 | * - register accesses fall within range of allocated registers |
| 312 | * - (N/A) access to constant pool must be of appropriate type |
| 313 | * - code does not end in the middle of an instruction |
| 314 | * - execution cannot fall off the end of the code |
| 315 | * - (earlier) for each exception handler, the "try" area must begin and |
| 316 | * end at the start of an instruction (end can be at the end of the code) |
| 317 | * - (earlier) for each exception handler, the handler must start at a valid |
| 318 | * instruction |
| 319 | */ |
| 320 | bool VerifyInstruction(const Instruction* inst, uint32_t code_offset); |
| 321 | |
| 322 | /* Ensure that the register index is valid for this code item. */ |
| 323 | bool CheckRegisterIndex(uint32_t idx); |
| 324 | |
| 325 | /* Ensure that the wide register index is valid for this code item. */ |
| 326 | bool CheckWideRegisterIndex(uint32_t idx); |
| 327 | |
| 328 | // Perform static checks on a field get or set instruction. All we do here is ensure that the |
| 329 | // field index is in the valid range. |
| 330 | bool CheckFieldIndex(uint32_t idx); |
| 331 | |
| 332 | // Perform static checks on a method invocation instruction. All we do here is ensure that the |
| 333 | // method index is in the valid range. |
| 334 | bool CheckMethodIndex(uint32_t idx); |
| 335 | |
| 336 | // Perform static checks on a "new-instance" instruction. Specifically, make sure the class |
| 337 | // reference isn't for an array class. |
| 338 | bool CheckNewInstance(uint32_t idx); |
| 339 | |
| 340 | /* Ensure that the string index is in the valid range. */ |
| 341 | bool CheckStringIndex(uint32_t idx); |
| 342 | |
| 343 | // Perform static checks on an instruction that takes a class constant. Ensure that the class |
| 344 | // index is in the valid range. |
| 345 | bool CheckTypeIndex(uint32_t idx); |
| 346 | |
| 347 | // Perform static checks on a "new-array" instruction. Specifically, make sure they aren't |
| 348 | // creating an array of arrays that causes the number of dimensions to exceed 255. |
| 349 | bool CheckNewArray(uint32_t idx); |
| 350 | |
| 351 | // Verify an array data table. "cur_offset" is the offset of the fill-array-data instruction. |
| 352 | bool CheckArrayData(uint32_t cur_offset); |
| 353 | |
| 354 | // Verify that the target of a branch instruction is valid. We don't expect code to jump directly |
| 355 | // into an exception handler, but it's valid to do so as long as the target isn't a |
| 356 | // "move-exception" instruction. We verify that in a later stage. |
| 357 | // The dex format forbids certain instructions from branching to themselves. |
Elliott Hughes | 24edeb5 | 2012-06-18 15:29:46 -0700 | [diff] [blame] | 358 | // Updates "insn_flags_", setting the "branch target" flag. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 359 | bool CheckBranchTarget(uint32_t cur_offset); |
| 360 | |
| 361 | // Verify a switch table. "cur_offset" is the offset of the switch instruction. |
Elliott Hughes | 24edeb5 | 2012-06-18 15:29:46 -0700 | [diff] [blame] | 362 | // Updates "insn_flags_", setting the "branch target" flag. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 363 | bool CheckSwitchTargets(uint32_t cur_offset); |
| 364 | |
| 365 | // Check the register indices used in a "vararg" instruction, such as invoke-virtual or |
| 366 | // filled-new-array. |
| 367 | // - vA holds word count (0-5), args[] have values. |
| 368 | // There are some tests we don't do here, e.g. we don't try to verify that invoking a method that |
| 369 | // takes a double is done with consecutive registers. This requires parsing the target method |
| 370 | // signature, which we will be doing later on during the code flow analysis. |
| 371 | bool CheckVarArgRegs(uint32_t vA, uint32_t arg[]); |
| 372 | |
| 373 | // Check the register indices used in a "vararg/range" instruction, such as invoke-virtual/range |
| 374 | // or filled-new-array/range. |
| 375 | // - vA holds word count, vC holds index of first reg. |
| 376 | bool CheckVarArgRangeRegs(uint32_t vA, uint32_t vC); |
| 377 | |
| 378 | // Extract the relative offset from a branch instruction. |
| 379 | // Returns "false" on failure (e.g. this isn't a branch instruction). |
| 380 | bool GetBranchOffset(uint32_t cur_offset, int32_t* pOffset, bool* pConditional, |
| 381 | bool* selfOkay); |
| 382 | |
| 383 | /* Perform detailed code-flow analysis on a single method. */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 384 | bool VerifyCodeFlow() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 385 | |
| 386 | // Set the register types for the first instruction in the method based on the method signature. |
| 387 | // This has the side-effect of validating the signature. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 388 | bool SetTypesFromSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 389 | |
| 390 | /* |
| 391 | * Perform code flow on a method. |
| 392 | * |
| 393 | * The basic strategy is as outlined in v3 4.11.1.2: set the "changed" bit on the first |
| 394 | * instruction, process it (setting additional "changed" bits), and repeat until there are no |
| 395 | * more. |
| 396 | * |
| 397 | * v3 4.11.1.1 |
| 398 | * - (N/A) operand stack is always the same size |
| 399 | * - operand stack [registers] contain the correct types of values |
| 400 | * - local variables [registers] contain the correct types of values |
| 401 | * - methods are invoked with the appropriate arguments |
| 402 | * - fields are assigned using values of appropriate types |
| 403 | * - opcodes have the correct type values in operand registers |
| 404 | * - there is never an uninitialized class instance in a local variable in code protected by an |
| 405 | * exception handler (operand stack is okay, because the operand stack is discarded when an |
| 406 | * exception is thrown) [can't know what's a local var w/o the debug info -- should fall out of |
| 407 | * register typing] |
| 408 | * |
| 409 | * v3 4.11.1.2 |
| 410 | * - execution cannot fall off the end of the code |
| 411 | * |
| 412 | * (We also do many of the items described in the "static checks" sections, because it's easier to |
| 413 | * do them here.) |
| 414 | * |
| 415 | * We need an array of RegType values, one per register, for every instruction. If the method uses |
| 416 | * monitor-enter, we need extra data for every register, and a stack for every "interesting" |
| 417 | * instruction. In theory this could become quite large -- up to several megabytes for a monster |
| 418 | * function. |
| 419 | * |
| 420 | * NOTE: |
| 421 | * The spec forbids backward branches when there's an uninitialized reference in a register. The |
| 422 | * idea is to prevent something like this: |
| 423 | * loop: |
| 424 | * move r1, r0 |
| 425 | * new-instance r0, MyClass |
| 426 | * ... |
| 427 | * if-eq rN, loop // once |
| 428 | * initialize r0 |
| 429 | * |
| 430 | * This leaves us with two different instances, both allocated by the same instruction, but only |
| 431 | * one is initialized. The scheme outlined in v3 4.11.1.4 wouldn't catch this, so they work around |
| 432 | * it by preventing backward branches. We achieve identical results without restricting code |
| 433 | * reordering by specifying that you can't execute the new-instance instruction if a register |
| 434 | * contains an uninitialized instance created by that same instruction. |
| 435 | */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 436 | bool CodeFlowVerifyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 437 | |
| 438 | /* |
| 439 | * Perform verification for a single instruction. |
| 440 | * |
| 441 | * This requires fully decoding the instruction to determine the effect it has on registers. |
| 442 | * |
| 443 | * Finds zero or more following instructions and sets the "changed" flag if execution at that |
| 444 | * point needs to be (re-)evaluated. Register changes are merged into "reg_types_" at the target |
| 445 | * addresses. Does not set or clear any other flags in "insn_flags_". |
| 446 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 447 | bool CodeFlowVerifyInstruction(uint32_t* start_guess) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 448 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 449 | |
| 450 | // Perform verification of a new array instruction |
| 451 | void VerifyNewArray(const DecodedInstruction& dec_insn, bool is_filled, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 452 | bool is_range) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 453 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 454 | |
| 455 | // Perform verification of an aget instruction. The destination register's type will be set to |
| 456 | // be that of component type of the array unless the array type is unknown, in which case a |
| 457 | // bottom type inferred from the type of instruction is used. is_primitive is false for an |
| 458 | // aget-object. |
| 459 | void VerifyAGet(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 460 | bool is_primitive) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 461 | |
| 462 | // Perform verification of an aput instruction. |
| 463 | void VerifyAPut(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 464 | bool is_primitive) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 465 | |
| 466 | // Lookup instance field and fail for resolution violations |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 467 | mirror::Field* GetInstanceField(const RegType& obj_type, int field_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 468 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 469 | |
| 470 | // Lookup static field and fail for resolution violations |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 471 | mirror::Field* GetStaticField(int field_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 472 | |
| 473 | // Perform verification of an iget or sget instruction. |
| 474 | void VerifyISGet(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 475 | bool is_primitive, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 476 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 477 | |
| 478 | // Perform verification of an iput or sput instruction. |
| 479 | void VerifyISPut(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 480 | bool is_primitive, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 481 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 482 | |
| 483 | // Resolves a class based on an index and performs access checks to ensure the referrer can |
| 484 | // access the resolved class. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 485 | const RegType& ResolveClassAndCheckAccess(uint32_t class_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 486 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 487 | |
| 488 | /* |
| 489 | * For the "move-exception" instruction at "work_insn_idx_", which must be at an exception handler |
| 490 | * address, determine the Join of all exceptions that can land here. Fails if no matching |
| 491 | * exception handler can be found or if the Join of exception types fails. |
| 492 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 493 | const RegType& GetCaughtExceptionType() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 494 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * Resolves a method based on an index and performs access checks to ensure |
| 498 | * the referrer can access the resolved method. |
| 499 | * Does not throw exceptions. |
| 500 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 501 | mirror::AbstractMethod* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 502 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * Verify the arguments to a method. We're executing in "method", making |
| 506 | * a call to the method reference in vB. |
| 507 | * |
| 508 | * If this is a "direct" invoke, we allow calls to <init>. For calls to |
| 509 | * <init>, the first argument may be an uninitialized reference. Otherwise, |
| 510 | * calls to anything starting with '<' will be rejected, as will any |
| 511 | * uninitialized reference arguments. |
| 512 | * |
| 513 | * For non-static method calls, this will verify that the method call is |
| 514 | * appropriate for the "this" argument. |
| 515 | * |
| 516 | * The method reference is in vBBBB. The "is_range" parameter determines |
| 517 | * whether we use 0-4 "args" values or a range of registers defined by |
| 518 | * vAA and vCCCC. |
| 519 | * |
| 520 | * Widening conversions on integers and references are allowed, but |
| 521 | * narrowing conversions are not. |
| 522 | * |
| 523 | * Returns the resolved method on success, NULL on failure (with *failure |
| 524 | * set appropriately). |
| 525 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 526 | mirror::AbstractMethod* VerifyInvocationArgs(const DecodedInstruction& dec_insn, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 527 | MethodType method_type, bool is_range, bool is_super) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 528 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 529 | |
| 530 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 531 | * Verify that the target instruction is not "move-exception". It's important that the only way |
| 532 | * to execute a move-exception is as the first instruction of an exception handler. |
| 533 | * Returns "true" if all is well, "false" if the target instruction is move-exception. |
| 534 | */ |
| 535 | bool CheckNotMoveException(const uint16_t* insns, int insn_idx); |
| 536 | |
| 537 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 538 | * Control can transfer to "next_insn". Merge the registers from merge_line into the table at |
| 539 | * next_insn, and set the changed flag on the target address if any of the registers were changed. |
| 540 | * Returns "false" if an error is encountered. |
| 541 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 542 | bool UpdateRegisters(uint32_t next_insn, const RegisterLine* merge_line) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 543 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 544 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 545 | // Is the method being verified a constructor? |
| 546 | bool IsConstructor() const { |
| 547 | return (method_access_flags_ & kAccConstructor) != 0; |
| 548 | } |
| 549 | |
| 550 | // Is the method verified static? |
| 551 | bool IsStatic() const { |
| 552 | return (method_access_flags_ & kAccStatic) != 0; |
| 553 | } |
| 554 | |
| 555 | // Return the register type for the method. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 556 | const RegType& GetMethodReturnType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 557 | |
| 558 | // Get a type representing the declaring class of the method. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 559 | const RegType& GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 560 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 561 | /* |
| 562 | * Generate the GC map for a method that has just been verified (i.e. we're doing this as part of |
| 563 | * verification). For type-precise determination we have all the data we need, so we just need to |
| 564 | * encode it in some clever fashion. |
| 565 | * Returns a pointer to a newly-allocated RegisterMap, or NULL on failure. |
| 566 | */ |
| 567 | const std::vector<uint8_t>* GenerateGcMap(); |
| 568 | |
| 569 | // Verify that the GC map associated with method_ is well formed |
| 570 | void VerifyGcMap(const std::vector<uint8_t>& data); |
| 571 | |
| 572 | // Compute sizes for GC map data |
| 573 | void ComputeGcMapSizes(size_t* gc_points, size_t* ref_bitmap_bits, size_t* log2_max_gc_pc); |
| 574 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 575 | InstructionFlags* CurrentInsnFlags(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 576 | |
| 577 | // All the GC maps that the verifier has created |
Ian Rogers | e3cd2f0 | 2013-05-24 15:32:56 -0700 | [diff] [blame] | 578 | typedef SafeMap<const CompilerDriver::MethodReference, const std::vector<uint8_t>*, |
| 579 | CompilerDriver::MethodReferenceComparator> DexGcMapTable; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 580 | static Mutex* dex_gc_maps_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 581 | static DexGcMapTable* dex_gc_maps_ GUARDED_BY(dex_gc_maps_lock_); |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 582 | static void SetDexGcMap(CompilerDriver::MethodReference ref, const std::vector<uint8_t>& dex_gc_map) |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 583 | LOCKS_EXCLUDED(dex_gc_maps_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 584 | |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 585 | |
| 586 | // Devirtualization map. |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame^] | 587 | typedef SafeMap<const uint32_t, CompilerDriver::MethodReference> PcToConcreteMethod; |
| 588 | typedef SafeMap<const CompilerDriver::MethodReference, const PcToConcreteMethod*, |
Ian Rogers | e3cd2f0 | 2013-05-24 15:32:56 -0700 | [diff] [blame] | 589 | CompilerDriver::MethodReferenceComparator> DevirtualizationMapTable; |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame^] | 590 | MethodVerifier::PcToConcreteMethod* GenerateDevirtMap() |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 591 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 592 | |
| 593 | static Mutex* devirt_maps_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 594 | static DevirtualizationMapTable* devirt_maps_ GUARDED_BY(devirt_maps_lock_); |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame^] | 595 | static void SetDevirtMap(CompilerDriver::MethodReference ref, |
| 596 | const PcToConcreteMethod* pc_method_map) |
Sameer Abu Asal | 02c4223 | 2013-04-30 12:09:45 -0700 | [diff] [blame] | 597 | LOCKS_EXCLUDED(devirt_maps_lock_); |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 598 | typedef std::set<CompilerDriver::ClassReference> RejectedClassesTable; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 599 | static Mutex* rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 600 | static RejectedClassesTable* rejected_classes_; |
| 601 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 602 | static void AddRejectedClass(CompilerDriver::ClassReference ref) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 603 | LOCKS_EXCLUDED(rejected_classes_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 604 | |
| 605 | RegTypeCache reg_types_; |
| 606 | |
| 607 | PcToRegisterLineTable reg_table_; |
| 608 | |
| 609 | // Storage for the register status we're currently working on. |
| 610 | UniquePtr<RegisterLine> work_line_; |
| 611 | |
| 612 | // The address of the instruction we're currently working on, note that this is in 2 byte |
| 613 | // quantities |
| 614 | uint32_t work_insn_idx_; |
| 615 | |
| 616 | // Storage for the register status we're saving for later. |
| 617 | UniquePtr<RegisterLine> saved_line_; |
| 618 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 619 | uint32_t dex_method_idx_; // The method we're working on. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 620 | // Its object representation if known. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 621 | mirror::AbstractMethod* foo_method_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 622 | uint32_t method_access_flags_; // Method's access flags. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 623 | const DexFile* dex_file_; // The dex file containing the method. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 624 | // The dex_cache for the declaring class of the method. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 625 | mirror::DexCache* dex_cache_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 626 | // The class loader for the declaring class of the method. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 627 | mirror::ClassLoader* class_loader_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 628 | uint32_t class_def_idx_; // The class def index of the declaring class of the method. |
| 629 | const DexFile::CodeItem* code_item_; // The code item containing the code for the method. |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 630 | // Instruction widths and flags, one entry per code unit. |
| 631 | UniquePtr<InstructionFlags[]> insn_flags_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 632 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 633 | // The dex PC of a FindLocksAtDexPc request, -1 otherwise. |
| 634 | uint32_t interesting_dex_pc_; |
| 635 | // The container into which FindLocksAtDexPc should write the registers containing held locks, |
| 636 | // NULL if we're not doing FindLocksAtDexPc. |
| 637 | std::vector<uint32_t>* monitor_enter_dex_pcs_; |
| 638 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 639 | // The types of any error that occurs. |
| 640 | std::vector<VerifyError> failures_; |
| 641 | // Error messages associated with failures. |
| 642 | std::vector<std::ostringstream*> failure_messages_; |
| 643 | // Is there a pending hard failure? |
| 644 | bool have_pending_hard_failure_; |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 645 | // Is there a pending runtime throw failure? A runtime throw failure is when an instruction |
| 646 | // would fail at runtime throwing an exception. Such an instruction causes the following code |
| 647 | // to be unreachable. This is set by Fail and used to ensure we don't process unreachable |
| 648 | // instructions that would hard fail the verification. |
| 649 | bool have_pending_runtime_throw_failure_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 650 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 651 | // Info message log use primarily for verifier diagnostics. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 652 | std::ostringstream info_messages_; |
| 653 | |
| 654 | // The number of occurrences of specific opcodes. |
| 655 | size_t new_instance_count_; |
| 656 | size_t monitor_enter_count_; |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 657 | |
| 658 | const bool can_load_classes_; |
Jeff Hao | ee98895 | 2013-04-16 14:23:47 -0700 | [diff] [blame] | 659 | |
| 660 | // Converts soft failures to hard failures when false. Only false when the compiler isn't |
| 661 | // running and the verifier is called from the class linker. |
| 662 | const bool allow_soft_failures_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 663 | }; |
jeffhao | e4f0b2a | 2012-08-30 11:18:57 -0700 | [diff] [blame] | 664 | std::ostream& operator<<(std::ostream& os, const MethodVerifier::FailureKind& rhs); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 665 | |
| 666 | } // namespace verifier |
| 667 | } // namespace art |
| 668 | |
| 669 | #endif // ART_SRC_VERIFIER_METHOD_VERIFIER_H_ |