src/share/vm/c1/c1_Instruction.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 8856
ac27a9c85bea
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_IR.hpp"
aoqi@0 27 #include "c1/c1_Instruction.hpp"
aoqi@0 28 #include "c1/c1_InstructionPrinter.hpp"
aoqi@0 29 #include "c1/c1_ValueStack.hpp"
aoqi@0 30 #include "ci/ciObjArrayKlass.hpp"
aoqi@0 31 #include "ci/ciTypeArrayKlass.hpp"
aoqi@0 32
aoqi@0 33
aoqi@0 34 // Implementation of Instruction
aoqi@0 35
aoqi@0 36
aoqi@0 37 int Instruction::dominator_depth() {
aoqi@0 38 int result = -1;
aoqi@0 39 if (block()) {
aoqi@0 40 result = block()->dominator_depth();
aoqi@0 41 }
aoqi@0 42 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
aoqi@0 43 return result;
aoqi@0 44 }
aoqi@0 45
aoqi@0 46 Instruction::Condition Instruction::mirror(Condition cond) {
aoqi@0 47 switch (cond) {
aoqi@0 48 case eql: return eql;
aoqi@0 49 case neq: return neq;
aoqi@0 50 case lss: return gtr;
aoqi@0 51 case leq: return geq;
aoqi@0 52 case gtr: return lss;
aoqi@0 53 case geq: return leq;
aoqi@0 54 case aeq: return beq;
aoqi@0 55 case beq: return aeq;
aoqi@0 56 }
aoqi@0 57 ShouldNotReachHere();
aoqi@0 58 return eql;
aoqi@0 59 }
aoqi@0 60
aoqi@0 61
aoqi@0 62 Instruction::Condition Instruction::negate(Condition cond) {
aoqi@0 63 switch (cond) {
aoqi@0 64 case eql: return neq;
aoqi@0 65 case neq: return eql;
aoqi@0 66 case lss: return geq;
aoqi@0 67 case leq: return gtr;
aoqi@0 68 case gtr: return leq;
aoqi@0 69 case geq: return lss;
aoqi@0 70 case aeq: assert(false, "Above equal cannot be negated");
aoqi@0 71 case beq: assert(false, "Below equal cannot be negated");
aoqi@0 72 }
aoqi@0 73 ShouldNotReachHere();
aoqi@0 74 return eql;
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 void Instruction::update_exception_state(ValueStack* state) {
aoqi@0 78 if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) {
aoqi@0 79 assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->jvmti_can_access_local_variables(), "unexpected state kind");
aoqi@0 80 _exception_state = state;
aoqi@0 81 } else {
aoqi@0 82 _exception_state = NULL;
aoqi@0 83 }
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 // Prev without need to have BlockBegin
aoqi@0 87 Instruction* Instruction::prev() {
aoqi@0 88 Instruction* p = NULL;
aoqi@0 89 Instruction* q = block();
aoqi@0 90 while (q != this) {
aoqi@0 91 assert(q != NULL, "this is not in the block's instruction list");
aoqi@0 92 p = q; q = q->next();
aoqi@0 93 }
aoqi@0 94 return p;
aoqi@0 95 }
aoqi@0 96
aoqi@0 97
aoqi@0 98 void Instruction::state_values_do(ValueVisitor* f) {
aoqi@0 99 if (state_before() != NULL) {
aoqi@0 100 state_before()->values_do(f);
aoqi@0 101 }
aoqi@0 102 if (exception_state() != NULL){
aoqi@0 103 exception_state()->values_do(f);
aoqi@0 104 }
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 ciType* Instruction::exact_type() const {
aoqi@0 108 ciType* t = declared_type();
aoqi@0 109 if (t != NULL && t->is_klass()) {
aoqi@0 110 return t->as_klass()->exact_klass();
aoqi@0 111 }
aoqi@0 112 return NULL;
aoqi@0 113 }
aoqi@0 114
aoqi@0 115
aoqi@0 116 #ifndef PRODUCT
aoqi@0 117 void Instruction::check_state(ValueStack* state) {
aoqi@0 118 if (state != NULL) {
aoqi@0 119 state->verify();
aoqi@0 120 }
aoqi@0 121 }
aoqi@0 122
aoqi@0 123
aoqi@0 124 void Instruction::print() {
aoqi@0 125 InstructionPrinter ip;
aoqi@0 126 print(ip);
aoqi@0 127 }
aoqi@0 128
aoqi@0 129
aoqi@0 130 void Instruction::print_line() {
aoqi@0 131 InstructionPrinter ip;
aoqi@0 132 ip.print_line(this);
aoqi@0 133 }
aoqi@0 134
aoqi@0 135
aoqi@0 136 void Instruction::print(InstructionPrinter& ip) {
aoqi@0 137 ip.print_head();
aoqi@0 138 ip.print_line(this);
aoqi@0 139 tty->cr();
aoqi@0 140 }
aoqi@0 141 #endif // PRODUCT
aoqi@0 142
aoqi@0 143
aoqi@0 144 // perform constant and interval tests on index value
aoqi@0 145 bool AccessIndexed::compute_needs_range_check() {
aoqi@0 146 if (length()) {
aoqi@0 147 Constant* clength = length()->as_Constant();
aoqi@0 148 Constant* cindex = index()->as_Constant();
aoqi@0 149 if (clength && cindex) {
aoqi@0 150 IntConstant* l = clength->type()->as_IntConstant();
aoqi@0 151 IntConstant* i = cindex->type()->as_IntConstant();
aoqi@0 152 if (l && i && i->value() < l->value() && i->value() >= 0) {
aoqi@0 153 return false;
aoqi@0 154 }
aoqi@0 155 }
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 if (!this->check_flag(NeedsRangeCheckFlag)) {
aoqi@0 159 return false;
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 return true;
aoqi@0 163 }
aoqi@0 164
aoqi@0 165
aoqi@0 166 ciType* Constant::exact_type() const {
aoqi@0 167 if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
aoqi@0 168 return type()->as_ObjectType()->exact_type();
aoqi@0 169 }
aoqi@0 170 return NULL;
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 ciType* LoadIndexed::exact_type() const {
aoqi@0 174 ciType* array_type = array()->exact_type();
aoqi@0 175 if (array_type != NULL) {
aoqi@0 176 assert(array_type->is_array_klass(), "what else?");
aoqi@0 177 ciArrayKlass* ak = (ciArrayKlass*)array_type;
aoqi@0 178
aoqi@0 179 if (ak->element_type()->is_instance_klass()) {
aoqi@0 180 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
aoqi@0 181 if (ik->is_loaded() && ik->is_final()) {
aoqi@0 182 return ik;
aoqi@0 183 }
aoqi@0 184 }
aoqi@0 185 }
aoqi@0 186 return Instruction::exact_type();
aoqi@0 187 }
aoqi@0 188
aoqi@0 189
aoqi@0 190 ciType* LoadIndexed::declared_type() const {
aoqi@0 191 ciType* array_type = array()->declared_type();
aoqi@0 192 if (array_type == NULL || !array_type->is_loaded()) {
aoqi@0 193 return NULL;
aoqi@0 194 }
aoqi@0 195 assert(array_type->is_array_klass(), "what else?");
aoqi@0 196 ciArrayKlass* ak = (ciArrayKlass*)array_type;
aoqi@0 197 return ak->element_type();
aoqi@0 198 }
aoqi@0 199
aoqi@0 200
aoqi@0 201 ciType* LoadField::declared_type() const {
aoqi@0 202 return field()->type();
aoqi@0 203 }
aoqi@0 204
aoqi@0 205
aoqi@0 206 ciType* NewTypeArray::exact_type() const {
aoqi@0 207 return ciTypeArrayKlass::make(elt_type());
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 ciType* NewObjectArray::exact_type() const {
aoqi@0 211 return ciObjArrayKlass::make(klass());
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 ciType* NewArray::declared_type() const {
aoqi@0 215 return exact_type();
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 ciType* NewInstance::exact_type() const {
aoqi@0 219 return klass();
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 ciType* NewInstance::declared_type() const {
aoqi@0 223 return exact_type();
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 ciType* CheckCast::declared_type() const {
aoqi@0 227 return klass();
aoqi@0 228 }
aoqi@0 229
aoqi@0 230 // Implementation of ArithmeticOp
aoqi@0 231
aoqi@0 232 bool ArithmeticOp::is_commutative() const {
aoqi@0 233 switch (op()) {
aoqi@0 234 case Bytecodes::_iadd: // fall through
aoqi@0 235 case Bytecodes::_ladd: // fall through
aoqi@0 236 case Bytecodes::_fadd: // fall through
aoqi@0 237 case Bytecodes::_dadd: // fall through
aoqi@0 238 case Bytecodes::_imul: // fall through
aoqi@0 239 case Bytecodes::_lmul: // fall through
aoqi@0 240 case Bytecodes::_fmul: // fall through
aoqi@0 241 case Bytecodes::_dmul: return true;
aoqi@0 242 }
aoqi@0 243 return false;
aoqi@0 244 }
aoqi@0 245
aoqi@0 246
aoqi@0 247 bool ArithmeticOp::can_trap() const {
aoqi@0 248 switch (op()) {
aoqi@0 249 case Bytecodes::_idiv: // fall through
aoqi@0 250 case Bytecodes::_ldiv: // fall through
aoqi@0 251 case Bytecodes::_irem: // fall through
aoqi@0 252 case Bytecodes::_lrem: return true;
aoqi@0 253 }
aoqi@0 254 return false;
aoqi@0 255 }
aoqi@0 256
aoqi@0 257
aoqi@0 258 // Implementation of LogicOp
aoqi@0 259
aoqi@0 260 bool LogicOp::is_commutative() const {
aoqi@0 261 #ifdef ASSERT
aoqi@0 262 switch (op()) {
aoqi@0 263 case Bytecodes::_iand: // fall through
aoqi@0 264 case Bytecodes::_land: // fall through
aoqi@0 265 case Bytecodes::_ior : // fall through
aoqi@0 266 case Bytecodes::_lor : // fall through
aoqi@0 267 case Bytecodes::_ixor: // fall through
aoqi@0 268 case Bytecodes::_lxor: break;
aoqi@0 269 default : ShouldNotReachHere();
aoqi@0 270 }
aoqi@0 271 #endif
aoqi@0 272 // all LogicOps are commutative
aoqi@0 273 return true;
aoqi@0 274 }
aoqi@0 275
aoqi@0 276
aoqi@0 277 // Implementation of IfOp
aoqi@0 278
aoqi@0 279 bool IfOp::is_commutative() const {
aoqi@0 280 return cond() == eql || cond() == neq;
aoqi@0 281 }
aoqi@0 282
aoqi@0 283
aoqi@0 284 // Implementation of StateSplit
aoqi@0 285
aoqi@0 286 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
aoqi@0 287 NOT_PRODUCT(bool assigned = false;)
aoqi@0 288 for (int i = 0; i < list.length(); i++) {
aoqi@0 289 BlockBegin** b = list.adr_at(i);
aoqi@0 290 if (*b == old_block) {
aoqi@0 291 *b = new_block;
aoqi@0 292 NOT_PRODUCT(assigned = true;)
aoqi@0 293 }
aoqi@0 294 }
aoqi@0 295 assert(assigned == true, "should have assigned at least once");
aoqi@0 296 }
aoqi@0 297
aoqi@0 298
aoqi@0 299 IRScope* StateSplit::scope() const {
aoqi@0 300 return _state->scope();
aoqi@0 301 }
aoqi@0 302
aoqi@0 303
aoqi@0 304 void StateSplit::state_values_do(ValueVisitor* f) {
aoqi@0 305 Instruction::state_values_do(f);
aoqi@0 306 if (state() != NULL) state()->values_do(f);
aoqi@0 307 }
aoqi@0 308
aoqi@0 309
aoqi@0 310 void BlockBegin::state_values_do(ValueVisitor* f) {
aoqi@0 311 StateSplit::state_values_do(f);
aoqi@0 312
aoqi@0 313 if (is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 314 for (int i = 0; i < number_of_exception_states(); i++) {
aoqi@0 315 exception_state_at(i)->values_do(f);
aoqi@0 316 }
aoqi@0 317 }
aoqi@0 318 }
aoqi@0 319
aoqi@0 320
aoqi@0 321 // Implementation of Invoke
aoqi@0 322
aoqi@0 323
aoqi@0 324 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
aoqi@0 325 int vtable_index, ciMethod* target, ValueStack* state_before)
aoqi@0 326 : StateSplit(result_type, state_before)
aoqi@0 327 , _code(code)
aoqi@0 328 , _recv(recv)
aoqi@0 329 , _args(args)
aoqi@0 330 , _vtable_index(vtable_index)
aoqi@0 331 , _target(target)
aoqi@0 332 {
aoqi@0 333 set_flag(TargetIsLoadedFlag, target->is_loaded());
aoqi@0 334 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
aoqi@0 335 set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
aoqi@0 336
aoqi@0 337 assert(args != NULL, "args must exist");
aoqi@0 338 #ifdef ASSERT
aoqi@0 339 AssertValues assert_value;
aoqi@0 340 values_do(&assert_value);
aoqi@0 341 #endif
aoqi@0 342
aoqi@0 343 // provide an initial guess of signature size.
aoqi@0 344 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
aoqi@0 345 if (has_receiver()) {
aoqi@0 346 _signature->append(as_BasicType(receiver()->type()));
aoqi@0 347 }
aoqi@0 348 for (int i = 0; i < number_of_arguments(); i++) {
aoqi@0 349 ValueType* t = argument_at(i)->type();
aoqi@0 350 BasicType bt = as_BasicType(t);
aoqi@0 351 _signature->append(bt);
aoqi@0 352 }
aoqi@0 353 }
aoqi@0 354
aoqi@0 355
aoqi@0 356 void Invoke::state_values_do(ValueVisitor* f) {
aoqi@0 357 StateSplit::state_values_do(f);
aoqi@0 358 if (state_before() != NULL) state_before()->values_do(f);
aoqi@0 359 if (state() != NULL) state()->values_do(f);
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 ciType* Invoke::declared_type() const {
aoqi@0 363 ciType *t = _target->signature()->return_type();
aoqi@0 364 assert(t->basic_type() != T_VOID, "need return value of void method?");
aoqi@0 365 return t;
aoqi@0 366 }
aoqi@0 367
aoqi@0 368 // Implementation of Contant
aoqi@0 369 intx Constant::hash() const {
aoqi@0 370 if (state_before() == NULL) {
aoqi@0 371 switch (type()->tag()) {
aoqi@0 372 case intTag:
aoqi@0 373 return HASH2(name(), type()->as_IntConstant()->value());
aoqi@0 374 case addressTag:
aoqi@0 375 return HASH2(name(), type()->as_AddressConstant()->value());
aoqi@0 376 case longTag:
aoqi@0 377 {
aoqi@0 378 jlong temp = type()->as_LongConstant()->value();
aoqi@0 379 return HASH3(name(), high(temp), low(temp));
aoqi@0 380 }
aoqi@0 381 case floatTag:
aoqi@0 382 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
aoqi@0 383 case doubleTag:
aoqi@0 384 {
aoqi@0 385 jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
aoqi@0 386 return HASH3(name(), high(temp), low(temp));
aoqi@0 387 }
aoqi@0 388 case objectTag:
aoqi@0 389 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
aoqi@0 390 return HASH2(name(), type()->as_ObjectType()->constant_value());
aoqi@0 391 case metaDataTag:
aoqi@0 392 assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");
aoqi@0 393 return HASH2(name(), type()->as_MetadataType()->constant_value());
aoqi@0 394 default:
aoqi@0 395 ShouldNotReachHere();
aoqi@0 396 }
aoqi@0 397 }
aoqi@0 398 return 0;
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 bool Constant::is_equal(Value v) const {
aoqi@0 402 if (v->as_Constant() == NULL) return false;
aoqi@0 403
aoqi@0 404 switch (type()->tag()) {
aoqi@0 405 case intTag:
aoqi@0 406 {
aoqi@0 407 IntConstant* t1 = type()->as_IntConstant();
aoqi@0 408 IntConstant* t2 = v->type()->as_IntConstant();
aoqi@0 409 return (t1 != NULL && t2 != NULL &&
aoqi@0 410 t1->value() == t2->value());
aoqi@0 411 }
aoqi@0 412 case longTag:
aoqi@0 413 {
aoqi@0 414 LongConstant* t1 = type()->as_LongConstant();
aoqi@0 415 LongConstant* t2 = v->type()->as_LongConstant();
aoqi@0 416 return (t1 != NULL && t2 != NULL &&
aoqi@0 417 t1->value() == t2->value());
aoqi@0 418 }
aoqi@0 419 case floatTag:
aoqi@0 420 {
aoqi@0 421 FloatConstant* t1 = type()->as_FloatConstant();
aoqi@0 422 FloatConstant* t2 = v->type()->as_FloatConstant();
aoqi@0 423 return (t1 != NULL && t2 != NULL &&
aoqi@0 424 jint_cast(t1->value()) == jint_cast(t2->value()));
aoqi@0 425 }
aoqi@0 426 case doubleTag:
aoqi@0 427 {
aoqi@0 428 DoubleConstant* t1 = type()->as_DoubleConstant();
aoqi@0 429 DoubleConstant* t2 = v->type()->as_DoubleConstant();
aoqi@0 430 return (t1 != NULL && t2 != NULL &&
aoqi@0 431 jlong_cast(t1->value()) == jlong_cast(t2->value()));
aoqi@0 432 }
aoqi@0 433 case objectTag:
aoqi@0 434 {
aoqi@0 435 ObjectType* t1 = type()->as_ObjectType();
aoqi@0 436 ObjectType* t2 = v->type()->as_ObjectType();
aoqi@0 437 return (t1 != NULL && t2 != NULL &&
aoqi@0 438 t1->is_loaded() && t2->is_loaded() &&
aoqi@0 439 t1->constant_value() == t2->constant_value());
aoqi@0 440 }
aoqi@0 441 case metaDataTag:
aoqi@0 442 {
aoqi@0 443 MetadataType* t1 = type()->as_MetadataType();
aoqi@0 444 MetadataType* t2 = v->type()->as_MetadataType();
aoqi@0 445 return (t1 != NULL && t2 != NULL &&
aoqi@0 446 t1->is_loaded() && t2->is_loaded() &&
aoqi@0 447 t1->constant_value() == t2->constant_value());
aoqi@0 448 }
aoqi@0 449 }
aoqi@0 450 return false;
aoqi@0 451 }
aoqi@0 452
aoqi@0 453 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
aoqi@0 454 Constant* rc = right->as_Constant();
aoqi@0 455 // other is not a constant
aoqi@0 456 if (rc == NULL) return not_comparable;
aoqi@0 457
aoqi@0 458 ValueType* lt = type();
aoqi@0 459 ValueType* rt = rc->type();
aoqi@0 460 // different types
aoqi@0 461 if (lt->base() != rt->base()) return not_comparable;
aoqi@0 462 switch (lt->tag()) {
aoqi@0 463 case intTag: {
aoqi@0 464 int x = lt->as_IntConstant()->value();
aoqi@0 465 int y = rt->as_IntConstant()->value();
aoqi@0 466 switch (cond) {
aoqi@0 467 case If::eql: return x == y ? cond_true : cond_false;
aoqi@0 468 case If::neq: return x != y ? cond_true : cond_false;
aoqi@0 469 case If::lss: return x < y ? cond_true : cond_false;
aoqi@0 470 case If::leq: return x <= y ? cond_true : cond_false;
aoqi@0 471 case If::gtr: return x > y ? cond_true : cond_false;
aoqi@0 472 case If::geq: return x >= y ? cond_true : cond_false;
aoqi@0 473 }
aoqi@0 474 break;
aoqi@0 475 }
aoqi@0 476 case longTag: {
aoqi@0 477 jlong x = lt->as_LongConstant()->value();
aoqi@0 478 jlong y = rt->as_LongConstant()->value();
aoqi@0 479 switch (cond) {
aoqi@0 480 case If::eql: return x == y ? cond_true : cond_false;
aoqi@0 481 case If::neq: return x != y ? cond_true : cond_false;
aoqi@0 482 case If::lss: return x < y ? cond_true : cond_false;
aoqi@0 483 case If::leq: return x <= y ? cond_true : cond_false;
aoqi@0 484 case If::gtr: return x > y ? cond_true : cond_false;
aoqi@0 485 case If::geq: return x >= y ? cond_true : cond_false;
aoqi@0 486 }
aoqi@0 487 break;
aoqi@0 488 }
aoqi@0 489 case objectTag: {
aoqi@0 490 ciObject* xvalue = lt->as_ObjectType()->constant_value();
aoqi@0 491 ciObject* yvalue = rt->as_ObjectType()->constant_value();
aoqi@0 492 assert(xvalue != NULL && yvalue != NULL, "not constants");
aoqi@0 493 if (xvalue->is_loaded() && yvalue->is_loaded()) {
aoqi@0 494 switch (cond) {
aoqi@0 495 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
aoqi@0 496 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
aoqi@0 497 }
aoqi@0 498 }
aoqi@0 499 break;
aoqi@0 500 }
aoqi@0 501 case metaDataTag: {
aoqi@0 502 ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
aoqi@0 503 ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
aoqi@0 504 assert(xvalue != NULL && yvalue != NULL, "not constants");
aoqi@0 505 if (xvalue->is_loaded() && yvalue->is_loaded()) {
aoqi@0 506 switch (cond) {
aoqi@0 507 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
aoqi@0 508 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
aoqi@0 509 }
aoqi@0 510 }
aoqi@0 511 break;
aoqi@0 512 }
aoqi@0 513 }
aoqi@0 514 return not_comparable;
aoqi@0 515 }
aoqi@0 516
aoqi@0 517
aoqi@0 518 // Implementation of BlockBegin
aoqi@0 519
aoqi@0 520 void BlockBegin::set_end(BlockEnd* end) {
aoqi@0 521 assert(end != NULL, "should not reset block end to NULL");
aoqi@0 522 if (end == _end) {
aoqi@0 523 return;
aoqi@0 524 }
aoqi@0 525 clear_end();
aoqi@0 526
aoqi@0 527 // Set the new end
aoqi@0 528 _end = end;
aoqi@0 529
aoqi@0 530 _successors.clear();
aoqi@0 531 // Now reset successors list based on BlockEnd
aoqi@0 532 for (int i = 0; i < end->number_of_sux(); i++) {
aoqi@0 533 BlockBegin* sux = end->sux_at(i);
aoqi@0 534 _successors.append(sux);
aoqi@0 535 sux->_predecessors.append(this);
aoqi@0 536 }
aoqi@0 537 _end->set_begin(this);
aoqi@0 538 }
aoqi@0 539
aoqi@0 540
aoqi@0 541 void BlockBegin::clear_end() {
aoqi@0 542 // Must make the predecessors/successors match up with the
aoqi@0 543 // BlockEnd's notion.
aoqi@0 544 if (_end != NULL) {
aoqi@0 545 // disconnect from the old end
aoqi@0 546 _end->set_begin(NULL);
aoqi@0 547
aoqi@0 548 // disconnect this block from it's current successors
aoqi@0 549 for (int i = 0; i < _successors.length(); i++) {
aoqi@0 550 _successors.at(i)->remove_predecessor(this);
aoqi@0 551 }
aoqi@0 552 _end = NULL;
aoqi@0 553 }
aoqi@0 554 }
aoqi@0 555
aoqi@0 556
aoqi@0 557 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
aoqi@0 558 // disconnect any edges between from and to
aoqi@0 559 #ifndef PRODUCT
aoqi@0 560 if (PrintIR && Verbose) {
aoqi@0 561 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
aoqi@0 562 }
aoqi@0 563 #endif
aoqi@0 564 for (int s = 0; s < from->number_of_sux();) {
aoqi@0 565 BlockBegin* sux = from->sux_at(s);
aoqi@0 566 if (sux == to) {
aoqi@0 567 int index = sux->_predecessors.index_of(from);
aoqi@0 568 if (index >= 0) {
aoqi@0 569 sux->_predecessors.remove_at(index);
aoqi@0 570 }
aoqi@0 571 from->_successors.remove_at(s);
aoqi@0 572 } else {
aoqi@0 573 s++;
aoqi@0 574 }
aoqi@0 575 }
aoqi@0 576 }
aoqi@0 577
aoqi@0 578
aoqi@0 579 void BlockBegin::disconnect_from_graph() {
aoqi@0 580 // disconnect this block from all other blocks
aoqi@0 581 for (int p = 0; p < number_of_preds(); p++) {
aoqi@0 582 pred_at(p)->remove_successor(this);
aoqi@0 583 }
aoqi@0 584 for (int s = 0; s < number_of_sux(); s++) {
aoqi@0 585 sux_at(s)->remove_predecessor(this);
aoqi@0 586 }
aoqi@0 587 }
aoqi@0 588
aoqi@0 589 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
aoqi@0 590 // modify predecessors before substituting successors
aoqi@0 591 for (int i = 0; i < number_of_sux(); i++) {
aoqi@0 592 if (sux_at(i) == old_sux) {
aoqi@0 593 // remove old predecessor before adding new predecessor
aoqi@0 594 // otherwise there is a dead predecessor in the list
aoqi@0 595 new_sux->remove_predecessor(old_sux);
aoqi@0 596 new_sux->add_predecessor(this);
aoqi@0 597 }
aoqi@0 598 }
aoqi@0 599 old_sux->remove_predecessor(this);
aoqi@0 600 end()->substitute_sux(old_sux, new_sux);
aoqi@0 601 }
aoqi@0 602
aoqi@0 603
aoqi@0 604
aoqi@0 605 // In general it is not possible to calculate a value for the field "depth_first_number"
aoqi@0 606 // of the inserted block, without recomputing the values of the other blocks
aoqi@0 607 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
aoqi@0 608 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
aoqi@0 609 int bci = sux->bci();
aoqi@0 610 // critical edge splitting may introduce a goto after a if and array
aoqi@0 611 // bound check elimination may insert a predicate between the if and
aoqi@0 612 // goto. The bci of the goto can't be the one of the if otherwise
aoqi@0 613 // the state and bci are inconsistent and a deoptimization triggered
aoqi@0 614 // by the predicate would lead to incorrect execution/a crash.
aoqi@0 615 BlockBegin* new_sux = new BlockBegin(bci);
aoqi@0 616
aoqi@0 617 // mark this block (special treatment when block order is computed)
aoqi@0 618 new_sux->set(critical_edge_split_flag);
aoqi@0 619
aoqi@0 620 // This goto is not a safepoint.
aoqi@0 621 Goto* e = new Goto(sux, false);
aoqi@0 622 new_sux->set_next(e, bci);
aoqi@0 623 new_sux->set_end(e);
aoqi@0 624 // setup states
aoqi@0 625 ValueStack* s = end()->state();
aoqi@0 626 new_sux->set_state(s->copy(s->kind(), bci));
aoqi@0 627 e->set_state(s->copy(s->kind(), bci));
aoqi@0 628 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
aoqi@0 629 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
aoqi@0 630 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
aoqi@0 631
aoqi@0 632 // link predecessor to new block
aoqi@0 633 end()->substitute_sux(sux, new_sux);
aoqi@0 634
aoqi@0 635 // The ordering needs to be the same, so remove the link that the
aoqi@0 636 // set_end call above added and substitute the new_sux for this
aoqi@0 637 // block.
aoqi@0 638 sux->remove_predecessor(new_sux);
aoqi@0 639
aoqi@0 640 // the successor could be the target of a switch so it might have
aoqi@0 641 // multiple copies of this predecessor, so substitute the new_sux
aoqi@0 642 // for the first and delete the rest.
aoqi@0 643 bool assigned = false;
aoqi@0 644 BlockList& list = sux->_predecessors;
aoqi@0 645 for (int i = 0; i < list.length(); i++) {
aoqi@0 646 BlockBegin** b = list.adr_at(i);
aoqi@0 647 if (*b == this) {
aoqi@0 648 if (assigned) {
aoqi@0 649 list.remove_at(i);
aoqi@0 650 // reprocess this index
aoqi@0 651 i--;
aoqi@0 652 } else {
aoqi@0 653 assigned = true;
aoqi@0 654 *b = new_sux;
aoqi@0 655 }
aoqi@0 656 // link the new block back to it's predecessors.
aoqi@0 657 new_sux->add_predecessor(this);
aoqi@0 658 }
aoqi@0 659 }
aoqi@0 660 assert(assigned == true, "should have assigned at least once");
aoqi@0 661 return new_sux;
aoqi@0 662 }
aoqi@0 663
aoqi@0 664
aoqi@0 665 void BlockBegin::remove_successor(BlockBegin* pred) {
aoqi@0 666 int idx;
aoqi@0 667 while ((idx = _successors.index_of(pred)) >= 0) {
aoqi@0 668 _successors.remove_at(idx);
aoqi@0 669 }
aoqi@0 670 }
aoqi@0 671
aoqi@0 672
aoqi@0 673 void BlockBegin::add_predecessor(BlockBegin* pred) {
aoqi@0 674 _predecessors.append(pred);
aoqi@0 675 }
aoqi@0 676
aoqi@0 677
aoqi@0 678 void BlockBegin::remove_predecessor(BlockBegin* pred) {
aoqi@0 679 int idx;
aoqi@0 680 while ((idx = _predecessors.index_of(pred)) >= 0) {
aoqi@0 681 _predecessors.remove_at(idx);
aoqi@0 682 }
aoqi@0 683 }
aoqi@0 684
aoqi@0 685
aoqi@0 686 void BlockBegin::add_exception_handler(BlockBegin* b) {
aoqi@0 687 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
aoqi@0 688 // add only if not in the list already
aoqi@0 689 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
aoqi@0 690 }
aoqi@0 691
aoqi@0 692 int BlockBegin::add_exception_state(ValueStack* state) {
aoqi@0 693 assert(is_set(exception_entry_flag), "only for xhandlers");
aoqi@0 694 if (_exception_states == NULL) {
aoqi@0 695 _exception_states = new ValueStackStack(4);
aoqi@0 696 }
aoqi@0 697 _exception_states->append(state);
aoqi@0 698 return _exception_states->length() - 1;
aoqi@0 699 }
aoqi@0 700
aoqi@0 701
aoqi@0 702 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
aoqi@0 703 if (!mark.at(block_id())) {
aoqi@0 704 mark.at_put(block_id(), true);
aoqi@0 705 closure->block_do(this);
aoqi@0 706 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
aoqi@0 707 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
aoqi@0 708 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
aoqi@0 709 }
aoqi@0 710 }
aoqi@0 711
aoqi@0 712
aoqi@0 713 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
aoqi@0 714 if (!mark.at(block_id())) {
aoqi@0 715 mark.at_put(block_id(), true);
aoqi@0 716 BlockEnd* e = end();
aoqi@0 717 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
aoqi@0 718 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
aoqi@0 719 closure->block_do(this);
aoqi@0 720 }
aoqi@0 721 }
aoqi@0 722
aoqi@0 723
aoqi@0 724 void BlockBegin::iterate_preorder(BlockClosure* closure) {
aoqi@0 725 boolArray mark(number_of_blocks(), false);
aoqi@0 726 iterate_preorder(mark, closure);
aoqi@0 727 }
aoqi@0 728
aoqi@0 729
aoqi@0 730 void BlockBegin::iterate_postorder(BlockClosure* closure) {
aoqi@0 731 boolArray mark(number_of_blocks(), false);
aoqi@0 732 iterate_postorder(mark, closure);
aoqi@0 733 }
aoqi@0 734
aoqi@0 735
aoqi@0 736 void BlockBegin::block_values_do(ValueVisitor* f) {
aoqi@0 737 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
aoqi@0 738 }
aoqi@0 739
aoqi@0 740
aoqi@0 741 #ifndef PRODUCT
aoqi@0 742 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
aoqi@0 743 #else
aoqi@0 744 #define TRACE_PHI(coce)
aoqi@0 745 #endif
aoqi@0 746
aoqi@0 747
aoqi@0 748 bool BlockBegin::try_merge(ValueStack* new_state) {
aoqi@0 749 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
aoqi@0 750
aoqi@0 751 // local variables used for state iteration
aoqi@0 752 int index;
aoqi@0 753 Value new_value, existing_value;
aoqi@0 754
aoqi@0 755 ValueStack* existing_state = state();
aoqi@0 756 if (existing_state == NULL) {
aoqi@0 757 TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
aoqi@0 758
aoqi@0 759 if (is_set(BlockBegin::was_visited_flag)) {
aoqi@0 760 // this actually happens for complicated jsr/ret structures
aoqi@0 761 return false; // BAILOUT in caller
aoqi@0 762 }
aoqi@0 763
aoqi@0 764 // copy state because it is altered
aoqi@0 765 new_state = new_state->copy(ValueStack::BlockBeginState, bci());
aoqi@0 766
aoqi@0 767 // Use method liveness to invalidate dead locals
aoqi@0 768 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
aoqi@0 769 if (liveness.is_valid()) {
aoqi@0 770 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
aoqi@0 771
aoqi@0 772 for_each_local_value(new_state, index, new_value) {
aoqi@0 773 if (!liveness.at(index) || new_value->type()->is_illegal()) {
aoqi@0 774 new_state->invalidate_local(index);
aoqi@0 775 TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
aoqi@0 776 }
aoqi@0 777 }
aoqi@0 778 }
aoqi@0 779
aoqi@0 780 if (is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 781 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
aoqi@0 782
aoqi@0 783 for_each_stack_value(new_state, index, new_value) {
aoqi@0 784 new_state->setup_phi_for_stack(this, index);
aoqi@0 785 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
aoqi@0 786 }
aoqi@0 787
aoqi@0 788 BitMap requires_phi_function = new_state->scope()->requires_phi_function();
aoqi@0 789
aoqi@0 790 for_each_local_value(new_state, index, new_value) {
aoqi@0 791 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
aoqi@0 792 if (requires_phi || !SelectivePhiFunctions) {
aoqi@0 793 new_state->setup_phi_for_local(this, index);
aoqi@0 794 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
aoqi@0 795 }
aoqi@0 796 }
aoqi@0 797 }
aoqi@0 798
aoqi@0 799 // initialize state of block
aoqi@0 800 set_state(new_state);
aoqi@0 801
aoqi@0 802 } else if (existing_state->is_same(new_state)) {
aoqi@0 803 TRACE_PHI(tty->print_cr("exisiting state found"));
aoqi@0 804
aoqi@0 805 assert(existing_state->scope() == new_state->scope(), "not matching");
aoqi@0 806 assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
aoqi@0 807 assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
aoqi@0 808
aoqi@0 809 if (is_set(BlockBegin::was_visited_flag)) {
aoqi@0 810 TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
aoqi@0 811
aoqi@0 812 if (!is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 813 // this actually happens for complicated jsr/ret structures
aoqi@0 814 return false; // BAILOUT in caller
aoqi@0 815 }
aoqi@0 816
aoqi@0 817 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 818 Value new_value = new_state->local_at(index);
aoqi@0 819 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
aoqi@0 820 // The old code invalidated the phi function here
aoqi@0 821 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out
aoqi@0 822 return false; // BAILOUT in caller
aoqi@0 823 }
aoqi@0 824 }
aoqi@0 825
aoqi@0 826 #ifdef ASSERT
aoqi@0 827 // check that all necessary phi functions are present
aoqi@0 828 for_each_stack_value(existing_state, index, existing_value) {
aoqi@0 829 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
aoqi@0 830 }
aoqi@0 831 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 832 assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
aoqi@0 833 }
aoqi@0 834 #endif
aoqi@0 835
aoqi@0 836 } else {
aoqi@0 837 TRACE_PHI(tty->print_cr("creating phi functions on demand"));
aoqi@0 838
aoqi@0 839 // create necessary phi functions for stack
aoqi@0 840 for_each_stack_value(existing_state, index, existing_value) {
aoqi@0 841 Value new_value = new_state->stack_at(index);
aoqi@0 842 Phi* existing_phi = existing_value->as_Phi();
aoqi@0 843
aoqi@0 844 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
aoqi@0 845 existing_state->setup_phi_for_stack(this, index);
aoqi@0 846 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
aoqi@0 847 }
aoqi@0 848 }
aoqi@0 849
aoqi@0 850 // create necessary phi functions for locals
aoqi@0 851 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 852 Value new_value = new_state->local_at(index);
aoqi@0 853 Phi* existing_phi = existing_value->as_Phi();
aoqi@0 854
aoqi@0 855 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
aoqi@0 856 existing_state->invalidate_local(index);
aoqi@0 857 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
aoqi@0 858 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
aoqi@0 859 existing_state->setup_phi_for_local(this, index);
aoqi@0 860 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
aoqi@0 861 }
aoqi@0 862 }
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
aoqi@0 866
aoqi@0 867 } else {
aoqi@0 868 assert(false, "stack or locks not matching (invalid bytecodes)");
aoqi@0 869 return false;
aoqi@0 870 }
aoqi@0 871
aoqi@0 872 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
aoqi@0 873
aoqi@0 874 return true;
aoqi@0 875 }
aoqi@0 876
aoqi@0 877
aoqi@0 878 #ifndef PRODUCT
aoqi@0 879 void BlockBegin::print_block() {
aoqi@0 880 InstructionPrinter ip;
aoqi@0 881 print_block(ip, false);
aoqi@0 882 }
aoqi@0 883
aoqi@0 884
aoqi@0 885 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
aoqi@0 886 ip.print_instr(this); tty->cr();
aoqi@0 887 ip.print_stack(this->state()); tty->cr();
aoqi@0 888 ip.print_inline_level(this);
aoqi@0 889 ip.print_head();
aoqi@0 890 for (Instruction* n = next(); n != NULL; n = n->next()) {
aoqi@0 891 if (!live_only || n->is_pinned() || n->use_count() > 0) {
aoqi@0 892 ip.print_line(n);
aoqi@0 893 }
aoqi@0 894 }
aoqi@0 895 tty->cr();
aoqi@0 896 }
aoqi@0 897 #endif // PRODUCT
aoqi@0 898
aoqi@0 899
aoqi@0 900 // Implementation of BlockList
aoqi@0 901
aoqi@0 902 void BlockList::iterate_forward (BlockClosure* closure) {
aoqi@0 903 const int l = length();
aoqi@0 904 for (int i = 0; i < l; i++) closure->block_do(at(i));
aoqi@0 905 }
aoqi@0 906
aoqi@0 907
aoqi@0 908 void BlockList::iterate_backward(BlockClosure* closure) {
aoqi@0 909 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
aoqi@0 910 }
aoqi@0 911
aoqi@0 912
aoqi@0 913 void BlockList::blocks_do(void f(BlockBegin*)) {
aoqi@0 914 for (int i = length() - 1; i >= 0; i--) f(at(i));
aoqi@0 915 }
aoqi@0 916
aoqi@0 917
aoqi@0 918 void BlockList::values_do(ValueVisitor* f) {
aoqi@0 919 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
aoqi@0 920 }
aoqi@0 921
aoqi@0 922
aoqi@0 923 #ifndef PRODUCT
aoqi@0 924 void BlockList::print(bool cfg_only, bool live_only) {
aoqi@0 925 InstructionPrinter ip;
aoqi@0 926 for (int i = 0; i < length(); i++) {
aoqi@0 927 BlockBegin* block = at(i);
aoqi@0 928 if (cfg_only) {
aoqi@0 929 ip.print_instr(block); tty->cr();
aoqi@0 930 } else {
aoqi@0 931 block->print_block(ip, live_only);
aoqi@0 932 }
aoqi@0 933 }
aoqi@0 934 }
aoqi@0 935 #endif // PRODUCT
aoqi@0 936
aoqi@0 937
aoqi@0 938 // Implementation of BlockEnd
aoqi@0 939
aoqi@0 940 void BlockEnd::set_begin(BlockBegin* begin) {
aoqi@0 941 BlockList* sux = NULL;
aoqi@0 942 if (begin != NULL) {
aoqi@0 943 sux = begin->successors();
aoqi@0 944 } else if (this->begin() != NULL) {
aoqi@0 945 // copy our sux list
aoqi@0 946 BlockList* sux = new BlockList(this->begin()->number_of_sux());
aoqi@0 947 for (int i = 0; i < this->begin()->number_of_sux(); i++) {
aoqi@0 948 sux->append(this->begin()->sux_at(i));
aoqi@0 949 }
aoqi@0 950 }
aoqi@0 951 _sux = sux;
aoqi@0 952 }
aoqi@0 953
aoqi@0 954
aoqi@0 955 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
aoqi@0 956 substitute(*_sux, old_sux, new_sux);
aoqi@0 957 }
aoqi@0 958
aoqi@0 959
aoqi@0 960 // Implementation of Phi
aoqi@0 961
aoqi@0 962 // Normal phi functions take their operands from the last instruction of the
aoqi@0 963 // predecessor. Special handling is needed for xhanlder entries because there
aoqi@0 964 // the state of arbitrary instructions are needed.
aoqi@0 965
aoqi@0 966 Value Phi::operand_at(int i) const {
aoqi@0 967 ValueStack* state;
aoqi@0 968 if (_block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 969 state = _block->exception_state_at(i);
aoqi@0 970 } else {
aoqi@0 971 state = _block->pred_at(i)->end()->state();
aoqi@0 972 }
aoqi@0 973 assert(state != NULL, "");
aoqi@0 974
aoqi@0 975 if (is_local()) {
aoqi@0 976 return state->local_at(local_index());
aoqi@0 977 } else {
aoqi@0 978 return state->stack_at(stack_index());
aoqi@0 979 }
aoqi@0 980 }
aoqi@0 981
aoqi@0 982
aoqi@0 983 int Phi::operand_count() const {
aoqi@0 984 if (_block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 985 return _block->number_of_exception_states();
aoqi@0 986 } else {
aoqi@0 987 return _block->number_of_preds();
aoqi@0 988 }
aoqi@0 989 }
aoqi@0 990
aoqi@0 991 #ifdef ASSERT
aoqi@0 992 // Constructor of Assert
aoqi@0 993 Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)
aoqi@0 994 , _x(x)
aoqi@0 995 , _cond(cond)
aoqi@0 996 , _y(y)
aoqi@0 997 {
aoqi@0 998 set_flag(UnorderedIsTrueFlag, unordered_is_true);
aoqi@0 999 assert(x->type()->tag() == y->type()->tag(), "types must match");
aoqi@0 1000 pin();
aoqi@0 1001
aoqi@0 1002 stringStream strStream;
aoqi@0 1003 Compilation::current()->method()->print_name(&strStream);
aoqi@0 1004
aoqi@0 1005 stringStream strStream1;
aoqi@0 1006 InstructionPrinter ip1(1, &strStream1);
aoqi@0 1007 ip1.print_instr(x);
aoqi@0 1008
aoqi@0 1009 stringStream strStream2;
aoqi@0 1010 InstructionPrinter ip2(1, &strStream2);
aoqi@0 1011 ip2.print_instr(y);
aoqi@0 1012
aoqi@0 1013 stringStream ss;
aoqi@0 1014 ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());
aoqi@0 1015
aoqi@0 1016 _message = ss.as_string();
aoqi@0 1017 }
aoqi@0 1018 #endif
aoqi@0 1019
aoqi@0 1020 void RangeCheckPredicate::check_state() {
aoqi@0 1021 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
aoqi@0 1022 }
aoqi@0 1023
aoqi@0 1024 void ProfileInvoke::state_values_do(ValueVisitor* f) {
aoqi@0 1025 if (state() != NULL) state()->values_do(f);
aoqi@0 1026 }

mercurial