method_verifier.h revision ec6e6c19662260c059b273dfc9c502900756487d
1776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/* 2776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Copyright (C) 2011 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_METHOD_VERIFIER_H_ 18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_VERIFIER_METHOD_VERIFIER_H_ 19776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 20700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers#include <memory> 21637ee0b9c10ab7732a7ee7b8335f3fff4ac1549cVladimir Marko#include <sstream> 22776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include <vector> 23776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 24de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier#include "base/arena_allocator.h" 25761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/macros.h" 26de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier#include "base/scoped_arena_containers.h" 27de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier#include "base/stl_util.h" 28776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers#include "dex_file.h" 29dc3761719fb5e2d1ced5708e3c73b965f9ef0c73Hiroshi Yamauchi#include "handle.h" 307b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers#include "instruction_flags.h" 3151c2467e8771b56e25ae4f17f66522f979f57a7eBrian Carlstrom#include "method_reference.h" 32576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers#include "reg_type_cache.h" 33776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 34776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace art { 35776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 368e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass Instruction; 37776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersstruct ReferenceMap2Visitor; 38d0ad2eea51850ed5972c23d03380b2305cdf7cb7Mathieu Chartierclass Thread; 398f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Markoclass VariableIndentationOutputStream; 40776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 41776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersnamespace verifier { 42776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 4346c6bb2f52cef82660b9be7576b49f83845df93aIan Rogersclass DexPcToReferenceMap; 448e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass MethodVerifier; 458e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass RegisterLine; 468e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersclass RegType; 47776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 48776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/* 49776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * "Direct" and "virtual" methods are stored independently. The type of call used to invoke the 50776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * method determines which list we search, and whether we travel up into superclasses. 51776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 52776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * (<clinit>, <init>, and methods declared "private" or "static" are stored in the "direct" list. 53776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * All others are stored in the "virtual" list.) 54776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 55776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersenum MethodType { 56776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers METHOD_UNKNOWN = 0, 57776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers METHOD_DIRECT, // <init>, private 58776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers METHOD_STATIC, // static 59776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers METHOD_VIRTUAL, // virtual, super 60776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers METHOD_INTERFACE // interface 61776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}; 622fc1427ee9c534ed44d72184ad6d74ea65f3d5b3Ian Rogersstd::ostream& operator<<(std::ostream& os, const MethodType& rhs); 63776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 64776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers/* 65776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * An enumeration of problems that can turn up during verification. 66776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Both VERIFY_ERROR_BAD_CLASS_SOFT and VERIFY_ERROR_BAD_CLASS_HARD denote failures that cause 67776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * the entire class to be rejected. However, VERIFY_ERROR_BAD_CLASS_SOFT denotes a soft failure 68776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * that can potentially be corrected, and the verifier will try again at runtime. 69776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * VERIFY_ERROR_BAD_CLASS_HARD denotes a hard failure that can't be corrected, and will cause 70776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * the class to remain uncompiled. Other errors denote verification errors that cause bytecode 71776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * to be rewritten to fail at runtime. 72776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 73776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersenum VerifyError { 74a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_BAD_CLASS_HARD = 1, // VerifyError; hard error that skips compilation. 75a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_BAD_CLASS_SOFT = 2, // VerifyError; soft error that verifies again at runtime. 760760a81257fa427646c309500d603194009265efAndreas Gampe 77a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_NO_CLASS = 4, // NoClassDefFoundError. 78a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_NO_FIELD = 8, // NoSuchFieldError. 79a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_NO_METHOD = 16, // NoSuchMethodError. 80a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_ACCESS_CLASS = 32, // IllegalAccessError. 81a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_ACCESS_FIELD = 64, // IllegalAccessError. 82a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_ACCESS_METHOD = 128, // IllegalAccessError. 83a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_CLASS_CHANGE = 256, // IncompatibleClassChangeError. 84a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_INSTANTIATION = 512, // InstantiationError. 85158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // For opcodes that don't have complete verifier support (such as lambda opcodes), 86158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // we need a way to continue execution at runtime without attempting to re-verify 87158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // (since we know it will fail no matter what). Instead, run as the interpreter 88158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // in a special "do access checks" mode which will perform verifier-like checking 89158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // on the fly. 90158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // 91158f35c98e2ec0d40d2c032b8cdce5fb60944a7fIgor Murashkin // TODO: Once all new opcodes have implemented full verifier support, this can be removed. 92a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_FORCE_INTERPRETER = 1024, // Skip the verification phase at runtime; 93a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe // force the interpreter to do access checks. 94a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe // (sets a soft fail at compile time). 95a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe VERIFY_ERROR_LOCKING = 2048, // Could not guarantee balanced locking. This should be 96a727e372d8f6929cd30b983f6969c7a50fc83bb6Andreas Gampe // punted to the interpreter with access checks. 97776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}; 98776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersstd::ostream& operator<<(std::ostream& os, const VerifyError& rhs); 99776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 100776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// We don't need to store the register data for many instructions, because we either only need 101776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// it at branch points (for verification) or GC points and branches (for verification + 102776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// type-precise register analysis). 103776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersenum RegisterTrackingMode { 104776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers kTrackRegsBranches, 10502c42237741b5573f9d790a5a0f17f408dceb543Sameer Abu Asal kTrackCompilerInterestPoints, 106776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers kTrackRegsAll, 107776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}; 108776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 1092bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers// A mapping from a dex pc to the register line statuses as they are immediately prior to the 1102bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers// execution of that instruction. 111776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersclass PcToRegisterLineTable { 112776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers public: 113de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier explicit PcToRegisterLineTable(ScopedArenaAllocator& arena); 114d0fbd85a82a266c21d6b72c61d6dc098ec362de7Ian Rogers ~PcToRegisterLineTable(); 115776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 116776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Initialize the RegisterTable. Every instruction address can have a different set of information 117776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // about what's in which register, but for verification purposes we only need to store it at 118776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // branch target addresses (because we merge into that). 1197b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers void Init(RegisterTrackingMode mode, InstructionFlags* flags, uint32_t insns_size, 120776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers uint16_t registers_size, MethodVerifier* verifier); 121776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 122de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier RegisterLine* GetLine(size_t idx) const { 123de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier return register_lines_[idx].get(); 124776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers } 125776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 126776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers private: 127de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ScopedArenaVector<ArenaUniquePtr<RegisterLine>> register_lines_; 1288e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers 1298e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers DISALLOW_COPY_AND_ASSIGN(PcToRegisterLineTable); 130776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}; 131776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 132776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers// The verifier 133776ac1fa61237db645adb4370a4aab888530caf4Ian Rogersclass MethodVerifier { 134776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers public: 135f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao enum FailureKind { 136f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao kNoFailure, 137f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao kSoftFailure, 138f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao kHardFailure, 139f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao }; 140f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao 141f1e6b7c8cd78c02f4eb36574f0e417c4edc2b91ejeffhao /* Verify a class. Returns "kNoFailure" on success. */ 142ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe static FailureKind VerifyClass(Thread* self, 143ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe mirror::Class* klass, 144ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool allow_soft_failures, 145ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool log_hard_failures, 1467b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers std::string* error) 14790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 148ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe static FailureKind VerifyClass(Thread* self, 149ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe const DexFile* dex_file, 1505a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::DexCache> dex_cache, 1515a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader, 1528b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers const DexFile::ClassDef* class_def, 153ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool allow_soft_failures, 154ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool log_hard_failures, 155ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe std::string* error) 15690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 157776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 1588f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko static MethodVerifier* VerifyMethodAndDump(Thread* self, 1598f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko VariableIndentationOutputStream* vios, 1608f1e08af6172781f91a17fce0a5a4183a9f70aa9Vladimir Marko uint32_t method_idx, 1612ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile* dex_file, 1625a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::DexCache> dex_cache, 1635a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader, 1642ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile::ClassDef* class_def, 165e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier const DexFile::CodeItem* code_item, ArtMethod* method, 1662ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe uint32_t method_access_flags) 16790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 1682bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 169776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers uint8_t EncodePcToReferenceMapData() const; 170776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 171776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers uint32_t DexFileVersion() const { 172776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers return dex_file_->GetVersion(); 173776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers } 174776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 175776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers RegTypeCache* GetRegTypeCache() { 176776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers return ®_types_; 177776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers } 178776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 179ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Log a verification failure. 180776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers std::ostream& Fail(VerifyError error); 181776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 182ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Log for verification information. 183576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers std::ostream& LogVerifyInfo(); 184776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 185ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Dump the failures encountered by the verifier. 186ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers std::ostream& DumpFailures(std::ostream& os); 187ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers 188776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Dump the state of the verifier, namely each instruction, what flags are set on it, register 189776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // information 19090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier void Dump(std::ostream& os) SHARED_REQUIRES(Locks::mutator_lock_); 19190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier void Dump(VariableIndentationOutputStream* vios) SHARED_REQUIRES(Locks::mutator_lock_); 192776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 19308fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes // Fills 'monitor_enter_dex_pcs' with the dex pcs of the monitor-enter instructions corresponding 1942d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz // to the locks held at 'dex_pc' in method 'm'. 195e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static void FindLocksAtDexPc(ArtMethod* m, uint32_t dex_pc, 19646960fe5dcc1be07b39a55114338423a73554449Ian Rogers std::vector<uint32_t>* monitor_enter_dex_pcs) 19790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 19808fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes 1992d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz // Returns the accessed field corresponding to the quick instruction's field 2002d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz // offset at 'dex_pc' in method 'm'. 201e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static ArtField* FindAccessedFieldAtDexPc(ArtMethod* m, uint32_t dex_pc) 20290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 2032d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 2042d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz // Returns the invoked method corresponding to the quick instruction's vtable 2052d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz // index at 'dex_pc' in method 'm'. 206e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static ArtMethod* FindInvokedMethodAtDexPc(ArtMethod* m, uint32_t dex_pc) 20790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 2082d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 209e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier static SafeMap<uint32_t, std::set<uint32_t>> FindStringInitMap(ArtMethod* m) 21090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 211848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao 21290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier static void Init() SHARED_REQUIRES(Locks::mutator_lock_); 2130a1038b0a30a52dff1a449a989825e808a83df80Elliott Hughes static void Shutdown(); 214776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 2154993bbc8eda377804e585efd918f8ab9d9eab7d4Elliott Hughes bool CanLoadClasses() const { 2164993bbc8eda377804e585efd918f8ab9d9eab7d4Elliott Hughes return can_load_classes_; 2174993bbc8eda377804e585efd918f8ab9d9eab7d4Elliott Hughes } 2184993bbc8eda377804e585efd918f8ab9d9eab7d4Elliott Hughes 2195a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe MethodVerifier(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, 2205a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader, const DexFile::ClassDef* class_def, 221bf99f77dda749e2b653e8c45259b1fb56e7bb012Mathieu Chartier const DexFile::CodeItem* code_item, uint32_t method_idx, 222e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* method, 22346960fe5dcc1be07b39a55114338423a73554449Ian Rogers uint32_t access_flags, bool can_load_classes, bool allow_soft_failures, 2244306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier bool need_precise_constants, bool allow_thread_suspension) 22590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_) 2262ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe : MethodVerifier(self, dex_file, dex_cache, class_loader, class_def, code_item, method_idx, 2272ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe method, access_flags, can_load_classes, allow_soft_failures, 2284306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier need_precise_constants, false, allow_thread_suspension) {} 229ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers 230590fee9e8972f872301c2d16a575d579ee564beeMathieu Chartier ~MethodVerifier(); 23133691abbc43850fd2b2951256c4b6bbc9733ccc8Sebastien Hertz 2327b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers // Run verification on the method. Returns true if verification completes and false if the input 2337b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers // has an irrecoverable corruption. 23490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool Verify() SHARED_REQUIRES(Locks::mutator_lock_); 2357b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers 2367b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers // Describe VRegs at the given dex pc. 2377b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers std::vector<int32_t> DescribeVRegs(uint32_t dex_pc); 2387b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers 239bb87e0f1a52de656bc77cb01cb887e51a0e5198bMathieu Chartier static void VisitStaticRoots(RootVisitor* visitor) 24090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 241bb87e0f1a52de656bc77cb01cb887e51a0e5198bMathieu Chartier void VisitRoots(RootVisitor* visitor, const RootInfo& roots) 24290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 243c528dba35b5faece51ca658fc008b688f8b690adMathieu Chartier 2442b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko // Accessors used by the compiler via CompilerCallback 2452b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko const DexFile::CodeItem* CodeItem() const; 2462b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko RegisterLine* GetRegLine(uint32_t dex_pc); 247de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ALWAYS_INLINE const InstructionFlags& GetInstructionFlags(size_t index) const; 248de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ALWAYS_INLINE InstructionFlags& GetInstructionFlags(size_t index); 24990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier mirror::ClassLoader* GetClassLoader() SHARED_REQUIRES(Locks::mutator_lock_); 25090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier mirror::DexCache* GetDexCache() SHARED_REQUIRES(Locks::mutator_lock_); 2512b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko MethodReference GetMethodReference() const; 2522b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko uint32_t GetAccessFlags() const; 2532b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko bool HasCheckCasts() const; 2542b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko bool HasVirtualOrInterfaceInvokes() const; 2552b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko bool HasFailures() const; 2564824c27988c8eeb302791624bb3ce1d557b0db6cNicolas Geoffray bool HasInstructionThatWillThrow() const { 257d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe return have_any_pending_runtime_throw_failure_; 2584824c27988c8eeb302791624bb3ce1d557b0db6cNicolas Geoffray } 2594824c27988c8eeb302791624bb3ce1d557b0db6cNicolas Geoffray 260d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType& ResolveCheckedClass(uint32_t class_idx) 26190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 2622cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier // Returns the method of a quick invoke or null if it cannot be found. 263e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* GetQuickInvokedMethod(const Instruction* inst, RegisterLine* reg_line, 264091d238936809f6668ca6b7606c62bc224add430Mathieu Chartier bool is_range, bool allow_failure) 26590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 2662cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier // Returns the access field of a quick field access (iget/iput-quick) or null 267e5f13e57ff8fa36342beb33830b3ec5942a61ccaMathieu Chartier // if it cannot be found. 268c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier ArtField* GetQuickFieldAccess(const Instruction* inst, RegisterLine* reg_line) 26990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 2702b5eaa2b49f7489bafdadc4b4463ae27e4261817Vladimir Marko 271e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe SafeMap<uint32_t, std::set<uint32_t>>& GetStringInitPcRegMap() { 272e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe return string_init_pc_reg_map_; 2737e541c91997b7747fa79014a8ea540395e54efc8Stephen Kyle } 2747e541c91997b7747fa79014a8ea540395e54efc8Stephen Kyle 275e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe uint32_t GetEncounteredFailureTypes() { 276e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe return encountered_failure_types_; 2777e541c91997b7747fa79014a8ea540395e54efc8Stephen Kyle } 2787e541c91997b7747fa79014a8ea540395e54efc8Stephen Kyle 279f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe bool IsInstanceConstructor() const { 280f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe return IsConstructor() && !IsStatic(); 281f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe } 282f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe 283de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ScopedArenaAllocator& GetArena() { 284de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier return arena_; 285de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier } 286de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier 287e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe private: 288de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier void UninstantiableError(const char* descriptor); 289de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier static bool IsInstantiableOrPrimitive(mirror::Class* klass) SHARED_REQUIRES(Locks::mutator_lock_); 290de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier 291e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // Is the method being verified a constructor? See the comment on the field. 292e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe bool IsConstructor() const { 293e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe return is_constructor_; 294848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao } 295848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao 296e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // Is the method verified static? 297e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe bool IsStatic() const { 298e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe return (method_access_flags_ & kAccStatic) != 0; 2990760a81257fa427646c309500d603194009265efAndreas Gampe } 3000760a81257fa427646c309500d603194009265efAndreas Gampe 3012ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe // Private constructor for dumping. 3025a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe MethodVerifier(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, 3035a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader, const DexFile::ClassDef* class_def, 3042ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const DexFile::CodeItem* code_item, uint32_t method_idx, 305e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* method, uint32_t access_flags, 3062ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe bool can_load_classes, bool allow_soft_failures, bool need_precise_constants, 3074306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier bool verify_to_dump, bool allow_thread_suspension) 30890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 3092ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe 310ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Adds the given string to the beginning of the last failure message. 311ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers void PrependToLastFailMessage(std::string); 312ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers 313ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Adds the given string to the end of the last failure message. 314ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers void AppendToLastFailMessage(std::string); 315776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 316ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe // Verify all direct or virtual methods of a class. The method assumes that the iterator is 317ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe // positioned correctly, and the iterator will be updated. 318ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe template <bool kDirect> 319ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe static void VerifyMethods(Thread* self, 320ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe ClassLinker* linker, 321ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe const DexFile* dex_file, 322ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe const DexFile::ClassDef* class_def, 323ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe ClassDataItemIterator* it, 324ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe Handle<mirror::DexCache> dex_cache, 325ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe Handle<mirror::ClassLoader> class_loader, 326ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool allow_soft_failures, 327ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool log_hard_failures, 328ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool need_precise_constants, 329ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool* hard_fail, 330ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe size_t* error_count, 331ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe std::string* error_string) 332ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe SHARED_REQUIRES(Locks::mutator_lock_); 333ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe 334776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 335776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Perform verification on a single method. 336776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 337776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * We do this in three passes: 338776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * (1) Walk through all code units, determining instruction locations, 339776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * widths, and other characteristics. 340776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * (2) Walk through all code units, performing static checks on 341776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * operands. 342776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * (3) Iterate through the method, checking type safety and looking 343776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * for code flow problems. 344e1758feb293c7ff67d6fe59dbc31af0811863ce5Ian Rogers */ 345ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe static FailureKind VerifyMethod(Thread* self, uint32_t method_idx, 346ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe const DexFile* dex_file, 3475a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::DexCache> dex_cache, 3485a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader, 3498b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers const DexFile::ClassDef* class_def_idx, 3502dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers const DexFile::CodeItem* code_item, 351ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe ArtMethod* method, 352ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe uint32_t method_access_flags, 353ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool allow_soft_failures, 354ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool log_hard_failures, 355ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe bool need_precise_constants, 356ec6e6c19662260c059b273dfc9c502900756487dAndreas Gampe std::string* hard_failure_msg) 35790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 358e1758feb293c7ff67d6fe59dbc31af0811863ce5Ian Rogers 35990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier void FindLocksAtDexPc() SHARED_REQUIRES(Locks::mutator_lock_); 36008fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes 361c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier ArtField* FindAccessedFieldAtDexPc(uint32_t dex_pc) 36290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 3632d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 364e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* FindInvokedMethodAtDexPc(uint32_t dex_pc) 36590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 3662d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 367848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao SafeMap<uint32_t, std::set<uint32_t>>& FindStringInitMap() 36890443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 369848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao 370776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 371776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Compute the width of the instruction at each address in the instruction stream, and store it in 372776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * insn_flags_. Addresses that are in the middle of an instruction, or that are part of switch 373776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * table data, are not touched (so the caller should probably initialize "insn_flags" to zero). 374776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 375776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * The "new_instance_count_" and "monitor_enter_count_" fields in vdata are also set. 376776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 377776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Performs some static checks, notably: 378776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - opcode of first instruction begins at index 0 379776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - only documented instructions may appear 380776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - each instruction follows the last 381776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - last byte of last instruction is at (code_length-1) 382776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 383776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Logs an error and returns "false" on failure. 384776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 385776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool ComputeWidthsAndCountOps(); 386776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 387776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 388776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Set the "in try" flags for all instructions protected by "try" statements. Also sets the 389776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * "branch target" flags for exception handlers. 390776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 391776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Call this after widths have been set in "insn_flags". 392776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 393776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Returns "false" if something in the exception table looks fishy, but we're expecting the 394776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * exception table to be somewhat sane. 395776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 39690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool ScanTryCatchBlocks() SHARED_REQUIRES(Locks::mutator_lock_); 397776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 398776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 399776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Perform static verification on all instructions in a method. 400776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 401776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Walks through instructions in a method calling VerifyInstruction on each. 402776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 403776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool VerifyInstructions(); 404776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 405776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 406776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Perform static verification on an instruction. 407776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 408776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * As a side effect, this sets the "branch target" flags in InsnFlags. 409776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 410776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * "(CF)" items are handled during code-flow analysis. 411776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 412776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * v3 4.10.1 413776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - target of each jump and branch instruction must be valid 414776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - targets of switch statements must be valid 415776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - operands referencing constant pool entries must be valid 416776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (CF) operands of getfield, putfield, getstatic, putstatic must be valid 417776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (CF) operands of method invocation instructions must be valid 418776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (CF) only invoke-direct can call a method starting with '<' 419776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (CF) <clinit> must never be called explicitly 420776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - operands of instanceof, checkcast, new (and variants) must be valid 421776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - new-array[-type] limited to 255 dimensions 422776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - can't use "new" on an array class 423776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (?) limit dimensions in multi-array creation 424776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - local variable load/store register values must be in valid range 425776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 426776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * v3 4.11.1.2 427776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - branches must be within the bounds of the code array 428776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - targets of all control-flow instructions are the start of an instruction 429776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - register accesses fall within range of allocated registers 430776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (N/A) access to constant pool must be of appropriate type 431776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - code does not end in the middle of an instruction 432776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - execution cannot fall off the end of the code 433776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (earlier) for each exception handler, the "try" area must begin and 434776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * end at the start of an instruction (end can be at the end of the code) 435776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (earlier) for each exception handler, the handler must start at a valid 436776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * instruction 437776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 438776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool VerifyInstruction(const Instruction* inst, uint32_t code_offset); 439776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 440776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* Ensure that the register index is valid for this code item. */ 441776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckRegisterIndex(uint32_t idx); 442776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 443776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* Ensure that the wide register index is valid for this code item. */ 444776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckWideRegisterIndex(uint32_t idx); 445776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 446eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier // Perform static checks on a field Get or set instruction. All we do here is ensure that the 447776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // field index is in the valid range. 448776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckFieldIndex(uint32_t idx); 449776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 450776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform static checks on a method invocation instruction. All we do here is ensure that the 451776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // method index is in the valid range. 452776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckMethodIndex(uint32_t idx); 453776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 454776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform static checks on a "new-instance" instruction. Specifically, make sure the class 455776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // reference isn't for an array class. 456776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckNewInstance(uint32_t idx); 457776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 458776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* Ensure that the string index is in the valid range. */ 459776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckStringIndex(uint32_t idx); 460776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 461776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform static checks on an instruction that takes a class constant. Ensure that the class 462776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // index is in the valid range. 463776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckTypeIndex(uint32_t idx); 464776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 465776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform static checks on a "new-array" instruction. Specifically, make sure they aren't 466776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // creating an array of arrays that causes the number of dimensions to exceed 255. 467776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckNewArray(uint32_t idx); 468776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 469776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Verify an array data table. "cur_offset" is the offset of the fill-array-data instruction. 470776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckArrayData(uint32_t cur_offset); 471776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 472776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Verify that the target of a branch instruction is valid. We don't expect code to jump directly 473776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // into an exception handler, but it's valid to do so as long as the target isn't a 474776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // "move-exception" instruction. We verify that in a later stage. 475776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // The dex format forbids certain instructions from branching to themselves. 47624edeb5f13c2fe67344cab01cb248b8f94e6faf9Elliott Hughes // Updates "insn_flags_", setting the "branch target" flag. 477776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckBranchTarget(uint32_t cur_offset); 478776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 479776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Verify a switch table. "cur_offset" is the offset of the switch instruction. 48024edeb5f13c2fe67344cab01cb248b8f94e6faf9Elliott Hughes // Updates "insn_flags_", setting the "branch target" flag. 481776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckSwitchTargets(uint32_t cur_offset); 482776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 483776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Check the register indices used in a "vararg" instruction, such as invoke-virtual or 484776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // filled-new-array. 485776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // - vA holds word count (0-5), args[] have values. 486776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // There are some tests we don't do here, e.g. we don't try to verify that invoking a method that 487776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // takes a double is done with consecutive registers. This requires parsing the target method 488776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // signature, which we will be doing later on during the code flow analysis. 489776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckVarArgRegs(uint32_t vA, uint32_t arg[]); 490776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 491776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Check the register indices used in a "vararg/range" instruction, such as invoke-virtual/range 492776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // or filled-new-array/range. 493776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // - vA holds word count, vC holds index of first reg. 494776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckVarArgRangeRegs(uint32_t vA, uint32_t vC); 495776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 496776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Extract the relative offset from a branch instruction. 497776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Returns "false" on failure (e.g. this isn't a branch instruction). 498776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool GetBranchOffset(uint32_t cur_offset, int32_t* pOffset, bool* pConditional, 499776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool* selfOkay); 500776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 501776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* Perform detailed code-flow analysis on a single method. */ 50290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool VerifyCodeFlow() SHARED_REQUIRES(Locks::mutator_lock_); 503776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 504776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Set the register types for the first instruction in the method based on the method signature. 505776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // This has the side-effect of validating the signature. 50690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool SetTypesFromSignature() SHARED_REQUIRES(Locks::mutator_lock_); 507776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 508776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 509776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Perform code flow on a method. 510776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 511776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * The basic strategy is as outlined in v3 4.11.1.2: set the "changed" bit on the first 512776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * instruction, process it (setting additional "changed" bits), and repeat until there are no 513776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * more. 514776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 515776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * v3 4.11.1.1 516776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - (N/A) operand stack is always the same size 517776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - operand stack [registers] contain the correct types of values 518776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - local variables [registers] contain the correct types of values 519776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - methods are invoked with the appropriate arguments 520776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - fields are assigned using values of appropriate types 521776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - opcodes have the correct type values in operand registers 522776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - there is never an uninitialized class instance in a local variable in code protected by an 523776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * exception handler (operand stack is okay, because the operand stack is discarded when an 524776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * exception is thrown) [can't know what's a local var w/o the debug info -- should fall out of 525776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * register typing] 526776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 527776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * v3 4.11.1.2 528776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * - execution cannot fall off the end of the code 529776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 530776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * (We also do many of the items described in the "static checks" sections, because it's easier to 531776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * do them here.) 532776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 533776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * We need an array of RegType values, one per register, for every instruction. If the method uses 534776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * monitor-enter, we need extra data for every register, and a stack for every "interesting" 535776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * instruction. In theory this could become quite large -- up to several megabytes for a monster 536776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * function. 537776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 538776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * NOTE: 539776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * The spec forbids backward branches when there's an uninitialized reference in a register. The 540776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * idea is to prevent something like this: 541776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * loop: 542776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * move r1, r0 543776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * new-instance r0, MyClass 544776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * ... 545776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * if-eq rN, loop // once 546776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * initialize r0 547776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 548776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * This leaves us with two different instances, both allocated by the same instruction, but only 549776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * one is initialized. The scheme outlined in v3 4.11.1.4 wouldn't catch this, so they work around 550776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * it by preventing backward branches. We achieve identical results without restricting code 551776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * reordering by specifying that you can't execute the new-instance instruction if a register 552776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * contains an uninitialized instance created by that same instruction. 553776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 55490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool CodeFlowVerifyMethod() SHARED_REQUIRES(Locks::mutator_lock_); 555776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 556776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 557776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Perform verification for a single instruction. 558776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 559776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * This requires fully decoding the instruction to determine the effect it has on registers. 560776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 561776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Finds zero or more following instructions and sets the "changed" flag if execution at that 562776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * point needs to be (re-)evaluated. Register changes are merged into "reg_types_" at the target 563776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * addresses. Does not set or clear any other flags in "insn_flags_". 564776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 56500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers bool CodeFlowVerifyInstruction(uint32_t* start_guess) 56690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 567776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 568776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform verification of a new array instruction 5695243e912875026f99428088db7e80cb11651d64eSebastien Hertz void VerifyNewArray(const Instruction* inst, bool is_filled, bool is_range) 57090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 571776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 572fe1f7c84369abbf5a0121557aa0c6c58e9477710Jeff Hao // Helper to perform verification on puts of primitive type. 573d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers void VerifyPrimitivePut(const RegType& target_type, const RegType& insn_type, 57490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier const uint32_t vregA) SHARED_REQUIRES(Locks::mutator_lock_); 575fe1f7c84369abbf5a0121557aa0c6c58e9477710Jeff Hao 576776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform verification of an aget instruction. The destination register's type will be set to 577776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // be that of component type of the array unless the array type is unknown, in which case a 578776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // bottom type inferred from the type of instruction is used. is_primitive is false for an 579776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // aget-object. 580d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers void VerifyAGet(const Instruction* inst, const RegType& insn_type, 58190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool is_primitive) SHARED_REQUIRES(Locks::mutator_lock_); 582776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 583776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Perform verification of an aput instruction. 584d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers void VerifyAPut(const Instruction* inst, const RegType& insn_type, 58590443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier bool is_primitive) SHARED_REQUIRES(Locks::mutator_lock_); 586776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 587776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Lookup instance field and fail for resolution violations 588c785344b87221f5e4e6473e5b762e4e61fe65dcfMathieu Chartier ArtField* GetInstanceField(const RegType& obj_type, int field_idx) 58990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 590776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 591776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Lookup static field and fail for resolution violations 59290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier ArtField* GetStaticField(int field_idx) SHARED_REQUIRES(Locks::mutator_lock_); 593776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 594896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe // Perform verification of an iget/sget/iput/sput instruction. 595896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe enum class FieldAccessType { // private 596896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe kAccGet, 597896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe kAccPut 598896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe }; 599896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe template <FieldAccessType kAccType> 600896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe void VerifyISFieldAccess(const Instruction* inst, const RegType& insn_type, 601896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe bool is_primitive, bool is_static) 60290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 603776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 604896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe template <FieldAccessType kAccType> 605896df40bbb20f4a1c468e87313b510c082016dd3Andreas Gampe void VerifyQuickFieldAccess(const Instruction* inst, const RegType& insn_type, bool is_primitive) 60690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 6072d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 608776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Resolves a class based on an index and performs access checks to ensure the referrer can 609776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // access the resolved class. 610d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType& ResolveClassAndCheckAccess(uint32_t class_idx) 61190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 612776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 613776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 614776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * For the "move-exception" instruction at "work_insn_idx_", which must be at an exception handler 615776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * address, determine the Join of all exceptions that can land here. Fails if no matching 616776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * exception handler can be found or if the Join of exception types fails. 617776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 618d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType& GetCaughtExceptionType() 61990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 620776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 621776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 622776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Resolves a method based on an index and performs access checks to ensure 623776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * the referrer can access the resolved method. 624776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Does not throw exceptions. 625776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 626e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type) 62790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 628776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 629776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 630776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Verify the arguments to a method. We're executing in "method", making 631776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * a call to the method reference in vB. 632776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 633776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * If this is a "direct" invoke, we allow calls to <init>. For calls to 634776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * <init>, the first argument may be an uninitialized reference. Otherwise, 635776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * calls to anything starting with '<' will be rejected, as will any 636776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * uninitialized reference arguments. 637776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 638776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * For non-static method calls, this will verify that the method call is 639776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * appropriate for the "this" argument. 640776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 641776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * The method reference is in vBBBB. The "is_range" parameter determines 642776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * whether we use 0-4 "args" values or a range of registers defined by 643776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * vAA and vCCCC. 644776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 645776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Widening conversions on integers and references are allowed, but 646776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * narrowing conversions are not. 647776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * 6482cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier * Returns the resolved method on success, null on failure (with *failure 649776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * set appropriately). 650776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 651e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* VerifyInvocationArgs(const Instruction* inst, 652ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom MethodType method_type, 653ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom bool is_range, bool is_super) 65490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 655776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 65695c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe // Similar checks to the above, but on the proto. Will be used when the method cannot be 65795c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe // resolved. 65895c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe void VerifyInvocationArgsUnresolvedMethod(const Instruction* inst, MethodType method_type, 65995c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe bool is_range) 66090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 66195c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe 66295c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe template <class T> 663e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* VerifyInvocationArgsFromIterator(T* it, const Instruction* inst, 66495c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe MethodType method_type, bool is_range, 665e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* res_method) 66690443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 66795c0bf8fb5847cff263639f889d04c7c3c26eeddAndreas Gampe 668e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* VerifyInvokeVirtualQuickArgs(const Instruction* inst, bool is_range) 66990443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 6702d6ba5158d7fd459db2870df47300b517dc4d08cSebastien Hertz 671776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 672776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Verify that the target instruction is not "move-exception". It's important that the only way 673776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * to execute a move-exception is as the first instruction of an exception handler. 674776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Returns "true" if all is well, "false" if the target instruction is move-exception. 675776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 676776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers bool CheckNotMoveException(const uint16_t* insns, int insn_idx); 677776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 678776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers /* 6799bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * Verify that the target instruction is not "move-result". It is important that we cannot 6809bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * branch to move-result instructions, but we have to make this a distinct check instead of 6819bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * adding it to CheckNotMoveException, because it is legal to continue into "move-result" 6829bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * instructions - as long as the previous instruction was an invoke, which is checked elsewhere. 6839bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle */ 6849bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle bool CheckNotMoveResult(const uint16_t* insns, int insn_idx); 6859bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle 6869bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle /* 6879bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * Verify that the target instruction is not "move-result" or "move-exception". This is to 6889bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * be used when checking branch and switch instructions, but not instructions that can 6899bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle * continue. 6909bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle */ 6919bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle bool CheckNotMoveExceptionOrMoveResult(const uint16_t* insns, int insn_idx); 6929bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle 6939bc6199a9a6e140102951f6f38845b43b561af83Stephen Kyle /* 694776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Control can transfer to "next_insn". Merge the registers from merge_line into the table at 695776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * next_insn, and set the changed flag on the target address if any of the registers were changed. 696ebbdd87cbb57e45da341fbf7325406e982810c10Ian Rogers * In the case of fall-through, update the merge line on a change as its the working line for the 697ebbdd87cbb57e45da341fbf7325406e982810c10Ian Rogers * next instruction. 698776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers * Returns "false" if an error is encountered. 699776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers */ 700ebbdd87cbb57e45da341fbf7325406e982810c10Ian Rogers bool UpdateRegisters(uint32_t next_insn, RegisterLine* merge_line, bool update_merge_line) 70190443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 702776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 703ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Return the register type for the method. 70490443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier const RegType& GetMethodReturnType() SHARED_REQUIRES(Locks::mutator_lock_); 705ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers 706ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Get a type representing the declaring class of the method. 70790443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier const RegType& GetDeclaringClass() SHARED_REQUIRES(Locks::mutator_lock_); 708ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers 7097b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers InstructionFlags* CurrentInsnFlags(); 710776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 711d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType& DetermineCat1Constant(int32_t value, bool precise) 71290443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 7130a1038b0a30a52dff1a449a989825e808a83df80Elliott Hughes 714f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe // Try to create a register type from the given class. In case a precise type is requested, but 715f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe // the class is not instantiable, a soft error (of type NO_CLASS) will be enqueued and a 716f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe // non-precise reference will be returned. 717f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe // Note: we reuse NO_CLASS as this will throw an exception at runtime, when the failing class is 718f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe // actually touched. 719f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe const RegType& FromClass(const char* descriptor, mirror::Class* klass, bool precise) 72090443477f9a0061581c420775ce3b7eeae7468bcMathieu Chartier SHARED_REQUIRES(Locks::mutator_lock_); 721f23f33de8b3e9abd16720e0f48d43d63d41dee16Andreas Gampe 7227b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers // The thread we're verifying on. 7237b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers Thread* const self_; 7247b078e8c04f3e1451dbdd18543c8b9692b5b067eIan Rogers 725de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier // Arena allocator. 726de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ArenaStack arena_stack_; 727de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ScopedArenaAllocator arena_; 728de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier 729776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers RegTypeCache reg_types_; 730776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 731776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers PcToRegisterLineTable reg_table_; 732776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 733776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Storage for the register status we're currently working on. 734de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ArenaUniquePtr<RegisterLine> work_line_; 735776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 736776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // The address of the instruction we're currently working on, note that this is in 2 byte 737776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // quantities 738776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers uint32_t work_insn_idx_; 739776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 740776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // Storage for the register status we're saving for later. 741de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ArenaUniquePtr<RegisterLine> saved_line_; 742776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 743637c65b1e431fd90195b71c141b3590bd81cc91aIan Rogers const uint32_t dex_method_idx_; // The method we're working on. 74400f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // Its object representation if known. 745e401d146407d61eeb99f8d6176b2ac13c4df1e33Mathieu Chartier ArtMethod* mirror_method_ GUARDED_BY(Locks::mutator_lock_); 746637c65b1e431fd90195b71c141b3590bd81cc91aIan Rogers const uint32_t method_access_flags_; // Method's access flags. 747d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType* return_type_; // Lazily computed return type of the method. 748637c65b1e431fd90195b71c141b3590bd81cc91aIan Rogers const DexFile* const dex_file_; // The dex file containing the method. 74900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // The dex_cache for the declaring class of the method. 7505a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::DexCache> dex_cache_ GUARDED_BY(Locks::mutator_lock_); 75100f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers // The class loader for the declaring class of the method. 7525a4b8a236030460651a3136397d23ca6744e7eb7Andreas Gampe Handle<mirror::ClassLoader> class_loader_ GUARDED_BY(Locks::mutator_lock_); 7538b2c0b9abc3f520495f4387ea040132ba85cae69Ian Rogers const DexFile::ClassDef* const class_def_; // The class def of the declaring class of the method. 754637c65b1e431fd90195b71c141b3590bd81cc91aIan Rogers const DexFile::CodeItem* const code_item_; // The code item containing the code for the method. 755d8f69b086baf6717ce949d1c4de90d73b91083b0Ian Rogers const RegType* declaring_class_; // Lazily computed reg type of the method's declaring class. 7567b3ddd27c223fcce784314f78fda7f67dcb37730Ian Rogers // Instruction widths and flags, one entry per code unit. 757de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier // Owned, but not unique_ptr since insn_flags_ are allocated in arenas. 758de40d478930d0889a2aea5cbf58aa63da24e5dfaMathieu Chartier ArenaUniquePtr<InstructionFlags[]> insn_flags_; 759c15853b8b5da9dd8fb28e2adbbd61af34555e4c2Sebastien Hertz // The dex PC of a FindLocksAtDexPc request, -1 otherwise. 76008fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes uint32_t interesting_dex_pc_; 76108fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes // The container into which FindLocksAtDexPc should write the registers containing held locks, 7622cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier // null if we're not doing FindLocksAtDexPc. 76308fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes std::vector<uint32_t>* monitor_enter_dex_pcs_; 76408fc03ae5dded4adc9b45b7014a4b9dfedbe95a6Elliott Hughes 765ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // The types of any error that occurs. 766ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers std::vector<VerifyError> failures_; 767ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Error messages associated with failures. 768ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers std::vector<std::ostringstream*> failure_messages_; 769ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Is there a pending hard failure? 770ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers bool have_pending_hard_failure_; 771faf459e5decdfcf6dd7844947898beefe31e6435jeffhao // Is there a pending runtime throw failure? A runtime throw failure is when an instruction 772faf459e5decdfcf6dd7844947898beefe31e6435jeffhao // would fail at runtime throwing an exception. Such an instruction causes the following code 773faf459e5decdfcf6dd7844947898beefe31e6435jeffhao // to be unreachable. This is set by Fail and used to ensure we don't process unreachable 774faf459e5decdfcf6dd7844947898beefe31e6435jeffhao // instructions that would hard fail the verification. 775d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe // Note: this flag is reset after processing each instruction. 776faf459e5decdfcf6dd7844947898beefe31e6435jeffhao bool have_pending_runtime_throw_failure_; 7774d7b75f9cbcf99134c0a1c69b267b6bc8d94134eIgor Murashkin // Is there a pending experimental failure? 7784d7b75f9cbcf99134c0a1c69b267b6bc8d94134eIgor Murashkin bool have_pending_experimental_failure_; 779776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 780d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe // A version of the above that is not reset and thus captures if there were *any* throw failures. 781d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe bool have_any_pending_runtime_throw_failure_; 782d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe 783ad0b3a35857d2cd2db720028ebc51176191e2219Ian Rogers // Info message log use primarily for verifier diagnostics. 784776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers std::ostringstream info_messages_; 785776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 786776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers // The number of occurrences of specific opcodes. 787776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers size_t new_instance_count_; 788776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers size_t monitor_enter_count_; 78980537bb742dff4ccdf6d04b1c0bb7d2179acc8cbElliott Hughes 7900760a81257fa427646c309500d603194009265efAndreas Gampe // Bitset of the encountered failure types. Bits are according to the values in VerifyError. 7910760a81257fa427646c309500d603194009265efAndreas Gampe uint32_t encountered_failure_types_; 7920760a81257fa427646c309500d603194009265efAndreas Gampe 79380537bb742dff4ccdf6d04b1c0bb7d2179acc8cbElliott Hughes const bool can_load_classes_; 794ee9889502a34a08741a6f8ecc02917202de9d773Jeff Hao 795ee9889502a34a08741a6f8ecc02917202de9d773Jeff Hao // Converts soft failures to hard failures when false. Only false when the compiler isn't 796ee9889502a34a08741a6f8ecc02917202de9d773Jeff Hao // running and the verifier is called from the class linker. 797ee9889502a34a08741a6f8ecc02917202de9d773Jeff Hao const bool allow_soft_failures_; 7984d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz 79946960fe5dcc1be07b39a55114338423a73554449Ian Rogers // An optimization where instead of generating unique RegTypes for constants we use imprecise 80046960fe5dcc1be07b39a55114338423a73554449Ian Rogers // constants that cover a range of constants. This isn't good enough for deoptimization that 80146960fe5dcc1be07b39a55114338423a73554449Ian Rogers // avoids loading from registers in the case of a constant as the dex instruction set lost the 80246960fe5dcc1be07b39a55114338423a73554449Ian Rogers // notion of whether a value should be in a floating point or general purpose register file. 80346960fe5dcc1be07b39a55114338423a73554449Ian Rogers const bool need_precise_constants_; 80446960fe5dcc1be07b39a55114338423a73554449Ian Rogers 805a9a8254c920ce8e22210abfc16c9842ce0aea28fIan Rogers // Indicates the method being verified contains at least one check-cast or aput-object 806a9a8254c920ce8e22210abfc16c9842ce0aea28fIan Rogers // instruction. Aput-object operations implicitly check for array-store exceptions, similar to 807a9a8254c920ce8e22210abfc16c9842ce0aea28fIan Rogers // check-cast. 8084d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz bool has_check_casts_; 8094d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz 810a9a8254c920ce8e22210abfc16c9842ce0aea28fIan Rogers // Indicates the method being verified contains at least one invoke-virtual/range 8114d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz // or invoke-interface/range. 8124d4adb1dae07bb7421e863732ab789413a3b43f0Sebastien Hertz bool has_virtual_or_interface_invokes_; 8132ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe 8142ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe // Indicates whether we verify to dump the info. In that case we accept quickened instructions 8152ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe // even though we might detect to be a compiler. Should only be set when running 8162ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe // VerifyMethodAndDump. 8172ed8deff799448e094fa7a7cb9cf3b718820f4c6Andreas Gampe const bool verify_to_dump_; 8188e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers 8194306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier // Whether or not we call AllowThreadSuspension periodically, we want a way to disable this for 8204306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier // thread dumping checkpoints since we may get thread suspension at an inopportune time due to 8214306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier // FindLocksAtDexPC, resulting in deadlocks. 8224306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier const bool allow_thread_suspension_; 8234306ef8a7ec8e3887e51f64e80d940d974cc3ac3Mathieu Chartier 824e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // Whether the method seems to be a constructor. Note that this field exists as we can't trust 825e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // the flags in the dex file. Some older code does not mark methods named "<init>" and "<clinit>" 826e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // correctly. 827e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // 828e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe // Note: this flag is only valid once Verify() has started. 829e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe bool is_constructor_; 830e6215c0ec4b1bb71b722fdbf7e62eaf3be8a91d5Andreas Gampe 831d0ad2eea51850ed5972c23d03380b2305cdf7cb7Mathieu Chartier // Link, for the method verifier root linked list. 832d0ad2eea51850ed5972c23d03380b2305cdf7cb7Mathieu Chartier MethodVerifier* link_; 833d0ad2eea51850ed5972c23d03380b2305cdf7cb7Mathieu Chartier 834d0ad2eea51850ed5972c23d03380b2305cdf7cb7Mathieu Chartier friend class art::Thread; 835848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao 836848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao // Map of dex pcs of invocations of java.lang.String.<init> to the set of other registers that 837848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao // contain the uninitialized this pointer to that invoke. Will contain no entry if there are 838848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao // no other registers. 839848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao SafeMap<uint32_t, std::set<uint32_t>> string_init_pc_reg_map_; 840848f70a3d73833fc1bf3032a9ff6812e429661d9Jeff Hao 8418e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers DISALLOW_COPY_AND_ASSIGN(MethodVerifier); 842776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers}; 843e4f0b2ab4abd8e942a099e9b9b4682fbdd9eb21cjeffhaostd::ostream& operator<<(std::ostream& os, const MethodVerifier::FailureKind& rhs); 844776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 845776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers} // namespace verifier 846776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers} // namespace art 847776ac1fa61237db645adb4370a4aab888530caf4Ian Rogers 848fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_VERIFIER_METHOD_VERIFIER_H_ 849