src/share/vm/c1/c1_Instruction.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 8856
ac27a9c85bea
child 10015
eb7ce841ccec
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 {
shshahma@8652 363 ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
shshahma@8652 364 ciType *t = declared_signature->return_type();
aoqi@0 365 assert(t->basic_type() != T_VOID, "need return value of void method?");
aoqi@0 366 return t;
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 // Implementation of Contant
aoqi@0 370 intx Constant::hash() const {
aoqi@0 371 if (state_before() == NULL) {
aoqi@0 372 switch (type()->tag()) {
aoqi@0 373 case intTag:
aoqi@0 374 return HASH2(name(), type()->as_IntConstant()->value());
aoqi@0 375 case addressTag:
aoqi@0 376 return HASH2(name(), type()->as_AddressConstant()->value());
aoqi@0 377 case longTag:
aoqi@0 378 {
aoqi@0 379 jlong temp = type()->as_LongConstant()->value();
aoqi@0 380 return HASH3(name(), high(temp), low(temp));
aoqi@0 381 }
aoqi@0 382 case floatTag:
aoqi@0 383 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
aoqi@0 384 case doubleTag:
aoqi@0 385 {
aoqi@0 386 jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
aoqi@0 387 return HASH3(name(), high(temp), low(temp));
aoqi@0 388 }
aoqi@0 389 case objectTag:
aoqi@0 390 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
aoqi@0 391 return HASH2(name(), type()->as_ObjectType()->constant_value());
aoqi@0 392 case metaDataTag:
aoqi@0 393 assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");
aoqi@0 394 return HASH2(name(), type()->as_MetadataType()->constant_value());
aoqi@0 395 default:
aoqi@0 396 ShouldNotReachHere();
aoqi@0 397 }
aoqi@0 398 }
aoqi@0 399 return 0;
aoqi@0 400 }
aoqi@0 401
aoqi@0 402 bool Constant::is_equal(Value v) const {
aoqi@0 403 if (v->as_Constant() == NULL) return false;
aoqi@0 404
aoqi@0 405 switch (type()->tag()) {
aoqi@0 406 case intTag:
aoqi@0 407 {
aoqi@0 408 IntConstant* t1 = type()->as_IntConstant();
aoqi@0 409 IntConstant* t2 = v->type()->as_IntConstant();
aoqi@0 410 return (t1 != NULL && t2 != NULL &&
aoqi@0 411 t1->value() == t2->value());
aoqi@0 412 }
aoqi@0 413 case longTag:
aoqi@0 414 {
aoqi@0 415 LongConstant* t1 = type()->as_LongConstant();
aoqi@0 416 LongConstant* t2 = v->type()->as_LongConstant();
aoqi@0 417 return (t1 != NULL && t2 != NULL &&
aoqi@0 418 t1->value() == t2->value());
aoqi@0 419 }
aoqi@0 420 case floatTag:
aoqi@0 421 {
aoqi@0 422 FloatConstant* t1 = type()->as_FloatConstant();
aoqi@0 423 FloatConstant* t2 = v->type()->as_FloatConstant();
aoqi@0 424 return (t1 != NULL && t2 != NULL &&
aoqi@0 425 jint_cast(t1->value()) == jint_cast(t2->value()));
aoqi@0 426 }
aoqi@0 427 case doubleTag:
aoqi@0 428 {
aoqi@0 429 DoubleConstant* t1 = type()->as_DoubleConstant();
aoqi@0 430 DoubleConstant* t2 = v->type()->as_DoubleConstant();
aoqi@0 431 return (t1 != NULL && t2 != NULL &&
aoqi@0 432 jlong_cast(t1->value()) == jlong_cast(t2->value()));
aoqi@0 433 }
aoqi@0 434 case objectTag:
aoqi@0 435 {
aoqi@0 436 ObjectType* t1 = type()->as_ObjectType();
aoqi@0 437 ObjectType* t2 = v->type()->as_ObjectType();
aoqi@0 438 return (t1 != NULL && t2 != NULL &&
aoqi@0 439 t1->is_loaded() && t2->is_loaded() &&
aoqi@0 440 t1->constant_value() == t2->constant_value());
aoqi@0 441 }
aoqi@0 442 case metaDataTag:
aoqi@0 443 {
aoqi@0 444 MetadataType* t1 = type()->as_MetadataType();
aoqi@0 445 MetadataType* t2 = v->type()->as_MetadataType();
aoqi@0 446 return (t1 != NULL && t2 != NULL &&
aoqi@0 447 t1->is_loaded() && t2->is_loaded() &&
aoqi@0 448 t1->constant_value() == t2->constant_value());
aoqi@0 449 }
aoqi@0 450 }
aoqi@0 451 return false;
aoqi@0 452 }
aoqi@0 453
aoqi@0 454 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
aoqi@0 455 Constant* rc = right->as_Constant();
aoqi@0 456 // other is not a constant
aoqi@0 457 if (rc == NULL) return not_comparable;
aoqi@0 458
aoqi@0 459 ValueType* lt = type();
aoqi@0 460 ValueType* rt = rc->type();
aoqi@0 461 // different types
aoqi@0 462 if (lt->base() != rt->base()) return not_comparable;
aoqi@0 463 switch (lt->tag()) {
aoqi@0 464 case intTag: {
aoqi@0 465 int x = lt->as_IntConstant()->value();
aoqi@0 466 int y = rt->as_IntConstant()->value();
aoqi@0 467 switch (cond) {
aoqi@0 468 case If::eql: return x == y ? cond_true : cond_false;
aoqi@0 469 case If::neq: return x != y ? cond_true : cond_false;
aoqi@0 470 case If::lss: return x < y ? cond_true : cond_false;
aoqi@0 471 case If::leq: return x <= y ? cond_true : cond_false;
aoqi@0 472 case If::gtr: return x > y ? cond_true : cond_false;
aoqi@0 473 case If::geq: return x >= y ? cond_true : cond_false;
aoqi@0 474 }
aoqi@0 475 break;
aoqi@0 476 }
aoqi@0 477 case longTag: {
aoqi@0 478 jlong x = lt->as_LongConstant()->value();
aoqi@0 479 jlong y = rt->as_LongConstant()->value();
aoqi@0 480 switch (cond) {
aoqi@0 481 case If::eql: return x == y ? cond_true : cond_false;
aoqi@0 482 case If::neq: return x != y ? cond_true : cond_false;
aoqi@0 483 case If::lss: return x < y ? cond_true : cond_false;
aoqi@0 484 case If::leq: return x <= y ? cond_true : cond_false;
aoqi@0 485 case If::gtr: return x > y ? cond_true : cond_false;
aoqi@0 486 case If::geq: return x >= y ? cond_true : cond_false;
aoqi@0 487 }
aoqi@0 488 break;
aoqi@0 489 }
aoqi@0 490 case objectTag: {
aoqi@0 491 ciObject* xvalue = lt->as_ObjectType()->constant_value();
aoqi@0 492 ciObject* yvalue = rt->as_ObjectType()->constant_value();
aoqi@0 493 assert(xvalue != NULL && yvalue != NULL, "not constants");
aoqi@0 494 if (xvalue->is_loaded() && yvalue->is_loaded()) {
aoqi@0 495 switch (cond) {
aoqi@0 496 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
aoqi@0 497 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
aoqi@0 498 }
aoqi@0 499 }
aoqi@0 500 break;
aoqi@0 501 }
aoqi@0 502 case metaDataTag: {
aoqi@0 503 ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
aoqi@0 504 ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
aoqi@0 505 assert(xvalue != NULL && yvalue != NULL, "not constants");
aoqi@0 506 if (xvalue->is_loaded() && yvalue->is_loaded()) {
aoqi@0 507 switch (cond) {
aoqi@0 508 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
aoqi@0 509 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
aoqi@0 510 }
aoqi@0 511 }
aoqi@0 512 break;
aoqi@0 513 }
aoqi@0 514 }
aoqi@0 515 return not_comparable;
aoqi@0 516 }
aoqi@0 517
aoqi@0 518
aoqi@0 519 // Implementation of BlockBegin
aoqi@0 520
aoqi@0 521 void BlockBegin::set_end(BlockEnd* end) {
aoqi@0 522 assert(end != NULL, "should not reset block end to NULL");
aoqi@0 523 if (end == _end) {
aoqi@0 524 return;
aoqi@0 525 }
aoqi@0 526 clear_end();
aoqi@0 527
aoqi@0 528 // Set the new end
aoqi@0 529 _end = end;
aoqi@0 530
aoqi@0 531 _successors.clear();
aoqi@0 532 // Now reset successors list based on BlockEnd
aoqi@0 533 for (int i = 0; i < end->number_of_sux(); i++) {
aoqi@0 534 BlockBegin* sux = end->sux_at(i);
aoqi@0 535 _successors.append(sux);
aoqi@0 536 sux->_predecessors.append(this);
aoqi@0 537 }
aoqi@0 538 _end->set_begin(this);
aoqi@0 539 }
aoqi@0 540
aoqi@0 541
aoqi@0 542 void BlockBegin::clear_end() {
aoqi@0 543 // Must make the predecessors/successors match up with the
aoqi@0 544 // BlockEnd's notion.
aoqi@0 545 if (_end != NULL) {
aoqi@0 546 // disconnect from the old end
aoqi@0 547 _end->set_begin(NULL);
aoqi@0 548
aoqi@0 549 // disconnect this block from it's current successors
aoqi@0 550 for (int i = 0; i < _successors.length(); i++) {
aoqi@0 551 _successors.at(i)->remove_predecessor(this);
aoqi@0 552 }
aoqi@0 553 _end = NULL;
aoqi@0 554 }
aoqi@0 555 }
aoqi@0 556
aoqi@0 557
aoqi@0 558 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
aoqi@0 559 // disconnect any edges between from and to
aoqi@0 560 #ifndef PRODUCT
aoqi@0 561 if (PrintIR && Verbose) {
aoqi@0 562 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
aoqi@0 563 }
aoqi@0 564 #endif
aoqi@0 565 for (int s = 0; s < from->number_of_sux();) {
aoqi@0 566 BlockBegin* sux = from->sux_at(s);
aoqi@0 567 if (sux == to) {
aoqi@0 568 int index = sux->_predecessors.index_of(from);
aoqi@0 569 if (index >= 0) {
aoqi@0 570 sux->_predecessors.remove_at(index);
aoqi@0 571 }
aoqi@0 572 from->_successors.remove_at(s);
aoqi@0 573 } else {
aoqi@0 574 s++;
aoqi@0 575 }
aoqi@0 576 }
aoqi@0 577 }
aoqi@0 578
aoqi@0 579
aoqi@0 580 void BlockBegin::disconnect_from_graph() {
aoqi@0 581 // disconnect this block from all other blocks
aoqi@0 582 for (int p = 0; p < number_of_preds(); p++) {
aoqi@0 583 pred_at(p)->remove_successor(this);
aoqi@0 584 }
aoqi@0 585 for (int s = 0; s < number_of_sux(); s++) {
aoqi@0 586 sux_at(s)->remove_predecessor(this);
aoqi@0 587 }
aoqi@0 588 }
aoqi@0 589
aoqi@0 590 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
aoqi@0 591 // modify predecessors before substituting successors
aoqi@0 592 for (int i = 0; i < number_of_sux(); i++) {
aoqi@0 593 if (sux_at(i) == old_sux) {
aoqi@0 594 // remove old predecessor before adding new predecessor
aoqi@0 595 // otherwise there is a dead predecessor in the list
aoqi@0 596 new_sux->remove_predecessor(old_sux);
aoqi@0 597 new_sux->add_predecessor(this);
aoqi@0 598 }
aoqi@0 599 }
aoqi@0 600 old_sux->remove_predecessor(this);
aoqi@0 601 end()->substitute_sux(old_sux, new_sux);
aoqi@0 602 }
aoqi@0 603
aoqi@0 604
aoqi@0 605
aoqi@0 606 // In general it is not possible to calculate a value for the field "depth_first_number"
aoqi@0 607 // of the inserted block, without recomputing the values of the other blocks
aoqi@0 608 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
aoqi@0 609 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
aoqi@0 610 int bci = sux->bci();
aoqi@0 611 // critical edge splitting may introduce a goto after a if and array
aoqi@0 612 // bound check elimination may insert a predicate between the if and
aoqi@0 613 // goto. The bci of the goto can't be the one of the if otherwise
aoqi@0 614 // the state and bci are inconsistent and a deoptimization triggered
aoqi@0 615 // by the predicate would lead to incorrect execution/a crash.
aoqi@0 616 BlockBegin* new_sux = new BlockBegin(bci);
aoqi@0 617
aoqi@0 618 // mark this block (special treatment when block order is computed)
aoqi@0 619 new_sux->set(critical_edge_split_flag);
aoqi@0 620
aoqi@0 621 // This goto is not a safepoint.
aoqi@0 622 Goto* e = new Goto(sux, false);
aoqi@0 623 new_sux->set_next(e, bci);
aoqi@0 624 new_sux->set_end(e);
aoqi@0 625 // setup states
aoqi@0 626 ValueStack* s = end()->state();
aoqi@0 627 new_sux->set_state(s->copy(s->kind(), bci));
aoqi@0 628 e->set_state(s->copy(s->kind(), bci));
aoqi@0 629 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
aoqi@0 630 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
aoqi@0 631 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
aoqi@0 632
aoqi@0 633 // link predecessor to new block
aoqi@0 634 end()->substitute_sux(sux, new_sux);
aoqi@0 635
aoqi@0 636 // The ordering needs to be the same, so remove the link that the
aoqi@0 637 // set_end call above added and substitute the new_sux for this
aoqi@0 638 // block.
aoqi@0 639 sux->remove_predecessor(new_sux);
aoqi@0 640
aoqi@0 641 // the successor could be the target of a switch so it might have
aoqi@0 642 // multiple copies of this predecessor, so substitute the new_sux
aoqi@0 643 // for the first and delete the rest.
aoqi@0 644 bool assigned = false;
aoqi@0 645 BlockList& list = sux->_predecessors;
aoqi@0 646 for (int i = 0; i < list.length(); i++) {
aoqi@0 647 BlockBegin** b = list.adr_at(i);
aoqi@0 648 if (*b == this) {
aoqi@0 649 if (assigned) {
aoqi@0 650 list.remove_at(i);
aoqi@0 651 // reprocess this index
aoqi@0 652 i--;
aoqi@0 653 } else {
aoqi@0 654 assigned = true;
aoqi@0 655 *b = new_sux;
aoqi@0 656 }
aoqi@0 657 // link the new block back to it's predecessors.
aoqi@0 658 new_sux->add_predecessor(this);
aoqi@0 659 }
aoqi@0 660 }
aoqi@0 661 assert(assigned == true, "should have assigned at least once");
aoqi@0 662 return new_sux;
aoqi@0 663 }
aoqi@0 664
aoqi@0 665
aoqi@0 666 void BlockBegin::remove_successor(BlockBegin* pred) {
aoqi@0 667 int idx;
aoqi@0 668 while ((idx = _successors.index_of(pred)) >= 0) {
aoqi@0 669 _successors.remove_at(idx);
aoqi@0 670 }
aoqi@0 671 }
aoqi@0 672
aoqi@0 673
aoqi@0 674 void BlockBegin::add_predecessor(BlockBegin* pred) {
aoqi@0 675 _predecessors.append(pred);
aoqi@0 676 }
aoqi@0 677
aoqi@0 678
aoqi@0 679 void BlockBegin::remove_predecessor(BlockBegin* pred) {
aoqi@0 680 int idx;
aoqi@0 681 while ((idx = _predecessors.index_of(pred)) >= 0) {
aoqi@0 682 _predecessors.remove_at(idx);
aoqi@0 683 }
aoqi@0 684 }
aoqi@0 685
aoqi@0 686
aoqi@0 687 void BlockBegin::add_exception_handler(BlockBegin* b) {
aoqi@0 688 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
aoqi@0 689 // add only if not in the list already
aoqi@0 690 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
aoqi@0 691 }
aoqi@0 692
aoqi@0 693 int BlockBegin::add_exception_state(ValueStack* state) {
aoqi@0 694 assert(is_set(exception_entry_flag), "only for xhandlers");
aoqi@0 695 if (_exception_states == NULL) {
aoqi@0 696 _exception_states = new ValueStackStack(4);
aoqi@0 697 }
aoqi@0 698 _exception_states->append(state);
aoqi@0 699 return _exception_states->length() - 1;
aoqi@0 700 }
aoqi@0 701
aoqi@0 702
aoqi@0 703 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
aoqi@0 704 if (!mark.at(block_id())) {
aoqi@0 705 mark.at_put(block_id(), true);
aoqi@0 706 closure->block_do(this);
aoqi@0 707 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
aoqi@0 708 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
aoqi@0 709 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
aoqi@0 710 }
aoqi@0 711 }
aoqi@0 712
aoqi@0 713
aoqi@0 714 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
aoqi@0 715 if (!mark.at(block_id())) {
aoqi@0 716 mark.at_put(block_id(), true);
aoqi@0 717 BlockEnd* e = end();
aoqi@0 718 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
aoqi@0 719 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
aoqi@0 720 closure->block_do(this);
aoqi@0 721 }
aoqi@0 722 }
aoqi@0 723
aoqi@0 724
aoqi@0 725 void BlockBegin::iterate_preorder(BlockClosure* closure) {
aoqi@0 726 boolArray mark(number_of_blocks(), false);
aoqi@0 727 iterate_preorder(mark, closure);
aoqi@0 728 }
aoqi@0 729
aoqi@0 730
aoqi@0 731 void BlockBegin::iterate_postorder(BlockClosure* closure) {
aoqi@0 732 boolArray mark(number_of_blocks(), false);
aoqi@0 733 iterate_postorder(mark, closure);
aoqi@0 734 }
aoqi@0 735
aoqi@0 736
aoqi@0 737 void BlockBegin::block_values_do(ValueVisitor* f) {
aoqi@0 738 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
aoqi@0 739 }
aoqi@0 740
aoqi@0 741
aoqi@0 742 #ifndef PRODUCT
aoqi@0 743 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
aoqi@0 744 #else
aoqi@0 745 #define TRACE_PHI(coce)
aoqi@0 746 #endif
aoqi@0 747
aoqi@0 748
aoqi@0 749 bool BlockBegin::try_merge(ValueStack* new_state) {
aoqi@0 750 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
aoqi@0 751
aoqi@0 752 // local variables used for state iteration
aoqi@0 753 int index;
aoqi@0 754 Value new_value, existing_value;
aoqi@0 755
aoqi@0 756 ValueStack* existing_state = state();
aoqi@0 757 if (existing_state == NULL) {
aoqi@0 758 TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
aoqi@0 759
aoqi@0 760 if (is_set(BlockBegin::was_visited_flag)) {
aoqi@0 761 // this actually happens for complicated jsr/ret structures
aoqi@0 762 return false; // BAILOUT in caller
aoqi@0 763 }
aoqi@0 764
aoqi@0 765 // copy state because it is altered
aoqi@0 766 new_state = new_state->copy(ValueStack::BlockBeginState, bci());
aoqi@0 767
aoqi@0 768 // Use method liveness to invalidate dead locals
aoqi@0 769 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
aoqi@0 770 if (liveness.is_valid()) {
aoqi@0 771 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
aoqi@0 772
aoqi@0 773 for_each_local_value(new_state, index, new_value) {
aoqi@0 774 if (!liveness.at(index) || new_value->type()->is_illegal()) {
aoqi@0 775 new_state->invalidate_local(index);
aoqi@0 776 TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
aoqi@0 777 }
aoqi@0 778 }
aoqi@0 779 }
aoqi@0 780
aoqi@0 781 if (is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 782 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
aoqi@0 783
aoqi@0 784 for_each_stack_value(new_state, index, new_value) {
aoqi@0 785 new_state->setup_phi_for_stack(this, index);
aoqi@0 786 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 787 }
aoqi@0 788
aoqi@0 789 BitMap requires_phi_function = new_state->scope()->requires_phi_function();
aoqi@0 790
aoqi@0 791 for_each_local_value(new_state, index, new_value) {
aoqi@0 792 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
aoqi@0 793 if (requires_phi || !SelectivePhiFunctions) {
aoqi@0 794 new_state->setup_phi_for_local(this, index);
aoqi@0 795 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 796 }
aoqi@0 797 }
aoqi@0 798 }
aoqi@0 799
aoqi@0 800 // initialize state of block
aoqi@0 801 set_state(new_state);
aoqi@0 802
aoqi@0 803 } else if (existing_state->is_same(new_state)) {
aoqi@0 804 TRACE_PHI(tty->print_cr("exisiting state found"));
aoqi@0 805
aoqi@0 806 assert(existing_state->scope() == new_state->scope(), "not matching");
aoqi@0 807 assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
aoqi@0 808 assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
aoqi@0 809
aoqi@0 810 if (is_set(BlockBegin::was_visited_flag)) {
aoqi@0 811 TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
aoqi@0 812
aoqi@0 813 if (!is_set(BlockBegin::parser_loop_header_flag)) {
aoqi@0 814 // this actually happens for complicated jsr/ret structures
aoqi@0 815 return false; // BAILOUT in caller
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 819 Value new_value = new_state->local_at(index);
aoqi@0 820 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
aoqi@0 821 // The old code invalidated the phi function here
aoqi@0 822 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out
aoqi@0 823 return false; // BAILOUT in caller
aoqi@0 824 }
aoqi@0 825 }
aoqi@0 826
aoqi@0 827 #ifdef ASSERT
aoqi@0 828 // check that all necessary phi functions are present
aoqi@0 829 for_each_stack_value(existing_state, index, existing_value) {
aoqi@0 830 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
aoqi@0 831 }
aoqi@0 832 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 833 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 834 }
aoqi@0 835 #endif
aoqi@0 836
aoqi@0 837 } else {
aoqi@0 838 TRACE_PHI(tty->print_cr("creating phi functions on demand"));
aoqi@0 839
aoqi@0 840 // create necessary phi functions for stack
aoqi@0 841 for_each_stack_value(existing_state, index, existing_value) {
aoqi@0 842 Value new_value = new_state->stack_at(index);
aoqi@0 843 Phi* existing_phi = existing_value->as_Phi();
aoqi@0 844
aoqi@0 845 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
aoqi@0 846 existing_state->setup_phi_for_stack(this, index);
aoqi@0 847 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 848 }
aoqi@0 849 }
aoqi@0 850
aoqi@0 851 // create necessary phi functions for locals
aoqi@0 852 for_each_local_value(existing_state, index, existing_value) {
aoqi@0 853 Value new_value = new_state->local_at(index);
aoqi@0 854 Phi* existing_phi = existing_value->as_Phi();
aoqi@0 855
aoqi@0 856 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
aoqi@0 857 existing_state->invalidate_local(index);
aoqi@0 858 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
aoqi@0 859 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
aoqi@0 860 existing_state->setup_phi_for_local(this, index);
aoqi@0 861 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 862 }
aoqi@0 863 }
aoqi@0 864 }
aoqi@0 865
aoqi@0 866 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
aoqi@0 867
aoqi@0 868 } else {
aoqi@0 869 assert(false, "stack or locks not matching (invalid bytecodes)");
aoqi@0 870 return false;
aoqi@0 871 }
aoqi@0 872
aoqi@0 873 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
aoqi@0 874
aoqi@0 875 return true;
aoqi@0 876 }
aoqi@0 877
aoqi@0 878
aoqi@0 879 #ifndef PRODUCT
aoqi@0 880 void BlockBegin::print_block() {
aoqi@0 881 InstructionPrinter ip;
aoqi@0 882 print_block(ip, false);
aoqi@0 883 }
aoqi@0 884
aoqi@0 885
aoqi@0 886 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
aoqi@0 887 ip.print_instr(this); tty->cr();
aoqi@0 888 ip.print_stack(this->state()); tty->cr();
aoqi@0 889 ip.print_inline_level(this);
aoqi@0 890 ip.print_head();
aoqi@0 891 for (Instruction* n = next(); n != NULL; n = n->next()) {
aoqi@0 892 if (!live_only || n->is_pinned() || n->use_count() > 0) {
aoqi@0 893 ip.print_line(n);
aoqi@0 894 }
aoqi@0 895 }
aoqi@0 896 tty->cr();
aoqi@0 897 }
aoqi@0 898 #endif // PRODUCT
aoqi@0 899
aoqi@0 900
aoqi@0 901 // Implementation of BlockList
aoqi@0 902
aoqi@0 903 void BlockList::iterate_forward (BlockClosure* closure) {
aoqi@0 904 const int l = length();
aoqi@0 905 for (int i = 0; i < l; i++) closure->block_do(at(i));
aoqi@0 906 }
aoqi@0 907
aoqi@0 908
aoqi@0 909 void BlockList::iterate_backward(BlockClosure* closure) {
aoqi@0 910 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
aoqi@0 911 }
aoqi@0 912
aoqi@0 913
aoqi@0 914 void BlockList::blocks_do(void f(BlockBegin*)) {
aoqi@0 915 for (int i = length() - 1; i >= 0; i--) f(at(i));
aoqi@0 916 }
aoqi@0 917
aoqi@0 918
aoqi@0 919 void BlockList::values_do(ValueVisitor* f) {
aoqi@0 920 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
aoqi@0 921 }
aoqi@0 922
aoqi@0 923
aoqi@0 924 #ifndef PRODUCT
aoqi@0 925 void BlockList::print(bool cfg_only, bool live_only) {
aoqi@0 926 InstructionPrinter ip;
aoqi@0 927 for (int i = 0; i < length(); i++) {
aoqi@0 928 BlockBegin* block = at(i);
aoqi@0 929 if (cfg_only) {
aoqi@0 930 ip.print_instr(block); tty->cr();
aoqi@0 931 } else {
aoqi@0 932 block->print_block(ip, live_only);
aoqi@0 933 }
aoqi@0 934 }
aoqi@0 935 }
aoqi@0 936 #endif // PRODUCT
aoqi@0 937
aoqi@0 938
aoqi@0 939 // Implementation of BlockEnd
aoqi@0 940
aoqi@0 941 void BlockEnd::set_begin(BlockBegin* begin) {
aoqi@0 942 BlockList* sux = NULL;
aoqi@0 943 if (begin != NULL) {
aoqi@0 944 sux = begin->successors();
aoqi@0 945 } else if (this->begin() != NULL) {
aoqi@0 946 // copy our sux list
aoqi@0 947 BlockList* sux = new BlockList(this->begin()->number_of_sux());
aoqi@0 948 for (int i = 0; i < this->begin()->number_of_sux(); i++) {
aoqi@0 949 sux->append(this->begin()->sux_at(i));
aoqi@0 950 }
aoqi@0 951 }
aoqi@0 952 _sux = sux;
aoqi@0 953 }
aoqi@0 954
aoqi@0 955
aoqi@0 956 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
aoqi@0 957 substitute(*_sux, old_sux, new_sux);
aoqi@0 958 }
aoqi@0 959
aoqi@0 960
aoqi@0 961 // Implementation of Phi
aoqi@0 962
aoqi@0 963 // Normal phi functions take their operands from the last instruction of the
aoqi@0 964 // predecessor. Special handling is needed for xhanlder entries because there
aoqi@0 965 // the state of arbitrary instructions are needed.
aoqi@0 966
aoqi@0 967 Value Phi::operand_at(int i) const {
aoqi@0 968 ValueStack* state;
aoqi@0 969 if (_block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 970 state = _block->exception_state_at(i);
aoqi@0 971 } else {
aoqi@0 972 state = _block->pred_at(i)->end()->state();
aoqi@0 973 }
aoqi@0 974 assert(state != NULL, "");
aoqi@0 975
aoqi@0 976 if (is_local()) {
aoqi@0 977 return state->local_at(local_index());
aoqi@0 978 } else {
aoqi@0 979 return state->stack_at(stack_index());
aoqi@0 980 }
aoqi@0 981 }
aoqi@0 982
aoqi@0 983
aoqi@0 984 int Phi::operand_count() const {
aoqi@0 985 if (_block->is_set(BlockBegin::exception_entry_flag)) {
aoqi@0 986 return _block->number_of_exception_states();
aoqi@0 987 } else {
aoqi@0 988 return _block->number_of_preds();
aoqi@0 989 }
aoqi@0 990 }
aoqi@0 991
aoqi@0 992 #ifdef ASSERT
aoqi@0 993 // Constructor of Assert
aoqi@0 994 Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)
aoqi@0 995 , _x(x)
aoqi@0 996 , _cond(cond)
aoqi@0 997 , _y(y)
aoqi@0 998 {
aoqi@0 999 set_flag(UnorderedIsTrueFlag, unordered_is_true);
aoqi@0 1000 assert(x->type()->tag() == y->type()->tag(), "types must match");
aoqi@0 1001 pin();
aoqi@0 1002
aoqi@0 1003 stringStream strStream;
aoqi@0 1004 Compilation::current()->method()->print_name(&strStream);
aoqi@0 1005
aoqi@0 1006 stringStream strStream1;
aoqi@0 1007 InstructionPrinter ip1(1, &strStream1);
aoqi@0 1008 ip1.print_instr(x);
aoqi@0 1009
aoqi@0 1010 stringStream strStream2;
aoqi@0 1011 InstructionPrinter ip2(1, &strStream2);
aoqi@0 1012 ip2.print_instr(y);
aoqi@0 1013
aoqi@0 1014 stringStream ss;
aoqi@0 1015 ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());
aoqi@0 1016
aoqi@0 1017 _message = ss.as_string();
aoqi@0 1018 }
aoqi@0 1019 #endif
aoqi@0 1020
aoqi@0 1021 void RangeCheckPredicate::check_state() {
aoqi@0 1022 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
aoqi@0 1023 }
aoqi@0 1024
aoqi@0 1025 void ProfileInvoke::state_values_do(ValueVisitor* f) {
aoqi@0 1026 if (state() != NULL) state()->values_do(f);
aoqi@0 1027 }

mercurial