87 Instruction* Instruction::prev() {
88 Instruction* p = NULL;
89 Instruction* q = block();
90 while (q != this) {
91 assert(q != NULL, "this is not in the block's instruction list");
92 p = q; q = q->next();
93 }
94 return p;
95 }
96
97
98 void Instruction::state_values_do(ValueVisitor* f) {
99 if (state_before() != NULL) {
100 state_before()->values_do(f);
101 }
102 if (exception_state() != NULL){
103 exception_state()->values_do(f);
104 }
105 }
106
107
108 #ifndef PRODUCT
109 void Instruction::check_state(ValueStack* state) {
110 if (state != NULL) {
111 state->verify();
112 }
113 }
114
115
116 void Instruction::print() {
117 InstructionPrinter ip;
118 print(ip);
119 }
120
121
122 void Instruction::print_line() {
123 InstructionPrinter ip;
124 ip.print_line(this);
125 }
126
127
128 void Instruction::print(InstructionPrinter& ip) {
129 ip.print_head();
130 ip.print_line(this);
131 tty->cr();
132 }
133 #endif // PRODUCT
134
135
136 // perform constant and interval tests on index value
137 bool AccessIndexed::compute_needs_range_check() {
138
139 if (length()) {
140
141 Constant* clength = length()->as_Constant();
142 Constant* cindex = index()->as_Constant();
143 if (clength && cindex) {
144 IntConstant* l = clength->type()->as_IntConstant();
145 IntConstant* i = cindex->type()->as_IntConstant();
146 if (l && i && i->value() < l->value() && i->value() >= 0) {
147 return false;
148 }
149 }
150 }
151
152 if (!this->check_flag(NeedsRangeCheckFlag)) {
153 return false;
154 }
155
156 return true;
157 }
158
159
160 ciType* Local::exact_type() const {
161 ciType* type = declared_type();
162
163 // for primitive arrays, the declared type is the exact type
164 if (type->is_type_array_klass()) {
165 return type;
166 } else if (type->is_instance_klass()) {
167 ciInstanceKlass* ik = (ciInstanceKlass*)type;
168 if (ik->is_loaded() && ik->is_final() && !ik->is_interface()) {
169 return type;
170 }
171 } else if (type->is_obj_array_klass()) {
172 ciObjArrayKlass* oak = (ciObjArrayKlass*)type;
173 ciType* base = oak->base_element_type();
174 if (base->is_instance_klass()) {
175 ciInstanceKlass* ik = base->as_instance_klass();
176 if (ik->is_loaded() && ik->is_final()) {
177 return type;
178 }
179 } else if (base->is_primitive_type()) {
180 return type;
181 }
182 }
183 return NULL;
184 }
185
186 ciType* Constant::exact_type() const {
187 if (type()->is_object()) {
188 return type()->as_ObjectType()->exact_type();
189 }
190 return NULL;
191 }
192
193 ciType* LoadIndexed::exact_type() const {
194 ciType* array_type = array()->exact_type();
195 if (array_type == NULL) {
196 return NULL;
197 }
198 assert(array_type->is_array_klass(), "what else?");
199 ciArrayKlass* ak = (ciArrayKlass*)array_type;
200
201 if (ak->element_type()->is_instance_klass()) {
202 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
203 if (ik->is_loaded() && ik->is_final()) {
204 return ik;
205 }
206 }
207 return NULL;
208 }
209
210
211 ciType* LoadIndexed::declared_type() const {
212 ciType* array_type = array()->declared_type();
213 if (array_type == NULL || !array_type->is_loaded()) {
214 return NULL;
215 }
216 assert(array_type->is_array_klass(), "what else?");
217 ciArrayKlass* ak = (ciArrayKlass*)array_type;
218 return ak->element_type();
219 }
220
221
222 ciType* LoadField::declared_type() const {
223 return field()->type();
224 }
225
226
227 ciType* LoadField::exact_type() const {
228 ciType* type = declared_type();
229 // for primitive arrays, the declared type is the exact type
230 if (type->is_type_array_klass()) {
231 return type;
232 }
233 if (type->is_instance_klass()) {
234 ciInstanceKlass* ik = (ciInstanceKlass*)type;
235 if (ik->is_loaded() && ik->is_final()) {
236 return type;
237 }
238 }
239 return NULL;
240 }
241
242
243 ciType* NewTypeArray::exact_type() const {
244 return ciTypeArrayKlass::make(elt_type());
245 }
246
247 ciType* NewObjectArray::exact_type() const {
248 return ciObjArrayKlass::make(klass());
249 }
250
251 ciType* NewArray::declared_type() const {
252 return exact_type();
253 }
254
255 ciType* NewInstance::exact_type() const {
256 return klass();
257 }
258
259 ciType* NewInstance::declared_type() const {
260 return exact_type();
261 }
262
263 ciType* CheckCast::declared_type() const {
264 return klass();
265 }
266
267 ciType* CheckCast::exact_type() const {
268 if (klass()->is_instance_klass()) {
269 ciInstanceKlass* ik = (ciInstanceKlass*)klass();
270 if (ik->is_loaded() && ik->is_final()) {
271 return ik;
272 }
273 }
274 return NULL;
275 }
276
277 // Implementation of ArithmeticOp
278
279 bool ArithmeticOp::is_commutative() const {
280 switch (op()) {
281 case Bytecodes::_iadd: // fall through
282 case Bytecodes::_ladd: // fall through
283 case Bytecodes::_fadd: // fall through
284 case Bytecodes::_dadd: // fall through
285 case Bytecodes::_imul: // fall through
286 case Bytecodes::_lmul: // fall through
287 case Bytecodes::_fmul: // fall through
288 case Bytecodes::_dmul: return true;
289 }
290 return false;
291 }
292
293
294 bool ArithmeticOp::can_trap() const {
|
87 Instruction* Instruction::prev() {
88 Instruction* p = NULL;
89 Instruction* q = block();
90 while (q != this) {
91 assert(q != NULL, "this is not in the block's instruction list");
92 p = q; q = q->next();
93 }
94 return p;
95 }
96
97
98 void Instruction::state_values_do(ValueVisitor* f) {
99 if (state_before() != NULL) {
100 state_before()->values_do(f);
101 }
102 if (exception_state() != NULL){
103 exception_state()->values_do(f);
104 }
105 }
106
107 ciType* Instruction::exact_type() const {
108 ciType* t = declared_type();
109 if (t != NULL && t->is_klass()) {
110 return t->as_klass()->exact_klass();
111 }
112 return NULL;
113 }
114
115
116 #ifndef PRODUCT
117 void Instruction::check_state(ValueStack* state) {
118 if (state != NULL) {
119 state->verify();
120 }
121 }
122
123
124 void Instruction::print() {
125 InstructionPrinter ip;
126 print(ip);
127 }
128
129
130 void Instruction::print_line() {
131 InstructionPrinter ip;
132 ip.print_line(this);
133 }
134
135
136 void Instruction::print(InstructionPrinter& ip) {
137 ip.print_head();
138 ip.print_line(this);
139 tty->cr();
140 }
141 #endif // PRODUCT
142
143
144 // perform constant and interval tests on index value
145 bool AccessIndexed::compute_needs_range_check() {
146 if (length()) {
147 Constant* clength = length()->as_Constant();
148 Constant* cindex = index()->as_Constant();
149 if (clength && cindex) {
150 IntConstant* l = clength->type()->as_IntConstant();
151 IntConstant* i = cindex->type()->as_IntConstant();
152 if (l && i && i->value() < l->value() && i->value() >= 0) {
153 return false;
154 }
155 }
156 }
157
158 if (!this->check_flag(NeedsRangeCheckFlag)) {
159 return false;
160 }
161
162 return true;
163 }
164
165
166 ciType* Constant::exact_type() const {
167 if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
168 return type()->as_ObjectType()->exact_type();
169 }
170 return NULL;
171 }
172
173 ciType* LoadIndexed::exact_type() const {
174 ciType* array_type = array()->exact_type();
175 if (array_type != NULL) {
176 assert(array_type->is_array_klass(), "what else?");
177 ciArrayKlass* ak = (ciArrayKlass*)array_type;
178
179 if (ak->element_type()->is_instance_klass()) {
180 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
181 if (ik->is_loaded() && ik->is_final()) {
182 return ik;
183 }
184 }
185 }
186 return Instruction::exact_type();
187 }
188
189
190 ciType* LoadIndexed::declared_type() const {
191 ciType* array_type = array()->declared_type();
192 if (array_type == NULL || !array_type->is_loaded()) {
193 return NULL;
194 }
195 assert(array_type->is_array_klass(), "what else?");
196 ciArrayKlass* ak = (ciArrayKlass*)array_type;
197 return ak->element_type();
198 }
199
200
201 ciType* LoadField::declared_type() const {
202 return field()->type();
203 }
204
205
206 ciType* NewTypeArray::exact_type() const {
207 return ciTypeArrayKlass::make(elt_type());
208 }
209
210 ciType* NewObjectArray::exact_type() const {
211 return ciObjArrayKlass::make(klass());
212 }
213
214 ciType* NewArray::declared_type() const {
215 return exact_type();
216 }
217
218 ciType* NewInstance::exact_type() const {
219 return klass();
220 }
221
222 ciType* NewInstance::declared_type() const {
223 return exact_type();
224 }
225
226 ciType* CheckCast::declared_type() const {
227 return klass();
228 }
229
230 // Implementation of ArithmeticOp
231
232 bool ArithmeticOp::is_commutative() const {
233 switch (op()) {
234 case Bytecodes::_iadd: // fall through
235 case Bytecodes::_ladd: // fall through
236 case Bytecodes::_fadd: // fall through
237 case Bytecodes::_dadd: // fall through
238 case Bytecodes::_imul: // fall through
239 case Bytecodes::_lmul: // fall through
240 case Bytecodes::_fmul: // fall through
241 case Bytecodes::_dmul: return true;
242 }
243 return false;
244 }
245
246
247 bool ArithmeticOp::can_trap() const {
|