blob: e50ba139329bd6d7f324af79db7e94bda14e1732 [file] [log] [blame]
Ian Rogers7b3ddd22013-02-21 15:19:52 -08001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
18#define ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_
Ian Rogers7b3ddd22013-02-21 15:19:52 -080019
20#include "base/logging.h"
21
22#include <stdint.h>
23#include <string>
24
25namespace art {
26namespace verifier {
27
28class InstructionFlags {
29 public:
30 InstructionFlags() : length_(0), flags_(0) {}
31
32 void SetLengthInCodeUnits(size_t length) {
33 DCHECK_LT(length, 65536u);
34 length_ = length;
35 }
36 size_t GetLengthInCodeUnits() {
37 return length_;
38 }
39 bool IsOpcode() const {
40 return length_ != 0;
41 }
42
43 void SetInTry() {
44 flags_ |= 1 << kInTry;
45 }
46 void ClearInTry() {
47 flags_ &= ~(1 << kInTry);
48 }
49 bool IsInTry() const {
50 return (flags_ & (1 << kInTry)) != 0;
51 }
52
53 void SetBranchTarget() {
54 flags_ |= 1 << kBranchTarget;
55 }
56 void ClearBranchTarget() {
57 flags_ &= ~(1 << kBranchTarget);
58 }
59 bool IsBranchTarget() const {
60 return (flags_ & (1 << kBranchTarget)) != 0;
61 }
Sameer Abu Asal02c42232013-04-30 12:09:45 -070062 void SetCompileTimeInfoPoint() {
63 flags_ |= 1 << kCompileTimeInfoPoint;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080064 }
Sameer Abu Asal02c42232013-04-30 12:09:45 -070065 void ClearCompileTimeInfoPoint() {
66 flags_ &= ~(1 << kCompileTimeInfoPoint);
Ian Rogers7b3ddd22013-02-21 15:19:52 -080067 }
Sameer Abu Asal02c42232013-04-30 12:09:45 -070068 bool IsCompileTimeInfoPoint() const {
69 return (flags_ & (1 << kCompileTimeInfoPoint)) != 0;
Ian Rogers7b3ddd22013-02-21 15:19:52 -080070 }
71
72 void SetVisited() {
73 flags_ |= 1 << kVisited;
74 }
75 void ClearVisited() {
76 flags_ &= ~(1 << kVisited);
77 }
78 bool IsVisited() const {
79 return (flags_ & (1 << kVisited)) != 0;
80 }
81
82 void SetChanged() {
83 flags_ |= 1 << kChanged;
84 }
85 void ClearChanged() {
86 flags_ &= ~(1 << kChanged);
87 }
88 bool IsChanged() const {
89 return (flags_ & (1 << kChanged)) != 0;
90 }
91
92 bool IsVisitedOrChanged() const {
93 return IsVisited() || IsChanged();
94 }
95
Ian Rogersb8c78592013-07-25 23:52:52 +000096 void SetReturn() {
97 flags_ |= 1 << kReturn;
98 }
99 void ClearReturn() {
100 flags_ &= ~(1 << kReturn);
101 }
102 bool IsReturn() const {
103 return (flags_ & (1 << kReturn)) != 0;
104 }
105
106 void SetCompileTimeInfoPointAndReturn() {
107 SetCompileTimeInfoPoint();
108 SetReturn();
109 }
110
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800111 std::string ToString() const;
112
113 private:
114 enum {
Ian Rogers6d376ae2013-07-23 15:12:40 -0700115 // The instruction has been visited and unless IsChanged() verified.
116 kVisited = 0,
117 // Register type information flowing into the instruction changed and so the instruction must be
118 // reprocessed.
119 kChanged = 1,
120 // Instruction is contained within a try region.
121 kInTry = 2,
122 // Instruction is the target of a branch (ie the start of a basic block).
123 kBranchTarget = 3,
124 // Location of interest to the compiler for GC maps and verifier based method sharpening.
125 kCompileTimeInfoPoint = 4,
Ian Rogersb8c78592013-07-25 23:52:52 +0000126 // A return instruction.
127 kReturn = 5,
Ian Rogers7b3ddd22013-02-21 15:19:52 -0800128 };
129
130 // Size of instruction in code units.
131 uint16_t length_;
132 uint8_t flags_;
133};
134
135} // namespace verifier
136} // namespace art
137
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700138#endif // ART_RUNTIME_VERIFIER_INSTRUCTION_FLAGS_H_