1776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/*
2776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Copyright (C) 2012 The Android Open Source Project
3776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
4776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License");
5776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * you may not use this file except in compliance with the License.
6776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * You may obtain a copy of the License at
7776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
8776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *      http://www.apache.org/licenses/LICENSE-2.0
9776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
10776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Unless required by applicable law or agreed to in writing, software
11776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS,
12776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * See the License for the specific language governing permissions and
14776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * limitations under the License.
15776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */
16776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_VERIFIER_REGISTER_LINE_H_
18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_VERIFIER_REGISTER_LINE_H_
19776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
20700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers#include <memory>
21776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include <vector>
22776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
23de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier#include "base/scoped_arena_containers.h"
24776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "safe_map.h"
25776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
26776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace art {
278e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
288e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass Instruction;
298e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
30776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace verifier {
31776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
32776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersclass MethodVerifier;
338e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass RegType;
34776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
35776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/*
36776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Register type categories, for type checking.
37776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
38776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * The spec says category 1 includes boolean, byte, char, short, int, float, reference, and
39776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * returnAddress. Category 2 includes long and double.
40776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers *
41776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * We treat object references separately, so we have "category1nr". We don't support jsr/ret, so
42776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * there is no "returnAddress" type.
43776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */
44776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersenum TypeCategory {
45776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  kTypeCategoryUnknown = 0,
46776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  kTypeCategory1nr = 1,         // boolean, byte, char, short, int, float
47776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  kTypeCategory2 = 2,           // long, double
48776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  kTypeCategoryRef = 3,         // object reference
49776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers};
50776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
51ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe// What to do with the lock levels when setting the register type.
52ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampeenum class LockOp {
53ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  kClear,                       // Clear the lock levels recorded.
54ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  kKeep                         // Leave the lock levels alone.
55ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe};
56ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe
57776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// During verification, we associate one of these with every "interesting" instruction. We track
58776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// the status of all registers, and (if the method has any monitor-enter instructions) maintain a
59776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// stack of entered monitors (identified by code unit offset).
60776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersclass RegisterLine {
61776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers public:
62de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  // A map from register to a bit vector of indices into the monitors_ stack.
63de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  using RegToLockDepthsMap = ScopedArenaSafeMap<uint32_t, uint32_t>;
64de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier
65de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  // Create a register line of num_regs registers.
66de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  static RegisterLine* Create(size_t num_regs, MethodVerifier* verifier);
67776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
68776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Implement category-1 "move" instructions. Copy a 32-bit value from "vsrc" to "vdst".
697b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void CopyRegister1(MethodVerifier* verifier, uint32_t vdst, uint32_t vsrc, TypeCategory cat)
7090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
71776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
72776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Implement category-2 "move" instructions. Copy a 64-bit value from "vsrc" to "vdst". This
73776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // copies both halves of the register.
747b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void CopyRegister2(MethodVerifier* verifier, uint32_t vdst, uint32_t vsrc)
7590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
76776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
77776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Implement "move-result". Copy the category-1 value from the result register to another
78776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // register, and reset the result register.
797b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void CopyResultRegister1(MethodVerifier* verifier, uint32_t vdst, bool is_reference)
8090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
81776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
82776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Implement "move-result-wide". Copy the category-2 value from the result register to another
83776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // register, and reset the result register.
847b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void CopyResultRegister2(MethodVerifier* verifier, uint32_t vdst)
8590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
86776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
87776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Set the invisible result register to unknown
8890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  void SetResultTypeToUnknown(MethodVerifier* verifier) SHARED_REQUIRES(Locks::mutator_lock_);
89776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
90776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Set the type of register N, verifying that the register is valid.  If "newType" is the "Lo"
91776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // part of a 64-bit value, register N+1 will be set to "newType+1".
92776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // The register index was validated during the static pass, so we don't need to check it here.
93ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  //
94ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // LockOp::kClear should be used by default; it will clear the lock levels associated with the
95ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // register. An example is setting the register type because an instruction writes to the
96ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // register.
97ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // LockOp::kKeep keeps the lock levels of the register and only changes the register type. This
98ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // is typical when the underlying value did not change, but we have "different" type information
99ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // available now. An example is sharpening types after a check-cast. Note that when given kKeep,
100ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  // the new_type is dchecked to be a reference type.
101ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe  template <LockOp kLockOp>
1028817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  ALWAYS_INLINE bool SetRegisterType(MethodVerifier* verifier,
1038817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                     uint32_t vdst,
1047b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers                                     const RegType& new_type)
10590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
106776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
1078817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  bool SetRegisterTypeWide(MethodVerifier* verifier,
1088817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                           uint32_t vdst,
1098817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                           const RegType& new_type1,
1107b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers                           const RegType& new_type2)
11190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
1122bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
113776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /* Set the type of the "result" register. */
1147b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void SetResultRegisterType(MethodVerifier* verifier, const RegType& new_type)
11590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
116776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
117d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers  void SetResultRegisterTypeWide(const RegType& new_type1, const RegType& new_type2)
11890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
1192bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
120776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Get the type of register vsrc.
1217b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  const RegType& GetRegisterType(MethodVerifier* verifier, uint32_t vsrc) const;
122776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
1238817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  ALWAYS_INLINE bool VerifyRegisterType(MethodVerifier* verifier,
1248817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                        uint32_t vsrc,
1257b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers                                        const RegType& check_type)
12690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
127776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
1288817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  bool VerifyRegisterTypeWide(MethodVerifier* verifier,
1298817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              uint32_t vsrc,
1308817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& check_type1,
1317b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers                              const RegType& check_type2)
13290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
1332bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
134776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  void CopyFromLine(const RegisterLine* src) {
135776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    DCHECK_EQ(num_regs_, src->num_regs_);
136d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers    memcpy(&line_, &src->line_, num_regs_ * sizeof(uint16_t));
137776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    monitors_ = src->monitors_;
138776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    reg_to_lock_depths_ = src->reg_to_lock_depths_;
139f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe    this_initialized_ = src->this_initialized_;
140776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
141776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
14290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier  std::string Dump(MethodVerifier* verifier) const SHARED_REQUIRES(Locks::mutator_lock_);
143776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
144776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  void FillWithGarbage() {
145d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers    memset(&line_, 0xf1, num_regs_ * sizeof(uint16_t));
146db0cccd9a74cb9aa5f3b62f377415f653e3c0ca4Logan Chien    monitors_.clear();
147776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    reg_to_lock_depths_.clear();
148776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
149776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
150776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
151776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * We're creating a new instance of class C at address A. Any registers holding instances
152776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * previously created at address A must be initialized by now. If not, we mark them as "conflict"
153776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * to prevent them from being used (otherwise, MarkRefsAsInitialized would mark the old ones and
154776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * the new ones at the same time).
155776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
1567b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void MarkUninitRefsAsInvalid(MethodVerifier* verifier, const RegType& uninit_type)
15790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
158776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
159776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
160776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Update all registers holding "uninit_type" to instead hold the corresponding initialized
161776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * reference type. This is called when an appropriate constructor is invoked -- all copies of
162776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * the reference must be marked as initialized.
163776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
16498e6ce44c700abd9375fe17f0aa31fea1e1e938bNicolas Geoffray  void MarkRefsAsInitialized(MethodVerifier* verifier, const RegType& uninit_type)
16590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
166776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
167776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
168b8c7859f21f5ae4c9b90f2ef2effc51967299737Ian Rogers   * Update all registers to be Conflict except vsrc.
169b8c7859f21f5ae4c9b90f2ef2effc51967299737Ian Rogers   */
1707b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void MarkAllRegistersAsConflicts(MethodVerifier* verifier);
1717b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void MarkAllRegistersAsConflictsExcept(MethodVerifier* verifier, uint32_t vsrc);
1727b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void MarkAllRegistersAsConflictsExceptWide(MethodVerifier* verifier, uint32_t vsrc);
173b8c7859f21f5ae4c9b90f2ef2effc51967299737Ian Rogers
174f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  void SetThisInitialized() {
175f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe    this_initialized_ = true;
176f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  }
177f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe
178f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  void CopyThisInitialized(const RegisterLine& src) {
179f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe    this_initialized_ = src.this_initialized_;
180f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  }
181f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe
182b8c7859f21f5ae4c9b90f2ef2effc51967299737Ian Rogers  /*
183776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Check constraints on constructor return. Specifically, make sure that the "this" argument got
184776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * initialized.
185776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * The "this" argument to <init> uses code offset kUninitThisArgAddr, which puts it at the start
186776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * of the list in slot 0. If we see a register with an uninitialized slot 0 reference, we know it
187776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * somehow didn't get initialized.
188776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
1897b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  bool CheckConstructorReturn(MethodVerifier* verifier) const;
190776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
191776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Compare two register lines. Returns 0 if they match.
192776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Using this for a sort is unwise, since the value can change based on machine endianness.
193776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  int CompareLine(const RegisterLine* line2) const {
194a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe    if (monitors_ != line2->monitors_) {
195a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe      return 1;
196a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe    }
197776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    // TODO: DCHECK(reg_to_lock_depths_ == line2->reg_to_lock_depths_);
198d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers    return memcmp(&line_, &line2->line_, num_regs_ * sizeof(uint16_t));
199776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
200776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
201776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  size_t NumRegs() const {
202776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    return num_regs_;
203776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
204776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
205361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier  // Return how many bytes of memory a register line uses.
206361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier  ALWAYS_INLINE static size_t ComputeSize(size_t num_regs);
207361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier
208776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
209776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Get the "this" pointer from a non-static method invocation. This returns the RegType so the
210776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * caller can decide whether it needs the reference to be initialized or not. (Can also return
211776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * kRegTypeZero if the reference can only be zero at this point.)
212776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   *
213776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * The argument count is in vA, and the first argument is in vC, for both "simple" and "range"
214776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * versions. We just need to make sure vA is >= 1 and then return vC.
215091d238936809f6668ca6b7606c62bc224add430Mathieu Chartier   * allow_failure will return Conflict() instead of causing a verification failure if there is an
216091d238936809f6668ca6b7606c62bc224add430Mathieu Chartier   * error.
217776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
2188817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  const RegType& GetInvocationThis(MethodVerifier* verifier,
2198817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   const Instruction* inst,
2208817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   bool is_range,
2218817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   bool allow_failure = false)
22290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
223776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
224776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
225776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Verify types for a simple two-register instruction (e.g. "neg-int").
226776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * "dst_type" is stored into vA, and "src_type" is verified against vB.
227776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
2288817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckUnaryOp(MethodVerifier* verifier,
2298817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                    const Instruction* inst,
2308817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                    const RegType& dst_type,
231d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                    const RegType& src_type)
23290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
233776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
2348817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckUnaryOpWide(MethodVerifier* verifier,
2358817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                        const Instruction* inst,
2368817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                        const RegType& dst_type1,
2378817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                        const RegType& dst_type2,
2388817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                        const RegType& src_type1,
2398817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                        const RegType& src_type2)
24090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
2412bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
2428817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckUnaryOpToWide(MethodVerifier* verifier,
2438817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const Instruction* inst,
2448817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const RegType& dst_type1,
2458817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const RegType& dst_type2,
246d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                          const RegType& src_type)
24790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
2482bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
2498817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckUnaryOpFromWide(MethodVerifier* verifier,
2508817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                            const Instruction* inst,
251d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                            const RegType& dst_type,
2528817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                            const RegType& src_type1,
2538817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                            const RegType& src_type2)
25490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
2552bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
256776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
257776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Verify types for a simple three-register instruction (e.g. "add-int").
258776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * "dst_type" is stored into vA, and "src_type1"/"src_type2" are verified
259776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * against vB/vC.
260776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
2618817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOp(MethodVerifier* verifier,
2628817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                     const Instruction* inst,
2638817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                     const RegType& dst_type,
2648817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                     const RegType& src_type1,
2658817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                     const RegType& src_type2,
26600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers                     bool check_boolean_op)
26790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
268776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
2698817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOpWide(MethodVerifier* verifier,
2708817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const Instruction* inst,
2718817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& dst_type1,
2728817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& dst_type2,
2738817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& src_type1_1,
2748817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& src_type1_2,
2758817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& src_type2_1,
2768817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                         const RegType& src_type2_2)
27790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
2782bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
2798817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOpWideShift(MethodVerifier* verifier,
2808817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const Instruction* inst,
2818817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& long_lo_type,
2828817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& long_hi_type,
283d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                              const RegType& int_type)
28490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
2852bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
286776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
287776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Verify types for a binary "2addr" operation. "src_type1"/"src_type2"
288776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * are verified against vA/vB, then "dst_type" is stored into vA.
289776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
2908817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOp2addr(MethodVerifier* verifier,
2918817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const Instruction* inst,
292d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                          const RegType& dst_type,
2938817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const RegType& src_type1,
2948817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                          const RegType& src_type2,
29500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers                          bool check_boolean_op)
29690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
297776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
2988817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOp2addrWide(MethodVerifier* verifier,
2998817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const Instruction* inst,
3008817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& dst_type1,
3018817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& dst_type2,
3028817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& src_type1_1,
3038817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& src_type1_2,
3048817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& src_type2_1,
3058817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                              const RegType& src_type2_2)
30690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
3072bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
3088817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckBinaryOp2addrWideShift(MethodVerifier* verifier,
3098817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   const Instruction* inst,
3108817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   const RegType& long_lo_type,
3118817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                                   const RegType& long_hi_type,
312d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers                                   const RegType& int_type)
31390443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
3142bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers
315776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  /*
316776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * Verify types for A two-register instruction with a literal constant (e.g. "add-int/lit8").
317776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * "dst_type" is stored into vA, and "src_type" is verified against vB.
318776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   *
319776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   * If "check_boolean_op" is set, we use the constant value in vC.
320776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers   */
3218817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier  void CheckLiteralOp(MethodVerifier* verifier,
3228817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                      const Instruction* inst,
3238817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                      const RegType& dst_type,
3248817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                      const RegType& src_type,
3258817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                      bool check_boolean_op,
3268817760ca9f0590be373f5939cc86941e25d8f18Mathieu Chartier                      bool is_lit16)
32790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
328776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
329776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Verify/push monitor onto the monitor stack, locking the value in reg_idx at location insn_idx.
3307b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void PushMonitor(MethodVerifier* verifier, uint32_t reg_idx, int32_t insn_idx)
33190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
332776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
333776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Verify/pop monitor from monitor stack ensuring that we believe the monitor is locked
3347b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  void PopMonitor(MethodVerifier* verifier, uint32_t reg_idx)
33590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
336776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
337776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Stack of currently held monitors and where they were locked
338776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  size_t MonitorStackDepth() const {
339776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    return monitors_.size();
340776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
341776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
342776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // We expect no monitors to be held at certain points, such a method returns. Verify the stack
343a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe  // is empty, queueing a LOCKING error else.
344a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe  void VerifyMonitorStackEmpty(MethodVerifier* verifier) const;
345776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
3467b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers  bool MergeRegisters(MethodVerifier* verifier, const RegisterLine* incoming_line)
34790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier      SHARED_REQUIRES(Locks::mutator_lock_);
348776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
349de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  size_t GetMonitorEnterCount() const {
35008fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes    return monitors_.size();
35108fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes  }
35208fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes
353de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  uint32_t GetMonitorEnterDexPc(size_t i) const {
35408fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes    return monitors_[i];
35508fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes  }
35608fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes
357a21039c3ae2b20e44ceb2735251c04d0aac89afdElliott Hughes private:
358776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  void CopyRegToLockDepth(size_t dst, size_t src) {
359bad0267eaab9d6a522d05469ff90501deefdb88bMathieu Chartier    auto it = reg_to_lock_depths_.find(src);
360776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    if (it != reg_to_lock_depths_.end()) {
361776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      reg_to_lock_depths_.Put(dst, it->second);
362776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    }
363776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
364776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
365776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  bool IsSetLockDepth(size_t reg, size_t depth) {
366bad0267eaab9d6a522d05469ff90501deefdb88bMathieu Chartier    auto it = reg_to_lock_depths_.find(reg);
367776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    if (it != reg_to_lock_depths_.end()) {
368776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      return (it->second & (1 << depth)) != 0;
369776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    } else {
370776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      return false;
371776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    }
372776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
373776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
3748e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers  bool SetRegToLockDepth(size_t reg, size_t depth) {
375776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    CHECK_LT(depth, 32u);
3768e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers    if (IsSetLockDepth(reg, depth)) {
3778e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers      return false;  // Register already holds lock so locking twice is erroneous.
3788e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers    }
379bad0267eaab9d6a522d05469ff90501deefdb88bMathieu Chartier    auto it = reg_to_lock_depths_.find(reg);
380776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    if (it == reg_to_lock_depths_.end()) {
381776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      reg_to_lock_depths_.Put(reg, 1 << depth);
382776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    } else {
383776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      it->second |= (1 << depth);
384776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    }
3858e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers    return true;
386776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
387776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
388776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  void ClearRegToLockDepth(size_t reg, size_t depth) {
389776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    CHECK_LT(depth, 32u);
390776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    DCHECK(IsSetLockDepth(reg, depth));
391bad0267eaab9d6a522d05469ff90501deefdb88bMathieu Chartier    auto it = reg_to_lock_depths_.find(reg);
392776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    DCHECK(it != reg_to_lock_depths_.end());
393776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    uint32_t depths = it->second ^ (1 << depth);
394776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    if (depths != 0) {
395776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      it->second = depths;
396776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    } else {
397776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers      reg_to_lock_depths_.erase(it);
398776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    }
399f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe    // Need to unlock every register at the same lock depth. These are aliased locks.
400f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe    uint32_t mask = 1 << depth;
401f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe    for (auto& pair : reg_to_lock_depths_) {
402f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe      if ((pair.second & mask) != 0) {
403f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe        VLOG(verifier) << "Also unlocking " << pair.first;
404f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe        pair.second ^= mask;
405f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe      }
406f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe    }
407776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
408776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
409776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  void ClearAllRegToLockDepths(size_t reg) {
410776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers    reg_to_lock_depths_.erase(reg);
411776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  }
412776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
413de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  RegisterLine(size_t num_regs, MethodVerifier* verifier);
414d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers
4158e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers  // Storage for the result register's type, valid after an invocation.
416776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  uint16_t result_[2];
417776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
418776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // Length of reg_types_
419ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers  const uint32_t num_regs_;
4207b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers
4218e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers  // A stack of monitor enter locations.
422de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  ScopedArenaVector<uint32_t> monitors_;
423de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier
424776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // A map from register to a bit vector of indices into the monitors_ stack. As we pop the monitor
425776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers  // stack we verify that monitor-enter/exit are correctly nested. That is, if there was a
4268e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers  // monitor-enter on v5 and then on v6, we expect the monitor-exit to be on v6 then on v5.
427de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  RegToLockDepthsMap reg_to_lock_depths_;
428d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers
429f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  // Whether "this" initialization (a constructor supercall) has happened.
430f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe  bool this_initialized_;
431f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe
432d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers  // An array of RegType Ids associated with each dex register.
433de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier  uint16_t line_[1];
4348e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
4358e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers  DISALLOW_COPY_AND_ASSIGN(RegisterLine);
436776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers};
437776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
438361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartierclass RegisterLineArenaDelete : public ArenaDelete<RegisterLine> {
439361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier public:
440361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier  void operator()(RegisterLine* ptr) const;
441361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier};
442361e04aaa5d3eca9f978a802ee44b1213f31da58Mathieu Chartier
443776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}  // namespace verifier
444776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}  // namespace art
445776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers
446fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_VERIFIER_REGISTER_LINE_H_
447