1 /* 2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciMethodData.hpp" 27 #include "classfile/systemDictionary.hpp" 28 #include "classfile/vmSymbols.hpp" 29 #include "compiler/compileLog.hpp" 30 #include "interpreter/linkResolver.hpp" 31 #include "memory/resourceArea.hpp" 32 #include "memory/universe.hpp" 33 #include "oops/oop.inline.hpp" 34 #include "opto/addnode.hpp" 35 #include "opto/castnode.hpp" 36 #include "opto/convertnode.hpp" 37 #include "opto/divnode.hpp" 38 #include "opto/idealGraphPrinter.hpp" 39 #include "opto/idealKit.hpp" 40 #include "opto/matcher.hpp" 41 #include "opto/memnode.hpp" 42 #include "opto/mulnode.hpp" 43 #include "opto/opaquenode.hpp" 44 #include "opto/parse.hpp" 45 #include "opto/runtime.hpp" 46 #include "opto/valuetypenode.hpp" 47 #include "runtime/deoptimization.hpp" 48 #include "runtime/sharedRuntime.hpp" 49 50 #ifndef PRODUCT 51 extern int explicit_null_checks_inserted, 52 explicit_null_checks_elided; 53 #endif 54 55 //---------------------------------array_load---------------------------------- 56 void Parse::array_load(BasicType bt) { 57 const Type* elemtype = Type::TOP; 58 Node* adr = array_addressing(bt, 0, &elemtype); 59 if (stopped()) return; // guaranteed null or range check 60 61 Node* idx = pop(); 62 Node* ary = pop(); 63 64 // Handle value type arrays 65 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 66 const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr(); 67 if (elemtype->isa_valuetype() != NULL) { 68 // Load from flattened value type array 69 ciValueKlass* vk = elemtype->is_valuetype()->value_klass(); 70 Node* vt = ValueTypeNode::make_from_flattened(this, vk, ary, adr); 71 push(vt); 72 return; 73 } else if (elemptr != NULL && elemptr->is_valuetypeptr()) { 74 // Load from non-flattened value type array (elements can never be null) 75 bt = T_VALUETYPE; 76 assert(elemptr->meet(TypePtr::NULL_PTR) != elemptr, "value type array elements should never be null"); 77 } else if (ValueArrayFlatten && elemptr != NULL && elemptr->can_be_value_type() && 78 !ary_t->klass_is_exact()) { 79 // Cannot statically determine if array is flattened, emit runtime check 80 IdealKit ideal(this); 81 IdealVariable res(ideal); 82 ideal.declarations_done(); 83 Node* kls = load_object_klass(ary); 84 Node* tag = load_lh_array_tag(kls); 85 ideal.if_then(tag, BoolTest::ne, intcon(Klass::_lh_array_tag_vt_value)); { 86 // non flattened 87 sync_kit(ideal); 88 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 89 elemtype = ary_t->elem()->make_oopptr(); 90 Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt, 91 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD); 92 ideal.sync_kit(this); 93 ideal.set(res, ld); 94 } ideal.else_(); { 95 // flattened 96 sync_kit(ideal); 97 Node* k_adr = basic_plus_adr(kls, in_bytes(ArrayKlass::element_klass_offset())); 98 Node* elem_klass = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS)); 99 Node* obj_size = NULL; 100 kill_dead_locals(); 101 inc_sp(2); 102 Node* alloc_obj = new_instance(elem_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); 103 dec_sp(2); 104 105 AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 106 assert(alloc->maybe_set_complete(&_gvn), ""); 107 alloc->initialization()->set_complete_with_arraycopy(); 108 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 109 // Unknown value type so might have reference fields 110 if (!bs->array_copy_requires_gc_barriers(false, T_OBJECT, false, BarrierSetC2::Parsing)) { 111 int base_off = sizeof(instanceOopDesc); 112 Node* dst_base = basic_plus_adr(alloc_obj, base_off); 113 Node* countx = obj_size; 114 countx = _gvn.transform(new SubXNode(countx, MakeConX(base_off))); 115 countx = _gvn.transform(new URShiftXNode(countx, intcon(LogBytesPerLong))); 116 117 assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place"); 118 Node* lhp = basic_plus_adr(kls, in_bytes(Klass::layout_helper_offset())); 119 Node* elem_shift = make_load(NULL, lhp, TypeInt::INT, T_INT, MemNode::unordered); 120 uint header = arrayOopDesc::base_offset_in_bytes(T_VALUETYPE); 121 Node* base = basic_plus_adr(ary, header); 122 idx = Compile::conv_I2X_index(&_gvn, idx, TypeInt::POS, control()); 123 Node* scale = _gvn.transform(new LShiftXNode(idx, elem_shift)); 124 Node* adr = basic_plus_adr(ary, base, scale); 125 126 access_clone(adr, dst_base, countx, false); 127 } else { 128 ideal.sync_kit(this); 129 ideal.make_leaf_call(OptoRuntime::load_unknown_value_Type(), 130 CAST_FROM_FN_PTR(address, OptoRuntime::load_unknown_value), 131 "load_unknown_value", 132 ary, idx, alloc_obj); 133 sync_kit(ideal); 134 } 135 136 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 137 138 ideal.sync_kit(this); 139 ideal.set(res, alloc_obj); 140 } ideal.end_if(); 141 sync_kit(ideal); 142 push_node(bt, ideal.value(res)); 143 return; 144 } 145 146 if (elemtype == TypeInt::BOOL) { 147 bt = T_BOOLEAN; 148 } else if (bt == T_OBJECT) { 149 elemtype = ary_t->elem()->make_oopptr(); 150 } 151 152 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 153 Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt, 154 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD); 155 if (bt == T_VALUETYPE) { 156 // Loading a non-flattened (but flattenable) value type from an array 157 assert(!gvn().type(ld)->maybe_null(), "value type array elements should never be null"); 158 if (elemptr->value_klass()->is_scalarizable()) { 159 ld = ValueTypeNode::make_from_oop(this, ld, elemptr->value_klass()); 160 } 161 } 162 163 push_node(bt, ld); 164 } 165 166 167 //--------------------------------array_store---------------------------------- 168 void Parse::array_store(BasicType bt) { 169 const Type* elemtype = Type::TOP; 170 Node* adr = array_addressing(bt, type2size[bt], &elemtype); 171 if (stopped()) return; // guaranteed null or range check 172 Node* cast_val = NULL; 173 if (bt == T_OBJECT) { 174 cast_val = array_store_check(); 175 if (stopped()) return; 176 } 177 Node* val = pop_node(bt); // Value to store 178 Node* idx = pop(); // Index in the array 179 Node* ary = pop(); // The array itself 180 181 const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr(); 182 if (bt == T_OBJECT) { 183 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 184 const Type* val_t = _gvn.type(val); 185 if (elemtype->isa_valuetype() != NULL) { 186 // Store to flattened value type array 187 if (!cast_val->is_ValueType()) { 188 inc_sp(3); 189 cast_val = null_check(cast_val); 190 if (stopped()) return; 191 dec_sp(3); 192 cast_val = ValueTypeNode::make_from_oop(this, cast_val, elemtype->is_valuetype()->value_klass()); 193 } 194 cast_val->as_ValueType()->store_flattened(this, ary, adr); 195 return; 196 } else if (elemptr->is_valuetypeptr()) { 197 // Store to non-flattened value type array 198 if (!cast_val->is_ValueType()) { 199 // Can not store null into a value type array 200 inc_sp(3); 201 cast_val = null_check(cast_val); 202 if (stopped()) return; 203 dec_sp(3); 204 } 205 } else if (elemptr->can_be_value_type() && !ary_t->klass_is_exact() && 206 (val->is_ValueType() || val_t == TypePtr::NULL_PTR || val_t->is_oopptr()->can_be_value_type())) { 207 if (ValueArrayFlatten) { 208 IdealKit ideal(this); 209 Node* kls = load_object_klass(ary); 210 Node* layout_val = load_lh_array_tag(kls); 211 ideal.if_then(layout_val, BoolTest::ne, intcon(Klass::_lh_array_tag_vt_value)); { 212 // non flattened 213 sync_kit(ideal); 214 215 if (!val->is_ValueType() && TypePtr::NULL_PTR->higher_equal(val_t)) { 216 gen_value_type_array_guard(ary, val, 3); 217 } 218 219 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 220 elemtype = ary_t->elem()->make_oopptr(); 221 access_store_at(ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 222 ideal.sync_kit(this); 223 } ideal.else_(); { 224 // flattened 225 // Object/interface array must be flattened, cast it 226 if (val->is_ValueType()) { 227 sync_kit(ideal); 228 const TypeValueType* vt = _gvn.type(val)->is_valuetype(); 229 ciArrayKlass* array_klass = ciArrayKlass::make(vt->value_klass()); 230 const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr(); 231 ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype)); 232 adr = array_element_address(ary, idx, T_OBJECT, arytype->size(), control()); 233 val->as_ValueType()->store_flattened(this, ary, adr); 234 ideal.sync_kit(this); 235 } else { 236 if (TypePtr::NULL_PTR->higher_equal(val_t)) { 237 sync_kit(ideal); 238 Node* null_ctl = top(); 239 val = null_check_oop(val, &null_ctl); 240 if (null_ctl != top()) { 241 PreserveJVMState pjvms(this); 242 inc_sp(3); 243 set_control(null_ctl); 244 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 245 dec_sp(3); 246 } 247 ideal.sync_kit(this); 248 } 249 if (!ideal.ctrl()->is_top()) { 250 ideal.make_leaf_call(OptoRuntime::store_unknown_value_Type(), 251 CAST_FROM_FN_PTR(address, OptoRuntime::store_unknown_value), 252 "store_unknown_value", 253 val, ary, idx); 254 } 255 } 256 } ideal.end_if(); 257 sync_kit(ideal); 258 return; 259 } else { 260 if (!val->is_ValueType() && TypePtr::NULL_PTR->higher_equal(val_t)) { 261 gen_value_type_array_guard(ary, val, 3); 262 } 263 } 264 } 265 } 266 267 if (elemtype == TypeInt::BOOL) { 268 bt = T_BOOLEAN; 269 } else if (bt == T_OBJECT) { 270 elemtype = ary_t->elem()->make_oopptr(); 271 } 272 273 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt); 274 275 access_store_at(ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY); 276 } 277 278 279 //------------------------------array_addressing------------------------------- 280 // Pull array and index from the stack. Compute pointer-to-element. 281 Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) { 282 Node *idx = peek(0+vals); // Get from stack without popping 283 Node *ary = peek(1+vals); // in case of exception 284 285 // Null check the array base, with correct stack contents 286 ary = null_check(ary, T_ARRAY); 287 // Compile-time detect of null-exception? 288 if (stopped()) return top(); 289 290 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr(); 291 const TypeInt* sizetype = arytype->size(); 292 const Type* elemtype = arytype->elem(); 293 294 if (UseUniqueSubclasses && result2 != NULL) { 295 const Type* el = elemtype->make_ptr(); 296 if (el && el->isa_instptr()) { 297 const TypeInstPtr* toop = el->is_instptr(); 298 if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) { 299 // If we load from "AbstractClass[]" we must see "ConcreteSubClass". 300 const Type* subklass = Type::get_const_type(toop->klass()); 301 elemtype = subklass->join_speculative(el); 302 } 303 } 304 } 305 306 // Check for big class initializers with all constant offsets 307 // feeding into a known-size array. 308 const TypeInt* idxtype = _gvn.type(idx)->is_int(); 309 // See if the highest idx value is less than the lowest array bound, 310 // and if the idx value cannot be negative: 311 bool need_range_check = true; 312 if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) { 313 need_range_check = false; 314 if (C->log() != NULL) C->log()->elem("observe that='!need_range_check'"); 315 } 316 317 ciKlass * arytype_klass = arytype->klass(); 318 if ((arytype_klass != NULL) && (!arytype_klass->is_loaded())) { 319 // Only fails for some -Xcomp runs 320 // The class is unloaded. We have to run this bytecode in the interpreter. 321 uncommon_trap(Deoptimization::Reason_unloaded, 322 Deoptimization::Action_reinterpret, 323 arytype->klass(), "!loaded array"); 324 return top(); 325 } 326 327 // Do the range check 328 if (GenerateRangeChecks && need_range_check) { 329 Node* tst; 330 if (sizetype->_hi <= 0) { 331 // The greatest array bound is negative, so we can conclude that we're 332 // compiling unreachable code, but the unsigned compare trick used below 333 // only works with non-negative lengths. Instead, hack "tst" to be zero so 334 // the uncommon_trap path will always be taken. 335 tst = _gvn.intcon(0); 336 } else { 337 // Range is constant in array-oop, so we can use the original state of mem 338 Node* len = load_array_length(ary); 339 340 // Test length vs index (standard trick using unsigned compare) 341 Node* chk = _gvn.transform( new CmpUNode(idx, len) ); 342 BoolTest::mask btest = BoolTest::lt; 343 tst = _gvn.transform( new BoolNode(chk, btest) ); 344 } 345 RangeCheckNode* rc = new RangeCheckNode(control(), tst, PROB_MAX, COUNT_UNKNOWN); 346 _gvn.set_type(rc, rc->Value(&_gvn)); 347 if (!tst->is_Con()) { 348 record_for_igvn(rc); 349 } 350 set_control(_gvn.transform(new IfTrueNode(rc))); 351 // Branch to failure if out of bounds 352 { 353 PreserveJVMState pjvms(this); 354 set_control(_gvn.transform(new IfFalseNode(rc))); 355 if (C->allow_range_check_smearing()) { 356 // Do not use builtin_throw, since range checks are sometimes 357 // made more stringent by an optimistic transformation. 358 // This creates "tentative" range checks at this point, 359 // which are not guaranteed to throw exceptions. 360 // See IfNode::Ideal, is_range_check, adjust_check. 361 uncommon_trap(Deoptimization::Reason_range_check, 362 Deoptimization::Action_make_not_entrant, 363 NULL, "range_check"); 364 } else { 365 // If we have already recompiled with the range-check-widening 366 // heroic optimization turned off, then we must really be throwing 367 // range check exceptions. 368 builtin_throw(Deoptimization::Reason_range_check, idx); 369 } 370 } 371 } 372 // Check for always knowing you are throwing a range-check exception 373 if (stopped()) return top(); 374 375 // Make array address computation control dependent to prevent it 376 // from floating above the range check during loop optimizations. 377 Node* ptr = array_element_address(ary, idx, type, sizetype, control()); 378 379 if (result2 != NULL) *result2 = elemtype; 380 381 assert(ptr != top(), "top should go hand-in-hand with stopped"); 382 383 return ptr; 384 } 385 386 387 // returns IfNode 388 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt) { 389 Node *cmp = _gvn.transform(new CmpINode(a, b)); // two cases: shiftcount > 32 and shiftcount <= 32 390 Node *tst = _gvn.transform(new BoolNode(cmp, mask)); 391 IfNode *iff = create_and_map_if(control(), tst, prob, cnt); 392 return iff; 393 } 394 395 // return Region node 396 Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) { 397 Node *region = new RegionNode(3); // 2 results 398 record_for_igvn(region); 399 region->init_req(1, iffalse); 400 region->init_req(2, iftrue ); 401 _gvn.set_type(region, Type::CONTROL); 402 region = _gvn.transform(region); 403 set_control (region); 404 return region; 405 } 406 407 // sentinel value for the target bci to mark never taken branches 408 // (according to profiling) 409 static const int never_reached = INT_MAX; 410 411 //------------------------------helper for tableswitch------------------------- 412 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index, bool unc) { 413 // True branch, use existing map info 414 { PreserveJVMState pjvms(this); 415 Node *iftrue = _gvn.transform( new IfTrueNode (iff) ); 416 set_control( iftrue ); 417 if (unc) { 418 repush_if_args(); 419 uncommon_trap(Deoptimization::Reason_unstable_if, 420 Deoptimization::Action_reinterpret, 421 NULL, 422 "taken always"); 423 } else { 424 assert(dest_bci_if_true != never_reached, "inconsistent dest"); 425 profile_switch_case(prof_table_index); 426 merge_new_path(dest_bci_if_true); 427 } 428 } 429 430 // False branch 431 Node *iffalse = _gvn.transform( new IfFalseNode(iff) ); 432 set_control( iffalse ); 433 } 434 435 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index, bool unc) { 436 // True branch, use existing map info 437 { PreserveJVMState pjvms(this); 438 Node *iffalse = _gvn.transform( new IfFalseNode (iff) ); 439 set_control( iffalse ); 440 if (unc) { 441 repush_if_args(); 442 uncommon_trap(Deoptimization::Reason_unstable_if, 443 Deoptimization::Action_reinterpret, 444 NULL, 445 "taken never"); 446 } else { 447 assert(dest_bci_if_true != never_reached, "inconsistent dest"); 448 profile_switch_case(prof_table_index); 449 merge_new_path(dest_bci_if_true); 450 } 451 } 452 453 // False branch 454 Node *iftrue = _gvn.transform( new IfTrueNode(iff) ); 455 set_control( iftrue ); 456 } 457 458 void Parse::jump_if_always_fork(int dest_bci, int prof_table_index, bool unc) { 459 // False branch, use existing map and control() 460 if (unc) { 461 repush_if_args(); 462 uncommon_trap(Deoptimization::Reason_unstable_if, 463 Deoptimization::Action_reinterpret, 464 NULL, 465 "taken never"); 466 } else { 467 assert(dest_bci != never_reached, "inconsistent dest"); 468 profile_switch_case(prof_table_index); 469 merge_new_path(dest_bci); 470 } 471 } 472 473 474 extern "C" { 475 static int jint_cmp(const void *i, const void *j) { 476 int a = *(jint *)i; 477 int b = *(jint *)j; 478 return a > b ? 1 : a < b ? -1 : 0; 479 } 480 } 481 482 483 // Default value for methodData switch indexing. Must be a negative value to avoid 484 // conflict with any legal switch index. 485 #define NullTableIndex -1 486 487 class SwitchRange : public StackObj { 488 // a range of integers coupled with a bci destination 489 jint _lo; // inclusive lower limit 490 jint _hi; // inclusive upper limit 491 int _dest; 492 int _table_index; // index into method data table 493 float _cnt; // how many times this range was hit according to profiling 494 495 public: 496 jint lo() const { return _lo; } 497 jint hi() const { return _hi; } 498 int dest() const { return _dest; } 499 int table_index() const { return _table_index; } 500 bool is_singleton() const { return _lo == _hi; } 501 float cnt() const { return _cnt; } 502 503 void setRange(jint lo, jint hi, int dest, int table_index, float cnt) { 504 assert(lo <= hi, "must be a non-empty range"); 505 _lo = lo, _hi = hi; _dest = dest; _table_index = table_index; _cnt = cnt; 506 assert(_cnt >= 0, ""); 507 } 508 bool adjoinRange(jint lo, jint hi, int dest, int table_index, float cnt, bool trim_ranges) { 509 assert(lo <= hi, "must be a non-empty range"); 510 if (lo == _hi+1 && table_index == _table_index) { 511 // see merge_ranges() comment below 512 if (trim_ranges) { 513 if (cnt == 0) { 514 if (_cnt != 0) { 515 return false; 516 } 517 if (dest != _dest) { 518 _dest = never_reached; 519 } 520 } else { 521 if (_cnt == 0) { 522 return false; 523 } 524 if (dest != _dest) { 525 return false; 526 } 527 } 528 } else { 529 if (dest != _dest) { 530 return false; 531 } 532 } 533 _hi = hi; 534 _cnt += cnt; 535 return true; 536 } 537 return false; 538 } 539 540 void set (jint value, int dest, int table_index, float cnt) { 541 setRange(value, value, dest, table_index, cnt); 542 } 543 bool adjoin(jint value, int dest, int table_index, float cnt, bool trim_ranges) { 544 return adjoinRange(value, value, dest, table_index, cnt, trim_ranges); 545 } 546 bool adjoin(SwitchRange& other) { 547 return adjoinRange(other._lo, other._hi, other._dest, other._table_index, other._cnt, false); 548 } 549 550 void print() { 551 if (is_singleton()) 552 tty->print(" {%d}=>%d (cnt=%f)", lo(), dest(), cnt()); 553 else if (lo() == min_jint) 554 tty->print(" {..%d}=>%d (cnt=%f)", hi(), dest(), cnt()); 555 else if (hi() == max_jint) 556 tty->print(" {%d..}=>%d (cnt=%f)", lo(), dest(), cnt()); 557 else 558 tty->print(" {%d..%d}=>%d (cnt=%f)", lo(), hi(), dest(), cnt()); 559 } 560 }; 561 562 // We try to minimize the number of ranges and the size of the taken 563 // ones using profiling data. When ranges are created, 564 // SwitchRange::adjoinRange() only allows 2 adjoining ranges to merge 565 // if both were never hit or both were hit to build longer unreached 566 // ranges. Here, we now merge adjoining ranges with the same 567 // destination and finally set destination of unreached ranges to the 568 // special value never_reached because it can help minimize the number 569 // of tests that are necessary. 570 // 571 // For instance: 572 // [0, 1] to target1 sometimes taken 573 // [1, 2] to target1 never taken 574 // [2, 3] to target2 never taken 575 // would lead to: 576 // [0, 1] to target1 sometimes taken 577 // [1, 3] never taken 578 // 579 // (first 2 ranges to target1 are not merged) 580 static void merge_ranges(SwitchRange* ranges, int& rp) { 581 if (rp == 0) { 582 return; 583 } 584 int shift = 0; 585 for (int j = 0; j < rp; j++) { 586 SwitchRange& r1 = ranges[j-shift]; 587 SwitchRange& r2 = ranges[j+1]; 588 if (r1.adjoin(r2)) { 589 shift++; 590 } else if (shift > 0) { 591 ranges[j+1-shift] = r2; 592 } 593 } 594 rp -= shift; 595 for (int j = 0; j <= rp; j++) { 596 SwitchRange& r = ranges[j]; 597 if (r.cnt() == 0 && r.dest() != never_reached) { 598 r.setRange(r.lo(), r.hi(), never_reached, r.table_index(), r.cnt()); 599 } 600 } 601 } 602 603 //-------------------------------do_tableswitch-------------------------------- 604 void Parse::do_tableswitch() { 605 Node* lookup = pop(); 606 // Get information about tableswitch 607 int default_dest = iter().get_dest_table(0); 608 int lo_index = iter().get_int_table(1); 609 int hi_index = iter().get_int_table(2); 610 int len = hi_index - lo_index + 1; 611 612 if (len < 1) { 613 // If this is a backward branch, add safepoint 614 maybe_add_safepoint(default_dest); 615 merge(default_dest); 616 return; 617 } 618 619 ciMethodData* methodData = method()->method_data(); 620 ciMultiBranchData* profile = NULL; 621 if (methodData->is_mature() && UseSwitchProfiling) { 622 ciProfileData* data = methodData->bci_to_data(bci()); 623 if (data != NULL && data->is_MultiBranchData()) { 624 profile = (ciMultiBranchData*)data; 625 } 626 } 627 bool trim_ranges = !method_data_update() && !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if); 628 629 // generate decision tree, using trichotomy when possible 630 int rnum = len+2; 631 bool makes_backward_branch = false; 632 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); 633 int rp = -1; 634 if (lo_index != min_jint) { 635 uint cnt = 1; 636 if (profile != NULL) { 637 cnt = profile->default_count() / (hi_index != max_jint ? 2 : 1); 638 } 639 ranges[++rp].setRange(min_jint, lo_index-1, default_dest, NullTableIndex, cnt); 640 } 641 for (int j = 0; j < len; j++) { 642 jint match_int = lo_index+j; 643 int dest = iter().get_dest_table(j+3); 644 makes_backward_branch |= (dest <= bci()); 645 int table_index = method_data_update() ? j : NullTableIndex; 646 uint cnt = 1; 647 if (profile != NULL) { 648 cnt = profile->count_at(j); 649 } 650 if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index, cnt, trim_ranges)) { 651 ranges[++rp].set(match_int, dest, table_index, cnt); 652 } 653 } 654 jint highest = lo_index+(len-1); 655 assert(ranges[rp].hi() == highest, ""); 656 if (highest != max_jint) { 657 uint cnt = 1; 658 if (profile != NULL) { 659 cnt = profile->default_count() / (lo_index != min_jint ? 2 : 1); 660 } 661 if (!ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex, cnt, trim_ranges)) { 662 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex, cnt); 663 } 664 } 665 assert(rp < len+2, "not too many ranges"); 666 667 if (trim_ranges) { 668 merge_ranges(ranges, rp); 669 } 670 671 // Safepoint in case if backward branch observed 672 if( makes_backward_branch && UseLoopSafepoints ) 673 add_safepoint(); 674 675 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); 676 } 677 678 679 //------------------------------do_lookupswitch-------------------------------- 680 void Parse::do_lookupswitch() { 681 Node *lookup = pop(); // lookup value 682 // Get information about lookupswitch 683 int default_dest = iter().get_dest_table(0); 684 int len = iter().get_int_table(1); 685 686 if (len < 1) { // If this is a backward branch, add safepoint 687 maybe_add_safepoint(default_dest); 688 merge(default_dest); 689 return; 690 } 691 692 ciMethodData* methodData = method()->method_data(); 693 ciMultiBranchData* profile = NULL; 694 if (methodData->is_mature() && UseSwitchProfiling) { 695 ciProfileData* data = methodData->bci_to_data(bci()); 696 if (data != NULL && data->is_MultiBranchData()) { 697 profile = (ciMultiBranchData*)data; 698 } 699 } 700 bool trim_ranges = !method_data_update() && !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if); 701 702 // generate decision tree, using trichotomy when possible 703 jint* table = NEW_RESOURCE_ARRAY(jint, len*3); 704 { 705 for (int j = 0; j < len; j++) { 706 table[3*j+0] = iter().get_int_table(2+2*j); 707 table[3*j+1] = iter().get_dest_table(2+2*j+1); 708 table[3*j+2] = profile == NULL ? 1 : profile->count_at(j); 709 } 710 qsort(table, len, 3*sizeof(table[0]), jint_cmp); 711 } 712 713 float defaults = 0; 714 jint prev = min_jint; 715 for (int j = 0; j < len; j++) { 716 jint match_int = table[3*j+0]; 717 if (match_int != prev) { 718 defaults += (float)match_int - prev; 719 } 720 prev = match_int+1; 721 } 722 if (prev-1 != max_jint) { 723 defaults += (float)max_jint - prev + 1; 724 } 725 float default_cnt = 1; 726 if (profile != NULL) { 727 default_cnt = profile->default_count()/defaults; 728 } 729 730 int rnum = len*2+1; 731 bool makes_backward_branch = false; 732 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); 733 int rp = -1; 734 for (int j = 0; j < len; j++) { 735 jint match_int = table[3*j+0]; 736 int dest = table[3*j+1]; 737 int cnt = table[3*j+2]; 738 int next_lo = rp < 0 ? min_jint : ranges[rp].hi()+1; 739 int table_index = method_data_update() ? j : NullTableIndex; 740 makes_backward_branch |= (dest <= bci()); 741 float c = default_cnt * ((float)match_int - next_lo); 742 if (match_int != next_lo && (rp < 0 || !ranges[rp].adjoinRange(next_lo, match_int-1, default_dest, NullTableIndex, c, trim_ranges))) { 743 assert(default_dest != never_reached, "sentinel value for dead destinations"); 744 ranges[++rp].setRange(next_lo, match_int-1, default_dest, NullTableIndex, c); 745 } 746 if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index, cnt, trim_ranges)) { 747 assert(dest != never_reached, "sentinel value for dead destinations"); 748 ranges[++rp].set(match_int, dest, table_index, cnt); 749 } 750 } 751 jint highest = table[3*(len-1)]; 752 assert(ranges[rp].hi() == highest, ""); 753 if (highest != max_jint && 754 !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex, default_cnt * ((float)max_jint - highest), trim_ranges)) { 755 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex, default_cnt * ((float)max_jint - highest)); 756 } 757 assert(rp < rnum, "not too many ranges"); 758 759 if (trim_ranges) { 760 merge_ranges(ranges, rp); 761 } 762 763 // Safepoint in case backward branch observed 764 if (makes_backward_branch && UseLoopSafepoints) 765 add_safepoint(); 766 767 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); 768 } 769 770 static float if_prob(float taken_cnt, float total_cnt) { 771 assert(taken_cnt <= total_cnt, ""); 772 if (total_cnt == 0) { 773 return PROB_FAIR; 774 } 775 float p = taken_cnt / total_cnt; 776 return MIN2(MAX2(p, PROB_MIN), PROB_MAX); 777 } 778 779 static float if_cnt(float cnt) { 780 if (cnt == 0) { 781 return COUNT_UNKNOWN; 782 } 783 return cnt; 784 } 785 786 static float sum_of_cnts(SwitchRange *lo, SwitchRange *hi) { 787 float total_cnt = 0; 788 for (SwitchRange* sr = lo; sr <= hi; sr++) { 789 total_cnt += sr->cnt(); 790 } 791 return total_cnt; 792 } 793 794 class SwitchRanges : public ResourceObj { 795 public: 796 SwitchRange* _lo; 797 SwitchRange* _hi; 798 SwitchRange* _mid; 799 float _cost; 800 801 enum { 802 Start, 803 LeftDone, 804 RightDone, 805 Done 806 } _state; 807 808 SwitchRanges(SwitchRange *lo, SwitchRange *hi) 809 : _lo(lo), _hi(hi), _mid(NULL), 810 _cost(0), _state(Start) { 811 } 812 813 SwitchRanges() 814 : _lo(NULL), _hi(NULL), _mid(NULL), 815 _cost(0), _state(Start) {} 816 }; 817 818 // Estimate cost of performing a binary search on lo..hi 819 static float compute_tree_cost(SwitchRange *lo, SwitchRange *hi, float total_cnt) { 820 GrowableArray<SwitchRanges> tree; 821 SwitchRanges root(lo, hi); 822 tree.push(root); 823 824 float cost = 0; 825 do { 826 SwitchRanges& r = *tree.adr_at(tree.length()-1); 827 if (r._hi != r._lo) { 828 if (r._mid == NULL) { 829 float r_cnt = sum_of_cnts(r._lo, r._hi); 830 831 if (r_cnt == 0) { 832 tree.pop(); 833 cost = 0; 834 continue; 835 } 836 837 SwitchRange* mid = NULL; 838 mid = r._lo; 839 for (float cnt = 0; ; ) { 840 assert(mid <= r._hi, "out of bounds"); 841 cnt += mid->cnt(); 842 if (cnt > r_cnt / 2) { 843 break; 844 } 845 mid++; 846 } 847 assert(mid <= r._hi, "out of bounds"); 848 r._mid = mid; 849 r._cost = r_cnt / total_cnt; 850 } 851 r._cost += cost; 852 if (r._state < SwitchRanges::LeftDone && r._mid > r._lo) { 853 cost = 0; 854 r._state = SwitchRanges::LeftDone; 855 tree.push(SwitchRanges(r._lo, r._mid-1)); 856 } else if (r._state < SwitchRanges::RightDone) { 857 cost = 0; 858 r._state = SwitchRanges::RightDone; 859 tree.push(SwitchRanges(r._mid == r._lo ? r._mid+1 : r._mid, r._hi)); 860 } else { 861 tree.pop(); 862 cost = r._cost; 863 } 864 } else { 865 tree.pop(); 866 cost = r._cost; 867 } 868 } while (tree.length() > 0); 869 870 871 return cost; 872 } 873 874 // It sometimes pays off to test most common ranges before the binary search 875 void Parse::linear_search_switch_ranges(Node* key_val, SwitchRange*& lo, SwitchRange*& hi) { 876 uint nr = hi - lo + 1; 877 float total_cnt = sum_of_cnts(lo, hi); 878 879 float min = compute_tree_cost(lo, hi, total_cnt); 880 float extra = 1; 881 float sub = 0; 882 883 SwitchRange* array1 = lo; 884 SwitchRange* array2 = NEW_RESOURCE_ARRAY(SwitchRange, nr); 885 886 SwitchRange* ranges = NULL; 887 888 while (nr >= 2) { 889 assert(lo == array1 || lo == array2, "one the 2 already allocated arrays"); 890 ranges = (lo == array1) ? array2 : array1; 891 892 // Find highest frequency range 893 SwitchRange* candidate = lo; 894 for (SwitchRange* sr = lo+1; sr <= hi; sr++) { 895 if (sr->cnt() > candidate->cnt()) { 896 candidate = sr; 897 } 898 } 899 SwitchRange most_freq = *candidate; 900 if (most_freq.cnt() == 0) { 901 break; 902 } 903 904 // Copy remaining ranges into another array 905 int shift = 0; 906 for (uint i = 0; i < nr; i++) { 907 SwitchRange* sr = &lo[i]; 908 if (sr != candidate) { 909 ranges[i-shift] = *sr; 910 } else { 911 shift++; 912 if (i > 0 && i < nr-1) { 913 SwitchRange prev = lo[i-1]; 914 prev.setRange(prev.lo(), sr->hi(), prev.dest(), prev.table_index(), prev.cnt()); 915 if (prev.adjoin(lo[i+1])) { 916 shift++; 917 i++; 918 } 919 ranges[i-shift] = prev; 920 } 921 } 922 } 923 nr -= shift; 924 925 // Evaluate cost of testing the most common range and performing a 926 // binary search on the other ranges 927 float cost = extra + compute_tree_cost(&ranges[0], &ranges[nr-1], total_cnt); 928 if (cost >= min) { 929 break; 930 } 931 // swap arrays 932 lo = &ranges[0]; 933 hi = &ranges[nr-1]; 934 935 // It pays off: emit the test for the most common range 936 assert(most_freq.cnt() > 0, "must be taken"); 937 Node* val = _gvn.transform(new SubINode(key_val, _gvn.intcon(most_freq.lo()))); 938 Node* cmp = _gvn.transform(new CmpUNode(val, _gvn.intcon(most_freq.hi() - most_freq.lo()))); 939 Node* tst = _gvn.transform(new BoolNode(cmp, BoolTest::le)); 940 IfNode* iff = create_and_map_if(control(), tst, if_prob(most_freq.cnt(), total_cnt), if_cnt(most_freq.cnt())); 941 jump_if_true_fork(iff, most_freq.dest(), most_freq.table_index(), false); 942 943 sub += most_freq.cnt() / total_cnt; 944 extra += 1 - sub; 945 min = cost; 946 } 947 } 948 949 //----------------------------create_jump_tables------------------------------- 950 bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) { 951 // Are jumptables enabled 952 if (!UseJumpTables) return false; 953 954 // Are jumptables supported 955 if (!Matcher::has_match_rule(Op_Jump)) return false; 956 957 // Don't make jump table if profiling 958 if (method_data_update()) return false; 959 960 bool trim_ranges = !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if); 961 962 // Decide if a guard is needed to lop off big ranges at either (or 963 // both) end(s) of the input set. We'll call this the default target 964 // even though we can't be sure that it is the true "default". 965 966 bool needs_guard = false; 967 int default_dest; 968 int64_t total_outlier_size = 0; 969 int64_t hi_size = ((int64_t)hi->hi()) - ((int64_t)hi->lo()) + 1; 970 int64_t lo_size = ((int64_t)lo->hi()) - ((int64_t)lo->lo()) + 1; 971 972 if (lo->dest() == hi->dest()) { 973 total_outlier_size = hi_size + lo_size; 974 default_dest = lo->dest(); 975 } else if (lo_size > hi_size) { 976 total_outlier_size = lo_size; 977 default_dest = lo->dest(); 978 } else { 979 total_outlier_size = hi_size; 980 default_dest = hi->dest(); 981 } 982 983 float total = sum_of_cnts(lo, hi); 984 float cost = compute_tree_cost(lo, hi, total); 985 986 // If a guard test will eliminate very sparse end ranges, then 987 // it is worth the cost of an extra jump. 988 float trimmed_cnt = 0; 989 if (total_outlier_size > (MaxJumpTableSparseness * 4)) { 990 needs_guard = true; 991 if (default_dest == lo->dest()) { 992 trimmed_cnt += lo->cnt(); 993 lo++; 994 } 995 if (default_dest == hi->dest()) { 996 trimmed_cnt += hi->cnt(); 997 hi--; 998 } 999 } 1000 1001 // Find the total number of cases and ranges 1002 int64_t num_cases = ((int64_t)hi->hi()) - ((int64_t)lo->lo()) + 1; 1003 int num_range = hi - lo + 1; 1004 1005 // Don't create table if: too large, too small, or too sparse. 1006 if (num_cases > MaxJumpTableSize) 1007 return false; 1008 if (UseSwitchProfiling) { 1009 // MinJumpTableSize is set so with a well balanced binary tree, 1010 // when the number of ranges is MinJumpTableSize, it's cheaper to 1011 // go through a JumpNode that a tree of IfNodes. Average cost of a 1012 // tree of IfNodes with MinJumpTableSize is 1013 // log2f(MinJumpTableSize) comparisons. So if the cost computed 1014 // from profile data is less than log2f(MinJumpTableSize) then 1015 // going with the binary search is cheaper. 1016 if (cost < log2f(MinJumpTableSize)) { 1017 return false; 1018 } 1019 } else { 1020 if (num_cases < MinJumpTableSize) 1021 return false; 1022 } 1023 if (num_cases > (MaxJumpTableSparseness * num_range)) 1024 return false; 1025 1026 // Normalize table lookups to zero 1027 int lowval = lo->lo(); 1028 key_val = _gvn.transform( new SubINode(key_val, _gvn.intcon(lowval)) ); 1029 1030 // Generate a guard to protect against input keyvals that aren't 1031 // in the switch domain. 1032 if (needs_guard) { 1033 Node* size = _gvn.intcon(num_cases); 1034 Node* cmp = _gvn.transform(new CmpUNode(key_val, size)); 1035 Node* tst = _gvn.transform(new BoolNode(cmp, BoolTest::ge)); 1036 IfNode* iff = create_and_map_if(control(), tst, if_prob(trimmed_cnt, total), if_cnt(trimmed_cnt)); 1037 jump_if_true_fork(iff, default_dest, NullTableIndex, trim_ranges && trimmed_cnt == 0); 1038 1039 total -= trimmed_cnt; 1040 } 1041 1042 // Create an ideal node JumpTable that has projections 1043 // of all possible ranges for a switch statement 1044 // The key_val input must be converted to a pointer offset and scaled. 1045 // Compare Parse::array_addressing above. 1046 1047 // Clean the 32-bit int into a real 64-bit offset. 1048 // Otherwise, the jint value 0 might turn into an offset of 0x0800000000. 1049 const TypeInt* ikeytype = TypeInt::make(0, num_cases, Type::WidenMin); 1050 // Make I2L conversion control dependent to prevent it from 1051 // floating above the range check during loop optimizations. 1052 key_val = C->conv_I2X_index(&_gvn, key_val, ikeytype, control()); 1053 1054 // Shift the value by wordsize so we have an index into the table, rather 1055 // than a switch value 1056 Node *shiftWord = _gvn.MakeConX(wordSize); 1057 key_val = _gvn.transform( new MulXNode( key_val, shiftWord)); 1058 1059 // Create the JumpNode 1060 Arena* arena = C->comp_arena(); 1061 float* probs = (float*)arena->Amalloc(sizeof(float)*num_cases); 1062 int i = 0; 1063 if (total == 0) { 1064 for (SwitchRange* r = lo; r <= hi; r++) { 1065 for (int64_t j = r->lo(); j <= r->hi(); j++, i++) { 1066 probs[i] = 1.0F / num_cases; 1067 } 1068 } 1069 } else { 1070 for (SwitchRange* r = lo; r <= hi; r++) { 1071 float prob = r->cnt()/total; 1072 for (int64_t j = r->lo(); j <= r->hi(); j++, i++) { 1073 probs[i] = prob / (r->hi() - r->lo() + 1); 1074 } 1075 } 1076 } 1077 1078 ciMethodData* methodData = method()->method_data(); 1079 ciMultiBranchData* profile = NULL; 1080 if (methodData->is_mature()) { 1081 ciProfileData* data = methodData->bci_to_data(bci()); 1082 if (data != NULL && data->is_MultiBranchData()) { 1083 profile = (ciMultiBranchData*)data; 1084 } 1085 } 1086 1087 Node* jtn = _gvn.transform(new JumpNode(control(), key_val, num_cases, probs, profile == NULL ? COUNT_UNKNOWN : total)); 1088 1089 // These are the switch destinations hanging off the jumpnode 1090 i = 0; 1091 for (SwitchRange* r = lo; r <= hi; r++) { 1092 for (int64_t j = r->lo(); j <= r->hi(); j++, i++) { 1093 Node* input = _gvn.transform(new JumpProjNode(jtn, i, r->dest(), (int)(j - lowval))); 1094 { 1095 PreserveJVMState pjvms(this); 1096 set_control(input); 1097 jump_if_always_fork(r->dest(), r->table_index(), trim_ranges && r->cnt() == 0); 1098 } 1099 } 1100 } 1101 assert(i == num_cases, "miscount of cases"); 1102 stop_and_kill_map(); // no more uses for this JVMS 1103 return true; 1104 } 1105 1106 //----------------------------jump_switch_ranges------------------------------- 1107 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) { 1108 Block* switch_block = block(); 1109 bool trim_ranges = !method_data_update() && !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if); 1110 1111 if (switch_depth == 0) { 1112 // Do special processing for the top-level call. 1113 assert(lo->lo() == min_jint, "initial range must exhaust Type::INT"); 1114 assert(hi->hi() == max_jint, "initial range must exhaust Type::INT"); 1115 1116 // Decrement pred-numbers for the unique set of nodes. 1117 #ifdef ASSERT 1118 if (!trim_ranges) { 1119 // Ensure that the block's successors are a (duplicate-free) set. 1120 int successors_counted = 0; // block occurrences in [hi..lo] 1121 int unique_successors = switch_block->num_successors(); 1122 for (int i = 0; i < unique_successors; i++) { 1123 Block* target = switch_block->successor_at(i); 1124 1125 // Check that the set of successors is the same in both places. 1126 int successors_found = 0; 1127 for (SwitchRange* p = lo; p <= hi; p++) { 1128 if (p->dest() == target->start()) successors_found++; 1129 } 1130 assert(successors_found > 0, "successor must be known"); 1131 successors_counted += successors_found; 1132 } 1133 assert(successors_counted == (hi-lo)+1, "no unexpected successors"); 1134 } 1135 #endif 1136 1137 // Maybe prune the inputs, based on the type of key_val. 1138 jint min_val = min_jint; 1139 jint max_val = max_jint; 1140 const TypeInt* ti = key_val->bottom_type()->isa_int(); 1141 if (ti != NULL) { 1142 min_val = ti->_lo; 1143 max_val = ti->_hi; 1144 assert(min_val <= max_val, "invalid int type"); 1145 } 1146 while (lo->hi() < min_val) { 1147 lo++; 1148 } 1149 if (lo->lo() < min_val) { 1150 lo->setRange(min_val, lo->hi(), lo->dest(), lo->table_index(), lo->cnt()); 1151 } 1152 while (hi->lo() > max_val) { 1153 hi--; 1154 } 1155 if (hi->hi() > max_val) { 1156 hi->setRange(hi->lo(), max_val, hi->dest(), hi->table_index(), hi->cnt()); 1157 } 1158 1159 linear_search_switch_ranges(key_val, lo, hi); 1160 } 1161 1162 #ifndef PRODUCT 1163 if (switch_depth == 0) { 1164 _max_switch_depth = 0; 1165 _est_switch_depth = log2_intptr((hi-lo+1)-1)+1; 1166 } 1167 #endif 1168 1169 assert(lo <= hi, "must be a non-empty set of ranges"); 1170 if (lo == hi) { 1171 jump_if_always_fork(lo->dest(), lo->table_index(), trim_ranges && lo->cnt() == 0); 1172 } else { 1173 assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges"); 1174 assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges"); 1175 1176 if (create_jump_tables(key_val, lo, hi)) return; 1177 1178 SwitchRange* mid = NULL; 1179 float total_cnt = sum_of_cnts(lo, hi); 1180 1181 int nr = hi - lo + 1; 1182 if (UseSwitchProfiling) { 1183 // Don't keep the binary search tree balanced: pick up mid point 1184 // that split frequencies in half. 1185 float cnt = 0; 1186 for (SwitchRange* sr = lo; sr <= hi; sr++) { 1187 cnt += sr->cnt(); 1188 if (cnt >= total_cnt / 2) { 1189 mid = sr; 1190 break; 1191 } 1192 } 1193 } else { 1194 mid = lo + nr/2; 1195 1196 // if there is an easy choice, pivot at a singleton: 1197 if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton()) mid--; 1198 1199 assert(lo < mid && mid <= hi, "good pivot choice"); 1200 assert(nr != 2 || mid == hi, "should pick higher of 2"); 1201 assert(nr != 3 || mid == hi-1, "should pick middle of 3"); 1202 } 1203 1204 1205 Node *test_val = _gvn.intcon(mid == lo ? mid->hi() : mid->lo()); 1206 1207 if (mid->is_singleton()) { 1208 IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne, 1-if_prob(mid->cnt(), total_cnt), if_cnt(mid->cnt())); 1209 jump_if_false_fork(iff_ne, mid->dest(), mid->table_index(), trim_ranges && mid->cnt() == 0); 1210 1211 // Special Case: If there are exactly three ranges, and the high 1212 // and low range each go to the same place, omit the "gt" test, 1213 // since it will not discriminate anything. 1214 bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest() && mid == hi-1) || mid == lo; 1215 1216 // if there is a higher range, test for it and process it: 1217 if (mid < hi && !eq_test_only) { 1218 // two comparisons of same values--should enable 1 test for 2 branches 1219 // Use BoolTest::le instead of BoolTest::gt 1220 float cnt = sum_of_cnts(lo, mid-1); 1221 IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le, if_prob(cnt, total_cnt), if_cnt(cnt)); 1222 Node *iftrue = _gvn.transform( new IfTrueNode(iff_le) ); 1223 Node *iffalse = _gvn.transform( new IfFalseNode(iff_le) ); 1224 { PreserveJVMState pjvms(this); 1225 set_control(iffalse); 1226 jump_switch_ranges(key_val, mid+1, hi, switch_depth+1); 1227 } 1228 set_control(iftrue); 1229 } 1230 1231 } else { 1232 // mid is a range, not a singleton, so treat mid..hi as a unit 1233 float cnt = sum_of_cnts(mid == lo ? mid+1 : mid, hi); 1234 IfNode *iff_ge = jump_if_fork_int(key_val, test_val, mid == lo ? BoolTest::gt : BoolTest::ge, if_prob(cnt, total_cnt), if_cnt(cnt)); 1235 1236 // if there is a higher range, test for it and process it: 1237 if (mid == hi) { 1238 jump_if_true_fork(iff_ge, mid->dest(), mid->table_index(), trim_ranges && cnt == 0); 1239 } else { 1240 Node *iftrue = _gvn.transform( new IfTrueNode(iff_ge) ); 1241 Node *iffalse = _gvn.transform( new IfFalseNode(iff_ge) ); 1242 { PreserveJVMState pjvms(this); 1243 set_control(iftrue); 1244 jump_switch_ranges(key_val, mid == lo ? mid+1 : mid, hi, switch_depth+1); 1245 } 1246 set_control(iffalse); 1247 } 1248 } 1249 1250 // in any case, process the lower range 1251 if (mid == lo) { 1252 if (mid->is_singleton()) { 1253 jump_switch_ranges(key_val, lo+1, hi, switch_depth+1); 1254 } else { 1255 jump_if_always_fork(lo->dest(), lo->table_index(), trim_ranges && lo->cnt() == 0); 1256 } 1257 } else { 1258 jump_switch_ranges(key_val, lo, mid-1, switch_depth+1); 1259 } 1260 } 1261 1262 // Decrease pred_count for each successor after all is done. 1263 if (switch_depth == 0) { 1264 int unique_successors = switch_block->num_successors(); 1265 for (int i = 0; i < unique_successors; i++) { 1266 Block* target = switch_block->successor_at(i); 1267 // Throw away the pre-allocated path for each unique successor. 1268 target->next_path_num(); 1269 } 1270 } 1271 1272 #ifndef PRODUCT 1273 _max_switch_depth = MAX2(switch_depth, _max_switch_depth); 1274 if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) { 1275 SwitchRange* r; 1276 int nsing = 0; 1277 for( r = lo; r <= hi; r++ ) { 1278 if( r->is_singleton() ) nsing++; 1279 } 1280 tty->print(">>> "); 1281 _method->print_short_name(); 1282 tty->print_cr(" switch decision tree"); 1283 tty->print_cr(" %d ranges (%d singletons), max_depth=%d, est_depth=%d", 1284 (int) (hi-lo+1), nsing, _max_switch_depth, _est_switch_depth); 1285 if (_max_switch_depth > _est_switch_depth) { 1286 tty->print_cr("******** BAD SWITCH DEPTH ********"); 1287 } 1288 tty->print(" "); 1289 for( r = lo; r <= hi; r++ ) { 1290 r->print(); 1291 } 1292 tty->cr(); 1293 } 1294 #endif 1295 } 1296 1297 void Parse::modf() { 1298 Node *f2 = pop(); 1299 Node *f1 = pop(); 1300 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(), 1301 CAST_FROM_FN_PTR(address, SharedRuntime::frem), 1302 "frem", NULL, //no memory effects 1303 f1, f2); 1304 Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 1305 1306 push(res); 1307 } 1308 1309 void Parse::modd() { 1310 Node *d2 = pop_pair(); 1311 Node *d1 = pop_pair(); 1312 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), 1313 CAST_FROM_FN_PTR(address, SharedRuntime::drem), 1314 "drem", NULL, //no memory effects 1315 d1, top(), d2, top()); 1316 Node* res_d = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 1317 1318 #ifdef ASSERT 1319 Node* res_top = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 1)); 1320 assert(res_top == top(), "second value must be top"); 1321 #endif 1322 1323 push_pair(res_d); 1324 } 1325 1326 void Parse::l2f() { 1327 Node* f2 = pop(); 1328 Node* f1 = pop(); 1329 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(), 1330 CAST_FROM_FN_PTR(address, SharedRuntime::l2f), 1331 "l2f", NULL, //no memory effects 1332 f1, f2); 1333 Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 1334 1335 push(res); 1336 } 1337 1338 void Parse::do_irem() { 1339 // Must keep both values on the expression-stack during null-check 1340 zero_check_int(peek()); 1341 // Compile-time detect of null-exception? 1342 if (stopped()) return; 1343 1344 Node* b = pop(); 1345 Node* a = pop(); 1346 1347 const Type *t = _gvn.type(b); 1348 if (t != Type::TOP) { 1349 const TypeInt *ti = t->is_int(); 1350 if (ti->is_con()) { 1351 int divisor = ti->get_con(); 1352 // check for positive power of 2 1353 if (divisor > 0 && 1354 (divisor & ~(divisor-1)) == divisor) { 1355 // yes ! 1356 Node *mask = _gvn.intcon((divisor - 1)); 1357 // Sigh, must handle negative dividends 1358 Node *zero = _gvn.intcon(0); 1359 IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt, PROB_FAIR, COUNT_UNKNOWN); 1360 Node *iff = _gvn.transform( new IfFalseNode(ifff) ); 1361 Node *ift = _gvn.transform( new IfTrueNode (ifff) ); 1362 Node *reg = jump_if_join(ift, iff); 1363 Node *phi = PhiNode::make(reg, NULL, TypeInt::INT); 1364 // Negative path; negate/and/negate 1365 Node *neg = _gvn.transform( new SubINode(zero, a) ); 1366 Node *andn= _gvn.transform( new AndINode(neg, mask) ); 1367 Node *negn= _gvn.transform( new SubINode(zero, andn) ); 1368 phi->init_req(1, negn); 1369 // Fast positive case 1370 Node *andx = _gvn.transform( new AndINode(a, mask) ); 1371 phi->init_req(2, andx); 1372 // Push the merge 1373 push( _gvn.transform(phi) ); 1374 return; 1375 } 1376 } 1377 } 1378 // Default case 1379 push( _gvn.transform( new ModINode(control(),a,b) ) ); 1380 } 1381 1382 // Handle jsr and jsr_w bytecode 1383 void Parse::do_jsr() { 1384 assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode"); 1385 1386 // Store information about current state, tagged with new _jsr_bci 1387 int return_bci = iter().next_bci(); 1388 int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest(); 1389 1390 // Update method data 1391 profile_taken_branch(jsr_bci); 1392 1393 // The way we do things now, there is only one successor block 1394 // for the jsr, because the target code is cloned by ciTypeFlow. 1395 Block* target = successor_for_bci(jsr_bci); 1396 1397 // What got pushed? 1398 const Type* ret_addr = target->peek(); 1399 assert(ret_addr->singleton(), "must be a constant (cloned jsr body)"); 1400 1401 // Effect on jsr on stack 1402 push(_gvn.makecon(ret_addr)); 1403 1404 // Flow to the jsr. 1405 merge(jsr_bci); 1406 } 1407 1408 // Handle ret bytecode 1409 void Parse::do_ret() { 1410 // Find to whom we return. 1411 assert(block()->num_successors() == 1, "a ret can only go one place now"); 1412 Block* target = block()->successor_at(0); 1413 assert(!target->is_ready(), "our arrival must be expected"); 1414 profile_ret(target->flow()->start()); 1415 int pnum = target->next_path_num(); 1416 merge_common(target, pnum); 1417 } 1418 1419 static bool has_injected_profile(BoolTest::mask btest, Node* test, int& taken, int& not_taken) { 1420 if (btest != BoolTest::eq && btest != BoolTest::ne) { 1421 // Only ::eq and ::ne are supported for profile injection. 1422 return false; 1423 } 1424 if (test->is_Cmp() && 1425 test->in(1)->Opcode() == Op_ProfileBoolean) { 1426 ProfileBooleanNode* profile = (ProfileBooleanNode*)test->in(1); 1427 int false_cnt = profile->false_count(); 1428 int true_cnt = profile->true_count(); 1429 1430 // Counts matching depends on the actual test operation (::eq or ::ne). 1431 // No need to scale the counts because profile injection was designed 1432 // to feed exact counts into VM. 1433 taken = (btest == BoolTest::eq) ? false_cnt : true_cnt; 1434 not_taken = (btest == BoolTest::eq) ? true_cnt : false_cnt; 1435 1436 profile->consume(); 1437 return true; 1438 } 1439 return false; 1440 } 1441 //--------------------------dynamic_branch_prediction-------------------------- 1442 // Try to gather dynamic branch prediction behavior. Return a probability 1443 // of the branch being taken and set the "cnt" field. Returns a -1.0 1444 // if we need to use static prediction for some reason. 1445 float Parse::dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test) { 1446 ResourceMark rm; 1447 1448 cnt = COUNT_UNKNOWN; 1449 1450 int taken = 0; 1451 int not_taken = 0; 1452 1453 bool use_mdo = !has_injected_profile(btest, test, taken, not_taken); 1454 1455 if (use_mdo) { 1456 // Use MethodData information if it is available 1457 // FIXME: free the ProfileData structure 1458 ciMethodData* methodData = method()->method_data(); 1459 if (!methodData->is_mature()) return PROB_UNKNOWN; 1460 ciProfileData* data = methodData->bci_to_data(bci()); 1461 if (data == NULL) { 1462 return PROB_UNKNOWN; 1463 } 1464 if (!data->is_JumpData()) return PROB_UNKNOWN; 1465 1466 // get taken and not taken values 1467 taken = data->as_JumpData()->taken(); 1468 not_taken = 0; 1469 if (data->is_BranchData()) { 1470 not_taken = data->as_BranchData()->not_taken(); 1471 } 1472 1473 // scale the counts to be commensurate with invocation counts: 1474 taken = method()->scale_count(taken); 1475 not_taken = method()->scale_count(not_taken); 1476 } 1477 1478 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. 1479 // We also check that individual counters are positive first, otherwise the sum can become positive. 1480 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { 1481 if (C->log() != NULL) { 1482 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); 1483 } 1484 return PROB_UNKNOWN; 1485 } 1486 1487 // Compute frequency that we arrive here 1488 float sum = taken + not_taken; 1489 // Adjust, if this block is a cloned private block but the 1490 // Jump counts are shared. Taken the private counts for 1491 // just this path instead of the shared counts. 1492 if( block()->count() > 0 ) 1493 sum = block()->count(); 1494 cnt = sum / FreqCountInvocations; 1495 1496 // Pin probability to sane limits 1497 float prob; 1498 if( !taken ) 1499 prob = (0+PROB_MIN) / 2; 1500 else if( !not_taken ) 1501 prob = (1+PROB_MAX) / 2; 1502 else { // Compute probability of true path 1503 prob = (float)taken / (float)(taken + not_taken); 1504 if (prob > PROB_MAX) prob = PROB_MAX; 1505 if (prob < PROB_MIN) prob = PROB_MIN; 1506 } 1507 1508 assert((cnt > 0.0f) && (prob > 0.0f), 1509 "Bad frequency assignment in if"); 1510 1511 if (C->log() != NULL) { 1512 const char* prob_str = NULL; 1513 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always"; 1514 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never"; 1515 char prob_str_buf[30]; 1516 if (prob_str == NULL) { 1517 jio_snprintf(prob_str_buf, sizeof(prob_str_buf), "%20.2f", prob); 1518 prob_str = prob_str_buf; 1519 } 1520 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%f' prob='%s'", 1521 iter().get_dest(), taken, not_taken, cnt, prob_str); 1522 } 1523 return prob; 1524 } 1525 1526 //-----------------------------branch_prediction------------------------------- 1527 float Parse::branch_prediction(float& cnt, 1528 BoolTest::mask btest, 1529 int target_bci, 1530 Node* test) { 1531 float prob = dynamic_branch_prediction(cnt, btest, test); 1532 // If prob is unknown, switch to static prediction 1533 if (prob != PROB_UNKNOWN) return prob; 1534 1535 prob = PROB_FAIR; // Set default value 1536 if (btest == BoolTest::eq) // Exactly equal test? 1537 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent 1538 else if (btest == BoolTest::ne) 1539 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent 1540 1541 // If this is a conditional test guarding a backwards branch, 1542 // assume its a loop-back edge. Make it a likely taken branch. 1543 if (target_bci < bci()) { 1544 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt 1545 // Since it's an OSR, we probably have profile data, but since 1546 // branch_prediction returned PROB_UNKNOWN, the counts are too small. 1547 // Let's make a special check here for completely zero counts. 1548 ciMethodData* methodData = method()->method_data(); 1549 if (!methodData->is_empty()) { 1550 ciProfileData* data = methodData->bci_to_data(bci()); 1551 // Only stop for truly zero counts, which mean an unknown part 1552 // of the OSR-ed method, and we want to deopt to gather more stats. 1553 // If you have ANY counts, then this loop is simply 'cold' relative 1554 // to the OSR loop. 1555 if (data == NULL || 1556 (data->as_BranchData()->taken() + data->as_BranchData()->not_taken() == 0)) { 1557 // This is the only way to return PROB_UNKNOWN: 1558 return PROB_UNKNOWN; 1559 } 1560 } 1561 } 1562 prob = PROB_STATIC_FREQUENT; // Likely to take backwards branch 1563 } 1564 1565 assert(prob != PROB_UNKNOWN, "must have some guess at this point"); 1566 return prob; 1567 } 1568 1569 // The magic constants are chosen so as to match the output of 1570 // branch_prediction() when the profile reports a zero taken count. 1571 // It is important to distinguish zero counts unambiguously, because 1572 // some branches (e.g., _213_javac.Assembler.eliminate) validly produce 1573 // very small but nonzero probabilities, which if confused with zero 1574 // counts would keep the program recompiling indefinitely. 1575 bool Parse::seems_never_taken(float prob) const { 1576 return prob < PROB_MIN; 1577 } 1578 1579 // True if the comparison seems to be the kind that will not change its 1580 // statistics from true to false. See comments in adjust_map_after_if. 1581 // This question is only asked along paths which are already 1582 // classifed as untaken (by seems_never_taken), so really, 1583 // if a path is never taken, its controlling comparison is 1584 // already acting in a stable fashion. If the comparison 1585 // seems stable, we will put an expensive uncommon trap 1586 // on the untaken path. 1587 bool Parse::seems_stable_comparison() const { 1588 if (C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if)) { 1589 return false; 1590 } 1591 return true; 1592 } 1593 1594 //-------------------------------repush_if_args-------------------------------- 1595 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. 1596 inline int Parse::repush_if_args() { 1597 if (PrintOpto && WizardMode) { 1598 tty->print("defending against excessive implicit null exceptions on %s @%d in ", 1599 Bytecodes::name(iter().cur_bc()), iter().cur_bci()); 1600 method()->print_name(); tty->cr(); 1601 } 1602 int bc_depth = - Bytecodes::depth(iter().cur_bc()); 1603 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches"); 1604 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms 1605 assert(argument(0) != NULL, "must exist"); 1606 assert(bc_depth == 1 || argument(1) != NULL, "two must exist"); 1607 inc_sp(bc_depth); 1608 return bc_depth; 1609 } 1610 1611 //----------------------------------do_ifnull---------------------------------- 1612 void Parse::do_ifnull(BoolTest::mask btest, Node *c) { 1613 int target_bci = iter().get_dest(); 1614 1615 Block* branch_block = successor_for_bci(target_bci); 1616 Block* next_block = successor_for_bci(iter().next_bci()); 1617 1618 float cnt; 1619 float prob = branch_prediction(cnt, btest, target_bci, c); 1620 if (prob == PROB_UNKNOWN) { 1621 // (An earlier version of do_ifnull omitted this trap for OSR methods.) 1622 if (PrintOpto && Verbose) { 1623 tty->print_cr("Never-taken edge stops compilation at bci %d", bci()); 1624 } 1625 repush_if_args(); // to gather stats on loop 1626 // We need to mark this branch as taken so that if we recompile we will 1627 // see that it is possible. In the tiered system the interpreter doesn't 1628 // do profiling and by the time we get to the lower tier from the interpreter 1629 // the path may be cold again. Make sure it doesn't look untaken 1630 profile_taken_branch(target_bci, !ProfileInterpreter); 1631 uncommon_trap(Deoptimization::Reason_unreached, 1632 Deoptimization::Action_reinterpret, 1633 NULL, "cold"); 1634 if (C->eliminate_boxing()) { 1635 // Mark the successor blocks as parsed 1636 branch_block->next_path_num(); 1637 next_block->next_path_num(); 1638 } 1639 return; 1640 } 1641 1642 NOT_PRODUCT(explicit_null_checks_inserted++); 1643 1644 // Generate real control flow 1645 Node *tst = _gvn.transform( new BoolNode( c, btest ) ); 1646 1647 // Sanity check the probability value 1648 assert(prob > 0.0f,"Bad probability in Parser"); 1649 // Need xform to put node in hash table 1650 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt ); 1651 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1652 // True branch 1653 { PreserveJVMState pjvms(this); 1654 Node* iftrue = _gvn.transform( new IfTrueNode (iff) ); 1655 set_control(iftrue); 1656 1657 if (stopped()) { // Path is dead? 1658 NOT_PRODUCT(explicit_null_checks_elided++); 1659 if (C->eliminate_boxing()) { 1660 // Mark the successor block as parsed 1661 branch_block->next_path_num(); 1662 } 1663 } else { // Path is live. 1664 // Update method data 1665 profile_taken_branch(target_bci); 1666 adjust_map_after_if(btest, c, prob, branch_block); 1667 if (!stopped()) { 1668 merge(target_bci); 1669 } 1670 } 1671 } 1672 1673 // False branch 1674 Node* iffalse = _gvn.transform( new IfFalseNode(iff) ); 1675 set_control(iffalse); 1676 1677 if (stopped()) { // Path is dead? 1678 NOT_PRODUCT(explicit_null_checks_elided++); 1679 if (C->eliminate_boxing()) { 1680 // Mark the successor block as parsed 1681 next_block->next_path_num(); 1682 } 1683 } else { // Path is live. 1684 // Update method data 1685 profile_not_taken_branch(); 1686 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block); 1687 } 1688 } 1689 1690 //------------------------------------do_if------------------------------------ 1691 void Parse::do_if(BoolTest::mask btest, Node* c, bool new_path, Node** ctrl_taken) { 1692 int target_bci = iter().get_dest(); 1693 1694 Block* branch_block = successor_for_bci(target_bci); 1695 Block* next_block = successor_for_bci(iter().next_bci()); 1696 1697 float cnt; 1698 float prob = branch_prediction(cnt, btest, target_bci, c); 1699 float untaken_prob = 1.0 - prob; 1700 1701 if (prob == PROB_UNKNOWN) { 1702 if (PrintOpto && Verbose) { 1703 tty->print_cr("Never-taken edge stops compilation at bci %d", bci()); 1704 } 1705 repush_if_args(); // to gather stats on loop 1706 // We need to mark this branch as taken so that if we recompile we will 1707 // see that it is possible. In the tiered system the interpreter doesn't 1708 // do profiling and by the time we get to the lower tier from the interpreter 1709 // the path may be cold again. Make sure it doesn't look untaken 1710 profile_taken_branch(target_bci, !ProfileInterpreter); 1711 uncommon_trap(Deoptimization::Reason_unreached, 1712 Deoptimization::Action_reinterpret, 1713 NULL, "cold"); 1714 if (C->eliminate_boxing()) { 1715 // Mark the successor blocks as parsed 1716 branch_block->next_path_num(); 1717 next_block->next_path_num(); 1718 } 1719 return; 1720 } 1721 1722 // Sanity check the probability value 1723 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser"); 1724 1725 bool taken_if_true = true; 1726 // Convert BoolTest to canonical form: 1727 if (!BoolTest(btest).is_canonical()) { 1728 btest = BoolTest(btest).negate(); 1729 taken_if_true = false; 1730 // prob is NOT updated here; it remains the probability of the taken 1731 // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). 1732 } 1733 assert(btest != BoolTest::eq, "!= is the only canonical exact test"); 1734 1735 Node* tst0 = new BoolNode(c, btest); 1736 Node* tst = _gvn.transform(tst0); 1737 BoolTest::mask taken_btest = BoolTest::illegal; 1738 BoolTest::mask untaken_btest = BoolTest::illegal; 1739 1740 if (tst->is_Bool()) { 1741 // Refresh c from the transformed bool node, since it may be 1742 // simpler than the original c. Also re-canonicalize btest. 1743 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). 1744 // That can arise from statements like: if (x instanceof C) ... 1745 if (tst != tst0) { 1746 // Canonicalize one more time since transform can change it. 1747 btest = tst->as_Bool()->_test._test; 1748 if (!BoolTest(btest).is_canonical()) { 1749 // Reverse edges one more time... 1750 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) ); 1751 btest = tst->as_Bool()->_test._test; 1752 assert(BoolTest(btest).is_canonical(), "sanity"); 1753 taken_if_true = !taken_if_true; 1754 } 1755 c = tst->in(1); 1756 } 1757 BoolTest::mask neg_btest = BoolTest(btest).negate(); 1758 taken_btest = taken_if_true ? btest : neg_btest; 1759 untaken_btest = taken_if_true ? neg_btest : btest; 1760 } 1761 1762 // Generate real control flow 1763 float true_prob = (taken_if_true ? prob : untaken_prob); 1764 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt); 1765 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1766 Node* taken_branch = new IfTrueNode(iff); 1767 Node* untaken_branch = new IfFalseNode(iff); 1768 if (!taken_if_true) { // Finish conversion to canonical form 1769 Node* tmp = taken_branch; 1770 taken_branch = untaken_branch; 1771 untaken_branch = tmp; 1772 } 1773 1774 // Branch is taken: 1775 { PreserveJVMState pjvms(this); 1776 taken_branch = _gvn.transform(taken_branch); 1777 set_control(taken_branch); 1778 1779 if (stopped()) { 1780 if (C->eliminate_boxing() && !new_path) { 1781 // Mark the successor block as parsed (if we haven't created a new path) 1782 branch_block->next_path_num(); 1783 } 1784 } else { 1785 // Update method data 1786 profile_taken_branch(target_bci); 1787 adjust_map_after_if(taken_btest, c, prob, branch_block); 1788 if (!stopped()) { 1789 if (new_path) { 1790 // Merge by using a new path 1791 merge_new_path(target_bci); 1792 } else if (ctrl_taken != NULL) { 1793 // Don't merge but save taken branch to be wired by caller 1794 *ctrl_taken = control(); 1795 } else { 1796 merge(target_bci); 1797 } 1798 } 1799 } 1800 } 1801 1802 untaken_branch = _gvn.transform(untaken_branch); 1803 set_control(untaken_branch); 1804 1805 // Branch not taken. 1806 if (stopped() && ctrl_taken == NULL) { 1807 if (C->eliminate_boxing()) { 1808 // Mark the successor block as parsed (if caller does not re-wire control flow) 1809 next_block->next_path_num(); 1810 } 1811 } else { 1812 // Update method data 1813 profile_not_taken_branch(); 1814 adjust_map_after_if(untaken_btest, c, untaken_prob, next_block); 1815 } 1816 } 1817 1818 void Parse::do_acmp(BoolTest::mask btest, Node* a, Node* b) { 1819 // In the case were both operands might be value types, we need to 1820 // use the new acmp implementation. Otherwise, i.e. if one operand 1821 // is not a value type, we can use the old acmp implementation. 1822 Node* cmp = C->optimize_acmp(&_gvn, a, b); 1823 if (cmp != NULL) { 1824 // Use optimized/old acmp 1825 cmp = optimize_cmp_with_klass(_gvn.transform(cmp)); 1826 do_if(btest, cmp); 1827 return; 1828 } 1829 1830 Node* ctrl = NULL; 1831 bool safe_for_replace = true; 1832 if (!UsePointerPerturbation) { 1833 // Emit old acmp before new acmp for quick a != b check 1834 cmp = CmpP(a, b); 1835 cmp = optimize_cmp_with_klass(_gvn.transform(cmp)); 1836 if (btest == BoolTest::ne) { 1837 do_if(btest, cmp, true); 1838 if (stopped()) { 1839 return; // Never equal 1840 } 1841 } else if (btest == BoolTest::eq) { 1842 Node* is_equal = NULL; 1843 { 1844 PreserveJVMState pjvms(this); 1845 do_if(btest, cmp, false, &is_equal); 1846 if (!stopped()) { 1847 // Not equal, skip valuetype check 1848 ctrl = new RegionNode(3); 1849 ctrl->init_req(1, control()); 1850 _gvn.set_type(ctrl, Type::CONTROL); 1851 record_for_igvn(ctrl); 1852 safe_for_replace = false; 1853 } 1854 } 1855 if (is_equal == NULL) { 1856 assert(ctrl != NULL, "no control left"); 1857 set_control(_gvn.transform(ctrl)); 1858 return; // Never equal 1859 } 1860 set_control(is_equal); 1861 } 1862 } 1863 1864 // Null check operand before loading the is_value bit 1865 bool speculate = false; 1866 if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(b))) { 1867 // Operand 'b' is never null, swap operands to avoid null check 1868 swap(a, b); 1869 } else if (!too_many_traps(Deoptimization::Reason_speculate_null_check)) { 1870 // Speculate on non-nullness of one operand 1871 if (!_gvn.type(a)->speculative_maybe_null()) { 1872 speculate = true; 1873 } else if (!_gvn.type(b)->speculative_maybe_null()) { 1874 speculate = true; 1875 swap(a, b); 1876 } 1877 } 1878 inc_sp(2); 1879 Node* null_ctl = top(); 1880 Node* not_null_a = null_check_oop(a, &null_ctl, speculate, safe_for_replace, speculate); 1881 assert(!stopped(), "operand is always null"); 1882 dec_sp(2); 1883 Node* region = new RegionNode(2); 1884 Node* is_value = new PhiNode(region, TypeX_X); 1885 if (null_ctl != top()) { 1886 assert(!speculate, "should never be null"); 1887 region->add_req(null_ctl); 1888 is_value->add_req(_gvn.MakeConX(0)); 1889 } 1890 1891 Node* value_mask = _gvn.MakeConX(markOopDesc::always_locked_pattern); 1892 if (UsePointerPerturbation) { 1893 Node* mark_addr = basic_plus_adr(not_null_a, oopDesc::mark_offset_in_bytes()); 1894 Node* mark = make_load(NULL, mark_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 1895 Node* not_mark = _gvn.transform(new XorXNode(mark, _gvn.MakeConX(-1))); 1896 Node* andn = _gvn.transform(new AndXNode(not_mark, value_mask)); 1897 Node* neg_if_value = _gvn.transform(new SubXNode(andn, _gvn.MakeConX(1))); 1898 is_value->init_req(1, _gvn.transform(new RShiftXNode(neg_if_value, _gvn.intcon(63)))); 1899 } else { 1900 is_value->init_req(1, is_always_locked(not_null_a)); 1901 } 1902 region->init_req(1, control()); 1903 1904 set_control(_gvn.transform(region)); 1905 is_value = _gvn.transform(is_value); 1906 1907 if (UsePointerPerturbation) { 1908 // Perturbe oop if operand is a value type to make comparison fail 1909 Node* pert = _gvn.transform(new AddPNode(a, a, is_value)); 1910 cmp = _gvn.transform(new CmpPNode(pert, b)); 1911 } else { 1912 // Check for a value type because we already know that operands are equal 1913 cmp = _gvn.transform(new CmpXNode(is_value, value_mask)); 1914 btest = (btest == BoolTest::eq) ? BoolTest::ne : BoolTest::eq; 1915 } 1916 cmp = optimize_cmp_with_klass(cmp); 1917 do_if(btest, cmp); 1918 1919 if (ctrl != NULL) { 1920 ctrl->init_req(2, control()); 1921 set_control(_gvn.transform(ctrl)); 1922 } 1923 } 1924 1925 bool Parse::path_is_suitable_for_uncommon_trap(float prob) const { 1926 // Don't want to speculate on uncommon traps when running with -Xcomp 1927 if (!UseInterpreter) { 1928 return false; 1929 } 1930 return (seems_never_taken(prob) && seems_stable_comparison()); 1931 } 1932 1933 void Parse::maybe_add_predicate_after_if(Block* path) { 1934 if (path->is_SEL_head() && path->preds_parsed() == 0) { 1935 // Add predicates at bci of if dominating the loop so traps can be 1936 // recorded on the if's profile data 1937 int bc_depth = repush_if_args(); 1938 add_predicate(); 1939 dec_sp(bc_depth); 1940 path->set_has_predicates(); 1941 } 1942 } 1943 1944 1945 //----------------------------adjust_map_after_if------------------------------ 1946 // Adjust the JVM state to reflect the result of taking this path. 1947 // Basically, it means inspecting the CmpNode controlling this 1948 // branch, seeing how it constrains a tested value, and then 1949 // deciding if it's worth our while to encode this constraint 1950 // as graph nodes in the current abstract interpretation map. 1951 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path) { 1952 if (!c->is_Cmp()) { 1953 maybe_add_predicate_after_if(path); 1954 return; 1955 } 1956 1957 if (stopped() || btest == BoolTest::illegal) { 1958 return; // nothing to do 1959 } 1960 1961 bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); 1962 1963 if (path_is_suitable_for_uncommon_trap(prob)) { 1964 repush_if_args(); 1965 uncommon_trap(Deoptimization::Reason_unstable_if, 1966 Deoptimization::Action_reinterpret, 1967 NULL, 1968 (is_fallthrough ? "taken always" : "taken never")); 1969 return; 1970 } 1971 1972 Node* val = c->in(1); 1973 Node* con = c->in(2); 1974 const Type* tcon = _gvn.type(con); 1975 const Type* tval = _gvn.type(val); 1976 bool have_con = tcon->singleton(); 1977 if (tval->singleton()) { 1978 if (!have_con) { 1979 // Swap, so constant is in con. 1980 con = val; 1981 tcon = tval; 1982 val = c->in(2); 1983 tval = _gvn.type(val); 1984 btest = BoolTest(btest).commute(); 1985 have_con = true; 1986 } else { 1987 // Do we have two constants? Then leave well enough alone. 1988 have_con = false; 1989 } 1990 } 1991 if (!have_con) { // remaining adjustments need a con 1992 maybe_add_predicate_after_if(path); 1993 return; 1994 } 1995 1996 sharpen_type_after_if(btest, con, tcon, val, tval); 1997 maybe_add_predicate_after_if(path); 1998 } 1999 2000 2001 static Node* extract_obj_from_klass_load(PhaseGVN* gvn, Node* n) { 2002 Node* ldk; 2003 if (n->is_DecodeNKlass()) { 2004 if (n->in(1)->Opcode() != Op_LoadNKlass) { 2005 return NULL; 2006 } else { 2007 ldk = n->in(1); 2008 } 2009 } else if (n->Opcode() != Op_LoadKlass) { 2010 return NULL; 2011 } else { 2012 ldk = n; 2013 } 2014 assert(ldk != NULL && ldk->is_Load(), "should have found a LoadKlass or LoadNKlass node"); 2015 2016 Node* adr = ldk->in(MemNode::Address); 2017 intptr_t off = 0; 2018 Node* obj = AddPNode::Ideal_base_and_offset(adr, gvn, off); 2019 if (obj == NULL || off != oopDesc::klass_offset_in_bytes()) // loading oopDesc::_klass? 2020 return NULL; 2021 const TypePtr* tp = gvn->type(obj)->is_ptr(); 2022 if (tp == NULL || !(tp->isa_instptr() || tp->isa_aryptr())) // is obj a Java object ptr? 2023 return NULL; 2024 2025 return obj; 2026 } 2027 2028 void Parse::sharpen_type_after_if(BoolTest::mask btest, 2029 Node* con, const Type* tcon, 2030 Node* val, const Type* tval) { 2031 // Look for opportunities to sharpen the type of a node 2032 // whose klass is compared with a constant klass. 2033 if (btest == BoolTest::eq && tcon->isa_klassptr()) { 2034 Node* obj = extract_obj_from_klass_load(&_gvn, val); 2035 const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type(); 2036 if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) { 2037 // Found: 2038 // Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]) 2039 // or the narrowOop equivalent. 2040 const Type* obj_type = _gvn.type(obj); 2041 const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr(); 2042 if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type && 2043 tboth->higher_equal(obj_type)) { 2044 // obj has to be of the exact type Foo if the CmpP succeeds. 2045 int obj_in_map = map()->find_edge(obj); 2046 JVMState* jvms = this->jvms(); 2047 if (obj_in_map >= 0 && 2048 (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) { 2049 TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth); 2050 const Type* tcc = ccast->as_Type()->type(); 2051 assert(tcc != obj_type && tcc->higher_equal(obj_type), "must improve"); 2052 // Delay transform() call to allow recovery of pre-cast value 2053 // at the control merge. 2054 _gvn.set_type_bottom(ccast); 2055 record_for_igvn(ccast); 2056 // Here's the payoff. 2057 replace_in_map(obj, ccast); 2058 } 2059 } 2060 } 2061 } 2062 2063 int val_in_map = map()->find_edge(val); 2064 if (val_in_map < 0) return; // replace_in_map would be useless 2065 { 2066 JVMState* jvms = this->jvms(); 2067 if (!(jvms->is_loc(val_in_map) || 2068 jvms->is_stk(val_in_map))) 2069 return; // again, it would be useless 2070 } 2071 2072 // Check for a comparison to a constant, and "know" that the compared 2073 // value is constrained on this path. 2074 assert(tcon->singleton(), ""); 2075 ConstraintCastNode* ccast = NULL; 2076 Node* cast = NULL; 2077 2078 switch (btest) { 2079 case BoolTest::eq: // Constant test? 2080 { 2081 const Type* tboth = tcon->join_speculative(tval); 2082 if (tboth == tval) break; // Nothing to gain. 2083 if (tcon->isa_int()) { 2084 ccast = new CastIINode(val, tboth); 2085 } else if (tcon == TypePtr::NULL_PTR) { 2086 // Cast to null, but keep the pointer identity temporarily live. 2087 ccast = new CastPPNode(val, tboth); 2088 } else { 2089 const TypeF* tf = tcon->isa_float_constant(); 2090 const TypeD* td = tcon->isa_double_constant(); 2091 // Exclude tests vs float/double 0 as these could be 2092 // either +0 or -0. Just because you are equal to +0 2093 // doesn't mean you ARE +0! 2094 // Note, following code also replaces Long and Oop values. 2095 if ((!tf || tf->_f != 0.0) && 2096 (!td || td->_d != 0.0)) 2097 cast = con; // Replace non-constant val by con. 2098 } 2099 } 2100 break; 2101 2102 case BoolTest::ne: 2103 if (tcon == TypePtr::NULL_PTR) { 2104 cast = cast_not_null(val, false); 2105 } 2106 break; 2107 2108 default: 2109 // (At this point we could record int range types with CastII.) 2110 break; 2111 } 2112 2113 if (ccast != NULL) { 2114 const Type* tcc = ccast->as_Type()->type(); 2115 assert(tcc != tval && tcc->higher_equal(tval), "must improve"); 2116 // Delay transform() call to allow recovery of pre-cast value 2117 // at the control merge. 2118 ccast->set_req(0, control()); 2119 _gvn.set_type_bottom(ccast); 2120 record_for_igvn(ccast); 2121 cast = ccast; 2122 } 2123 2124 if (cast != NULL) { // Here's the payoff. 2125 replace_in_map(val, cast); 2126 } 2127 } 2128 2129 /** 2130 * Use speculative type to optimize CmpP node: if comparison is 2131 * against the low level class, cast the object to the speculative 2132 * type if any. CmpP should then go away. 2133 * 2134 * @param c expected CmpP node 2135 * @return result of CmpP on object casted to speculative type 2136 * 2137 */ 2138 Node* Parse::optimize_cmp_with_klass(Node* c) { 2139 // If this is transformed by the _gvn to a comparison with the low 2140 // level klass then we may be able to use speculation 2141 if (c->Opcode() == Op_CmpP && 2142 (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) && 2143 c->in(2)->is_Con()) { 2144 Node* load_klass = NULL; 2145 Node* decode = NULL; 2146 if (c->in(1)->Opcode() == Op_DecodeNKlass) { 2147 decode = c->in(1); 2148 load_klass = c->in(1)->in(1); 2149 } else { 2150 load_klass = c->in(1); 2151 } 2152 if (load_klass->in(2)->is_AddP()) { 2153 Node* addp = load_klass->in(2); 2154 Node* obj = addp->in(AddPNode::Address); 2155 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 2156 if (obj_type->speculative_type_not_null() != NULL) { 2157 ciKlass* k = obj_type->speculative_type(); 2158 inc_sp(2); 2159 obj = maybe_cast_profiled_obj(obj, k); 2160 dec_sp(2); 2161 if (obj->is_ValueType()) { 2162 assert(obj->as_ValueType()->is_allocated(&_gvn), "must be allocated"); 2163 obj = obj->as_ValueType()->get_oop(); 2164 } 2165 // Make the CmpP use the casted obj 2166 addp = basic_plus_adr(obj, addp->in(AddPNode::Offset)); 2167 load_klass = load_klass->clone(); 2168 load_klass->set_req(2, addp); 2169 load_klass = _gvn.transform(load_klass); 2170 if (decode != NULL) { 2171 decode = decode->clone(); 2172 decode->set_req(1, load_klass); 2173 load_klass = _gvn.transform(decode); 2174 } 2175 c = c->clone(); 2176 c->set_req(1, load_klass); 2177 c = _gvn.transform(c); 2178 } 2179 } 2180 } 2181 return c; 2182 } 2183 2184 //------------------------------do_one_bytecode-------------------------------- 2185 // Parse this bytecode, and alter the Parsers JVM->Node mapping 2186 void Parse::do_one_bytecode() { 2187 Node *a, *b, *c, *d; // Handy temps 2188 BoolTest::mask btest; 2189 int i; 2190 2191 assert(!has_exceptions(), "bytecode entry state must be clear of throws"); 2192 2193 if (C->check_node_count(NodeLimitFudgeFactor * 5, 2194 "out of nodes parsing method")) { 2195 return; 2196 } 2197 2198 #ifdef ASSERT 2199 // for setting breakpoints 2200 if (TraceOptoParse) { 2201 tty->print(" @"); 2202 dump_bci(bci()); 2203 tty->cr(); 2204 } 2205 #endif 2206 2207 switch (bc()) { 2208 case Bytecodes::_nop: 2209 // do nothing 2210 break; 2211 case Bytecodes::_lconst_0: 2212 push_pair(longcon(0)); 2213 break; 2214 2215 case Bytecodes::_lconst_1: 2216 push_pair(longcon(1)); 2217 break; 2218 2219 case Bytecodes::_fconst_0: 2220 push(zerocon(T_FLOAT)); 2221 break; 2222 2223 case Bytecodes::_fconst_1: 2224 push(makecon(TypeF::ONE)); 2225 break; 2226 2227 case Bytecodes::_fconst_2: 2228 push(makecon(TypeF::make(2.0f))); 2229 break; 2230 2231 case Bytecodes::_dconst_0: 2232 push_pair(zerocon(T_DOUBLE)); 2233 break; 2234 2235 case Bytecodes::_dconst_1: 2236 push_pair(makecon(TypeD::ONE)); 2237 break; 2238 2239 case Bytecodes::_iconst_m1:push(intcon(-1)); break; 2240 case Bytecodes::_iconst_0: push(intcon( 0)); break; 2241 case Bytecodes::_iconst_1: push(intcon( 1)); break; 2242 case Bytecodes::_iconst_2: push(intcon( 2)); break; 2243 case Bytecodes::_iconst_3: push(intcon( 3)); break; 2244 case Bytecodes::_iconst_4: push(intcon( 4)); break; 2245 case Bytecodes::_iconst_5: push(intcon( 5)); break; 2246 case Bytecodes::_bipush: push(intcon(iter().get_constant_u1())); break; 2247 case Bytecodes::_sipush: push(intcon(iter().get_constant_u2())); break; 2248 case Bytecodes::_aconst_null: push(null()); break; 2249 case Bytecodes::_ldc: 2250 case Bytecodes::_ldc_w: 2251 case Bytecodes::_ldc2_w: 2252 // If the constant is unresolved, run this BC once in the interpreter. 2253 { 2254 ciConstant constant = iter().get_constant(); 2255 if (!constant.is_valid() || 2256 (constant.basic_type() == T_OBJECT && 2257 !constant.as_object()->is_loaded())) { 2258 int index = iter().get_constant_pool_index(); 2259 constantTag tag = iter().get_constant_pool_tag(index); 2260 uncommon_trap(Deoptimization::make_trap_request 2261 (Deoptimization::Reason_unloaded, 2262 Deoptimization::Action_reinterpret, 2263 index), 2264 NULL, tag.internal_name()); 2265 break; 2266 } 2267 assert(constant.basic_type() != T_OBJECT || constant.as_object()->is_instance(), 2268 "must be java_mirror of klass"); 2269 const Type* con_type = Type::make_from_constant(constant); 2270 if (con_type != NULL) { 2271 push_node(con_type->basic_type(), makecon(con_type)); 2272 } 2273 } 2274 2275 break; 2276 2277 case Bytecodes::_aload_0: 2278 push( local(0) ); 2279 break; 2280 case Bytecodes::_aload_1: 2281 push( local(1) ); 2282 break; 2283 case Bytecodes::_aload_2: 2284 push( local(2) ); 2285 break; 2286 case Bytecodes::_aload_3: 2287 push( local(3) ); 2288 break; 2289 case Bytecodes::_aload: 2290 push( local(iter().get_index()) ); 2291 break; 2292 2293 case Bytecodes::_fload_0: 2294 case Bytecodes::_iload_0: 2295 push( local(0) ); 2296 break; 2297 case Bytecodes::_fload_1: 2298 case Bytecodes::_iload_1: 2299 push( local(1) ); 2300 break; 2301 case Bytecodes::_fload_2: 2302 case Bytecodes::_iload_2: 2303 push( local(2) ); 2304 break; 2305 case Bytecodes::_fload_3: 2306 case Bytecodes::_iload_3: 2307 push( local(3) ); 2308 break; 2309 case Bytecodes::_fload: 2310 case Bytecodes::_iload: 2311 push( local(iter().get_index()) ); 2312 break; 2313 case Bytecodes::_lload_0: 2314 push_pair_local( 0 ); 2315 break; 2316 case Bytecodes::_lload_1: 2317 push_pair_local( 1 ); 2318 break; 2319 case Bytecodes::_lload_2: 2320 push_pair_local( 2 ); 2321 break; 2322 case Bytecodes::_lload_3: 2323 push_pair_local( 3 ); 2324 break; 2325 case Bytecodes::_lload: 2326 push_pair_local( iter().get_index() ); 2327 break; 2328 2329 case Bytecodes::_dload_0: 2330 push_pair_local(0); 2331 break; 2332 case Bytecodes::_dload_1: 2333 push_pair_local(1); 2334 break; 2335 case Bytecodes::_dload_2: 2336 push_pair_local(2); 2337 break; 2338 case Bytecodes::_dload_3: 2339 push_pair_local(3); 2340 break; 2341 case Bytecodes::_dload: 2342 push_pair_local(iter().get_index()); 2343 break; 2344 case Bytecodes::_fstore_0: 2345 case Bytecodes::_istore_0: 2346 case Bytecodes::_astore_0: 2347 set_local( 0, pop() ); 2348 break; 2349 case Bytecodes::_fstore_1: 2350 case Bytecodes::_istore_1: 2351 case Bytecodes::_astore_1: 2352 set_local( 1, pop() ); 2353 break; 2354 case Bytecodes::_fstore_2: 2355 case Bytecodes::_istore_2: 2356 case Bytecodes::_astore_2: 2357 set_local( 2, pop() ); 2358 break; 2359 case Bytecodes::_fstore_3: 2360 case Bytecodes::_istore_3: 2361 case Bytecodes::_astore_3: 2362 set_local( 3, pop() ); 2363 break; 2364 case Bytecodes::_fstore: 2365 case Bytecodes::_istore: 2366 case Bytecodes::_astore: 2367 set_local( iter().get_index(), pop() ); 2368 break; 2369 // long stores 2370 case Bytecodes::_lstore_0: 2371 set_pair_local( 0, pop_pair() ); 2372 break; 2373 case Bytecodes::_lstore_1: 2374 set_pair_local( 1, pop_pair() ); 2375 break; 2376 case Bytecodes::_lstore_2: 2377 set_pair_local( 2, pop_pair() ); 2378 break; 2379 case Bytecodes::_lstore_3: 2380 set_pair_local( 3, pop_pair() ); 2381 break; 2382 case Bytecodes::_lstore: 2383 set_pair_local( iter().get_index(), pop_pair() ); 2384 break; 2385 2386 // double stores 2387 case Bytecodes::_dstore_0: 2388 set_pair_local( 0, dstore_rounding(pop_pair()) ); 2389 break; 2390 case Bytecodes::_dstore_1: 2391 set_pair_local( 1, dstore_rounding(pop_pair()) ); 2392 break; 2393 case Bytecodes::_dstore_2: 2394 set_pair_local( 2, dstore_rounding(pop_pair()) ); 2395 break; 2396 case Bytecodes::_dstore_3: 2397 set_pair_local( 3, dstore_rounding(pop_pair()) ); 2398 break; 2399 case Bytecodes::_dstore: 2400 set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) ); 2401 break; 2402 2403 case Bytecodes::_pop: dec_sp(1); break; 2404 case Bytecodes::_pop2: dec_sp(2); break; 2405 case Bytecodes::_swap: 2406 a = pop(); 2407 b = pop(); 2408 push(a); 2409 push(b); 2410 break; 2411 case Bytecodes::_dup: 2412 a = pop(); 2413 push(a); 2414 push(a); 2415 break; 2416 case Bytecodes::_dup_x1: 2417 a = pop(); 2418 b = pop(); 2419 push( a ); 2420 push( b ); 2421 push( a ); 2422 break; 2423 case Bytecodes::_dup_x2: 2424 a = pop(); 2425 b = pop(); 2426 c = pop(); 2427 push( a ); 2428 push( c ); 2429 push( b ); 2430 push( a ); 2431 break; 2432 case Bytecodes::_dup2: 2433 a = pop(); 2434 b = pop(); 2435 push( b ); 2436 push( a ); 2437 push( b ); 2438 push( a ); 2439 break; 2440 2441 case Bytecodes::_dup2_x1: 2442 // before: .. c, b, a 2443 // after: .. b, a, c, b, a 2444 // not tested 2445 a = pop(); 2446 b = pop(); 2447 c = pop(); 2448 push( b ); 2449 push( a ); 2450 push( c ); 2451 push( b ); 2452 push( a ); 2453 break; 2454 case Bytecodes::_dup2_x2: 2455 // before: .. d, c, b, a 2456 // after: .. b, a, d, c, b, a 2457 // not tested 2458 a = pop(); 2459 b = pop(); 2460 c = pop(); 2461 d = pop(); 2462 push( b ); 2463 push( a ); 2464 push( d ); 2465 push( c ); 2466 push( b ); 2467 push( a ); 2468 break; 2469 2470 case Bytecodes::_arraylength: { 2471 // Must do null-check with value on expression stack 2472 Node *ary = null_check(peek(), T_ARRAY); 2473 // Compile-time detect of null-exception? 2474 if (stopped()) return; 2475 a = pop(); 2476 push(load_array_length(a)); 2477 break; 2478 } 2479 2480 case Bytecodes::_baload: array_load(T_BYTE); break; 2481 case Bytecodes::_caload: array_load(T_CHAR); break; 2482 case Bytecodes::_iaload: array_load(T_INT); break; 2483 case Bytecodes::_saload: array_load(T_SHORT); break; 2484 case Bytecodes::_faload: array_load(T_FLOAT); break; 2485 case Bytecodes::_aaload: array_load(T_OBJECT); break; 2486 case Bytecodes::_laload: array_load(T_LONG); break; 2487 case Bytecodes::_daload: array_load(T_DOUBLE); break; 2488 case Bytecodes::_bastore: array_store(T_BYTE); break; 2489 case Bytecodes::_castore: array_store(T_CHAR); break; 2490 case Bytecodes::_iastore: array_store(T_INT); break; 2491 case Bytecodes::_sastore: array_store(T_SHORT); break; 2492 case Bytecodes::_fastore: array_store(T_FLOAT); break; 2493 case Bytecodes::_aastore: array_store(T_OBJECT); break; 2494 case Bytecodes::_lastore: array_store(T_LONG); break; 2495 case Bytecodes::_dastore: array_store(T_DOUBLE); break; 2496 2497 case Bytecodes::_getfield: 2498 do_getfield(); 2499 break; 2500 2501 case Bytecodes::_getstatic: 2502 do_getstatic(); 2503 break; 2504 2505 case Bytecodes::_putfield: 2506 do_putfield(); 2507 break; 2508 2509 case Bytecodes::_putstatic: 2510 do_putstatic(); 2511 break; 2512 2513 case Bytecodes::_irem: 2514 do_irem(); 2515 break; 2516 case Bytecodes::_idiv: 2517 // Must keep both values on the expression-stack during null-check 2518 zero_check_int(peek()); 2519 // Compile-time detect of null-exception? 2520 if (stopped()) return; 2521 b = pop(); 2522 a = pop(); 2523 push( _gvn.transform( new DivINode(control(),a,b) ) ); 2524 break; 2525 case Bytecodes::_imul: 2526 b = pop(); a = pop(); 2527 push( _gvn.transform( new MulINode(a,b) ) ); 2528 break; 2529 case Bytecodes::_iadd: 2530 b = pop(); a = pop(); 2531 push( _gvn.transform( new AddINode(a,b) ) ); 2532 break; 2533 case Bytecodes::_ineg: 2534 a = pop(); 2535 push( _gvn.transform( new SubINode(_gvn.intcon(0),a)) ); 2536 break; 2537 case Bytecodes::_isub: 2538 b = pop(); a = pop(); 2539 push( _gvn.transform( new SubINode(a,b) ) ); 2540 break; 2541 case Bytecodes::_iand: 2542 b = pop(); a = pop(); 2543 push( _gvn.transform( new AndINode(a,b) ) ); 2544 break; 2545 case Bytecodes::_ior: 2546 b = pop(); a = pop(); 2547 push( _gvn.transform( new OrINode(a,b) ) ); 2548 break; 2549 case Bytecodes::_ixor: 2550 b = pop(); a = pop(); 2551 push( _gvn.transform( new XorINode(a,b) ) ); 2552 break; 2553 case Bytecodes::_ishl: 2554 b = pop(); a = pop(); 2555 push( _gvn.transform( new LShiftINode(a,b) ) ); 2556 break; 2557 case Bytecodes::_ishr: 2558 b = pop(); a = pop(); 2559 push( _gvn.transform( new RShiftINode(a,b) ) ); 2560 break; 2561 case Bytecodes::_iushr: 2562 b = pop(); a = pop(); 2563 push( _gvn.transform( new URShiftINode(a,b) ) ); 2564 break; 2565 2566 case Bytecodes::_fneg: 2567 a = pop(); 2568 b = _gvn.transform(new NegFNode (a)); 2569 push(b); 2570 break; 2571 2572 case Bytecodes::_fsub: 2573 b = pop(); 2574 a = pop(); 2575 c = _gvn.transform( new SubFNode(a,b) ); 2576 d = precision_rounding(c); 2577 push( d ); 2578 break; 2579 2580 case Bytecodes::_fadd: 2581 b = pop(); 2582 a = pop(); 2583 c = _gvn.transform( new AddFNode(a,b) ); 2584 d = precision_rounding(c); 2585 push( d ); 2586 break; 2587 2588 case Bytecodes::_fmul: 2589 b = pop(); 2590 a = pop(); 2591 c = _gvn.transform( new MulFNode(a,b) ); 2592 d = precision_rounding(c); 2593 push( d ); 2594 break; 2595 2596 case Bytecodes::_fdiv: 2597 b = pop(); 2598 a = pop(); 2599 c = _gvn.transform( new DivFNode(0,a,b) ); 2600 d = precision_rounding(c); 2601 push( d ); 2602 break; 2603 2604 case Bytecodes::_frem: 2605 if (Matcher::has_match_rule(Op_ModF)) { 2606 // Generate a ModF node. 2607 b = pop(); 2608 a = pop(); 2609 c = _gvn.transform( new ModFNode(0,a,b) ); 2610 d = precision_rounding(c); 2611 push( d ); 2612 } 2613 else { 2614 // Generate a call. 2615 modf(); 2616 } 2617 break; 2618 2619 case Bytecodes::_fcmpl: 2620 b = pop(); 2621 a = pop(); 2622 c = _gvn.transform( new CmpF3Node( a, b)); 2623 push(c); 2624 break; 2625 case Bytecodes::_fcmpg: 2626 b = pop(); 2627 a = pop(); 2628 2629 // Same as fcmpl but need to flip the unordered case. Swap the inputs, 2630 // which negates the result sign except for unordered. Flip the unordered 2631 // as well by using CmpF3 which implements unordered-lesser instead of 2632 // unordered-greater semantics. Finally, commute the result bits. Result 2633 // is same as using a CmpF3Greater except we did it with CmpF3 alone. 2634 c = _gvn.transform( new CmpF3Node( b, a)); 2635 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 2636 push(c); 2637 break; 2638 2639 case Bytecodes::_f2i: 2640 a = pop(); 2641 push(_gvn.transform(new ConvF2INode(a))); 2642 break; 2643 2644 case Bytecodes::_d2i: 2645 a = pop_pair(); 2646 b = _gvn.transform(new ConvD2INode(a)); 2647 push( b ); 2648 break; 2649 2650 case Bytecodes::_f2d: 2651 a = pop(); 2652 b = _gvn.transform( new ConvF2DNode(a)); 2653 push_pair( b ); 2654 break; 2655 2656 case Bytecodes::_d2f: 2657 a = pop_pair(); 2658 b = _gvn.transform( new ConvD2FNode(a)); 2659 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) 2660 //b = _gvn.transform(new RoundFloatNode(0, b) ); 2661 push( b ); 2662 break; 2663 2664 case Bytecodes::_l2f: 2665 if (Matcher::convL2FSupported()) { 2666 a = pop_pair(); 2667 b = _gvn.transform( new ConvL2FNode(a)); 2668 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. 2669 // Rather than storing the result into an FP register then pushing 2670 // out to memory to round, the machine instruction that implements 2671 // ConvL2D is responsible for rounding. 2672 // c = precision_rounding(b); 2673 c = _gvn.transform(b); 2674 push(c); 2675 } else { 2676 l2f(); 2677 } 2678 break; 2679 2680 case Bytecodes::_l2d: 2681 a = pop_pair(); 2682 b = _gvn.transform( new ConvL2DNode(a)); 2683 // For i486.ad, rounding is always necessary (see _l2f above). 2684 // c = dprecision_rounding(b); 2685 c = _gvn.transform(b); 2686 push_pair(c); 2687 break; 2688 2689 case Bytecodes::_f2l: 2690 a = pop(); 2691 b = _gvn.transform( new ConvF2LNode(a)); 2692 push_pair(b); 2693 break; 2694 2695 case Bytecodes::_d2l: 2696 a = pop_pair(); 2697 b = _gvn.transform( new ConvD2LNode(a)); 2698 push_pair(b); 2699 break; 2700 2701 case Bytecodes::_dsub: 2702 b = pop_pair(); 2703 a = pop_pair(); 2704 c = _gvn.transform( new SubDNode(a,b) ); 2705 d = dprecision_rounding(c); 2706 push_pair( d ); 2707 break; 2708 2709 case Bytecodes::_dadd: 2710 b = pop_pair(); 2711 a = pop_pair(); 2712 c = _gvn.transform( new AddDNode(a,b) ); 2713 d = dprecision_rounding(c); 2714 push_pair( d ); 2715 break; 2716 2717 case Bytecodes::_dmul: 2718 b = pop_pair(); 2719 a = pop_pair(); 2720 c = _gvn.transform( new MulDNode(a,b) ); 2721 d = dprecision_rounding(c); 2722 push_pair( d ); 2723 break; 2724 2725 case Bytecodes::_ddiv: 2726 b = pop_pair(); 2727 a = pop_pair(); 2728 c = _gvn.transform( new DivDNode(0,a,b) ); 2729 d = dprecision_rounding(c); 2730 push_pair( d ); 2731 break; 2732 2733 case Bytecodes::_dneg: 2734 a = pop_pair(); 2735 b = _gvn.transform(new NegDNode (a)); 2736 push_pair(b); 2737 break; 2738 2739 case Bytecodes::_drem: 2740 if (Matcher::has_match_rule(Op_ModD)) { 2741 // Generate a ModD node. 2742 b = pop_pair(); 2743 a = pop_pair(); 2744 // a % b 2745 2746 c = _gvn.transform( new ModDNode(0,a,b) ); 2747 d = dprecision_rounding(c); 2748 push_pair( d ); 2749 } 2750 else { 2751 // Generate a call. 2752 modd(); 2753 } 2754 break; 2755 2756 case Bytecodes::_dcmpl: 2757 b = pop_pair(); 2758 a = pop_pair(); 2759 c = _gvn.transform( new CmpD3Node( a, b)); 2760 push(c); 2761 break; 2762 2763 case Bytecodes::_dcmpg: 2764 b = pop_pair(); 2765 a = pop_pair(); 2766 // Same as dcmpl but need to flip the unordered case. 2767 // Commute the inputs, which negates the result sign except for unordered. 2768 // Flip the unordered as well by using CmpD3 which implements 2769 // unordered-lesser instead of unordered-greater semantics. 2770 // Finally, negate the result bits. Result is same as using a 2771 // CmpD3Greater except we did it with CmpD3 alone. 2772 c = _gvn.transform( new CmpD3Node( b, a)); 2773 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 2774 push(c); 2775 break; 2776 2777 2778 // Note for longs -> lo word is on TOS, hi word is on TOS - 1 2779 case Bytecodes::_land: 2780 b = pop_pair(); 2781 a = pop_pair(); 2782 c = _gvn.transform( new AndLNode(a,b) ); 2783 push_pair(c); 2784 break; 2785 case Bytecodes::_lor: 2786 b = pop_pair(); 2787 a = pop_pair(); 2788 c = _gvn.transform( new OrLNode(a,b) ); 2789 push_pair(c); 2790 break; 2791 case Bytecodes::_lxor: 2792 b = pop_pair(); 2793 a = pop_pair(); 2794 c = _gvn.transform( new XorLNode(a,b) ); 2795 push_pair(c); 2796 break; 2797 2798 case Bytecodes::_lshl: 2799 b = pop(); // the shift count 2800 a = pop_pair(); // value to be shifted 2801 c = _gvn.transform( new LShiftLNode(a,b) ); 2802 push_pair(c); 2803 break; 2804 case Bytecodes::_lshr: 2805 b = pop(); // the shift count 2806 a = pop_pair(); // value to be shifted 2807 c = _gvn.transform( new RShiftLNode(a,b) ); 2808 push_pair(c); 2809 break; 2810 case Bytecodes::_lushr: 2811 b = pop(); // the shift count 2812 a = pop_pair(); // value to be shifted 2813 c = _gvn.transform( new URShiftLNode(a,b) ); 2814 push_pair(c); 2815 break; 2816 case Bytecodes::_lmul: 2817 b = pop_pair(); 2818 a = pop_pair(); 2819 c = _gvn.transform( new MulLNode(a,b) ); 2820 push_pair(c); 2821 break; 2822 2823 case Bytecodes::_lrem: 2824 // Must keep both values on the expression-stack during null-check 2825 assert(peek(0) == top(), "long word order"); 2826 zero_check_long(peek(1)); 2827 // Compile-time detect of null-exception? 2828 if (stopped()) return; 2829 b = pop_pair(); 2830 a = pop_pair(); 2831 c = _gvn.transform( new ModLNode(control(),a,b) ); 2832 push_pair(c); 2833 break; 2834 2835 case Bytecodes::_ldiv: 2836 // Must keep both values on the expression-stack during null-check 2837 assert(peek(0) == top(), "long word order"); 2838 zero_check_long(peek(1)); 2839 // Compile-time detect of null-exception? 2840 if (stopped()) return; 2841 b = pop_pair(); 2842 a = pop_pair(); 2843 c = _gvn.transform( new DivLNode(control(),a,b) ); 2844 push_pair(c); 2845 break; 2846 2847 case Bytecodes::_ladd: 2848 b = pop_pair(); 2849 a = pop_pair(); 2850 c = _gvn.transform( new AddLNode(a,b) ); 2851 push_pair(c); 2852 break; 2853 case Bytecodes::_lsub: 2854 b = pop_pair(); 2855 a = pop_pair(); 2856 c = _gvn.transform( new SubLNode(a,b) ); 2857 push_pair(c); 2858 break; 2859 case Bytecodes::_lcmp: 2860 // Safepoints are now inserted _before_ branches. The long-compare 2861 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a 2862 // slew of control flow. These are usually followed by a CmpI vs zero and 2863 // a branch; this pattern then optimizes to the obvious long-compare and 2864 // branch. However, if the branch is backwards there's a Safepoint 2865 // inserted. The inserted Safepoint captures the JVM state at the 2866 // pre-branch point, i.e. it captures the 3-way value. Thus if a 2867 // long-compare is used to control a loop the debug info will force 2868 // computation of the 3-way value, even though the generated code uses a 2869 // long-compare and branch. We try to rectify the situation by inserting 2870 // a SafePoint here and have it dominate and kill the safepoint added at a 2871 // following backwards branch. At this point the JVM state merely holds 2 2872 // longs but not the 3-way value. 2873 if( UseLoopSafepoints ) { 2874 switch( iter().next_bc() ) { 2875 case Bytecodes::_ifgt: 2876 case Bytecodes::_iflt: 2877 case Bytecodes::_ifge: 2878 case Bytecodes::_ifle: 2879 case Bytecodes::_ifne: 2880 case Bytecodes::_ifeq: 2881 // If this is a backwards branch in the bytecodes, add Safepoint 2882 maybe_add_safepoint(iter().next_get_dest()); 2883 default: 2884 break; 2885 } 2886 } 2887 b = pop_pair(); 2888 a = pop_pair(); 2889 c = _gvn.transform( new CmpL3Node( a, b )); 2890 push(c); 2891 break; 2892 2893 case Bytecodes::_lneg: 2894 a = pop_pair(); 2895 b = _gvn.transform( new SubLNode(longcon(0),a)); 2896 push_pair(b); 2897 break; 2898 case Bytecodes::_l2i: 2899 a = pop_pair(); 2900 push( _gvn.transform( new ConvL2INode(a))); 2901 break; 2902 case Bytecodes::_i2l: 2903 a = pop(); 2904 b = _gvn.transform( new ConvI2LNode(a)); 2905 push_pair(b); 2906 break; 2907 case Bytecodes::_i2b: 2908 // Sign extend 2909 a = pop(); 2910 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(24)) ); 2911 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(24)) ); 2912 push( a ); 2913 break; 2914 case Bytecodes::_i2s: 2915 a = pop(); 2916 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(16)) ); 2917 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(16)) ); 2918 push( a ); 2919 break; 2920 case Bytecodes::_i2c: 2921 a = pop(); 2922 push( _gvn.transform( new AndINode(a,_gvn.intcon(0xFFFF)) ) ); 2923 break; 2924 2925 case Bytecodes::_i2f: 2926 a = pop(); 2927 b = _gvn.transform( new ConvI2FNode(a) ) ; 2928 c = precision_rounding(b); 2929 push (b); 2930 break; 2931 2932 case Bytecodes::_i2d: 2933 a = pop(); 2934 b = _gvn.transform( new ConvI2DNode(a)); 2935 push_pair(b); 2936 break; 2937 2938 case Bytecodes::_iinc: // Increment local 2939 i = iter().get_index(); // Get local index 2940 set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) ); 2941 break; 2942 2943 // Exit points of synchronized methods must have an unlock node 2944 case Bytecodes::_return: 2945 return_current(NULL); 2946 break; 2947 2948 case Bytecodes::_ireturn: 2949 case Bytecodes::_areturn: 2950 case Bytecodes::_freturn: 2951 return_current(pop()); 2952 break; 2953 case Bytecodes::_lreturn: 2954 return_current(pop_pair()); 2955 break; 2956 case Bytecodes::_dreturn: 2957 return_current(pop_pair()); 2958 break; 2959 2960 case Bytecodes::_athrow: 2961 // null exception oop throws NULL pointer exception 2962 null_check(peek()); 2963 if (stopped()) return; 2964 // Hook the thrown exception directly to subsequent handlers. 2965 if (BailoutToInterpreterForThrows) { 2966 // Keep method interpreted from now on. 2967 uncommon_trap(Deoptimization::Reason_unhandled, 2968 Deoptimization::Action_make_not_compilable); 2969 return; 2970 } 2971 if (env()->jvmti_can_post_on_exceptions()) { 2972 // check if we must post exception events, take uncommon trap if so (with must_throw = false) 2973 uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false); 2974 } 2975 // Here if either can_post_on_exceptions or should_post_on_exceptions is false 2976 add_exception_state(make_exception_state(peek())); 2977 break; 2978 2979 case Bytecodes::_goto: // fall through 2980 case Bytecodes::_goto_w: { 2981 int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest(); 2982 2983 // If this is a backwards branch in the bytecodes, add Safepoint 2984 maybe_add_safepoint(target_bci); 2985 2986 // Update method data 2987 profile_taken_branch(target_bci); 2988 2989 // Merge the current control into the target basic block 2990 merge(target_bci); 2991 2992 // See if we can get some profile data and hand it off to the next block 2993 Block *target_block = block()->successor_for_bci(target_bci); 2994 if (target_block->pred_count() != 1) break; 2995 ciMethodData* methodData = method()->method_data(); 2996 if (!methodData->is_mature()) break; 2997 ciProfileData* data = methodData->bci_to_data(bci()); 2998 assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch"); 2999 int taken = ((ciJumpData*)data)->taken(); 3000 taken = method()->scale_count(taken); 3001 target_block->set_count(taken); 3002 break; 3003 } 3004 3005 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null; 3006 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null; 3007 handle_if_null: 3008 // If this is a backwards branch in the bytecodes, add Safepoint 3009 maybe_add_safepoint(iter().get_dest()); 3010 a = null(); 3011 b = pop(); 3012 if (b->is_ValueType()) { 3013 // Return constant false because 'b' is always non-null 3014 c = _gvn.makecon(TypeInt::CC_GT); 3015 } else { 3016 if (!_gvn.type(b)->speculative_maybe_null() && 3017 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 3018 inc_sp(1); 3019 Node* null_ctl = top(); 3020 b = null_check_oop(b, &null_ctl, true, true, true); 3021 assert(null_ctl->is_top(), "no null control here"); 3022 dec_sp(1); 3023 } else if (_gvn.type(b)->speculative_always_null() && 3024 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) { 3025 inc_sp(1); 3026 b = null_assert(b); 3027 dec_sp(1); 3028 } 3029 c = _gvn.transform( new CmpPNode(b, a) ); 3030 } 3031 do_ifnull(btest, c); 3032 break; 3033 3034 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp; 3035 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp; 3036 handle_if_acmp: 3037 // If this is a backwards branch in the bytecodes, add Safepoint 3038 maybe_add_safepoint(iter().get_dest()); 3039 a = access_resolve(pop(), 0); 3040 b = access_resolve(pop(), 0); 3041 do_acmp(btest, a, b); 3042 break; 3043 3044 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx; 3045 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx; 3046 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx; 3047 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx; 3048 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx; 3049 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx; 3050 handle_ifxx: 3051 // If this is a backwards branch in the bytecodes, add Safepoint 3052 maybe_add_safepoint(iter().get_dest()); 3053 a = _gvn.intcon(0); 3054 b = pop(); 3055 c = _gvn.transform( new CmpINode(b, a) ); 3056 do_if(btest, c); 3057 break; 3058 3059 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp; 3060 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp; 3061 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp; 3062 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp; 3063 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp; 3064 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp; 3065 handle_if_icmp: 3066 // If this is a backwards branch in the bytecodes, add Safepoint 3067 maybe_add_safepoint(iter().get_dest()); 3068 a = pop(); 3069 b = pop(); 3070 c = _gvn.transform( new CmpINode( b, a ) ); 3071 do_if(btest, c); 3072 break; 3073 3074 case Bytecodes::_tableswitch: 3075 do_tableswitch(); 3076 break; 3077 3078 case Bytecodes::_lookupswitch: 3079 do_lookupswitch(); 3080 break; 3081 3082 case Bytecodes::_invokestatic: 3083 case Bytecodes::_invokedynamic: 3084 case Bytecodes::_invokespecial: 3085 case Bytecodes::_invokevirtual: 3086 case Bytecodes::_invokeinterface: 3087 do_call(); 3088 break; 3089 case Bytecodes::_checkcast: 3090 do_checkcast(); 3091 break; 3092 case Bytecodes::_instanceof: 3093 do_instanceof(); 3094 break; 3095 case Bytecodes::_anewarray: 3096 do_newarray(); 3097 break; 3098 case Bytecodes::_newarray: 3099 do_newarray((BasicType)iter().get_index()); 3100 break; 3101 case Bytecodes::_multianewarray: 3102 do_multianewarray(); 3103 break; 3104 case Bytecodes::_new: 3105 do_new(); 3106 break; 3107 case Bytecodes::_defaultvalue: 3108 do_defaultvalue(); 3109 break; 3110 case Bytecodes::_withfield: 3111 do_withfield(); 3112 break; 3113 3114 case Bytecodes::_jsr: 3115 case Bytecodes::_jsr_w: 3116 do_jsr(); 3117 break; 3118 3119 case Bytecodes::_ret: 3120 do_ret(); 3121 break; 3122 3123 3124 case Bytecodes::_monitorenter: 3125 do_monitor_enter(); 3126 break; 3127 3128 case Bytecodes::_monitorexit: 3129 do_monitor_exit(); 3130 break; 3131 3132 case Bytecodes::_breakpoint: 3133 // Breakpoint set concurrently to compile 3134 // %%% use an uncommon trap? 3135 C->record_failure("breakpoint in method"); 3136 return; 3137 3138 default: 3139 #ifndef PRODUCT 3140 map()->dump(99); 3141 #endif 3142 tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) ); 3143 ShouldNotReachHere(); 3144 } 3145 3146 #ifndef PRODUCT 3147 IdealGraphPrinter *printer = C->printer(); 3148 if (printer && printer->should_print(1)) { 3149 char buffer[256]; 3150 jio_snprintf(buffer, sizeof(buffer), "Bytecode %d: %s", bci(), Bytecodes::name(bc())); 3151 bool old = printer->traverse_outs(); 3152 printer->set_traverse_outs(true); 3153 printer->print_method(buffer, 4); 3154 printer->set_traverse_outs(old); 3155 } 3156 #endif 3157 }