blob: fc5b7eae57e3cbd8edf6217f86bbc448906e66cd [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 Rogerse1758fe2012-04-19 11:31:15 -070086 VERIFY_ERROR_NONE = 0, // No error; must be zero.
Ian Rogers776ac1f2012-04-13 23:36:36 -070087 VERIFY_ERROR_BAD_CLASS_HARD, // VerifyError; hard error that skips compilation.
88 VERIFY_ERROR_BAD_CLASS_SOFT, // VerifyError; soft error that verifies again at runtime.
89
90 VERIFY_ERROR_NO_CLASS, // NoClassDefFoundError.
91 VERIFY_ERROR_NO_FIELD, // NoSuchFieldError.
92 VERIFY_ERROR_NO_METHOD, // NoSuchMethodError.
93 VERIFY_ERROR_ACCESS_CLASS, // IllegalAccessError.
94 VERIFY_ERROR_ACCESS_FIELD, // IllegalAccessError.
95 VERIFY_ERROR_ACCESS_METHOD, // IllegalAccessError.
96 VERIFY_ERROR_CLASS_CHANGE, // IncompatibleClassChangeError.
97 VERIFY_ERROR_INSTANTIATION, // InstantiationError.
98};
99std::ostream& operator<<(std::ostream& os, const VerifyError& rhs);
100
101/*
102 * Identifies the type of reference in the instruction that generated the verify error
103 * (e.g. VERIFY_ERROR_ACCESS_CLASS could come from a method, field, or class reference).
104 *
105 * This must fit in two bits.
106 */
107enum VerifyErrorRefType {
108 VERIFY_ERROR_REF_CLASS = 0,
109 VERIFY_ERROR_REF_FIELD = 1,
110 VERIFY_ERROR_REF_METHOD = 2,
111};
112const int kVerifyErrorRefTypeShift = 6;
113
114// We don't need to store the register data for many instructions, because we either only need
115// it at branch points (for verification) or GC points and branches (for verification +
116// type-precise register analysis).
117enum RegisterTrackingMode {
118 kTrackRegsBranches,
119 kTrackRegsGcPoints,
120 kTrackRegsAll,
121};
122
123class PcToRegisterLineTable {
124 public:
125 PcToRegisterLineTable() {}
126 ~PcToRegisterLineTable() {
127 STLDeleteValues(&pc_to_register_line_);
128 }
129
130 // Initialize the RegisterTable. Every instruction address can have a different set of information
131 // about what's in which register, but for verification purposes we only need to store it at
132 // branch target addresses (because we merge into that).
133 void Init(RegisterTrackingMode mode, InsnFlags* flags, uint32_t insns_size,
134 uint16_t registers_size, MethodVerifier* verifier);
135
136 RegisterLine* GetLine(size_t idx) {
137 Table::iterator result = pc_to_register_line_.find(idx); // TODO: C++0x auto
138 if (result == pc_to_register_line_.end()) {
139 return NULL;
140 } else {
141 return result->second;
142 }
143 }
144
145 private:
146 typedef SafeMap<int32_t, RegisterLine*> Table;
147 // Map from a dex pc to the register status associated with it
148 Table pc_to_register_line_;
149};
150
151// The verifier
152class MethodVerifier {
153 public:
154 /* Verify a class. Returns "true" on success. */
155 static bool VerifyClass(const Class* klass, std::string& error);
Ian Rogerse1758fe2012-04-19 11:31:15 -0700156
157 /*
158 * Structurally verify a class. Returns "true" on success. Used at compile time
159 * when the pointer for the method or declaring class can't be resolved.
160 */
Ian Rogers776ac1f2012-04-13 23:36:36 -0700161 static bool VerifyClass(const DexFile* dex_file, DexCache* dex_cache,
162 const ClassLoader* class_loader, uint32_t class_def_idx, std::string& error);
163
164 uint8_t EncodePcToReferenceMapData() const;
165
166 uint32_t DexFileVersion() const {
167 return dex_file_->GetVersion();
168 }
169
170 RegTypeCache* GetRegTypeCache() {
171 return &reg_types_;
172 }
173
Ian Rogerse1758fe2012-04-19 11:31:15 -0700174 // Verification failed
Ian Rogers776ac1f2012-04-13 23:36:36 -0700175 std::ostream& Fail(VerifyError error);
176
Ian Rogerse1758fe2012-04-19 11:31:15 -0700177 // Log for verification information
Ian Rogers776ac1f2012-04-13 23:36:36 -0700178 std::ostream& LogVerifyInfo() {
Ian Rogerse1758fe2012-04-19 11:31:15 -0700179 return info_messages_ << "VFY: " << PrettyMethod(method_)
Ian Rogers776ac1f2012-04-13 23:36:36 -0700180 << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : ";
181 }
182
183 // Dump the state of the verifier, namely each instruction, what flags are set on it, register
184 // information
185 void Dump(std::ostream& os);
186
187 static const std::vector<uint8_t>* GetGcMap(Compiler::MethodReference ref);
188 static void InitGcMaps();
189 static void DeleteGcMaps();
190
191#if defined(ART_USE_LLVM_COMPILER)
192 static const compiler_llvm::InferredRegCategoryMap* GetInferredRegCategoryMap(Compiler::MethodReference ref);
193 static void InitInferredRegCategoryMaps();
194 static void DeleteInferredRegCategoryMaps();
195#endif
196
197 static bool IsClassRejected(Compiler::ClassReference ref);
198
199 private:
200
Ian Rogerse1758fe2012-04-19 11:31:15 -0700201 explicit MethodVerifier(Method* method);
Ian Rogers776ac1f2012-04-13 23:36:36 -0700202 explicit MethodVerifier(const DexFile* dex_file, DexCache* dex_cache,
Ian Rogerse1758fe2012-04-19 11:31:15 -0700203 const ClassLoader* class_loader, uint32_t class_def_idx, const DexFile::CodeItem* code_item);
Ian Rogers776ac1f2012-04-13 23:36:36 -0700204
205 /*
206 * Perform verification on a single method.
207 *
208 * We do this in three passes:
209 * (1) Walk through all code units, determining instruction locations,
210 * widths, and other characteristics.
211 * (2) Walk through all code units, performing static checks on
212 * operands.
213 * (3) Iterate through the method, checking type safety and looking
214 * for code flow problems.
Ian Rogerse1758fe2012-04-19 11:31:15 -0700215 *
216 * Some checks may be bypassed depending on the verification mode. We can't
217 * turn this stuff off completely if we want to do "exact" GC.
218 *
219 * Confirmed here:
220 * - code array must not be empty
221 * Confirmed by ComputeWidthsAndCountOps():
222 * - opcode of first instruction begins at index 0
223 * - only documented instructions may appear
224 * - each instruction follows the last
225 * - last byte of last instruction is at (code_length-1)
Ian Rogers776ac1f2012-04-13 23:36:36 -0700226 */
Ian Rogerse1758fe2012-04-19 11:31:15 -0700227 static bool VerifyMethod(Method* method);
Ian Rogers0d604842012-04-16 14:50:24 -0700228 static void VerifyMethodAndDump(Method* method);
Ian Rogers776ac1f2012-04-13 23:36:36 -0700229
Ian Rogerse1758fe2012-04-19 11:31:15 -0700230 /*
231 * Perform structural verification on a single method. Used at compile time
232 * when the pointer for the method or declaring class can't be resolved.
233 *
234 * We do this in two 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 *
240 * Code flow verification is skipped since a resolved method and class are
241 * necessary to perform all the checks.
242 */
243 static bool VerifyMethod(uint32_t method_idx, const DexFile* dex_file, DexCache* dex_cache,
244 const ClassLoader* class_loader, uint32_t class_def_idx, const DexFile::CodeItem* code_item);
245
246 /* Run both structural and code flow verification on the method. */
247 bool VerifyAll();
248
249 /* Perform structural verification on a single method. */
250 bool VerifyStructure();
Ian Rogers776ac1f2012-04-13 23:36:36 -0700251
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 */
278 bool ScanTryCatchBlocks();
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.
358 // Updates "insnFlags", setting the "branch target" flag.
359 bool CheckBranchTarget(uint32_t cur_offset);
360
361 // Verify a switch table. "cur_offset" is the offset of the switch instruction.
362 // Updates "insnFlags", setting the "branch target" flag.
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. */
384 bool VerifyCodeFlow();
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.
388 bool SetTypesFromSignature();
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 */
436 bool CodeFlowVerifyMethod();
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 */
447 bool CodeFlowVerifyInstruction(uint32_t* start_guess);
448
449 // Perform verification of a new array instruction
450 void VerifyNewArray(const DecodedInstruction& dec_insn, bool is_filled,
451 bool is_range);
452
453 // Perform verification of an aget instruction. The destination register's type will be set to
454 // be that of component type of the array unless the array type is unknown, in which case a
455 // bottom type inferred from the type of instruction is used. is_primitive is false for an
456 // aget-object.
457 void VerifyAGet(const DecodedInstruction& insn, const RegType& insn_type,
458 bool is_primitive);
459
460 // Perform verification of an aput instruction.
461 void VerifyAPut(const DecodedInstruction& insn, const RegType& insn_type,
462 bool is_primitive);
463
464 // Lookup instance field and fail for resolution violations
465 Field* GetInstanceField(const RegType& obj_type, int field_idx);
466
467 // Lookup static field and fail for resolution violations
468 Field* GetStaticField(int field_idx);
469
470 // Perform verification of an iget or sget instruction.
471 void VerifyISGet(const DecodedInstruction& insn, const RegType& insn_type,
472 bool is_primitive, bool is_static);
473
474 // Perform verification of an iput or sput instruction.
475 void VerifyISPut(const DecodedInstruction& insn, const RegType& insn_type,
476 bool is_primitive, bool is_static);
477
478 // Resolves a class based on an index and performs access checks to ensure the referrer can
479 // access the resolved class.
480 const RegType& ResolveClassAndCheckAccess(uint32_t class_idx);
481
482 /*
483 * For the "move-exception" instruction at "work_insn_idx_", which must be at an exception handler
484 * address, determine the Join of all exceptions that can land here. Fails if no matching
485 * exception handler can be found or if the Join of exception types fails.
486 */
487 const RegType& GetCaughtExceptionType();
488
489 /*
490 * Resolves a method based on an index and performs access checks to ensure
491 * the referrer can access the resolved method.
492 * Does not throw exceptions.
493 */
494 Method* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type);
495
496 /*
497 * Verify the arguments to a method. We're executing in "method", making
498 * a call to the method reference in vB.
499 *
500 * If this is a "direct" invoke, we allow calls to <init>. For calls to
501 * <init>, the first argument may be an uninitialized reference. Otherwise,
502 * calls to anything starting with '<' will be rejected, as will any
503 * uninitialized reference arguments.
504 *
505 * For non-static method calls, this will verify that the method call is
506 * appropriate for the "this" argument.
507 *
508 * The method reference is in vBBBB. The "is_range" parameter determines
509 * whether we use 0-4 "args" values or a range of registers defined by
510 * vAA and vCCCC.
511 *
512 * Widening conversions on integers and references are allowed, but
513 * narrowing conversions are not.
514 *
515 * Returns the resolved method on success, NULL on failure (with *failure
516 * set appropriately).
517 */
518 Method* VerifyInvocationArgs(const DecodedInstruction& dec_insn,
519 MethodType method_type, bool is_range, bool is_super);
520
521 /*
Ian Rogerse1758fe2012-04-19 11:31:15 -0700522 * Return the register type for the method. We can't just use the already-computed
523 * DalvikJniReturnType, because if it's a reference type we need to do the class lookup.
524 * Returned references are assumed to be initialized. Returns kRegTypeUnknown for "void".
525 */
526 const RegType& GetMethodReturnType();
527
528 /*
Ian Rogers776ac1f2012-04-13 23:36:36 -0700529 * Verify that the target instruction is not "move-exception". It's important that the only way
530 * to execute a move-exception is as the first instruction of an exception handler.
531 * Returns "true" if all is well, "false" if the target instruction is move-exception.
532 */
533 bool CheckNotMoveException(const uint16_t* insns, int insn_idx);
534
535 /*
536 * Replace an instruction with "throw-verification-error". This allows us to
537 * defer error reporting until the code path is first used.
538 */
539 void ReplaceFailingInstruction();
540
541 /*
542 * Control can transfer to "next_insn". Merge the registers from merge_line into the table at
543 * next_insn, and set the changed flag on the target address if any of the registers were changed.
544 * Returns "false" if an error is encountered.
545 */
546 bool UpdateRegisters(uint32_t next_insn, const RegisterLine* merge_line);
547
548#if defined(ART_USE_LLVM_COMPILER)
549 /*
550 * Generate the inferred register category for LLVM-based code generator.
551 * Returns a pointer to a two-dimension Class array, or NULL on failure.
552 */
553 const compiler_llvm::InferredRegCategoryMap* GenerateInferredRegCategoryMap();
554#endif
555
556 /*
557 * Generate the GC map for a method that has just been verified (i.e. we're doing this as part of
558 * verification). For type-precise determination we have all the data we need, so we just need to
559 * encode it in some clever fashion.
560 * Returns a pointer to a newly-allocated RegisterMap, or NULL on failure.
561 */
562 const std::vector<uint8_t>* GenerateGcMap();
563
564 // Verify that the GC map associated with method_ is well formed
565 void VerifyGcMap(const std::vector<uint8_t>& data);
566
567 // Compute sizes for GC map data
568 void ComputeGcMapSizes(size_t* gc_points, size_t* ref_bitmap_bits, size_t* log2_max_gc_pc);
569
570 InsnFlags* CurrentInsnFlags();
571
572 // All the GC maps that the verifier has created
573 typedef SafeMap<const Compiler::MethodReference, const std::vector<uint8_t>*> GcMapTable;
574 static Mutex* gc_maps_lock_;
575 static GcMapTable* gc_maps_;
576 static void SetGcMap(Compiler::MethodReference ref, const std::vector<uint8_t>& gc_map);
577
578#if defined(ART_USE_LLVM_COMPILER)
579 // All the inferred register category maps that the verifier has created
580 typedef SafeMap<const Compiler::MethodReference,
581 const compiler_llvm::InferredRegCategoryMap*> InferredRegCategoryMapTable;
582 static Mutex* inferred_reg_category_maps_lock_;
583 static InferredRegCategoryMapTable* inferred_reg_category_maps_;
584 static void SetInferredRegCategoryMap(Compiler::MethodReference ref,
585 const compiler_llvm::InferredRegCategoryMap& m);
586#endif
587
588 static void AddRejectedClass(Compiler::ClassReference ref);
589
590 RegTypeCache reg_types_;
591
592 PcToRegisterLineTable reg_table_;
593
594 // Storage for the register status we're currently working on.
595 UniquePtr<RegisterLine> work_line_;
596
597 // The address of the instruction we're currently working on, note that this is in 2 byte
598 // quantities
599 uint32_t work_insn_idx_;
600
601 // Storage for the register status we're saving for later.
602 UniquePtr<RegisterLine> saved_line_;
603
Ian Rogerse1758fe2012-04-19 11:31:15 -0700604 Method* method_; // The method we're working on.
Ian Rogers776ac1f2012-04-13 23:36:36 -0700605 const DexFile* dex_file_; // The dex file containing the method.
606 DexCache* dex_cache_; // The dex_cache for the declaring class of the method.
607 const ClassLoader* class_loader_; // The class loader for the declaring class of the method.
608 uint32_t class_def_idx_; // The class def index of the declaring class of the method.
609 const DexFile::CodeItem* code_item_; // The code item containing the code for the method.
610 UniquePtr<InsnFlags[]> insn_flags_; // Instruction widths and flags, one entry per code unit.
611
Ian Rogerse1758fe2012-04-19 11:31:15 -0700612 // The type of any error that occurs
613 VerifyError failure_;
Ian Rogers776ac1f2012-04-13 23:36:36 -0700614
Ian Rogerse1758fe2012-04-19 11:31:15 -0700615 // Failure message log
616 std::ostringstream fail_messages_;
617 // Info message log
Ian Rogers776ac1f2012-04-13 23:36:36 -0700618 std::ostringstream info_messages_;
619
620 // The number of occurrences of specific opcodes.
621 size_t new_instance_count_;
622 size_t monitor_enter_count_;
623
624 friend struct art::ReferenceMap2Visitor; // for VerifyMethodAndDump
625};
626
627} // namespace verifier
628} // namespace art
629
630#endif // ART_SRC_VERIFIER_METHOD_VERIFIER_H_