113 uncommon_trap(Deoptimization::Reason_unloaded, 114 Deoptimization::Action_reinterpret, 115 arytype->klass(), "!loaded array"); 116 return top(); 117 } 118 119 // Do the range check 120 if (GenerateRangeChecks && need_range_check) { 121 Node* tst; 122 if (sizetype->_hi <= 0) { 123 // The greatest array bound is negative, so we can conclude that we're 124 // compiling unreachable code, but the unsigned compare trick used below 125 // only works with non-negative lengths. Instead, hack "tst" to be zero so 126 // the uncommon_trap path will always be taken. 127 tst = _gvn.intcon(0); 128 } else { 129 // Range is constant in array-oop, so we can use the original state of mem 130 Node* len = load_array_length(ary); 131 132 // Test length vs index (standard trick using unsigned compare) 133 Node* chk = _gvn.transform( new (C) CmpUNode(idx, len) ); 134 BoolTest::mask btest = BoolTest::lt; 135 tst = _gvn.transform( new (C) BoolNode(chk, btest) ); 136 } 137 // Branch to failure if out of bounds 138 { BuildCutout unless(this, tst, PROB_MAX); 139 if (C->allow_range_check_smearing()) { 140 // Do not use builtin_throw, since range checks are sometimes 141 // made more stringent by an optimistic transformation. 142 // This creates "tentative" range checks at this point, 143 // which are not guaranteed to throw exceptions. 144 // See IfNode::Ideal, is_range_check, adjust_check. 145 uncommon_trap(Deoptimization::Reason_range_check, 146 Deoptimization::Action_make_not_entrant, 147 NULL, "range_check"); 148 } else { 149 // If we have already recompiled with the range-check-widening 150 // heroic optimization turned off, then we must really be throwing 151 // range check exceptions. 152 builtin_throw(Deoptimization::Reason_range_check, idx); 153 } 154 } 155 } 156 // Check for always knowing you are throwing a range-check exception 157 if (stopped()) return top(); 158 159 Node* ptr = array_element_address(ary, idx, type, sizetype); 160 161 if (result2 != NULL) *result2 = elemtype; 162 163 assert(ptr != top(), "top should go hand-in-hand with stopped"); 164 165 return ptr; 166 } 167 168 169 // returns IfNode 170 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask) { 171 Node *cmp = _gvn.transform( new (C) CmpINode( a, b)); // two cases: shiftcount > 32 and shiftcount <= 32 172 Node *tst = _gvn.transform( new (C) BoolNode( cmp, mask)); 173 IfNode *iff = create_and_map_if( control(), tst, ((mask == BoolTest::eq) ? PROB_STATIC_INFREQUENT : PROB_FAIR), COUNT_UNKNOWN ); 174 return iff; 175 } 176 177 // return Region node 178 Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) { 179 Node *region = new (C) RegionNode(3); // 2 results 180 record_for_igvn(region); 181 region->init_req(1, iffalse); 182 region->init_req(2, iftrue ); 183 _gvn.set_type(region, Type::CONTROL); 184 region = _gvn.transform(region); 185 set_control (region); 186 return region; 187 } 188 189 190 //------------------------------helper for tableswitch------------------------- 191 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { 192 // True branch, use existing map info 193 { PreserveJVMState pjvms(this); 194 Node *iftrue = _gvn.transform( new (C) IfTrueNode (iff) ); 195 set_control( iftrue ); 196 profile_switch_case(prof_table_index); 197 merge_new_path(dest_bci_if_true); 198 } 199 200 // False branch 201 Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff) ); 202 set_control( iffalse ); 203 } 204 205 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { 206 // True branch, use existing map info 207 { PreserveJVMState pjvms(this); 208 Node *iffalse = _gvn.transform( new (C) IfFalseNode (iff) ); 209 set_control( iffalse ); 210 profile_switch_case(prof_table_index); 211 merge_new_path(dest_bci_if_true); 212 } 213 214 // False branch 215 Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff) ); 216 set_control( iftrue ); 217 } 218 219 void Parse::jump_if_always_fork(int dest_bci, int prof_table_index) { 220 // False branch, use existing map and control() 221 profile_switch_case(prof_table_index); 222 merge_new_path(dest_bci); 223 } 224 225 226 extern "C" { 227 static int jint_cmp(const void *i, const void *j) { 228 int a = *(jint *)i; 229 int b = *(jint *)j; 230 return a > b ? 1 : a < b ? -1 : 0; 231 } 232 } 233 234 235 // Default value for methodData switch indexing. Must be a negative value to avoid 423 // If a guard test will eliminate very sparse end ranges, then 424 // it is worth the cost of an extra jump. 425 if (total_outlier_size > (MaxJumpTableSparseness * 4)) { 426 needs_guard = true; 427 if (default_dest == lo->dest()) lo++; 428 if (default_dest == hi->dest()) hi--; 429 } 430 431 // Find the total number of cases and ranges 432 int64 num_cases = ((int64)hi->hi()) - ((int64)lo->lo()) + 1; 433 int num_range = hi - lo + 1; 434 435 // Don't create table if: too large, too small, or too sparse. 436 if (num_cases < MinJumpTableSize || num_cases > MaxJumpTableSize) 437 return false; 438 if (num_cases > (MaxJumpTableSparseness * num_range)) 439 return false; 440 441 // Normalize table lookups to zero 442 int lowval = lo->lo(); 443 key_val = _gvn.transform( new (C) SubINode(key_val, _gvn.intcon(lowval)) ); 444 445 // Generate a guard to protect against input keyvals that aren't 446 // in the switch domain. 447 if (needs_guard) { 448 Node* size = _gvn.intcon(num_cases); 449 Node* cmp = _gvn.transform( new (C) CmpUNode(key_val, size) ); 450 Node* tst = _gvn.transform( new (C) BoolNode(cmp, BoolTest::ge) ); 451 IfNode* iff = create_and_map_if( control(), tst, PROB_FAIR, COUNT_UNKNOWN); 452 jump_if_true_fork(iff, default_dest, NullTableIndex); 453 } 454 455 // Create an ideal node JumpTable that has projections 456 // of all possible ranges for a switch statement 457 // The key_val input must be converted to a pointer offset and scaled. 458 // Compare Parse::array_addressing above. 459 #ifdef _LP64 460 // Clean the 32-bit int into a real 64-bit offset. 461 // Otherwise, the jint value 0 might turn into an offset of 0x0800000000. 462 const TypeLong* lkeytype = TypeLong::make(CONST64(0), num_cases-1, Type::WidenMin); 463 key_val = _gvn.transform( new (C) ConvI2LNode(key_val, lkeytype) ); 464 #endif 465 // Shift the value by wordsize so we have an index into the table, rather 466 // than a switch value 467 Node *shiftWord = _gvn.MakeConX(wordSize); 468 key_val = _gvn.transform( new (C) MulXNode( key_val, shiftWord)); 469 470 // Create the JumpNode 471 Node* jtn = _gvn.transform( new (C) JumpNode(control(), key_val, num_cases) ); 472 473 // These are the switch destinations hanging off the jumpnode 474 int i = 0; 475 for (SwitchRange* r = lo; r <= hi; r++) { 476 for (int64 j = r->lo(); j <= r->hi(); j++, i++) { 477 Node* input = _gvn.transform(new (C) JumpProjNode(jtn, i, r->dest(), (int)(j - lowval))); 478 { 479 PreserveJVMState pjvms(this); 480 set_control(input); 481 jump_if_always_fork(r->dest(), r->table_index()); 482 } 483 } 484 } 485 assert(i == num_cases, "miscount of cases"); 486 stop_and_kill_map(); // no more uses for this JVMS 487 return true; 488 } 489 490 //----------------------------jump_switch_ranges------------------------------- 491 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) { 492 Block* switch_block = block(); 493 494 if (switch_depth == 0) { 495 // Do special processing for the top-level call. 496 assert(lo->lo() == min_jint, "initial range must exhaust Type::INT"); 497 assert(hi->hi() == max_jint, "initial range must exhaust Type::INT"); 558 559 Node *test_val = _gvn.intcon(mid->lo()); 560 561 if (mid->is_singleton()) { 562 IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne); 563 jump_if_false_fork(iff_ne, mid->dest(), mid->table_index()); 564 565 // Special Case: If there are exactly three ranges, and the high 566 // and low range each go to the same place, omit the "gt" test, 567 // since it will not discriminate anything. 568 bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest()); 569 if (eq_test_only) { 570 assert(mid == hi-1, ""); 571 } 572 573 // if there is a higher range, test for it and process it: 574 if (mid < hi && !eq_test_only) { 575 // two comparisons of same values--should enable 1 test for 2 branches 576 // Use BoolTest::le instead of BoolTest::gt 577 IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le); 578 Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff_le) ); 579 Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff_le) ); 580 { PreserveJVMState pjvms(this); 581 set_control(iffalse); 582 jump_switch_ranges(key_val, mid+1, hi, switch_depth+1); 583 } 584 set_control(iftrue); 585 } 586 587 } else { 588 // mid is a range, not a singleton, so treat mid..hi as a unit 589 IfNode *iff_ge = jump_if_fork_int(key_val, test_val, BoolTest::ge); 590 591 // if there is a higher range, test for it and process it: 592 if (mid == hi) { 593 jump_if_true_fork(iff_ge, mid->dest(), mid->table_index()); 594 } else { 595 Node *iftrue = _gvn.transform( new (C) IfTrueNode(iff_ge) ); 596 Node *iffalse = _gvn.transform( new (C) IfFalseNode(iff_ge) ); 597 { PreserveJVMState pjvms(this); 598 set_control(iftrue); 599 jump_switch_ranges(key_val, mid, hi, switch_depth+1); 600 } 601 set_control(iffalse); 602 } 603 } 604 605 // in any case, process the lower range 606 jump_switch_ranges(key_val, lo, mid-1, switch_depth+1); 607 } 608 609 // Decrease pred_count for each successor after all is done. 610 if (switch_depth == 0) { 611 int unique_successors = switch_block->num_successors(); 612 for (int i = 0; i < unique_successors; i++) { 613 Block* target = switch_block->successor_at(i); 614 // Throw away the pre-allocated path for each unique successor. 615 target->next_path_num(); 616 } 631 (int) (hi-lo+1), nsing, _max_switch_depth, _est_switch_depth); 632 if (_max_switch_depth > _est_switch_depth) { 633 tty->print_cr("******** BAD SWITCH DEPTH ********"); 634 } 635 tty->print(" "); 636 for( r = lo; r <= hi; r++ ) { 637 r->print(); 638 } 639 tty->cr(); 640 } 641 #endif 642 } 643 644 void Parse::modf() { 645 Node *f2 = pop(); 646 Node *f1 = pop(); 647 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(), 648 CAST_FROM_FN_PTR(address, SharedRuntime::frem), 649 "frem", NULL, //no memory effects 650 f1, f2); 651 Node* res = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); 652 653 push(res); 654 } 655 656 void Parse::modd() { 657 Node *d2 = pop_pair(); 658 Node *d1 = pop_pair(); 659 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), 660 CAST_FROM_FN_PTR(address, SharedRuntime::drem), 661 "drem", NULL, //no memory effects 662 d1, top(), d2, top()); 663 Node* res_d = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); 664 665 #ifdef ASSERT 666 Node* res_top = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 1)); 667 assert(res_top == top(), "second value must be top"); 668 #endif 669 670 push_pair(res_d); 671 } 672 673 void Parse::l2f() { 674 Node* f2 = pop(); 675 Node* f1 = pop(); 676 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(), 677 CAST_FROM_FN_PTR(address, SharedRuntime::l2f), 678 "l2f", NULL, //no memory effects 679 f1, f2); 680 Node* res = _gvn.transform(new (C) ProjNode(c, TypeFunc::Parms + 0)); 681 682 push(res); 683 } 684 685 void Parse::do_irem() { 686 // Must keep both values on the expression-stack during null-check 687 zero_check_int(peek()); 688 // Compile-time detect of null-exception? 689 if (stopped()) return; 690 691 Node* b = pop(); 692 Node* a = pop(); 693 694 const Type *t = _gvn.type(b); 695 if (t != Type::TOP) { 696 const TypeInt *ti = t->is_int(); 697 if (ti->is_con()) { 698 int divisor = ti->get_con(); 699 // check for positive power of 2 700 if (divisor > 0 && 701 (divisor & ~(divisor-1)) == divisor) { 702 // yes ! 703 Node *mask = _gvn.intcon((divisor - 1)); 704 // Sigh, must handle negative dividends 705 Node *zero = _gvn.intcon(0); 706 IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt); 707 Node *iff = _gvn.transform( new (C) IfFalseNode(ifff) ); 708 Node *ift = _gvn.transform( new (C) IfTrueNode (ifff) ); 709 Node *reg = jump_if_join(ift, iff); 710 Node *phi = PhiNode::make(reg, NULL, TypeInt::INT); 711 // Negative path; negate/and/negate 712 Node *neg = _gvn.transform( new (C) SubINode(zero, a) ); 713 Node *andn= _gvn.transform( new (C) AndINode(neg, mask) ); 714 Node *negn= _gvn.transform( new (C) SubINode(zero, andn) ); 715 phi->init_req(1, negn); 716 // Fast positive case 717 Node *andx = _gvn.transform( new (C) AndINode(a, mask) ); 718 phi->init_req(2, andx); 719 // Push the merge 720 push( _gvn.transform(phi) ); 721 return; 722 } 723 } 724 } 725 // Default case 726 push( _gvn.transform( new (C) ModINode(control(),a,b) ) ); 727 } 728 729 // Handle jsr and jsr_w bytecode 730 void Parse::do_jsr() { 731 assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode"); 732 733 // Store information about current state, tagged with new _jsr_bci 734 int return_bci = iter().next_bci(); 735 int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest(); 736 737 // Update method data 738 profile_taken_branch(jsr_bci); 739 740 // The way we do things now, there is only one successor block 741 // for the jsr, because the target code is cloned by ciTypeFlow. 742 Block* target = successor_for_bci(jsr_bci); 743 744 // What got pushed? 745 const Type* ret_addr = target->peek(); 746 assert(ret_addr->singleton(), "must be a constant (cloned jsr body)"); 983 repush_if_args(); // to gather stats on loop 984 // We need to mark this branch as taken so that if we recompile we will 985 // see that it is possible. In the tiered system the interpreter doesn't 986 // do profiling and by the time we get to the lower tier from the interpreter 987 // the path may be cold again. Make sure it doesn't look untaken 988 profile_taken_branch(target_bci, !ProfileInterpreter); 989 uncommon_trap(Deoptimization::Reason_unreached, 990 Deoptimization::Action_reinterpret, 991 NULL, "cold"); 992 if (C->eliminate_boxing()) { 993 // Mark the successor blocks as parsed 994 branch_block->next_path_num(); 995 next_block->next_path_num(); 996 } 997 return; 998 } 999 1000 explicit_null_checks_inserted++; 1001 1002 // Generate real control flow 1003 Node *tst = _gvn.transform( new (C) BoolNode( c, btest ) ); 1004 1005 // Sanity check the probability value 1006 assert(prob > 0.0f,"Bad probability in Parser"); 1007 // Need xform to put node in hash table 1008 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt ); 1009 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1010 // True branch 1011 { PreserveJVMState pjvms(this); 1012 Node* iftrue = _gvn.transform( new (C) IfTrueNode (iff) ); 1013 set_control(iftrue); 1014 1015 if (stopped()) { // Path is dead? 1016 explicit_null_checks_elided++; 1017 if (C->eliminate_boxing()) { 1018 // Mark the successor block as parsed 1019 branch_block->next_path_num(); 1020 } 1021 } else { // Path is live. 1022 // Update method data 1023 profile_taken_branch(target_bci); 1024 adjust_map_after_if(btest, c, prob, branch_block, next_block); 1025 if (!stopped()) { 1026 merge(target_bci); 1027 } 1028 } 1029 } 1030 1031 // False branch 1032 Node* iffalse = _gvn.transform( new (C) IfFalseNode(iff) ); 1033 set_control(iffalse); 1034 1035 if (stopped()) { // Path is dead? 1036 explicit_null_checks_elided++; 1037 if (C->eliminate_boxing()) { 1038 // Mark the successor block as parsed 1039 next_block->next_path_num(); 1040 } 1041 } else { // Path is live. 1042 // Update method data 1043 profile_not_taken_branch(); 1044 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, 1045 next_block, branch_block); 1046 } 1047 } 1048 1049 //------------------------------------do_if------------------------------------ 1050 void Parse::do_if(BoolTest::mask btest, Node* c) { 1051 int target_bci = iter().get_dest(); 1052 1075 // Mark the successor blocks as parsed 1076 branch_block->next_path_num(); 1077 next_block->next_path_num(); 1078 } 1079 return; 1080 } 1081 1082 // Sanity check the probability value 1083 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser"); 1084 1085 bool taken_if_true = true; 1086 // Convert BoolTest to canonical form: 1087 if (!BoolTest(btest).is_canonical()) { 1088 btest = BoolTest(btest).negate(); 1089 taken_if_true = false; 1090 // prob is NOT updated here; it remains the probability of the taken 1091 // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). 1092 } 1093 assert(btest != BoolTest::eq, "!= is the only canonical exact test"); 1094 1095 Node* tst0 = new (C) BoolNode(c, btest); 1096 Node* tst = _gvn.transform(tst0); 1097 BoolTest::mask taken_btest = BoolTest::illegal; 1098 BoolTest::mask untaken_btest = BoolTest::illegal; 1099 1100 if (tst->is_Bool()) { 1101 // Refresh c from the transformed bool node, since it may be 1102 // simpler than the original c. Also re-canonicalize btest. 1103 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). 1104 // That can arise from statements like: if (x instanceof C) ... 1105 if (tst != tst0) { 1106 // Canonicalize one more time since transform can change it. 1107 btest = tst->as_Bool()->_test._test; 1108 if (!BoolTest(btest).is_canonical()) { 1109 // Reverse edges one more time... 1110 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) ); 1111 btest = tst->as_Bool()->_test._test; 1112 assert(BoolTest(btest).is_canonical(), "sanity"); 1113 taken_if_true = !taken_if_true; 1114 } 1115 c = tst->in(1); 1116 } 1117 BoolTest::mask neg_btest = BoolTest(btest).negate(); 1118 taken_btest = taken_if_true ? btest : neg_btest; 1119 untaken_btest = taken_if_true ? neg_btest : btest; 1120 } 1121 1122 // Generate real control flow 1123 float true_prob = (taken_if_true ? prob : untaken_prob); 1124 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt); 1125 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1126 Node* taken_branch = new (C) IfTrueNode(iff); 1127 Node* untaken_branch = new (C) IfFalseNode(iff); 1128 if (!taken_if_true) { // Finish conversion to canonical form 1129 Node* tmp = taken_branch; 1130 taken_branch = untaken_branch; 1131 untaken_branch = tmp; 1132 } 1133 1134 // Branch is taken: 1135 { PreserveJVMState pjvms(this); 1136 taken_branch = _gvn.transform(taken_branch); 1137 set_control(taken_branch); 1138 1139 if (stopped()) { 1140 if (C->eliminate_boxing()) { 1141 // Mark the successor block as parsed 1142 branch_block->next_path_num(); 1143 } 1144 } else { 1145 // Update method data 1146 profile_taken_branch(target_bci); 1147 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block); 1271 Node* con, const Type* tcon, 1272 Node* val, const Type* tval) { 1273 // Look for opportunities to sharpen the type of a node 1274 // whose klass is compared with a constant klass. 1275 if (btest == BoolTest::eq && tcon->isa_klassptr()) { 1276 Node* obj = extract_obj_from_klass_load(&_gvn, val); 1277 const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type(); 1278 if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) { 1279 // Found: 1280 // Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]) 1281 // or the narrowOop equivalent. 1282 const Type* obj_type = _gvn.type(obj); 1283 const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr(); 1284 if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type && 1285 tboth->higher_equal(obj_type)) { 1286 // obj has to be of the exact type Foo if the CmpP succeeds. 1287 int obj_in_map = map()->find_edge(obj); 1288 JVMState* jvms = this->jvms(); 1289 if (obj_in_map >= 0 && 1290 (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) { 1291 TypeNode* ccast = new (C) CheckCastPPNode(control(), obj, tboth); 1292 const Type* tcc = ccast->as_Type()->type(); 1293 assert(tcc != obj_type && tcc->higher_equal(obj_type), "must improve"); 1294 // Delay transform() call to allow recovery of pre-cast value 1295 // at the control merge. 1296 _gvn.set_type_bottom(ccast); 1297 record_for_igvn(ccast); 1298 // Here's the payoff. 1299 replace_in_map(obj, ccast); 1300 } 1301 } 1302 } 1303 } 1304 1305 int val_in_map = map()->find_edge(val); 1306 if (val_in_map < 0) return; // replace_in_map would be useless 1307 { 1308 JVMState* jvms = this->jvms(); 1309 if (!(jvms->is_loc(val_in_map) || 1310 jvms->is_stk(val_in_map))) 1311 return; // again, it would be useless 1312 } 1313 1314 // Check for a comparison to a constant, and "know" that the compared 1315 // value is constrained on this path. 1316 assert(tcon->singleton(), ""); 1317 ConstraintCastNode* ccast = NULL; 1318 Node* cast = NULL; 1319 1320 switch (btest) { 1321 case BoolTest::eq: // Constant test? 1322 { 1323 const Type* tboth = tcon->join_speculative(tval); 1324 if (tboth == tval) break; // Nothing to gain. 1325 if (tcon->isa_int()) { 1326 ccast = new (C) CastIINode(val, tboth); 1327 } else if (tcon == TypePtr::NULL_PTR) { 1328 // Cast to null, but keep the pointer identity temporarily live. 1329 ccast = new (C) CastPPNode(val, tboth); 1330 } else { 1331 const TypeF* tf = tcon->isa_float_constant(); 1332 const TypeD* td = tcon->isa_double_constant(); 1333 // Exclude tests vs float/double 0 as these could be 1334 // either +0 or -0. Just because you are equal to +0 1335 // doesn't mean you ARE +0! 1336 // Note, following code also replaces Long and Oop values. 1337 if ((!tf || tf->_f != 0.0) && 1338 (!td || td->_d != 0.0)) 1339 cast = con; // Replace non-constant val by con. 1340 } 1341 } 1342 break; 1343 1344 case BoolTest::ne: 1345 if (tcon == TypePtr::NULL_PTR) { 1346 cast = cast_not_null(val, false); 1347 } 1348 break; 1349 1775 break; 1776 1777 case Bytecodes::_putfield: 1778 do_putfield(); 1779 break; 1780 1781 case Bytecodes::_putstatic: 1782 do_putstatic(); 1783 break; 1784 1785 case Bytecodes::_irem: 1786 do_irem(); 1787 break; 1788 case Bytecodes::_idiv: 1789 // Must keep both values on the expression-stack during null-check 1790 zero_check_int(peek()); 1791 // Compile-time detect of null-exception? 1792 if (stopped()) return; 1793 b = pop(); 1794 a = pop(); 1795 push( _gvn.transform( new (C) DivINode(control(),a,b) ) ); 1796 break; 1797 case Bytecodes::_imul: 1798 b = pop(); a = pop(); 1799 push( _gvn.transform( new (C) MulINode(a,b) ) ); 1800 break; 1801 case Bytecodes::_iadd: 1802 b = pop(); a = pop(); 1803 push( _gvn.transform( new (C) AddINode(a,b) ) ); 1804 break; 1805 case Bytecodes::_ineg: 1806 a = pop(); 1807 push( _gvn.transform( new (C) SubINode(_gvn.intcon(0),a)) ); 1808 break; 1809 case Bytecodes::_isub: 1810 b = pop(); a = pop(); 1811 push( _gvn.transform( new (C) SubINode(a,b) ) ); 1812 break; 1813 case Bytecodes::_iand: 1814 b = pop(); a = pop(); 1815 push( _gvn.transform( new (C) AndINode(a,b) ) ); 1816 break; 1817 case Bytecodes::_ior: 1818 b = pop(); a = pop(); 1819 push( _gvn.transform( new (C) OrINode(a,b) ) ); 1820 break; 1821 case Bytecodes::_ixor: 1822 b = pop(); a = pop(); 1823 push( _gvn.transform( new (C) XorINode(a,b) ) ); 1824 break; 1825 case Bytecodes::_ishl: 1826 b = pop(); a = pop(); 1827 push( _gvn.transform( new (C) LShiftINode(a,b) ) ); 1828 break; 1829 case Bytecodes::_ishr: 1830 b = pop(); a = pop(); 1831 push( _gvn.transform( new (C) RShiftINode(a,b) ) ); 1832 break; 1833 case Bytecodes::_iushr: 1834 b = pop(); a = pop(); 1835 push( _gvn.transform( new (C) URShiftINode(a,b) ) ); 1836 break; 1837 1838 case Bytecodes::_fneg: 1839 a = pop(); 1840 b = _gvn.transform(new (C) NegFNode (a)); 1841 push(b); 1842 break; 1843 1844 case Bytecodes::_fsub: 1845 b = pop(); 1846 a = pop(); 1847 c = _gvn.transform( new (C) SubFNode(a,b) ); 1848 d = precision_rounding(c); 1849 push( d ); 1850 break; 1851 1852 case Bytecodes::_fadd: 1853 b = pop(); 1854 a = pop(); 1855 c = _gvn.transform( new (C) AddFNode(a,b) ); 1856 d = precision_rounding(c); 1857 push( d ); 1858 break; 1859 1860 case Bytecodes::_fmul: 1861 b = pop(); 1862 a = pop(); 1863 c = _gvn.transform( new (C) MulFNode(a,b) ); 1864 d = precision_rounding(c); 1865 push( d ); 1866 break; 1867 1868 case Bytecodes::_fdiv: 1869 b = pop(); 1870 a = pop(); 1871 c = _gvn.transform( new (C) DivFNode(0,a,b) ); 1872 d = precision_rounding(c); 1873 push( d ); 1874 break; 1875 1876 case Bytecodes::_frem: 1877 if (Matcher::has_match_rule(Op_ModF)) { 1878 // Generate a ModF node. 1879 b = pop(); 1880 a = pop(); 1881 c = _gvn.transform( new (C) ModFNode(0,a,b) ); 1882 d = precision_rounding(c); 1883 push( d ); 1884 } 1885 else { 1886 // Generate a call. 1887 modf(); 1888 } 1889 break; 1890 1891 case Bytecodes::_fcmpl: 1892 b = pop(); 1893 a = pop(); 1894 c = _gvn.transform( new (C) CmpF3Node( a, b)); 1895 push(c); 1896 break; 1897 case Bytecodes::_fcmpg: 1898 b = pop(); 1899 a = pop(); 1900 1901 // Same as fcmpl but need to flip the unordered case. Swap the inputs, 1902 // which negates the result sign except for unordered. Flip the unordered 1903 // as well by using CmpF3 which implements unordered-lesser instead of 1904 // unordered-greater semantics. Finally, commute the result bits. Result 1905 // is same as using a CmpF3Greater except we did it with CmpF3 alone. 1906 c = _gvn.transform( new (C) CmpF3Node( b, a)); 1907 c = _gvn.transform( new (C) SubINode(_gvn.intcon(0),c) ); 1908 push(c); 1909 break; 1910 1911 case Bytecodes::_f2i: 1912 a = pop(); 1913 push(_gvn.transform(new (C) ConvF2INode(a))); 1914 break; 1915 1916 case Bytecodes::_d2i: 1917 a = pop_pair(); 1918 b = _gvn.transform(new (C) ConvD2INode(a)); 1919 push( b ); 1920 break; 1921 1922 case Bytecodes::_f2d: 1923 a = pop(); 1924 b = _gvn.transform( new (C) ConvF2DNode(a)); 1925 push_pair( b ); 1926 break; 1927 1928 case Bytecodes::_d2f: 1929 a = pop_pair(); 1930 b = _gvn.transform( new (C) ConvD2FNode(a)); 1931 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) 1932 //b = _gvn.transform(new (C) RoundFloatNode(0, b) ); 1933 push( b ); 1934 break; 1935 1936 case Bytecodes::_l2f: 1937 if (Matcher::convL2FSupported()) { 1938 a = pop_pair(); 1939 b = _gvn.transform( new (C) ConvL2FNode(a)); 1940 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. 1941 // Rather than storing the result into an FP register then pushing 1942 // out to memory to round, the machine instruction that implements 1943 // ConvL2D is responsible for rounding. 1944 // c = precision_rounding(b); 1945 c = _gvn.transform(b); 1946 push(c); 1947 } else { 1948 l2f(); 1949 } 1950 break; 1951 1952 case Bytecodes::_l2d: 1953 a = pop_pair(); 1954 b = _gvn.transform( new (C) ConvL2DNode(a)); 1955 // For i486.ad, rounding is always necessary (see _l2f above). 1956 // c = dprecision_rounding(b); 1957 c = _gvn.transform(b); 1958 push_pair(c); 1959 break; 1960 1961 case Bytecodes::_f2l: 1962 a = pop(); 1963 b = _gvn.transform( new (C) ConvF2LNode(a)); 1964 push_pair(b); 1965 break; 1966 1967 case Bytecodes::_d2l: 1968 a = pop_pair(); 1969 b = _gvn.transform( new (C) ConvD2LNode(a)); 1970 push_pair(b); 1971 break; 1972 1973 case Bytecodes::_dsub: 1974 b = pop_pair(); 1975 a = pop_pair(); 1976 c = _gvn.transform( new (C) SubDNode(a,b) ); 1977 d = dprecision_rounding(c); 1978 push_pair( d ); 1979 break; 1980 1981 case Bytecodes::_dadd: 1982 b = pop_pair(); 1983 a = pop_pair(); 1984 c = _gvn.transform( new (C) AddDNode(a,b) ); 1985 d = dprecision_rounding(c); 1986 push_pair( d ); 1987 break; 1988 1989 case Bytecodes::_dmul: 1990 b = pop_pair(); 1991 a = pop_pair(); 1992 c = _gvn.transform( new (C) MulDNode(a,b) ); 1993 d = dprecision_rounding(c); 1994 push_pair( d ); 1995 break; 1996 1997 case Bytecodes::_ddiv: 1998 b = pop_pair(); 1999 a = pop_pair(); 2000 c = _gvn.transform( new (C) DivDNode(0,a,b) ); 2001 d = dprecision_rounding(c); 2002 push_pair( d ); 2003 break; 2004 2005 case Bytecodes::_dneg: 2006 a = pop_pair(); 2007 b = _gvn.transform(new (C) NegDNode (a)); 2008 push_pair(b); 2009 break; 2010 2011 case Bytecodes::_drem: 2012 if (Matcher::has_match_rule(Op_ModD)) { 2013 // Generate a ModD node. 2014 b = pop_pair(); 2015 a = pop_pair(); 2016 // a % b 2017 2018 c = _gvn.transform( new (C) ModDNode(0,a,b) ); 2019 d = dprecision_rounding(c); 2020 push_pair( d ); 2021 } 2022 else { 2023 // Generate a call. 2024 modd(); 2025 } 2026 break; 2027 2028 case Bytecodes::_dcmpl: 2029 b = pop_pair(); 2030 a = pop_pair(); 2031 c = _gvn.transform( new (C) CmpD3Node( a, b)); 2032 push(c); 2033 break; 2034 2035 case Bytecodes::_dcmpg: 2036 b = pop_pair(); 2037 a = pop_pair(); 2038 // Same as dcmpl but need to flip the unordered case. 2039 // Commute the inputs, which negates the result sign except for unordered. 2040 // Flip the unordered as well by using CmpD3 which implements 2041 // unordered-lesser instead of unordered-greater semantics. 2042 // Finally, negate the result bits. Result is same as using a 2043 // CmpD3Greater except we did it with CmpD3 alone. 2044 c = _gvn.transform( new (C) CmpD3Node( b, a)); 2045 c = _gvn.transform( new (C) SubINode(_gvn.intcon(0),c) ); 2046 push(c); 2047 break; 2048 2049 2050 // Note for longs -> lo word is on TOS, hi word is on TOS - 1 2051 case Bytecodes::_land: 2052 b = pop_pair(); 2053 a = pop_pair(); 2054 c = _gvn.transform( new (C) AndLNode(a,b) ); 2055 push_pair(c); 2056 break; 2057 case Bytecodes::_lor: 2058 b = pop_pair(); 2059 a = pop_pair(); 2060 c = _gvn.transform( new (C) OrLNode(a,b) ); 2061 push_pair(c); 2062 break; 2063 case Bytecodes::_lxor: 2064 b = pop_pair(); 2065 a = pop_pair(); 2066 c = _gvn.transform( new (C) XorLNode(a,b) ); 2067 push_pair(c); 2068 break; 2069 2070 case Bytecodes::_lshl: 2071 b = pop(); // the shift count 2072 a = pop_pair(); // value to be shifted 2073 c = _gvn.transform( new (C) LShiftLNode(a,b) ); 2074 push_pair(c); 2075 break; 2076 case Bytecodes::_lshr: 2077 b = pop(); // the shift count 2078 a = pop_pair(); // value to be shifted 2079 c = _gvn.transform( new (C) RShiftLNode(a,b) ); 2080 push_pair(c); 2081 break; 2082 case Bytecodes::_lushr: 2083 b = pop(); // the shift count 2084 a = pop_pair(); // value to be shifted 2085 c = _gvn.transform( new (C) URShiftLNode(a,b) ); 2086 push_pair(c); 2087 break; 2088 case Bytecodes::_lmul: 2089 b = pop_pair(); 2090 a = pop_pair(); 2091 c = _gvn.transform( new (C) MulLNode(a,b) ); 2092 push_pair(c); 2093 break; 2094 2095 case Bytecodes::_lrem: 2096 // Must keep both values on the expression-stack during null-check 2097 assert(peek(0) == top(), "long word order"); 2098 zero_check_long(peek(1)); 2099 // Compile-time detect of null-exception? 2100 if (stopped()) return; 2101 b = pop_pair(); 2102 a = pop_pair(); 2103 c = _gvn.transform( new (C) ModLNode(control(),a,b) ); 2104 push_pair(c); 2105 break; 2106 2107 case Bytecodes::_ldiv: 2108 // Must keep both values on the expression-stack during null-check 2109 assert(peek(0) == top(), "long word order"); 2110 zero_check_long(peek(1)); 2111 // Compile-time detect of null-exception? 2112 if (stopped()) return; 2113 b = pop_pair(); 2114 a = pop_pair(); 2115 c = _gvn.transform( new (C) DivLNode(control(),a,b) ); 2116 push_pair(c); 2117 break; 2118 2119 case Bytecodes::_ladd: 2120 b = pop_pair(); 2121 a = pop_pair(); 2122 c = _gvn.transform( new (C) AddLNode(a,b) ); 2123 push_pair(c); 2124 break; 2125 case Bytecodes::_lsub: 2126 b = pop_pair(); 2127 a = pop_pair(); 2128 c = _gvn.transform( new (C) SubLNode(a,b) ); 2129 push_pair(c); 2130 break; 2131 case Bytecodes::_lcmp: 2132 // Safepoints are now inserted _before_ branches. The long-compare 2133 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a 2134 // slew of control flow. These are usually followed by a CmpI vs zero and 2135 // a branch; this pattern then optimizes to the obvious long-compare and 2136 // branch. However, if the branch is backwards there's a Safepoint 2137 // inserted. The inserted Safepoint captures the JVM state at the 2138 // pre-branch point, i.e. it captures the 3-way value. Thus if a 2139 // long-compare is used to control a loop the debug info will force 2140 // computation of the 3-way value, even though the generated code uses a 2141 // long-compare and branch. We try to rectify the situation by inserting 2142 // a SafePoint here and have it dominate and kill the safepoint added at a 2143 // following backwards branch. At this point the JVM state merely holds 2 2144 // longs but not the 3-way value. 2145 if( UseLoopSafepoints ) { 2146 switch( iter().next_bc() ) { 2147 case Bytecodes::_ifgt: 2148 case Bytecodes::_iflt: 2149 case Bytecodes::_ifge: 2150 case Bytecodes::_ifle: 2151 case Bytecodes::_ifne: 2152 case Bytecodes::_ifeq: 2153 // If this is a backwards branch in the bytecodes, add Safepoint 2154 maybe_add_safepoint(iter().next_get_dest()); 2155 } 2156 } 2157 b = pop_pair(); 2158 a = pop_pair(); 2159 c = _gvn.transform( new (C) CmpL3Node( a, b )); 2160 push(c); 2161 break; 2162 2163 case Bytecodes::_lneg: 2164 a = pop_pair(); 2165 b = _gvn.transform( new (C) SubLNode(longcon(0),a)); 2166 push_pair(b); 2167 break; 2168 case Bytecodes::_l2i: 2169 a = pop_pair(); 2170 push( _gvn.transform( new (C) ConvL2INode(a))); 2171 break; 2172 case Bytecodes::_i2l: 2173 a = pop(); 2174 b = _gvn.transform( new (C) ConvI2LNode(a)); 2175 push_pair(b); 2176 break; 2177 case Bytecodes::_i2b: 2178 // Sign extend 2179 a = pop(); 2180 a = _gvn.transform( new (C) LShiftINode(a,_gvn.intcon(24)) ); 2181 a = _gvn.transform( new (C) RShiftINode(a,_gvn.intcon(24)) ); 2182 push( a ); 2183 break; 2184 case Bytecodes::_i2s: 2185 a = pop(); 2186 a = _gvn.transform( new (C) LShiftINode(a,_gvn.intcon(16)) ); 2187 a = _gvn.transform( new (C) RShiftINode(a,_gvn.intcon(16)) ); 2188 push( a ); 2189 break; 2190 case Bytecodes::_i2c: 2191 a = pop(); 2192 push( _gvn.transform( new (C) AndINode(a,_gvn.intcon(0xFFFF)) ) ); 2193 break; 2194 2195 case Bytecodes::_i2f: 2196 a = pop(); 2197 b = _gvn.transform( new (C) ConvI2FNode(a) ) ; 2198 c = precision_rounding(b); 2199 push (b); 2200 break; 2201 2202 case Bytecodes::_i2d: 2203 a = pop(); 2204 b = _gvn.transform( new (C) ConvI2DNode(a)); 2205 push_pair(b); 2206 break; 2207 2208 case Bytecodes::_iinc: // Increment local 2209 i = iter().get_index(); // Get local index 2210 set_local( i, _gvn.transform( new (C) AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) ); 2211 break; 2212 2213 // Exit points of synchronized methods must have an unlock node 2214 case Bytecodes::_return: 2215 return_current(NULL); 2216 break; 2217 2218 case Bytecodes::_ireturn: 2219 case Bytecodes::_areturn: 2220 case Bytecodes::_freturn: 2221 return_current(pop()); 2222 break; 2223 case Bytecodes::_lreturn: 2224 return_current(pop_pair()); 2225 break; 2226 case Bytecodes::_dreturn: 2227 return_current(pop_pair()); 2228 break; 2229 2230 case Bytecodes::_athrow: 2270 taken = method()->scale_count(taken); 2271 target_block->set_count(taken); 2272 break; 2273 } 2274 2275 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null; 2276 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null; 2277 handle_if_null: 2278 // If this is a backwards branch in the bytecodes, add Safepoint 2279 maybe_add_safepoint(iter().get_dest()); 2280 a = null(); 2281 b = pop(); 2282 if (!_gvn.type(b)->speculative_maybe_null() && 2283 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2284 inc_sp(1); 2285 Node* null_ctl = top(); 2286 b = null_check_oop(b, &null_ctl, true, true, true); 2287 assert(null_ctl->is_top(), "no null control here"); 2288 dec_sp(1); 2289 } 2290 c = _gvn.transform( new (C) CmpPNode(b, a) ); 2291 do_ifnull(btest, c); 2292 break; 2293 2294 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp; 2295 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp; 2296 handle_if_acmp: 2297 // If this is a backwards branch in the bytecodes, add Safepoint 2298 maybe_add_safepoint(iter().get_dest()); 2299 a = pop(); 2300 b = pop(); 2301 c = _gvn.transform( new (C) CmpPNode(b, a) ); 2302 c = optimize_cmp_with_klass(c); 2303 do_if(btest, c); 2304 break; 2305 2306 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx; 2307 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx; 2308 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx; 2309 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx; 2310 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx; 2311 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx; 2312 handle_ifxx: 2313 // If this is a backwards branch in the bytecodes, add Safepoint 2314 maybe_add_safepoint(iter().get_dest()); 2315 a = _gvn.intcon(0); 2316 b = pop(); 2317 c = _gvn.transform( new (C) CmpINode(b, a) ); 2318 do_if(btest, c); 2319 break; 2320 2321 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp; 2322 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp; 2323 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp; 2324 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp; 2325 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp; 2326 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp; 2327 handle_if_icmp: 2328 // If this is a backwards branch in the bytecodes, add Safepoint 2329 maybe_add_safepoint(iter().get_dest()); 2330 a = pop(); 2331 b = pop(); 2332 c = _gvn.transform( new (C) CmpINode( b, a ) ); 2333 do_if(btest, c); 2334 break; 2335 2336 case Bytecodes::_tableswitch: 2337 do_tableswitch(); 2338 break; 2339 2340 case Bytecodes::_lookupswitch: 2341 do_lookupswitch(); 2342 break; 2343 2344 case Bytecodes::_invokestatic: 2345 case Bytecodes::_invokedynamic: 2346 case Bytecodes::_invokespecial: 2347 case Bytecodes::_invokevirtual: 2348 case Bytecodes::_invokeinterface: 2349 do_call(); 2350 break; 2351 case Bytecodes::_checkcast: 2352 do_checkcast(); | 113 uncommon_trap(Deoptimization::Reason_unloaded, 114 Deoptimization::Action_reinterpret, 115 arytype->klass(), "!loaded array"); 116 return top(); 117 } 118 119 // Do the range check 120 if (GenerateRangeChecks && need_range_check) { 121 Node* tst; 122 if (sizetype->_hi <= 0) { 123 // The greatest array bound is negative, so we can conclude that we're 124 // compiling unreachable code, but the unsigned compare trick used below 125 // only works with non-negative lengths. Instead, hack "tst" to be zero so 126 // the uncommon_trap path will always be taken. 127 tst = _gvn.intcon(0); 128 } else { 129 // Range is constant in array-oop, so we can use the original state of mem 130 Node* len = load_array_length(ary); 131 132 // Test length vs index (standard trick using unsigned compare) 133 Node* chk = _gvn.transform( new CmpUNode(idx, len) ); 134 BoolTest::mask btest = BoolTest::lt; 135 tst = _gvn.transform( new BoolNode(chk, btest) ); 136 } 137 // Branch to failure if out of bounds 138 { BuildCutout unless(this, tst, PROB_MAX); 139 if (C->allow_range_check_smearing()) { 140 // Do not use builtin_throw, since range checks are sometimes 141 // made more stringent by an optimistic transformation. 142 // This creates "tentative" range checks at this point, 143 // which are not guaranteed to throw exceptions. 144 // See IfNode::Ideal, is_range_check, adjust_check. 145 uncommon_trap(Deoptimization::Reason_range_check, 146 Deoptimization::Action_make_not_entrant, 147 NULL, "range_check"); 148 } else { 149 // If we have already recompiled with the range-check-widening 150 // heroic optimization turned off, then we must really be throwing 151 // range check exceptions. 152 builtin_throw(Deoptimization::Reason_range_check, idx); 153 } 154 } 155 } 156 // Check for always knowing you are throwing a range-check exception 157 if (stopped()) return top(); 158 159 Node* ptr = array_element_address(ary, idx, type, sizetype); 160 161 if (result2 != NULL) *result2 = elemtype; 162 163 assert(ptr != top(), "top should go hand-in-hand with stopped"); 164 165 return ptr; 166 } 167 168 169 // returns IfNode 170 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask) { 171 Node *cmp = _gvn.transform( new CmpINode( a, b)); // two cases: shiftcount > 32 and shiftcount <= 32 172 Node *tst = _gvn.transform( new BoolNode( cmp, mask)); 173 IfNode *iff = create_and_map_if( control(), tst, ((mask == BoolTest::eq) ? PROB_STATIC_INFREQUENT : PROB_FAIR), COUNT_UNKNOWN ); 174 return iff; 175 } 176 177 // return Region node 178 Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) { 179 Node *region = new RegionNode(3); // 2 results 180 record_for_igvn(region); 181 region->init_req(1, iffalse); 182 region->init_req(2, iftrue ); 183 _gvn.set_type(region, Type::CONTROL); 184 region = _gvn.transform(region); 185 set_control (region); 186 return region; 187 } 188 189 190 //------------------------------helper for tableswitch------------------------- 191 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { 192 // True branch, use existing map info 193 { PreserveJVMState pjvms(this); 194 Node *iftrue = _gvn.transform( new IfTrueNode (iff) ); 195 set_control( iftrue ); 196 profile_switch_case(prof_table_index); 197 merge_new_path(dest_bci_if_true); 198 } 199 200 // False branch 201 Node *iffalse = _gvn.transform( new IfFalseNode(iff) ); 202 set_control( iffalse ); 203 } 204 205 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) { 206 // True branch, use existing map info 207 { PreserveJVMState pjvms(this); 208 Node *iffalse = _gvn.transform( new IfFalseNode (iff) ); 209 set_control( iffalse ); 210 profile_switch_case(prof_table_index); 211 merge_new_path(dest_bci_if_true); 212 } 213 214 // False branch 215 Node *iftrue = _gvn.transform( new IfTrueNode(iff) ); 216 set_control( iftrue ); 217 } 218 219 void Parse::jump_if_always_fork(int dest_bci, int prof_table_index) { 220 // False branch, use existing map and control() 221 profile_switch_case(prof_table_index); 222 merge_new_path(dest_bci); 223 } 224 225 226 extern "C" { 227 static int jint_cmp(const void *i, const void *j) { 228 int a = *(jint *)i; 229 int b = *(jint *)j; 230 return a > b ? 1 : a < b ? -1 : 0; 231 } 232 } 233 234 235 // Default value for methodData switch indexing. Must be a negative value to avoid 423 // If a guard test will eliminate very sparse end ranges, then 424 // it is worth the cost of an extra jump. 425 if (total_outlier_size > (MaxJumpTableSparseness * 4)) { 426 needs_guard = true; 427 if (default_dest == lo->dest()) lo++; 428 if (default_dest == hi->dest()) hi--; 429 } 430 431 // Find the total number of cases and ranges 432 int64 num_cases = ((int64)hi->hi()) - ((int64)lo->lo()) + 1; 433 int num_range = hi - lo + 1; 434 435 // Don't create table if: too large, too small, or too sparse. 436 if (num_cases < MinJumpTableSize || num_cases > MaxJumpTableSize) 437 return false; 438 if (num_cases > (MaxJumpTableSparseness * num_range)) 439 return false; 440 441 // Normalize table lookups to zero 442 int lowval = lo->lo(); 443 key_val = _gvn.transform( new SubINode(key_val, _gvn.intcon(lowval)) ); 444 445 // Generate a guard to protect against input keyvals that aren't 446 // in the switch domain. 447 if (needs_guard) { 448 Node* size = _gvn.intcon(num_cases); 449 Node* cmp = _gvn.transform( new CmpUNode(key_val, size) ); 450 Node* tst = _gvn.transform( new BoolNode(cmp, BoolTest::ge) ); 451 IfNode* iff = create_and_map_if( control(), tst, PROB_FAIR, COUNT_UNKNOWN); 452 jump_if_true_fork(iff, default_dest, NullTableIndex); 453 } 454 455 // Create an ideal node JumpTable that has projections 456 // of all possible ranges for a switch statement 457 // The key_val input must be converted to a pointer offset and scaled. 458 // Compare Parse::array_addressing above. 459 #ifdef _LP64 460 // Clean the 32-bit int into a real 64-bit offset. 461 // Otherwise, the jint value 0 might turn into an offset of 0x0800000000. 462 const TypeLong* lkeytype = TypeLong::make(CONST64(0), num_cases-1, Type::WidenMin); 463 key_val = _gvn.transform( new ConvI2LNode(key_val, lkeytype) ); 464 #endif 465 // Shift the value by wordsize so we have an index into the table, rather 466 // than a switch value 467 Node *shiftWord = _gvn.MakeConX(wordSize); 468 key_val = _gvn.transform( new MulXNode( key_val, shiftWord)); 469 470 // Create the JumpNode 471 Node* jtn = _gvn.transform( new JumpNode(control(), key_val, num_cases) ); 472 473 // These are the switch destinations hanging off the jumpnode 474 int i = 0; 475 for (SwitchRange* r = lo; r <= hi; r++) { 476 for (int64 j = r->lo(); j <= r->hi(); j++, i++) { 477 Node* input = _gvn.transform(new JumpProjNode(jtn, i, r->dest(), (int)(j - lowval))); 478 { 479 PreserveJVMState pjvms(this); 480 set_control(input); 481 jump_if_always_fork(r->dest(), r->table_index()); 482 } 483 } 484 } 485 assert(i == num_cases, "miscount of cases"); 486 stop_and_kill_map(); // no more uses for this JVMS 487 return true; 488 } 489 490 //----------------------------jump_switch_ranges------------------------------- 491 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) { 492 Block* switch_block = block(); 493 494 if (switch_depth == 0) { 495 // Do special processing for the top-level call. 496 assert(lo->lo() == min_jint, "initial range must exhaust Type::INT"); 497 assert(hi->hi() == max_jint, "initial range must exhaust Type::INT"); 558 559 Node *test_val = _gvn.intcon(mid->lo()); 560 561 if (mid->is_singleton()) { 562 IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne); 563 jump_if_false_fork(iff_ne, mid->dest(), mid->table_index()); 564 565 // Special Case: If there are exactly three ranges, and the high 566 // and low range each go to the same place, omit the "gt" test, 567 // since it will not discriminate anything. 568 bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest()); 569 if (eq_test_only) { 570 assert(mid == hi-1, ""); 571 } 572 573 // if there is a higher range, test for it and process it: 574 if (mid < hi && !eq_test_only) { 575 // two comparisons of same values--should enable 1 test for 2 branches 576 // Use BoolTest::le instead of BoolTest::gt 577 IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le); 578 Node *iftrue = _gvn.transform( new IfTrueNode(iff_le) ); 579 Node *iffalse = _gvn.transform( new IfFalseNode(iff_le) ); 580 { PreserveJVMState pjvms(this); 581 set_control(iffalse); 582 jump_switch_ranges(key_val, mid+1, hi, switch_depth+1); 583 } 584 set_control(iftrue); 585 } 586 587 } else { 588 // mid is a range, not a singleton, so treat mid..hi as a unit 589 IfNode *iff_ge = jump_if_fork_int(key_val, test_val, BoolTest::ge); 590 591 // if there is a higher range, test for it and process it: 592 if (mid == hi) { 593 jump_if_true_fork(iff_ge, mid->dest(), mid->table_index()); 594 } else { 595 Node *iftrue = _gvn.transform( new IfTrueNode(iff_ge) ); 596 Node *iffalse = _gvn.transform( new IfFalseNode(iff_ge) ); 597 { PreserveJVMState pjvms(this); 598 set_control(iftrue); 599 jump_switch_ranges(key_val, mid, hi, switch_depth+1); 600 } 601 set_control(iffalse); 602 } 603 } 604 605 // in any case, process the lower range 606 jump_switch_ranges(key_val, lo, mid-1, switch_depth+1); 607 } 608 609 // Decrease pred_count for each successor after all is done. 610 if (switch_depth == 0) { 611 int unique_successors = switch_block->num_successors(); 612 for (int i = 0; i < unique_successors; i++) { 613 Block* target = switch_block->successor_at(i); 614 // Throw away the pre-allocated path for each unique successor. 615 target->next_path_num(); 616 } 631 (int) (hi-lo+1), nsing, _max_switch_depth, _est_switch_depth); 632 if (_max_switch_depth > _est_switch_depth) { 633 tty->print_cr("******** BAD SWITCH DEPTH ********"); 634 } 635 tty->print(" "); 636 for( r = lo; r <= hi; r++ ) { 637 r->print(); 638 } 639 tty->cr(); 640 } 641 #endif 642 } 643 644 void Parse::modf() { 645 Node *f2 = pop(); 646 Node *f1 = pop(); 647 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(), 648 CAST_FROM_FN_PTR(address, SharedRuntime::frem), 649 "frem", NULL, //no memory effects 650 f1, f2); 651 Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 652 653 push(res); 654 } 655 656 void Parse::modd() { 657 Node *d2 = pop_pair(); 658 Node *d1 = pop_pair(); 659 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), 660 CAST_FROM_FN_PTR(address, SharedRuntime::drem), 661 "drem", NULL, //no memory effects 662 d1, top(), d2, top()); 663 Node* res_d = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 664 665 #ifdef ASSERT 666 Node* res_top = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 1)); 667 assert(res_top == top(), "second value must be top"); 668 #endif 669 670 push_pair(res_d); 671 } 672 673 void Parse::l2f() { 674 Node* f2 = pop(); 675 Node* f1 = pop(); 676 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(), 677 CAST_FROM_FN_PTR(address, SharedRuntime::l2f), 678 "l2f", NULL, //no memory effects 679 f1, f2); 680 Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0)); 681 682 push(res); 683 } 684 685 void Parse::do_irem() { 686 // Must keep both values on the expression-stack during null-check 687 zero_check_int(peek()); 688 // Compile-time detect of null-exception? 689 if (stopped()) return; 690 691 Node* b = pop(); 692 Node* a = pop(); 693 694 const Type *t = _gvn.type(b); 695 if (t != Type::TOP) { 696 const TypeInt *ti = t->is_int(); 697 if (ti->is_con()) { 698 int divisor = ti->get_con(); 699 // check for positive power of 2 700 if (divisor > 0 && 701 (divisor & ~(divisor-1)) == divisor) { 702 // yes ! 703 Node *mask = _gvn.intcon((divisor - 1)); 704 // Sigh, must handle negative dividends 705 Node *zero = _gvn.intcon(0); 706 IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt); 707 Node *iff = _gvn.transform( new IfFalseNode(ifff) ); 708 Node *ift = _gvn.transform( new IfTrueNode (ifff) ); 709 Node *reg = jump_if_join(ift, iff); 710 Node *phi = PhiNode::make(reg, NULL, TypeInt::INT); 711 // Negative path; negate/and/negate 712 Node *neg = _gvn.transform( new SubINode(zero, a) ); 713 Node *andn= _gvn.transform( new AndINode(neg, mask) ); 714 Node *negn= _gvn.transform( new SubINode(zero, andn) ); 715 phi->init_req(1, negn); 716 // Fast positive case 717 Node *andx = _gvn.transform( new AndINode(a, mask) ); 718 phi->init_req(2, andx); 719 // Push the merge 720 push( _gvn.transform(phi) ); 721 return; 722 } 723 } 724 } 725 // Default case 726 push( _gvn.transform( new ModINode(control(),a,b) ) ); 727 } 728 729 // Handle jsr and jsr_w bytecode 730 void Parse::do_jsr() { 731 assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode"); 732 733 // Store information about current state, tagged with new _jsr_bci 734 int return_bci = iter().next_bci(); 735 int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest(); 736 737 // Update method data 738 profile_taken_branch(jsr_bci); 739 740 // The way we do things now, there is only one successor block 741 // for the jsr, because the target code is cloned by ciTypeFlow. 742 Block* target = successor_for_bci(jsr_bci); 743 744 // What got pushed? 745 const Type* ret_addr = target->peek(); 746 assert(ret_addr->singleton(), "must be a constant (cloned jsr body)"); 983 repush_if_args(); // to gather stats on loop 984 // We need to mark this branch as taken so that if we recompile we will 985 // see that it is possible. In the tiered system the interpreter doesn't 986 // do profiling and by the time we get to the lower tier from the interpreter 987 // the path may be cold again. Make sure it doesn't look untaken 988 profile_taken_branch(target_bci, !ProfileInterpreter); 989 uncommon_trap(Deoptimization::Reason_unreached, 990 Deoptimization::Action_reinterpret, 991 NULL, "cold"); 992 if (C->eliminate_boxing()) { 993 // Mark the successor blocks as parsed 994 branch_block->next_path_num(); 995 next_block->next_path_num(); 996 } 997 return; 998 } 999 1000 explicit_null_checks_inserted++; 1001 1002 // Generate real control flow 1003 Node *tst = _gvn.transform( new BoolNode( c, btest ) ); 1004 1005 // Sanity check the probability value 1006 assert(prob > 0.0f,"Bad probability in Parser"); 1007 // Need xform to put node in hash table 1008 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt ); 1009 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1010 // True branch 1011 { PreserveJVMState pjvms(this); 1012 Node* iftrue = _gvn.transform( new IfTrueNode (iff) ); 1013 set_control(iftrue); 1014 1015 if (stopped()) { // Path is dead? 1016 explicit_null_checks_elided++; 1017 if (C->eliminate_boxing()) { 1018 // Mark the successor block as parsed 1019 branch_block->next_path_num(); 1020 } 1021 } else { // Path is live. 1022 // Update method data 1023 profile_taken_branch(target_bci); 1024 adjust_map_after_if(btest, c, prob, branch_block, next_block); 1025 if (!stopped()) { 1026 merge(target_bci); 1027 } 1028 } 1029 } 1030 1031 // False branch 1032 Node* iffalse = _gvn.transform( new IfFalseNode(iff) ); 1033 set_control(iffalse); 1034 1035 if (stopped()) { // Path is dead? 1036 explicit_null_checks_elided++; 1037 if (C->eliminate_boxing()) { 1038 // Mark the successor block as parsed 1039 next_block->next_path_num(); 1040 } 1041 } else { // Path is live. 1042 // Update method data 1043 profile_not_taken_branch(); 1044 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, 1045 next_block, branch_block); 1046 } 1047 } 1048 1049 //------------------------------------do_if------------------------------------ 1050 void Parse::do_if(BoolTest::mask btest, Node* c) { 1051 int target_bci = iter().get_dest(); 1052 1075 // Mark the successor blocks as parsed 1076 branch_block->next_path_num(); 1077 next_block->next_path_num(); 1078 } 1079 return; 1080 } 1081 1082 // Sanity check the probability value 1083 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser"); 1084 1085 bool taken_if_true = true; 1086 // Convert BoolTest to canonical form: 1087 if (!BoolTest(btest).is_canonical()) { 1088 btest = BoolTest(btest).negate(); 1089 taken_if_true = false; 1090 // prob is NOT updated here; it remains the probability of the taken 1091 // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). 1092 } 1093 assert(btest != BoolTest::eq, "!= is the only canonical exact test"); 1094 1095 Node* tst0 = new BoolNode(c, btest); 1096 Node* tst = _gvn.transform(tst0); 1097 BoolTest::mask taken_btest = BoolTest::illegal; 1098 BoolTest::mask untaken_btest = BoolTest::illegal; 1099 1100 if (tst->is_Bool()) { 1101 // Refresh c from the transformed bool node, since it may be 1102 // simpler than the original c. Also re-canonicalize btest. 1103 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). 1104 // That can arise from statements like: if (x instanceof C) ... 1105 if (tst != tst0) { 1106 // Canonicalize one more time since transform can change it. 1107 btest = tst->as_Bool()->_test._test; 1108 if (!BoolTest(btest).is_canonical()) { 1109 // Reverse edges one more time... 1110 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) ); 1111 btest = tst->as_Bool()->_test._test; 1112 assert(BoolTest(btest).is_canonical(), "sanity"); 1113 taken_if_true = !taken_if_true; 1114 } 1115 c = tst->in(1); 1116 } 1117 BoolTest::mask neg_btest = BoolTest(btest).negate(); 1118 taken_btest = taken_if_true ? btest : neg_btest; 1119 untaken_btest = taken_if_true ? neg_btest : btest; 1120 } 1121 1122 // Generate real control flow 1123 float true_prob = (taken_if_true ? prob : untaken_prob); 1124 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt); 1125 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1126 Node* taken_branch = new IfTrueNode(iff); 1127 Node* untaken_branch = new IfFalseNode(iff); 1128 if (!taken_if_true) { // Finish conversion to canonical form 1129 Node* tmp = taken_branch; 1130 taken_branch = untaken_branch; 1131 untaken_branch = tmp; 1132 } 1133 1134 // Branch is taken: 1135 { PreserveJVMState pjvms(this); 1136 taken_branch = _gvn.transform(taken_branch); 1137 set_control(taken_branch); 1138 1139 if (stopped()) { 1140 if (C->eliminate_boxing()) { 1141 // Mark the successor block as parsed 1142 branch_block->next_path_num(); 1143 } 1144 } else { 1145 // Update method data 1146 profile_taken_branch(target_bci); 1147 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block); 1271 Node* con, const Type* tcon, 1272 Node* val, const Type* tval) { 1273 // Look for opportunities to sharpen the type of a node 1274 // whose klass is compared with a constant klass. 1275 if (btest == BoolTest::eq && tcon->isa_klassptr()) { 1276 Node* obj = extract_obj_from_klass_load(&_gvn, val); 1277 const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type(); 1278 if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) { 1279 // Found: 1280 // Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]) 1281 // or the narrowOop equivalent. 1282 const Type* obj_type = _gvn.type(obj); 1283 const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr(); 1284 if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type && 1285 tboth->higher_equal(obj_type)) { 1286 // obj has to be of the exact type Foo if the CmpP succeeds. 1287 int obj_in_map = map()->find_edge(obj); 1288 JVMState* jvms = this->jvms(); 1289 if (obj_in_map >= 0 && 1290 (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) { 1291 TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth); 1292 const Type* tcc = ccast->as_Type()->type(); 1293 assert(tcc != obj_type && tcc->higher_equal(obj_type), "must improve"); 1294 // Delay transform() call to allow recovery of pre-cast value 1295 // at the control merge. 1296 _gvn.set_type_bottom(ccast); 1297 record_for_igvn(ccast); 1298 // Here's the payoff. 1299 replace_in_map(obj, ccast); 1300 } 1301 } 1302 } 1303 } 1304 1305 int val_in_map = map()->find_edge(val); 1306 if (val_in_map < 0) return; // replace_in_map would be useless 1307 { 1308 JVMState* jvms = this->jvms(); 1309 if (!(jvms->is_loc(val_in_map) || 1310 jvms->is_stk(val_in_map))) 1311 return; // again, it would be useless 1312 } 1313 1314 // Check for a comparison to a constant, and "know" that the compared 1315 // value is constrained on this path. 1316 assert(tcon->singleton(), ""); 1317 ConstraintCastNode* ccast = NULL; 1318 Node* cast = NULL; 1319 1320 switch (btest) { 1321 case BoolTest::eq: // Constant test? 1322 { 1323 const Type* tboth = tcon->join_speculative(tval); 1324 if (tboth == tval) break; // Nothing to gain. 1325 if (tcon->isa_int()) { 1326 ccast = new CastIINode(val, tboth); 1327 } else if (tcon == TypePtr::NULL_PTR) { 1328 // Cast to null, but keep the pointer identity temporarily live. 1329 ccast = new CastPPNode(val, tboth); 1330 } else { 1331 const TypeF* tf = tcon->isa_float_constant(); 1332 const TypeD* td = tcon->isa_double_constant(); 1333 // Exclude tests vs float/double 0 as these could be 1334 // either +0 or -0. Just because you are equal to +0 1335 // doesn't mean you ARE +0! 1336 // Note, following code also replaces Long and Oop values. 1337 if ((!tf || tf->_f != 0.0) && 1338 (!td || td->_d != 0.0)) 1339 cast = con; // Replace non-constant val by con. 1340 } 1341 } 1342 break; 1343 1344 case BoolTest::ne: 1345 if (tcon == TypePtr::NULL_PTR) { 1346 cast = cast_not_null(val, false); 1347 } 1348 break; 1349 1775 break; 1776 1777 case Bytecodes::_putfield: 1778 do_putfield(); 1779 break; 1780 1781 case Bytecodes::_putstatic: 1782 do_putstatic(); 1783 break; 1784 1785 case Bytecodes::_irem: 1786 do_irem(); 1787 break; 1788 case Bytecodes::_idiv: 1789 // Must keep both values on the expression-stack during null-check 1790 zero_check_int(peek()); 1791 // Compile-time detect of null-exception? 1792 if (stopped()) return; 1793 b = pop(); 1794 a = pop(); 1795 push( _gvn.transform( new DivINode(control(),a,b) ) ); 1796 break; 1797 case Bytecodes::_imul: 1798 b = pop(); a = pop(); 1799 push( _gvn.transform( new MulINode(a,b) ) ); 1800 break; 1801 case Bytecodes::_iadd: 1802 b = pop(); a = pop(); 1803 push( _gvn.transform( new AddINode(a,b) ) ); 1804 break; 1805 case Bytecodes::_ineg: 1806 a = pop(); 1807 push( _gvn.transform( new SubINode(_gvn.intcon(0),a)) ); 1808 break; 1809 case Bytecodes::_isub: 1810 b = pop(); a = pop(); 1811 push( _gvn.transform( new SubINode(a,b) ) ); 1812 break; 1813 case Bytecodes::_iand: 1814 b = pop(); a = pop(); 1815 push( _gvn.transform( new AndINode(a,b) ) ); 1816 break; 1817 case Bytecodes::_ior: 1818 b = pop(); a = pop(); 1819 push( _gvn.transform( new OrINode(a,b) ) ); 1820 break; 1821 case Bytecodes::_ixor: 1822 b = pop(); a = pop(); 1823 push( _gvn.transform( new XorINode(a,b) ) ); 1824 break; 1825 case Bytecodes::_ishl: 1826 b = pop(); a = pop(); 1827 push( _gvn.transform( new LShiftINode(a,b) ) ); 1828 break; 1829 case Bytecodes::_ishr: 1830 b = pop(); a = pop(); 1831 push( _gvn.transform( new RShiftINode(a,b) ) ); 1832 break; 1833 case Bytecodes::_iushr: 1834 b = pop(); a = pop(); 1835 push( _gvn.transform( new URShiftINode(a,b) ) ); 1836 break; 1837 1838 case Bytecodes::_fneg: 1839 a = pop(); 1840 b = _gvn.transform(new NegFNode (a)); 1841 push(b); 1842 break; 1843 1844 case Bytecodes::_fsub: 1845 b = pop(); 1846 a = pop(); 1847 c = _gvn.transform( new SubFNode(a,b) ); 1848 d = precision_rounding(c); 1849 push( d ); 1850 break; 1851 1852 case Bytecodes::_fadd: 1853 b = pop(); 1854 a = pop(); 1855 c = _gvn.transform( new AddFNode(a,b) ); 1856 d = precision_rounding(c); 1857 push( d ); 1858 break; 1859 1860 case Bytecodes::_fmul: 1861 b = pop(); 1862 a = pop(); 1863 c = _gvn.transform( new MulFNode(a,b) ); 1864 d = precision_rounding(c); 1865 push( d ); 1866 break; 1867 1868 case Bytecodes::_fdiv: 1869 b = pop(); 1870 a = pop(); 1871 c = _gvn.transform( new DivFNode(0,a,b) ); 1872 d = precision_rounding(c); 1873 push( d ); 1874 break; 1875 1876 case Bytecodes::_frem: 1877 if (Matcher::has_match_rule(Op_ModF)) { 1878 // Generate a ModF node. 1879 b = pop(); 1880 a = pop(); 1881 c = _gvn.transform( new ModFNode(0,a,b) ); 1882 d = precision_rounding(c); 1883 push( d ); 1884 } 1885 else { 1886 // Generate a call. 1887 modf(); 1888 } 1889 break; 1890 1891 case Bytecodes::_fcmpl: 1892 b = pop(); 1893 a = pop(); 1894 c = _gvn.transform( new CmpF3Node( a, b)); 1895 push(c); 1896 break; 1897 case Bytecodes::_fcmpg: 1898 b = pop(); 1899 a = pop(); 1900 1901 // Same as fcmpl but need to flip the unordered case. Swap the inputs, 1902 // which negates the result sign except for unordered. Flip the unordered 1903 // as well by using CmpF3 which implements unordered-lesser instead of 1904 // unordered-greater semantics. Finally, commute the result bits. Result 1905 // is same as using a CmpF3Greater except we did it with CmpF3 alone. 1906 c = _gvn.transform( new CmpF3Node( b, a)); 1907 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 1908 push(c); 1909 break; 1910 1911 case Bytecodes::_f2i: 1912 a = pop(); 1913 push(_gvn.transform(new ConvF2INode(a))); 1914 break; 1915 1916 case Bytecodes::_d2i: 1917 a = pop_pair(); 1918 b = _gvn.transform(new ConvD2INode(a)); 1919 push( b ); 1920 break; 1921 1922 case Bytecodes::_f2d: 1923 a = pop(); 1924 b = _gvn.transform( new ConvF2DNode(a)); 1925 push_pair( b ); 1926 break; 1927 1928 case Bytecodes::_d2f: 1929 a = pop_pair(); 1930 b = _gvn.transform( new ConvD2FNode(a)); 1931 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) 1932 //b = _gvn.transform(new RoundFloatNode(0, b) ); 1933 push( b ); 1934 break; 1935 1936 case Bytecodes::_l2f: 1937 if (Matcher::convL2FSupported()) { 1938 a = pop_pair(); 1939 b = _gvn.transform( new ConvL2FNode(a)); 1940 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. 1941 // Rather than storing the result into an FP register then pushing 1942 // out to memory to round, the machine instruction that implements 1943 // ConvL2D is responsible for rounding. 1944 // c = precision_rounding(b); 1945 c = _gvn.transform(b); 1946 push(c); 1947 } else { 1948 l2f(); 1949 } 1950 break; 1951 1952 case Bytecodes::_l2d: 1953 a = pop_pair(); 1954 b = _gvn.transform( new ConvL2DNode(a)); 1955 // For i486.ad, rounding is always necessary (see _l2f above). 1956 // c = dprecision_rounding(b); 1957 c = _gvn.transform(b); 1958 push_pair(c); 1959 break; 1960 1961 case Bytecodes::_f2l: 1962 a = pop(); 1963 b = _gvn.transform( new ConvF2LNode(a)); 1964 push_pair(b); 1965 break; 1966 1967 case Bytecodes::_d2l: 1968 a = pop_pair(); 1969 b = _gvn.transform( new ConvD2LNode(a)); 1970 push_pair(b); 1971 break; 1972 1973 case Bytecodes::_dsub: 1974 b = pop_pair(); 1975 a = pop_pair(); 1976 c = _gvn.transform( new SubDNode(a,b) ); 1977 d = dprecision_rounding(c); 1978 push_pair( d ); 1979 break; 1980 1981 case Bytecodes::_dadd: 1982 b = pop_pair(); 1983 a = pop_pair(); 1984 c = _gvn.transform( new AddDNode(a,b) ); 1985 d = dprecision_rounding(c); 1986 push_pair( d ); 1987 break; 1988 1989 case Bytecodes::_dmul: 1990 b = pop_pair(); 1991 a = pop_pair(); 1992 c = _gvn.transform( new MulDNode(a,b) ); 1993 d = dprecision_rounding(c); 1994 push_pair( d ); 1995 break; 1996 1997 case Bytecodes::_ddiv: 1998 b = pop_pair(); 1999 a = pop_pair(); 2000 c = _gvn.transform( new DivDNode(0,a,b) ); 2001 d = dprecision_rounding(c); 2002 push_pair( d ); 2003 break; 2004 2005 case Bytecodes::_dneg: 2006 a = pop_pair(); 2007 b = _gvn.transform(new NegDNode (a)); 2008 push_pair(b); 2009 break; 2010 2011 case Bytecodes::_drem: 2012 if (Matcher::has_match_rule(Op_ModD)) { 2013 // Generate a ModD node. 2014 b = pop_pair(); 2015 a = pop_pair(); 2016 // a % b 2017 2018 c = _gvn.transform( new ModDNode(0,a,b) ); 2019 d = dprecision_rounding(c); 2020 push_pair( d ); 2021 } 2022 else { 2023 // Generate a call. 2024 modd(); 2025 } 2026 break; 2027 2028 case Bytecodes::_dcmpl: 2029 b = pop_pair(); 2030 a = pop_pair(); 2031 c = _gvn.transform( new CmpD3Node( a, b)); 2032 push(c); 2033 break; 2034 2035 case Bytecodes::_dcmpg: 2036 b = pop_pair(); 2037 a = pop_pair(); 2038 // Same as dcmpl but need to flip the unordered case. 2039 // Commute the inputs, which negates the result sign except for unordered. 2040 // Flip the unordered as well by using CmpD3 which implements 2041 // unordered-lesser instead of unordered-greater semantics. 2042 // Finally, negate the result bits. Result is same as using a 2043 // CmpD3Greater except we did it with CmpD3 alone. 2044 c = _gvn.transform( new CmpD3Node( b, a)); 2045 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 2046 push(c); 2047 break; 2048 2049 2050 // Note for longs -> lo word is on TOS, hi word is on TOS - 1 2051 case Bytecodes::_land: 2052 b = pop_pair(); 2053 a = pop_pair(); 2054 c = _gvn.transform( new AndLNode(a,b) ); 2055 push_pair(c); 2056 break; 2057 case Bytecodes::_lor: 2058 b = pop_pair(); 2059 a = pop_pair(); 2060 c = _gvn.transform( new OrLNode(a,b) ); 2061 push_pair(c); 2062 break; 2063 case Bytecodes::_lxor: 2064 b = pop_pair(); 2065 a = pop_pair(); 2066 c = _gvn.transform( new XorLNode(a,b) ); 2067 push_pair(c); 2068 break; 2069 2070 case Bytecodes::_lshl: 2071 b = pop(); // the shift count 2072 a = pop_pair(); // value to be shifted 2073 c = _gvn.transform( new LShiftLNode(a,b) ); 2074 push_pair(c); 2075 break; 2076 case Bytecodes::_lshr: 2077 b = pop(); // the shift count 2078 a = pop_pair(); // value to be shifted 2079 c = _gvn.transform( new RShiftLNode(a,b) ); 2080 push_pair(c); 2081 break; 2082 case Bytecodes::_lushr: 2083 b = pop(); // the shift count 2084 a = pop_pair(); // value to be shifted 2085 c = _gvn.transform( new URShiftLNode(a,b) ); 2086 push_pair(c); 2087 break; 2088 case Bytecodes::_lmul: 2089 b = pop_pair(); 2090 a = pop_pair(); 2091 c = _gvn.transform( new MulLNode(a,b) ); 2092 push_pair(c); 2093 break; 2094 2095 case Bytecodes::_lrem: 2096 // Must keep both values on the expression-stack during null-check 2097 assert(peek(0) == top(), "long word order"); 2098 zero_check_long(peek(1)); 2099 // Compile-time detect of null-exception? 2100 if (stopped()) return; 2101 b = pop_pair(); 2102 a = pop_pair(); 2103 c = _gvn.transform( new ModLNode(control(),a,b) ); 2104 push_pair(c); 2105 break; 2106 2107 case Bytecodes::_ldiv: 2108 // Must keep both values on the expression-stack during null-check 2109 assert(peek(0) == top(), "long word order"); 2110 zero_check_long(peek(1)); 2111 // Compile-time detect of null-exception? 2112 if (stopped()) return; 2113 b = pop_pair(); 2114 a = pop_pair(); 2115 c = _gvn.transform( new DivLNode(control(),a,b) ); 2116 push_pair(c); 2117 break; 2118 2119 case Bytecodes::_ladd: 2120 b = pop_pair(); 2121 a = pop_pair(); 2122 c = _gvn.transform( new AddLNode(a,b) ); 2123 push_pair(c); 2124 break; 2125 case Bytecodes::_lsub: 2126 b = pop_pair(); 2127 a = pop_pair(); 2128 c = _gvn.transform( new SubLNode(a,b) ); 2129 push_pair(c); 2130 break; 2131 case Bytecodes::_lcmp: 2132 // Safepoints are now inserted _before_ branches. The long-compare 2133 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a 2134 // slew of control flow. These are usually followed by a CmpI vs zero and 2135 // a branch; this pattern then optimizes to the obvious long-compare and 2136 // branch. However, if the branch is backwards there's a Safepoint 2137 // inserted. The inserted Safepoint captures the JVM state at the 2138 // pre-branch point, i.e. it captures the 3-way value. Thus if a 2139 // long-compare is used to control a loop the debug info will force 2140 // computation of the 3-way value, even though the generated code uses a 2141 // long-compare and branch. We try to rectify the situation by inserting 2142 // a SafePoint here and have it dominate and kill the safepoint added at a 2143 // following backwards branch. At this point the JVM state merely holds 2 2144 // longs but not the 3-way value. 2145 if( UseLoopSafepoints ) { 2146 switch( iter().next_bc() ) { 2147 case Bytecodes::_ifgt: 2148 case Bytecodes::_iflt: 2149 case Bytecodes::_ifge: 2150 case Bytecodes::_ifle: 2151 case Bytecodes::_ifne: 2152 case Bytecodes::_ifeq: 2153 // If this is a backwards branch in the bytecodes, add Safepoint 2154 maybe_add_safepoint(iter().next_get_dest()); 2155 } 2156 } 2157 b = pop_pair(); 2158 a = pop_pair(); 2159 c = _gvn.transform( new CmpL3Node( a, b )); 2160 push(c); 2161 break; 2162 2163 case Bytecodes::_lneg: 2164 a = pop_pair(); 2165 b = _gvn.transform( new SubLNode(longcon(0),a)); 2166 push_pair(b); 2167 break; 2168 case Bytecodes::_l2i: 2169 a = pop_pair(); 2170 push( _gvn.transform( new ConvL2INode(a))); 2171 break; 2172 case Bytecodes::_i2l: 2173 a = pop(); 2174 b = _gvn.transform( new ConvI2LNode(a)); 2175 push_pair(b); 2176 break; 2177 case Bytecodes::_i2b: 2178 // Sign extend 2179 a = pop(); 2180 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(24)) ); 2181 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(24)) ); 2182 push( a ); 2183 break; 2184 case Bytecodes::_i2s: 2185 a = pop(); 2186 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(16)) ); 2187 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(16)) ); 2188 push( a ); 2189 break; 2190 case Bytecodes::_i2c: 2191 a = pop(); 2192 push( _gvn.transform( new AndINode(a,_gvn.intcon(0xFFFF)) ) ); 2193 break; 2194 2195 case Bytecodes::_i2f: 2196 a = pop(); 2197 b = _gvn.transform( new ConvI2FNode(a) ) ; 2198 c = precision_rounding(b); 2199 push (b); 2200 break; 2201 2202 case Bytecodes::_i2d: 2203 a = pop(); 2204 b = _gvn.transform( new ConvI2DNode(a)); 2205 push_pair(b); 2206 break; 2207 2208 case Bytecodes::_iinc: // Increment local 2209 i = iter().get_index(); // Get local index 2210 set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) ); 2211 break; 2212 2213 // Exit points of synchronized methods must have an unlock node 2214 case Bytecodes::_return: 2215 return_current(NULL); 2216 break; 2217 2218 case Bytecodes::_ireturn: 2219 case Bytecodes::_areturn: 2220 case Bytecodes::_freturn: 2221 return_current(pop()); 2222 break; 2223 case Bytecodes::_lreturn: 2224 return_current(pop_pair()); 2225 break; 2226 case Bytecodes::_dreturn: 2227 return_current(pop_pair()); 2228 break; 2229 2230 case Bytecodes::_athrow: 2270 taken = method()->scale_count(taken); 2271 target_block->set_count(taken); 2272 break; 2273 } 2274 2275 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null; 2276 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null; 2277 handle_if_null: 2278 // If this is a backwards branch in the bytecodes, add Safepoint 2279 maybe_add_safepoint(iter().get_dest()); 2280 a = null(); 2281 b = pop(); 2282 if (!_gvn.type(b)->speculative_maybe_null() && 2283 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2284 inc_sp(1); 2285 Node* null_ctl = top(); 2286 b = null_check_oop(b, &null_ctl, true, true, true); 2287 assert(null_ctl->is_top(), "no null control here"); 2288 dec_sp(1); 2289 } 2290 c = _gvn.transform( new CmpPNode(b, a) ); 2291 do_ifnull(btest, c); 2292 break; 2293 2294 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp; 2295 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp; 2296 handle_if_acmp: 2297 // If this is a backwards branch in the bytecodes, add Safepoint 2298 maybe_add_safepoint(iter().get_dest()); 2299 a = pop(); 2300 b = pop(); 2301 c = _gvn.transform( new CmpPNode(b, a) ); 2302 c = optimize_cmp_with_klass(c); 2303 do_if(btest, c); 2304 break; 2305 2306 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx; 2307 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx; 2308 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx; 2309 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx; 2310 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx; 2311 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx; 2312 handle_ifxx: 2313 // If this is a backwards branch in the bytecodes, add Safepoint 2314 maybe_add_safepoint(iter().get_dest()); 2315 a = _gvn.intcon(0); 2316 b = pop(); 2317 c = _gvn.transform( new CmpINode(b, a) ); 2318 do_if(btest, c); 2319 break; 2320 2321 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp; 2322 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp; 2323 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp; 2324 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp; 2325 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp; 2326 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp; 2327 handle_if_icmp: 2328 // If this is a backwards branch in the bytecodes, add Safepoint 2329 maybe_add_safepoint(iter().get_dest()); 2330 a = pop(); 2331 b = pop(); 2332 c = _gvn.transform( new CmpINode( b, a ) ); 2333 do_if(btest, c); 2334 break; 2335 2336 case Bytecodes::_tableswitch: 2337 do_tableswitch(); 2338 break; 2339 2340 case Bytecodes::_lookupswitch: 2341 do_lookupswitch(); 2342 break; 2343 2344 case Bytecodes::_invokestatic: 2345 case Bytecodes::_invokedynamic: 2346 case Bytecodes::_invokespecial: 2347 case Bytecodes::_invokevirtual: 2348 case Bytecodes::_invokeinterface: 2349 do_call(); 2350 break; 2351 case Bytecodes::_checkcast: 2352 do_checkcast(); |