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