1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ 18 #define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ 19 20 #include <stdint.h> 21 #include <string> 22 23 #include "base/macros.h" 24 25 namespace art { 26 namespace verifier { 27 28 class InstructionFlags FINAL { 29 public: 30 InstructionFlags() : flags_(0) {} 31 32 void SetIsOpcode() { 33 flags_ |= 1 << kOpcode; 34 } 35 void ClearIsOpcode() { 36 flags_ &= ~(1 << kOpcode); 37 } 38 bool IsOpcode() const { 39 return (flags_ & (1 << kOpcode)) != 0; 40 } 41 42 void SetInTry() { 43 flags_ |= 1 << kInTry; 44 } 45 void ClearInTry() { 46 flags_ &= ~(1 << kInTry); 47 } 48 bool IsInTry() const { 49 return (flags_ & (1 << kInTry)) != 0; 50 } 51 52 void SetBranchTarget() { 53 flags_ |= 1 << kBranchTarget; 54 } 55 void ClearBranchTarget() { 56 flags_ &= ~(1 << kBranchTarget); 57 } 58 bool IsBranchTarget() const { 59 return (flags_ & (1 << kBranchTarget)) != 0; 60 } 61 void SetCompileTimeInfoPoint() { 62 flags_ |= 1 << kCompileTimeInfoPoint; 63 } 64 void ClearCompileTimeInfoPoint() { 65 flags_ &= ~(1 << kCompileTimeInfoPoint); 66 } 67 bool IsCompileTimeInfoPoint() const { 68 return (flags_ & (1 << kCompileTimeInfoPoint)) != 0; 69 } 70 71 void SetVisited() { 72 flags_ |= 1 << kVisited; 73 } 74 void ClearVisited() { 75 flags_ &= ~(1 << kVisited); 76 } 77 bool IsVisited() const { 78 return (flags_ & (1 << kVisited)) != 0; 79 } 80 81 void SetChanged() { 82 flags_ |= 1 << kChanged; 83 } 84 void ClearChanged() { 85 flags_ &= ~(1 << kChanged); 86 } 87 bool IsChanged() const { 88 return (flags_ & (1 << kChanged)) != 0; 89 } 90 91 bool IsVisitedOrChanged() const { 92 return IsVisited() || IsChanged(); 93 } 94 95 void SetReturn() { 96 flags_ |= 1 << kReturn; 97 } 98 void ClearReturn() { 99 flags_ &= ~(1 << kReturn); 100 } 101 bool IsReturn() const { 102 return (flags_ & (1 << kReturn)) != 0; 103 } 104 105 void SetCompileTimeInfoPointAndReturn() { 106 SetCompileTimeInfoPoint(); 107 SetReturn(); 108 } 109 110 std::string ToString() const; 111 112 private: 113 enum { 114 // The instruction has been visited and unless IsChanged() verified. 115 kVisited = 0, 116 // Register type information flowing into the instruction changed and so the instruction must be 117 // reprocessed. 118 kChanged = 1, 119 // The item at this location is an opcode. 120 kOpcode = 2, 121 // Instruction is contained within a try region. 122 kInTry = 3, 123 // Instruction is the target of a branch (ie the start of a basic block). 124 kBranchTarget = 4, 125 // Location of interest to the compiler for GC maps and verifier based method sharpening. 126 kCompileTimeInfoPoint = 5, 127 // A return instruction. 128 kReturn = 6, 129 }; 130 uint8_t flags_; 131 }; 132 133 static_assert(sizeof(InstructionFlags) == sizeof(uint8_t), 134 "Size of InstructionFlags not equal to uint8_t"); 135 136 } // namespace verifier 137 } // namespace art 138 139 #endif // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_ 140