parse2.cpp revision 6557:6ad207fd3e26
1/* 2 * Copyright (c) 1998, 2014, 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/universe.inline.hpp" 32#include "opto/addnode.hpp" 33#include "opto/castnode.hpp" 34#include "opto/convertnode.hpp" 35#include "opto/divnode.hpp" 36#include "opto/idealGraphPrinter.hpp" 37#include "opto/matcher.hpp" 38#include "opto/memnode.hpp" 39#include "opto/mulnode.hpp" 40#include "opto/parse.hpp" 41#include "opto/runtime.hpp" 42#include "runtime/deoptimization.hpp" 43#include "runtime/sharedRuntime.hpp" 44 45extern int explicit_null_checks_inserted, 46 explicit_null_checks_elided; 47 48//---------------------------------array_load---------------------------------- 49void Parse::array_load(BasicType elem_type) { 50 const Type* elem = Type::TOP; 51 Node* adr = array_addressing(elem_type, 0, &elem); 52 if (stopped()) return; // guaranteed null or range check 53 dec_sp(2); // Pop array and index 54 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type); 55 Node* ld = make_load(control(), adr, elem, elem_type, adr_type, MemNode::unordered); 56 push(ld); 57} 58 59 60//--------------------------------array_store---------------------------------- 61void Parse::array_store(BasicType elem_type) { 62 Node* adr = array_addressing(elem_type, 1); 63 if (stopped()) return; // guaranteed null or range check 64 Node* val = pop(); 65 dec_sp(2); // Pop array and index 66 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type); 67 store_to_memory(control(), adr, val, elem_type, adr_type, StoreNode::release_if_reference(elem_type)); 68} 69 70 71//------------------------------array_addressing------------------------------- 72// Pull array and index from the stack. Compute pointer-to-element. 73Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) { 74 Node *idx = peek(0+vals); // Get from stack without popping 75 Node *ary = peek(1+vals); // in case of exception 76 77 // Null check the array base, with correct stack contents 78 ary = null_check(ary, T_ARRAY); 79 // Compile-time detect of null-exception? 80 if (stopped()) return top(); 81 82 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr(); 83 const TypeInt* sizetype = arytype->size(); 84 const Type* elemtype = arytype->elem(); 85 86 if (UseUniqueSubclasses && result2 != NULL) { 87 const Type* el = elemtype->make_ptr(); 88 if (el && el->isa_instptr()) { 89 const TypeInstPtr* toop = el->is_instptr(); 90 if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) { 91 // If we load from "AbstractClass[]" we must see "ConcreteSubClass". 92 const Type* subklass = Type::get_const_type(toop->klass()); 93 elemtype = subklass->join_speculative(el); 94 } 95 } 96 } 97 98 // Check for big class initializers with all constant offsets 99 // feeding into a known-size array. 100 const TypeInt* idxtype = _gvn.type(idx)->is_int(); 101 // See if the highest idx value is less than the lowest array bound, 102 // and if the idx value cannot be negative: 103 bool need_range_check = true; 104 if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) { 105 need_range_check = false; 106 if (C->log() != NULL) C->log()->elem("observe that='!need_range_check'"); 107 } 108 109 ciKlass * arytype_klass = arytype->klass(); 110 if ((arytype_klass != NULL) && (!arytype_klass->is_loaded())) { 111 // Only fails for some -Xcomp runs 112 // The class is unloaded. We have to run this bytecode in the interpreter. 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 170IfNode* 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 178Node* 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------------------------- 191void 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 205void 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 219void 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 226extern "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 236// conflict with any legal switch index. 237#define NullTableIndex -1 238 239class SwitchRange : public StackObj { 240 // a range of integers coupled with a bci destination 241 jint _lo; // inclusive lower limit 242 jint _hi; // inclusive upper limit 243 int _dest; 244 int _table_index; // index into method data table 245 246public: 247 jint lo() const { return _lo; } 248 jint hi() const { return _hi; } 249 int dest() const { return _dest; } 250 int table_index() const { return _table_index; } 251 bool is_singleton() const { return _lo == _hi; } 252 253 void setRange(jint lo, jint hi, int dest, int table_index) { 254 assert(lo <= hi, "must be a non-empty range"); 255 _lo = lo, _hi = hi; _dest = dest; _table_index = table_index; 256 } 257 bool adjoinRange(jint lo, jint hi, int dest, int table_index) { 258 assert(lo <= hi, "must be a non-empty range"); 259 if (lo == _hi+1 && dest == _dest && table_index == _table_index) { 260 _hi = hi; 261 return true; 262 } 263 return false; 264 } 265 266 void set (jint value, int dest, int table_index) { 267 setRange(value, value, dest, table_index); 268 } 269 bool adjoin(jint value, int dest, int table_index) { 270 return adjoinRange(value, value, dest, table_index); 271 } 272 273 void print() { 274 if (is_singleton()) 275 tty->print(" {%d}=>%d", lo(), dest()); 276 else if (lo() == min_jint) 277 tty->print(" {..%d}=>%d", hi(), dest()); 278 else if (hi() == max_jint) 279 tty->print(" {%d..}=>%d", lo(), dest()); 280 else 281 tty->print(" {%d..%d}=>%d", lo(), hi(), dest()); 282 } 283}; 284 285 286//-------------------------------do_tableswitch-------------------------------- 287void Parse::do_tableswitch() { 288 Node* lookup = pop(); 289 290 // Get information about tableswitch 291 int default_dest = iter().get_dest_table(0); 292 int lo_index = iter().get_int_table(1); 293 int hi_index = iter().get_int_table(2); 294 int len = hi_index - lo_index + 1; 295 296 if (len < 1) { 297 // If this is a backward branch, add safepoint 298 maybe_add_safepoint(default_dest); 299 merge(default_dest); 300 return; 301 } 302 303 // generate decision tree, using trichotomy when possible 304 int rnum = len+2; 305 bool makes_backward_branch = false; 306 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); 307 int rp = -1; 308 if (lo_index != min_jint) { 309 ranges[++rp].setRange(min_jint, lo_index-1, default_dest, NullTableIndex); 310 } 311 for (int j = 0; j < len; j++) { 312 jint match_int = lo_index+j; 313 int dest = iter().get_dest_table(j+3); 314 makes_backward_branch |= (dest <= bci()); 315 int table_index = method_data_update() ? j : NullTableIndex; 316 if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index)) { 317 ranges[++rp].set(match_int, dest, table_index); 318 } 319 } 320 jint highest = lo_index+(len-1); 321 assert(ranges[rp].hi() == highest, ""); 322 if (highest != max_jint 323 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex)) { 324 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex); 325 } 326 assert(rp < len+2, "not too many ranges"); 327 328 // Safepoint in case if backward branch observed 329 if( makes_backward_branch && UseLoopSafepoints ) 330 add_safepoint(); 331 332 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); 333} 334 335 336//------------------------------do_lookupswitch-------------------------------- 337void Parse::do_lookupswitch() { 338 Node *lookup = pop(); // lookup value 339 // Get information about lookupswitch 340 int default_dest = iter().get_dest_table(0); 341 int len = iter().get_int_table(1); 342 343 if (len < 1) { // If this is a backward branch, add safepoint 344 maybe_add_safepoint(default_dest); 345 merge(default_dest); 346 return; 347 } 348 349 // generate decision tree, using trichotomy when possible 350 jint* table = NEW_RESOURCE_ARRAY(jint, len*2); 351 { 352 for( int j = 0; j < len; j++ ) { 353 table[j+j+0] = iter().get_int_table(2+j+j); 354 table[j+j+1] = iter().get_dest_table(2+j+j+1); 355 } 356 qsort( table, len, 2*sizeof(table[0]), jint_cmp ); 357 } 358 359 int rnum = len*2+1; 360 bool makes_backward_branch = false; 361 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum); 362 int rp = -1; 363 for( int j = 0; j < len; j++ ) { 364 jint match_int = table[j+j+0]; 365 int dest = table[j+j+1]; 366 int next_lo = rp < 0 ? min_jint : ranges[rp].hi()+1; 367 int table_index = method_data_update() ? j : NullTableIndex; 368 makes_backward_branch |= (dest <= bci()); 369 if( match_int != next_lo ) { 370 ranges[++rp].setRange(next_lo, match_int-1, default_dest, NullTableIndex); 371 } 372 if( rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index) ) { 373 ranges[++rp].set(match_int, dest, table_index); 374 } 375 } 376 jint highest = table[2*(len-1)]; 377 assert(ranges[rp].hi() == highest, ""); 378 if( highest != max_jint 379 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex) ) { 380 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex); 381 } 382 assert(rp < rnum, "not too many ranges"); 383 384 // Safepoint in case backward branch observed 385 if( makes_backward_branch && UseLoopSafepoints ) 386 add_safepoint(); 387 388 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]); 389} 390 391//----------------------------create_jump_tables------------------------------- 392bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) { 393 // Are jumptables enabled 394 if (!UseJumpTables) return false; 395 396 // Are jumptables supported 397 if (!Matcher::has_match_rule(Op_Jump)) return false; 398 399 // Don't make jump table if profiling 400 if (method_data_update()) return false; 401 402 // Decide if a guard is needed to lop off big ranges at either (or 403 // both) end(s) of the input set. We'll call this the default target 404 // even though we can't be sure that it is the true "default". 405 406 bool needs_guard = false; 407 int default_dest; 408 int64_t total_outlier_size = 0; 409 int64_t hi_size = ((int64_t)hi->hi()) - ((int64_t)hi->lo()) + 1; 410 int64_t lo_size = ((int64_t)lo->hi()) - ((int64_t)lo->lo()) + 1; 411 412 if (lo->dest() == hi->dest()) { 413 total_outlier_size = hi_size + lo_size; 414 default_dest = lo->dest(); 415 } else if (lo_size > hi_size) { 416 total_outlier_size = lo_size; 417 default_dest = lo->dest(); 418 } else { 419 total_outlier_size = hi_size; 420 default_dest = hi->dest(); 421 } 422 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_t num_cases = ((int64_t)hi->hi()) - ((int64_t)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_t 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------------------------------- 491void 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"); 498 499 // Decrement pred-numbers for the unique set of nodes. 500#ifdef ASSERT 501 // Ensure that the block's successors are a (duplicate-free) set. 502 int successors_counted = 0; // block occurrences in [hi..lo] 503 int unique_successors = switch_block->num_successors(); 504 for (int i = 0; i < unique_successors; i++) { 505 Block* target = switch_block->successor_at(i); 506 507 // Check that the set of successors is the same in both places. 508 int successors_found = 0; 509 for (SwitchRange* p = lo; p <= hi; p++) { 510 if (p->dest() == target->start()) successors_found++; 511 } 512 assert(successors_found > 0, "successor must be known"); 513 successors_counted += successors_found; 514 } 515 assert(successors_counted == (hi-lo)+1, "no unexpected successors"); 516#endif 517 518 // Maybe prune the inputs, based on the type of key_val. 519 jint min_val = min_jint; 520 jint max_val = max_jint; 521 const TypeInt* ti = key_val->bottom_type()->isa_int(); 522 if (ti != NULL) { 523 min_val = ti->_lo; 524 max_val = ti->_hi; 525 assert(min_val <= max_val, "invalid int type"); 526 } 527 while (lo->hi() < min_val) lo++; 528 if (lo->lo() < min_val) lo->setRange(min_val, lo->hi(), lo->dest(), lo->table_index()); 529 while (hi->lo() > max_val) hi--; 530 if (hi->hi() > max_val) hi->setRange(hi->lo(), max_val, hi->dest(), hi->table_index()); 531 } 532 533#ifndef PRODUCT 534 if (switch_depth == 0) { 535 _max_switch_depth = 0; 536 _est_switch_depth = log2_intptr((hi-lo+1)-1)+1; 537 } 538#endif 539 540 assert(lo <= hi, "must be a non-empty set of ranges"); 541 if (lo == hi) { 542 jump_if_always_fork(lo->dest(), lo->table_index()); 543 } else { 544 assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges"); 545 assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges"); 546 547 if (create_jump_tables(key_val, lo, hi)) return; 548 549 int nr = hi - lo + 1; 550 551 SwitchRange* mid = lo + nr/2; 552 // if there is an easy choice, pivot at a singleton: 553 if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton()) mid--; 554 555 assert(lo < mid && mid <= hi, "good pivot choice"); 556 assert(nr != 2 || mid == hi, "should pick higher of 2"); 557 assert(nr != 3 || mid == hi-1, "should pick middle of 3"); 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 } 617 } 618 619#ifndef PRODUCT 620 _max_switch_depth = MAX2(switch_depth, _max_switch_depth); 621 if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) { 622 SwitchRange* r; 623 int nsing = 0; 624 for( r = lo; r <= hi; r++ ) { 625 if( r->is_singleton() ) nsing++; 626 } 627 tty->print(">>> "); 628 _method->print_short_name(); 629 tty->print_cr(" switch decision tree"); 630 tty->print_cr(" %d ranges (%d singletons), max_depth=%d, est_depth=%d", 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 644void 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 656void 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 673void 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 685void 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 730void 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)"); 747 748 // Effect on jsr on stack 749 push(_gvn.makecon(ret_addr)); 750 751 // Flow to the jsr. 752 merge(jsr_bci); 753} 754 755// Handle ret bytecode 756void Parse::do_ret() { 757 // Find to whom we return. 758 assert(block()->num_successors() == 1, "a ret can only go one place now"); 759 Block* target = block()->successor_at(0); 760 assert(!target->is_ready(), "our arrival must be expected"); 761 profile_ret(target->flow()->start()); 762 int pnum = target->next_path_num(); 763 merge_common(target, pnum); 764} 765 766//--------------------------dynamic_branch_prediction-------------------------- 767// Try to gather dynamic branch prediction behavior. Return a probability 768// of the branch being taken and set the "cnt" field. Returns a -1.0 769// if we need to use static prediction for some reason. 770float Parse::dynamic_branch_prediction(float &cnt) { 771 ResourceMark rm; 772 773 cnt = COUNT_UNKNOWN; 774 775 // Use MethodData information if it is available 776 // FIXME: free the ProfileData structure 777 ciMethodData* methodData = method()->method_data(); 778 if (!methodData->is_mature()) return PROB_UNKNOWN; 779 ciProfileData* data = methodData->bci_to_data(bci()); 780 if (!data->is_JumpData()) return PROB_UNKNOWN; 781 782 // get taken and not taken values 783 int taken = data->as_JumpData()->taken(); 784 int not_taken = 0; 785 if (data->is_BranchData()) { 786 not_taken = data->as_BranchData()->not_taken(); 787 } 788 789 // scale the counts to be commensurate with invocation counts: 790 taken = method()->scale_count(taken); 791 not_taken = method()->scale_count(not_taken); 792 793 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. 794 // We also check that individual counters are positive first, overwise the sum can become positive. 795 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { 796 if (C->log() != NULL) { 797 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); 798 } 799 return PROB_UNKNOWN; 800 } 801 802 // Compute frequency that we arrive here 803 float sum = taken + not_taken; 804 // Adjust, if this block is a cloned private block but the 805 // Jump counts are shared. Taken the private counts for 806 // just this path instead of the shared counts. 807 if( block()->count() > 0 ) 808 sum = block()->count(); 809 cnt = sum / FreqCountInvocations; 810 811 // Pin probability to sane limits 812 float prob; 813 if( !taken ) 814 prob = (0+PROB_MIN) / 2; 815 else if( !not_taken ) 816 prob = (1+PROB_MAX) / 2; 817 else { // Compute probability of true path 818 prob = (float)taken / (float)(taken + not_taken); 819 if (prob > PROB_MAX) prob = PROB_MAX; 820 if (prob < PROB_MIN) prob = PROB_MIN; 821 } 822 823 assert((cnt > 0.0f) && (prob > 0.0f), 824 "Bad frequency assignment in if"); 825 826 if (C->log() != NULL) { 827 const char* prob_str = NULL; 828 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always"; 829 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never"; 830 char prob_str_buf[30]; 831 if (prob_str == NULL) { 832 sprintf(prob_str_buf, "%g", prob); 833 prob_str = prob_str_buf; 834 } 835 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'", 836 iter().get_dest(), taken, not_taken, cnt, prob_str); 837 } 838 return prob; 839} 840 841//-----------------------------branch_prediction------------------------------- 842float Parse::branch_prediction(float& cnt, 843 BoolTest::mask btest, 844 int target_bci) { 845 float prob = dynamic_branch_prediction(cnt); 846 // If prob is unknown, switch to static prediction 847 if (prob != PROB_UNKNOWN) return prob; 848 849 prob = PROB_FAIR; // Set default value 850 if (btest == BoolTest::eq) // Exactly equal test? 851 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent 852 else if (btest == BoolTest::ne) 853 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent 854 855 // If this is a conditional test guarding a backwards branch, 856 // assume its a loop-back edge. Make it a likely taken branch. 857 if (target_bci < bci()) { 858 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt 859 // Since it's an OSR, we probably have profile data, but since 860 // branch_prediction returned PROB_UNKNOWN, the counts are too small. 861 // Let's make a special check here for completely zero counts. 862 ciMethodData* methodData = method()->method_data(); 863 if (!methodData->is_empty()) { 864 ciProfileData* data = methodData->bci_to_data(bci()); 865 // Only stop for truly zero counts, which mean an unknown part 866 // of the OSR-ed method, and we want to deopt to gather more stats. 867 // If you have ANY counts, then this loop is simply 'cold' relative 868 // to the OSR loop. 869 if (data->as_BranchData()->taken() + 870 data->as_BranchData()->not_taken() == 0 ) { 871 // This is the only way to return PROB_UNKNOWN: 872 return PROB_UNKNOWN; 873 } 874 } 875 } 876 prob = PROB_STATIC_FREQUENT; // Likely to take backwards branch 877 } 878 879 assert(prob != PROB_UNKNOWN, "must have some guess at this point"); 880 return prob; 881} 882 883// The magic constants are chosen so as to match the output of 884// branch_prediction() when the profile reports a zero taken count. 885// It is important to distinguish zero counts unambiguously, because 886// some branches (e.g., _213_javac.Assembler.eliminate) validly produce 887// very small but nonzero probabilities, which if confused with zero 888// counts would keep the program recompiling indefinitely. 889bool Parse::seems_never_taken(float prob) { 890 return prob < PROB_MIN; 891} 892 893// True if the comparison seems to be the kind that will not change its 894// statistics from true to false. See comments in adjust_map_after_if. 895// This question is only asked along paths which are already 896// classifed as untaken (by seems_never_taken), so really, 897// if a path is never taken, its controlling comparison is 898// already acting in a stable fashion. If the comparison 899// seems stable, we will put an expensive uncommon trap 900// on the untaken path. 901bool Parse::seems_stable_comparison(BoolTest::mask btest, Node* cmp) { 902 if (C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if)) { 903 return false; 904 } 905 return true; 906} 907 908//-------------------------------repush_if_args-------------------------------- 909// Push arguments of an "if" bytecode back onto the stack by adjusting _sp. 910inline int Parse::repush_if_args() { 911#ifndef PRODUCT 912 if (PrintOpto && WizardMode) { 913 tty->print("defending against excessive implicit null exceptions on %s @%d in ", 914 Bytecodes::name(iter().cur_bc()), iter().cur_bci()); 915 method()->print_name(); tty->cr(); 916 } 917#endif 918 int bc_depth = - Bytecodes::depth(iter().cur_bc()); 919 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches"); 920 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms 921 assert(argument(0) != NULL, "must exist"); 922 assert(bc_depth == 1 || argument(1) != NULL, "two must exist"); 923 inc_sp(bc_depth); 924 return bc_depth; 925} 926 927//----------------------------------do_ifnull---------------------------------- 928void Parse::do_ifnull(BoolTest::mask btest, Node *c) { 929 int target_bci = iter().get_dest(); 930 931 Block* branch_block = successor_for_bci(target_bci); 932 Block* next_block = successor_for_bci(iter().next_bci()); 933 934 float cnt; 935 float prob = branch_prediction(cnt, btest, target_bci); 936 if (prob == PROB_UNKNOWN) { 937 // (An earlier version of do_ifnull omitted this trap for OSR methods.) 938#ifndef PRODUCT 939 if (PrintOpto && Verbose) 940 tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); 941#endif 942 repush_if_args(); // to gather stats on loop 943 // We need to mark this branch as taken so that if we recompile we will 944 // see that it is possible. In the tiered system the interpreter doesn't 945 // do profiling and by the time we get to the lower tier from the interpreter 946 // the path may be cold again. Make sure it doesn't look untaken 947 profile_taken_branch(target_bci, !ProfileInterpreter); 948 uncommon_trap(Deoptimization::Reason_unreached, 949 Deoptimization::Action_reinterpret, 950 NULL, "cold"); 951 if (C->eliminate_boxing()) { 952 // Mark the successor blocks as parsed 953 branch_block->next_path_num(); 954 next_block->next_path_num(); 955 } 956 return; 957 } 958 959 explicit_null_checks_inserted++; 960 961 // Generate real control flow 962 Node *tst = _gvn.transform( new BoolNode( c, btest ) ); 963 964 // Sanity check the probability value 965 assert(prob > 0.0f,"Bad probability in Parser"); 966 // Need xform to put node in hash table 967 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt ); 968 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 969 // True branch 970 { PreserveJVMState pjvms(this); 971 Node* iftrue = _gvn.transform( new IfTrueNode (iff) ); 972 set_control(iftrue); 973 974 if (stopped()) { // Path is dead? 975 explicit_null_checks_elided++; 976 if (C->eliminate_boxing()) { 977 // Mark the successor block as parsed 978 branch_block->next_path_num(); 979 } 980 } else { // Path is live. 981 // Update method data 982 profile_taken_branch(target_bci); 983 adjust_map_after_if(btest, c, prob, branch_block, next_block); 984 if (!stopped()) { 985 merge(target_bci); 986 } 987 } 988 } 989 990 // False branch 991 Node* iffalse = _gvn.transform( new IfFalseNode(iff) ); 992 set_control(iffalse); 993 994 if (stopped()) { // Path is dead? 995 explicit_null_checks_elided++; 996 if (C->eliminate_boxing()) { 997 // Mark the successor block as parsed 998 next_block->next_path_num(); 999 } 1000 } else { // Path is live. 1001 // Update method data 1002 profile_not_taken_branch(); 1003 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, 1004 next_block, branch_block); 1005 } 1006} 1007 1008//------------------------------------do_if------------------------------------ 1009void Parse::do_if(BoolTest::mask btest, Node* c) { 1010 int target_bci = iter().get_dest(); 1011 1012 Block* branch_block = successor_for_bci(target_bci); 1013 Block* next_block = successor_for_bci(iter().next_bci()); 1014 1015 float cnt; 1016 float prob = branch_prediction(cnt, btest, target_bci); 1017 float untaken_prob = 1.0 - prob; 1018 1019 if (prob == PROB_UNKNOWN) { 1020#ifndef PRODUCT 1021 if (PrintOpto && Verbose) 1022 tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); 1023#endif 1024 repush_if_args(); // to gather stats on loop 1025 // We need to mark this branch as taken so that if we recompile we will 1026 // see that it is possible. In the tiered system the interpreter doesn't 1027 // do profiling and by the time we get to the lower tier from the interpreter 1028 // the path may be cold again. Make sure it doesn't look untaken 1029 profile_taken_branch(target_bci, !ProfileInterpreter); 1030 uncommon_trap(Deoptimization::Reason_unreached, 1031 Deoptimization::Action_reinterpret, 1032 NULL, "cold"); 1033 if (C->eliminate_boxing()) { 1034 // Mark the successor blocks as parsed 1035 branch_block->next_path_num(); 1036 next_block->next_path_num(); 1037 } 1038 return; 1039 } 1040 1041 // Sanity check the probability value 1042 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser"); 1043 1044 bool taken_if_true = true; 1045 // Convert BoolTest to canonical form: 1046 if (!BoolTest(btest).is_canonical()) { 1047 btest = BoolTest(btest).negate(); 1048 taken_if_true = false; 1049 // prob is NOT updated here; it remains the probability of the taken 1050 // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). 1051 } 1052 assert(btest != BoolTest::eq, "!= is the only canonical exact test"); 1053 1054 Node* tst0 = new BoolNode(c, btest); 1055 Node* tst = _gvn.transform(tst0); 1056 BoolTest::mask taken_btest = BoolTest::illegal; 1057 BoolTest::mask untaken_btest = BoolTest::illegal; 1058 1059 if (tst->is_Bool()) { 1060 // Refresh c from the transformed bool node, since it may be 1061 // simpler than the original c. Also re-canonicalize btest. 1062 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). 1063 // That can arise from statements like: if (x instanceof C) ... 1064 if (tst != tst0) { 1065 // Canonicalize one more time since transform can change it. 1066 btest = tst->as_Bool()->_test._test; 1067 if (!BoolTest(btest).is_canonical()) { 1068 // Reverse edges one more time... 1069 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) ); 1070 btest = tst->as_Bool()->_test._test; 1071 assert(BoolTest(btest).is_canonical(), "sanity"); 1072 taken_if_true = !taken_if_true; 1073 } 1074 c = tst->in(1); 1075 } 1076 BoolTest::mask neg_btest = BoolTest(btest).negate(); 1077 taken_btest = taken_if_true ? btest : neg_btest; 1078 untaken_btest = taken_if_true ? neg_btest : btest; 1079 } 1080 1081 // Generate real control flow 1082 float true_prob = (taken_if_true ? prob : untaken_prob); 1083 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt); 1084 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser"); 1085 Node* taken_branch = new IfTrueNode(iff); 1086 Node* untaken_branch = new IfFalseNode(iff); 1087 if (!taken_if_true) { // Finish conversion to canonical form 1088 Node* tmp = taken_branch; 1089 taken_branch = untaken_branch; 1090 untaken_branch = tmp; 1091 } 1092 1093 // Branch is taken: 1094 { PreserveJVMState pjvms(this); 1095 taken_branch = _gvn.transform(taken_branch); 1096 set_control(taken_branch); 1097 1098 if (stopped()) { 1099 if (C->eliminate_boxing()) { 1100 // Mark the successor block as parsed 1101 branch_block->next_path_num(); 1102 } 1103 } else { 1104 // Update method data 1105 profile_taken_branch(target_bci); 1106 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block); 1107 if (!stopped()) { 1108 merge(target_bci); 1109 } 1110 } 1111 } 1112 1113 untaken_branch = _gvn.transform(untaken_branch); 1114 set_control(untaken_branch); 1115 1116 // Branch not taken. 1117 if (stopped()) { 1118 if (C->eliminate_boxing()) { 1119 // Mark the successor block as parsed 1120 next_block->next_path_num(); 1121 } 1122 } else { 1123 // Update method data 1124 profile_not_taken_branch(); 1125 adjust_map_after_if(untaken_btest, c, untaken_prob, 1126 next_block, branch_block); 1127 } 1128} 1129 1130//----------------------------adjust_map_after_if------------------------------ 1131// Adjust the JVM state to reflect the result of taking this path. 1132// Basically, it means inspecting the CmpNode controlling this 1133// branch, seeing how it constrains a tested value, and then 1134// deciding if it's worth our while to encode this constraint 1135// as graph nodes in the current abstract interpretation map. 1136void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, 1137 Block* path, Block* other_path) { 1138 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal) 1139 return; // nothing to do 1140 1141 bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); 1142 1143 if (seems_never_taken(prob) && seems_stable_comparison(btest, c)) { 1144 repush_if_args(); 1145 uncommon_trap(Deoptimization::Reason_unstable_if, 1146 Deoptimization::Action_reinterpret, 1147 NULL, 1148 (is_fallthrough ? "taken always" : "taken never")); 1149 return; 1150 } 1151 1152 Node* val = c->in(1); 1153 Node* con = c->in(2); 1154 const Type* tcon = _gvn.type(con); 1155 const Type* tval = _gvn.type(val); 1156 bool have_con = tcon->singleton(); 1157 if (tval->singleton()) { 1158 if (!have_con) { 1159 // Swap, so constant is in con. 1160 con = val; 1161 tcon = tval; 1162 val = c->in(2); 1163 tval = _gvn.type(val); 1164 btest = BoolTest(btest).commute(); 1165 have_con = true; 1166 } else { 1167 // Do we have two constants? Then leave well enough alone. 1168 have_con = false; 1169 } 1170 } 1171 if (!have_con) // remaining adjustments need a con 1172 return; 1173 1174 sharpen_type_after_if(btest, con, tcon, val, tval); 1175} 1176 1177 1178static Node* extract_obj_from_klass_load(PhaseGVN* gvn, Node* n) { 1179 Node* ldk; 1180 if (n->is_DecodeNKlass()) { 1181 if (n->in(1)->Opcode() != Op_LoadNKlass) { 1182 return NULL; 1183 } else { 1184 ldk = n->in(1); 1185 } 1186 } else if (n->Opcode() != Op_LoadKlass) { 1187 return NULL; 1188 } else { 1189 ldk = n; 1190 } 1191 assert(ldk != NULL && ldk->is_Load(), "should have found a LoadKlass or LoadNKlass node"); 1192 1193 Node* adr = ldk->in(MemNode::Address); 1194 intptr_t off = 0; 1195 Node* obj = AddPNode::Ideal_base_and_offset(adr, gvn, off); 1196 if (obj == NULL || off != oopDesc::klass_offset_in_bytes()) // loading oopDesc::_klass? 1197 return NULL; 1198 const TypePtr* tp = gvn->type(obj)->is_ptr(); 1199 if (tp == NULL || !(tp->isa_instptr() || tp->isa_aryptr())) // is obj a Java object ptr? 1200 return NULL; 1201 1202 return obj; 1203} 1204 1205void Parse::sharpen_type_after_if(BoolTest::mask btest, 1206 Node* con, const Type* tcon, 1207 Node* val, const Type* tval) { 1208 // Look for opportunities to sharpen the type of a node 1209 // whose klass is compared with a constant klass. 1210 if (btest == BoolTest::eq && tcon->isa_klassptr()) { 1211 Node* obj = extract_obj_from_klass_load(&_gvn, val); 1212 const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type(); 1213 if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) { 1214 // Found: 1215 // Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]) 1216 // or the narrowOop equivalent. 1217 const Type* obj_type = _gvn.type(obj); 1218 const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr(); 1219 if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type && 1220 tboth->higher_equal(obj_type)) { 1221 // obj has to be of the exact type Foo if the CmpP succeeds. 1222 int obj_in_map = map()->find_edge(obj); 1223 JVMState* jvms = this->jvms(); 1224 if (obj_in_map >= 0 && 1225 (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) { 1226 TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth); 1227 const Type* tcc = ccast->as_Type()->type(); 1228 assert(tcc != obj_type && tcc->higher_equal(obj_type), "must improve"); 1229 // Delay transform() call to allow recovery of pre-cast value 1230 // at the control merge. 1231 _gvn.set_type_bottom(ccast); 1232 record_for_igvn(ccast); 1233 // Here's the payoff. 1234 replace_in_map(obj, ccast); 1235 } 1236 } 1237 } 1238 } 1239 1240 int val_in_map = map()->find_edge(val); 1241 if (val_in_map < 0) return; // replace_in_map would be useless 1242 { 1243 JVMState* jvms = this->jvms(); 1244 if (!(jvms->is_loc(val_in_map) || 1245 jvms->is_stk(val_in_map))) 1246 return; // again, it would be useless 1247 } 1248 1249 // Check for a comparison to a constant, and "know" that the compared 1250 // value is constrained on this path. 1251 assert(tcon->singleton(), ""); 1252 ConstraintCastNode* ccast = NULL; 1253 Node* cast = NULL; 1254 1255 switch (btest) { 1256 case BoolTest::eq: // Constant test? 1257 { 1258 const Type* tboth = tcon->join_speculative(tval); 1259 if (tboth == tval) break; // Nothing to gain. 1260 if (tcon->isa_int()) { 1261 ccast = new CastIINode(val, tboth); 1262 } else if (tcon == TypePtr::NULL_PTR) { 1263 // Cast to null, but keep the pointer identity temporarily live. 1264 ccast = new CastPPNode(val, tboth); 1265 } else { 1266 const TypeF* tf = tcon->isa_float_constant(); 1267 const TypeD* td = tcon->isa_double_constant(); 1268 // Exclude tests vs float/double 0 as these could be 1269 // either +0 or -0. Just because you are equal to +0 1270 // doesn't mean you ARE +0! 1271 // Note, following code also replaces Long and Oop values. 1272 if ((!tf || tf->_f != 0.0) && 1273 (!td || td->_d != 0.0)) 1274 cast = con; // Replace non-constant val by con. 1275 } 1276 } 1277 break; 1278 1279 case BoolTest::ne: 1280 if (tcon == TypePtr::NULL_PTR) { 1281 cast = cast_not_null(val, false); 1282 } 1283 break; 1284 1285 default: 1286 // (At this point we could record int range types with CastII.) 1287 break; 1288 } 1289 1290 if (ccast != NULL) { 1291 const Type* tcc = ccast->as_Type()->type(); 1292 assert(tcc != tval && tcc->higher_equal(tval), "must improve"); 1293 // Delay transform() call to allow recovery of pre-cast value 1294 // at the control merge. 1295 ccast->set_req(0, control()); 1296 _gvn.set_type_bottom(ccast); 1297 record_for_igvn(ccast); 1298 cast = ccast; 1299 } 1300 1301 if (cast != NULL) { // Here's the payoff. 1302 replace_in_map(val, cast); 1303 } 1304} 1305 1306/** 1307 * Use speculative type to optimize CmpP node: if comparison is 1308 * against the low level class, cast the object to the speculative 1309 * type if any. CmpP should then go away. 1310 * 1311 * @param c expected CmpP node 1312 * @return result of CmpP on object casted to speculative type 1313 * 1314 */ 1315Node* Parse::optimize_cmp_with_klass(Node* c) { 1316 // If this is transformed by the _gvn to a comparison with the low 1317 // level klass then we may be able to use speculation 1318 if (c->Opcode() == Op_CmpP && 1319 (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) && 1320 c->in(2)->is_Con()) { 1321 Node* load_klass = NULL; 1322 Node* decode = NULL; 1323 if (c->in(1)->Opcode() == Op_DecodeNKlass) { 1324 decode = c->in(1); 1325 load_klass = c->in(1)->in(1); 1326 } else { 1327 load_klass = c->in(1); 1328 } 1329 if (load_klass->in(2)->is_AddP()) { 1330 Node* addp = load_klass->in(2); 1331 Node* obj = addp->in(AddPNode::Address); 1332 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 1333 if (obj_type->speculative_type_not_null() != NULL) { 1334 ciKlass* k = obj_type->speculative_type(); 1335 inc_sp(2); 1336 obj = maybe_cast_profiled_obj(obj, k); 1337 dec_sp(2); 1338 // Make the CmpP use the casted obj 1339 addp = basic_plus_adr(obj, addp->in(AddPNode::Offset)); 1340 load_klass = load_klass->clone(); 1341 load_klass->set_req(2, addp); 1342 load_klass = _gvn.transform(load_klass); 1343 if (decode != NULL) { 1344 decode = decode->clone(); 1345 decode->set_req(1, load_klass); 1346 load_klass = _gvn.transform(decode); 1347 } 1348 c = c->clone(); 1349 c->set_req(1, load_klass); 1350 c = _gvn.transform(c); 1351 } 1352 } 1353 } 1354 return c; 1355} 1356 1357//------------------------------do_one_bytecode-------------------------------- 1358// Parse this bytecode, and alter the Parsers JVM->Node mapping 1359void Parse::do_one_bytecode() { 1360 Node *a, *b, *c, *d; // Handy temps 1361 BoolTest::mask btest; 1362 int i; 1363 1364 assert(!has_exceptions(), "bytecode entry state must be clear of throws"); 1365 1366 if (C->check_node_count(NodeLimitFudgeFactor * 5, 1367 "out of nodes parsing method")) { 1368 return; 1369 } 1370 1371#ifdef ASSERT 1372 // for setting breakpoints 1373 if (TraceOptoParse) { 1374 tty->print(" @"); 1375 dump_bci(bci()); 1376 tty->cr(); 1377 } 1378#endif 1379 1380 switch (bc()) { 1381 case Bytecodes::_nop: 1382 // do nothing 1383 break; 1384 case Bytecodes::_lconst_0: 1385 push_pair(longcon(0)); 1386 break; 1387 1388 case Bytecodes::_lconst_1: 1389 push_pair(longcon(1)); 1390 break; 1391 1392 case Bytecodes::_fconst_0: 1393 push(zerocon(T_FLOAT)); 1394 break; 1395 1396 case Bytecodes::_fconst_1: 1397 push(makecon(TypeF::ONE)); 1398 break; 1399 1400 case Bytecodes::_fconst_2: 1401 push(makecon(TypeF::make(2.0f))); 1402 break; 1403 1404 case Bytecodes::_dconst_0: 1405 push_pair(zerocon(T_DOUBLE)); 1406 break; 1407 1408 case Bytecodes::_dconst_1: 1409 push_pair(makecon(TypeD::ONE)); 1410 break; 1411 1412 case Bytecodes::_iconst_m1:push(intcon(-1)); break; 1413 case Bytecodes::_iconst_0: push(intcon( 0)); break; 1414 case Bytecodes::_iconst_1: push(intcon( 1)); break; 1415 case Bytecodes::_iconst_2: push(intcon( 2)); break; 1416 case Bytecodes::_iconst_3: push(intcon( 3)); break; 1417 case Bytecodes::_iconst_4: push(intcon( 4)); break; 1418 case Bytecodes::_iconst_5: push(intcon( 5)); break; 1419 case Bytecodes::_bipush: push(intcon(iter().get_constant_u1())); break; 1420 case Bytecodes::_sipush: push(intcon(iter().get_constant_u2())); break; 1421 case Bytecodes::_aconst_null: push(null()); break; 1422 case Bytecodes::_ldc: 1423 case Bytecodes::_ldc_w: 1424 case Bytecodes::_ldc2_w: 1425 // If the constant is unresolved, run this BC once in the interpreter. 1426 { 1427 ciConstant constant = iter().get_constant(); 1428 if (constant.basic_type() == T_OBJECT && 1429 !constant.as_object()->is_loaded()) { 1430 int index = iter().get_constant_pool_index(); 1431 constantTag tag = iter().get_constant_pool_tag(index); 1432 uncommon_trap(Deoptimization::make_trap_request 1433 (Deoptimization::Reason_unloaded, 1434 Deoptimization::Action_reinterpret, 1435 index), 1436 NULL, tag.internal_name()); 1437 break; 1438 } 1439 assert(constant.basic_type() != T_OBJECT || constant.as_object()->is_instance(), 1440 "must be java_mirror of klass"); 1441 bool pushed = push_constant(constant, true); 1442 guarantee(pushed, "must be possible to push this constant"); 1443 } 1444 1445 break; 1446 1447 case Bytecodes::_aload_0: 1448 push( local(0) ); 1449 break; 1450 case Bytecodes::_aload_1: 1451 push( local(1) ); 1452 break; 1453 case Bytecodes::_aload_2: 1454 push( local(2) ); 1455 break; 1456 case Bytecodes::_aload_3: 1457 push( local(3) ); 1458 break; 1459 case Bytecodes::_aload: 1460 push( local(iter().get_index()) ); 1461 break; 1462 1463 case Bytecodes::_fload_0: 1464 case Bytecodes::_iload_0: 1465 push( local(0) ); 1466 break; 1467 case Bytecodes::_fload_1: 1468 case Bytecodes::_iload_1: 1469 push( local(1) ); 1470 break; 1471 case Bytecodes::_fload_2: 1472 case Bytecodes::_iload_2: 1473 push( local(2) ); 1474 break; 1475 case Bytecodes::_fload_3: 1476 case Bytecodes::_iload_3: 1477 push( local(3) ); 1478 break; 1479 case Bytecodes::_fload: 1480 case Bytecodes::_iload: 1481 push( local(iter().get_index()) ); 1482 break; 1483 case Bytecodes::_lload_0: 1484 push_pair_local( 0 ); 1485 break; 1486 case Bytecodes::_lload_1: 1487 push_pair_local( 1 ); 1488 break; 1489 case Bytecodes::_lload_2: 1490 push_pair_local( 2 ); 1491 break; 1492 case Bytecodes::_lload_3: 1493 push_pair_local( 3 ); 1494 break; 1495 case Bytecodes::_lload: 1496 push_pair_local( iter().get_index() ); 1497 break; 1498 1499 case Bytecodes::_dload_0: 1500 push_pair_local(0); 1501 break; 1502 case Bytecodes::_dload_1: 1503 push_pair_local(1); 1504 break; 1505 case Bytecodes::_dload_2: 1506 push_pair_local(2); 1507 break; 1508 case Bytecodes::_dload_3: 1509 push_pair_local(3); 1510 break; 1511 case Bytecodes::_dload: 1512 push_pair_local(iter().get_index()); 1513 break; 1514 case Bytecodes::_fstore_0: 1515 case Bytecodes::_istore_0: 1516 case Bytecodes::_astore_0: 1517 set_local( 0, pop() ); 1518 break; 1519 case Bytecodes::_fstore_1: 1520 case Bytecodes::_istore_1: 1521 case Bytecodes::_astore_1: 1522 set_local( 1, pop() ); 1523 break; 1524 case Bytecodes::_fstore_2: 1525 case Bytecodes::_istore_2: 1526 case Bytecodes::_astore_2: 1527 set_local( 2, pop() ); 1528 break; 1529 case Bytecodes::_fstore_3: 1530 case Bytecodes::_istore_3: 1531 case Bytecodes::_astore_3: 1532 set_local( 3, pop() ); 1533 break; 1534 case Bytecodes::_fstore: 1535 case Bytecodes::_istore: 1536 case Bytecodes::_astore: 1537 set_local( iter().get_index(), pop() ); 1538 break; 1539 // long stores 1540 case Bytecodes::_lstore_0: 1541 set_pair_local( 0, pop_pair() ); 1542 break; 1543 case Bytecodes::_lstore_1: 1544 set_pair_local( 1, pop_pair() ); 1545 break; 1546 case Bytecodes::_lstore_2: 1547 set_pair_local( 2, pop_pair() ); 1548 break; 1549 case Bytecodes::_lstore_3: 1550 set_pair_local( 3, pop_pair() ); 1551 break; 1552 case Bytecodes::_lstore: 1553 set_pair_local( iter().get_index(), pop_pair() ); 1554 break; 1555 1556 // double stores 1557 case Bytecodes::_dstore_0: 1558 set_pair_local( 0, dstore_rounding(pop_pair()) ); 1559 break; 1560 case Bytecodes::_dstore_1: 1561 set_pair_local( 1, dstore_rounding(pop_pair()) ); 1562 break; 1563 case Bytecodes::_dstore_2: 1564 set_pair_local( 2, dstore_rounding(pop_pair()) ); 1565 break; 1566 case Bytecodes::_dstore_3: 1567 set_pair_local( 3, dstore_rounding(pop_pair()) ); 1568 break; 1569 case Bytecodes::_dstore: 1570 set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) ); 1571 break; 1572 1573 case Bytecodes::_pop: dec_sp(1); break; 1574 case Bytecodes::_pop2: dec_sp(2); break; 1575 case Bytecodes::_swap: 1576 a = pop(); 1577 b = pop(); 1578 push(a); 1579 push(b); 1580 break; 1581 case Bytecodes::_dup: 1582 a = pop(); 1583 push(a); 1584 push(a); 1585 break; 1586 case Bytecodes::_dup_x1: 1587 a = pop(); 1588 b = pop(); 1589 push( a ); 1590 push( b ); 1591 push( a ); 1592 break; 1593 case Bytecodes::_dup_x2: 1594 a = pop(); 1595 b = pop(); 1596 c = pop(); 1597 push( a ); 1598 push( c ); 1599 push( b ); 1600 push( a ); 1601 break; 1602 case Bytecodes::_dup2: 1603 a = pop(); 1604 b = pop(); 1605 push( b ); 1606 push( a ); 1607 push( b ); 1608 push( a ); 1609 break; 1610 1611 case Bytecodes::_dup2_x1: 1612 // before: .. c, b, a 1613 // after: .. b, a, c, b, a 1614 // not tested 1615 a = pop(); 1616 b = pop(); 1617 c = pop(); 1618 push( b ); 1619 push( a ); 1620 push( c ); 1621 push( b ); 1622 push( a ); 1623 break; 1624 case Bytecodes::_dup2_x2: 1625 // before: .. d, c, b, a 1626 // after: .. b, a, d, c, b, a 1627 // not tested 1628 a = pop(); 1629 b = pop(); 1630 c = pop(); 1631 d = pop(); 1632 push( b ); 1633 push( a ); 1634 push( d ); 1635 push( c ); 1636 push( b ); 1637 push( a ); 1638 break; 1639 1640 case Bytecodes::_arraylength: { 1641 // Must do null-check with value on expression stack 1642 Node *ary = null_check(peek(), T_ARRAY); 1643 // Compile-time detect of null-exception? 1644 if (stopped()) return; 1645 a = pop(); 1646 push(load_array_length(a)); 1647 break; 1648 } 1649 1650 case Bytecodes::_baload: array_load(T_BYTE); break; 1651 case Bytecodes::_caload: array_load(T_CHAR); break; 1652 case Bytecodes::_iaload: array_load(T_INT); break; 1653 case Bytecodes::_saload: array_load(T_SHORT); break; 1654 case Bytecodes::_faload: array_load(T_FLOAT); break; 1655 case Bytecodes::_aaload: array_load(T_OBJECT); break; 1656 case Bytecodes::_laload: { 1657 a = array_addressing(T_LONG, 0); 1658 if (stopped()) return; // guaranteed null or range check 1659 dec_sp(2); // Pop array and index 1660 push_pair(make_load(control(), a, TypeLong::LONG, T_LONG, TypeAryPtr::LONGS, MemNode::unordered)); 1661 break; 1662 } 1663 case Bytecodes::_daload: { 1664 a = array_addressing(T_DOUBLE, 0); 1665 if (stopped()) return; // guaranteed null or range check 1666 dec_sp(2); // Pop array and index 1667 push_pair(make_load(control(), a, Type::DOUBLE, T_DOUBLE, TypeAryPtr::DOUBLES, MemNode::unordered)); 1668 break; 1669 } 1670 case Bytecodes::_bastore: array_store(T_BYTE); break; 1671 case Bytecodes::_castore: array_store(T_CHAR); break; 1672 case Bytecodes::_iastore: array_store(T_INT); break; 1673 case Bytecodes::_sastore: array_store(T_SHORT); break; 1674 case Bytecodes::_fastore: array_store(T_FLOAT); break; 1675 case Bytecodes::_aastore: { 1676 d = array_addressing(T_OBJECT, 1); 1677 if (stopped()) return; // guaranteed null or range check 1678 array_store_check(); 1679 c = pop(); // Oop to store 1680 b = pop(); // index (already used) 1681 a = pop(); // the array itself 1682 const TypeOopPtr* elemtype = _gvn.type(a)->is_aryptr()->elem()->make_oopptr(); 1683 const TypeAryPtr* adr_type = TypeAryPtr::OOPS; 1684 Node* store = store_oop_to_array(control(), a, d, adr_type, c, elemtype, T_OBJECT, MemNode::release); 1685 break; 1686 } 1687 case Bytecodes::_lastore: { 1688 a = array_addressing(T_LONG, 2); 1689 if (stopped()) return; // guaranteed null or range check 1690 c = pop_pair(); 1691 dec_sp(2); // Pop array and index 1692 store_to_memory(control(), a, c, T_LONG, TypeAryPtr::LONGS, MemNode::unordered); 1693 break; 1694 } 1695 case Bytecodes::_dastore: { 1696 a = array_addressing(T_DOUBLE, 2); 1697 if (stopped()) return; // guaranteed null or range check 1698 c = pop_pair(); 1699 dec_sp(2); // Pop array and index 1700 c = dstore_rounding(c); 1701 store_to_memory(control(), a, c, T_DOUBLE, TypeAryPtr::DOUBLES, MemNode::unordered); 1702 break; 1703 } 1704 case Bytecodes::_getfield: 1705 do_getfield(); 1706 break; 1707 1708 case Bytecodes::_getstatic: 1709 do_getstatic(); 1710 break; 1711 1712 case Bytecodes::_putfield: 1713 do_putfield(); 1714 break; 1715 1716 case Bytecodes::_putstatic: 1717 do_putstatic(); 1718 break; 1719 1720 case Bytecodes::_irem: 1721 do_irem(); 1722 break; 1723 case Bytecodes::_idiv: 1724 // Must keep both values on the expression-stack during null-check 1725 zero_check_int(peek()); 1726 // Compile-time detect of null-exception? 1727 if (stopped()) return; 1728 b = pop(); 1729 a = pop(); 1730 push( _gvn.transform( new DivINode(control(),a,b) ) ); 1731 break; 1732 case Bytecodes::_imul: 1733 b = pop(); a = pop(); 1734 push( _gvn.transform( new MulINode(a,b) ) ); 1735 break; 1736 case Bytecodes::_iadd: 1737 b = pop(); a = pop(); 1738 push( _gvn.transform( new AddINode(a,b) ) ); 1739 break; 1740 case Bytecodes::_ineg: 1741 a = pop(); 1742 push( _gvn.transform( new SubINode(_gvn.intcon(0),a)) ); 1743 break; 1744 case Bytecodes::_isub: 1745 b = pop(); a = pop(); 1746 push( _gvn.transform( new SubINode(a,b) ) ); 1747 break; 1748 case Bytecodes::_iand: 1749 b = pop(); a = pop(); 1750 push( _gvn.transform( new AndINode(a,b) ) ); 1751 break; 1752 case Bytecodes::_ior: 1753 b = pop(); a = pop(); 1754 push( _gvn.transform( new OrINode(a,b) ) ); 1755 break; 1756 case Bytecodes::_ixor: 1757 b = pop(); a = pop(); 1758 push( _gvn.transform( new XorINode(a,b) ) ); 1759 break; 1760 case Bytecodes::_ishl: 1761 b = pop(); a = pop(); 1762 push( _gvn.transform( new LShiftINode(a,b) ) ); 1763 break; 1764 case Bytecodes::_ishr: 1765 b = pop(); a = pop(); 1766 push( _gvn.transform( new RShiftINode(a,b) ) ); 1767 break; 1768 case Bytecodes::_iushr: 1769 b = pop(); a = pop(); 1770 push( _gvn.transform( new URShiftINode(a,b) ) ); 1771 break; 1772 1773 case Bytecodes::_fneg: 1774 a = pop(); 1775 b = _gvn.transform(new NegFNode (a)); 1776 push(b); 1777 break; 1778 1779 case Bytecodes::_fsub: 1780 b = pop(); 1781 a = pop(); 1782 c = _gvn.transform( new SubFNode(a,b) ); 1783 d = precision_rounding(c); 1784 push( d ); 1785 break; 1786 1787 case Bytecodes::_fadd: 1788 b = pop(); 1789 a = pop(); 1790 c = _gvn.transform( new AddFNode(a,b) ); 1791 d = precision_rounding(c); 1792 push( d ); 1793 break; 1794 1795 case Bytecodes::_fmul: 1796 b = pop(); 1797 a = pop(); 1798 c = _gvn.transform( new MulFNode(a,b) ); 1799 d = precision_rounding(c); 1800 push( d ); 1801 break; 1802 1803 case Bytecodes::_fdiv: 1804 b = pop(); 1805 a = pop(); 1806 c = _gvn.transform( new DivFNode(0,a,b) ); 1807 d = precision_rounding(c); 1808 push( d ); 1809 break; 1810 1811 case Bytecodes::_frem: 1812 if (Matcher::has_match_rule(Op_ModF)) { 1813 // Generate a ModF node. 1814 b = pop(); 1815 a = pop(); 1816 c = _gvn.transform( new ModFNode(0,a,b) ); 1817 d = precision_rounding(c); 1818 push( d ); 1819 } 1820 else { 1821 // Generate a call. 1822 modf(); 1823 } 1824 break; 1825 1826 case Bytecodes::_fcmpl: 1827 b = pop(); 1828 a = pop(); 1829 c = _gvn.transform( new CmpF3Node( a, b)); 1830 push(c); 1831 break; 1832 case Bytecodes::_fcmpg: 1833 b = pop(); 1834 a = pop(); 1835 1836 // Same as fcmpl but need to flip the unordered case. Swap the inputs, 1837 // which negates the result sign except for unordered. Flip the unordered 1838 // as well by using CmpF3 which implements unordered-lesser instead of 1839 // unordered-greater semantics. Finally, commute the result bits. Result 1840 // is same as using a CmpF3Greater except we did it with CmpF3 alone. 1841 c = _gvn.transform( new CmpF3Node( b, a)); 1842 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 1843 push(c); 1844 break; 1845 1846 case Bytecodes::_f2i: 1847 a = pop(); 1848 push(_gvn.transform(new ConvF2INode(a))); 1849 break; 1850 1851 case Bytecodes::_d2i: 1852 a = pop_pair(); 1853 b = _gvn.transform(new ConvD2INode(a)); 1854 push( b ); 1855 break; 1856 1857 case Bytecodes::_f2d: 1858 a = pop(); 1859 b = _gvn.transform( new ConvF2DNode(a)); 1860 push_pair( b ); 1861 break; 1862 1863 case Bytecodes::_d2f: 1864 a = pop_pair(); 1865 b = _gvn.transform( new ConvD2FNode(a)); 1866 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) 1867 //b = _gvn.transform(new RoundFloatNode(0, b) ); 1868 push( b ); 1869 break; 1870 1871 case Bytecodes::_l2f: 1872 if (Matcher::convL2FSupported()) { 1873 a = pop_pair(); 1874 b = _gvn.transform( new ConvL2FNode(a)); 1875 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. 1876 // Rather than storing the result into an FP register then pushing 1877 // out to memory to round, the machine instruction that implements 1878 // ConvL2D is responsible for rounding. 1879 // c = precision_rounding(b); 1880 c = _gvn.transform(b); 1881 push(c); 1882 } else { 1883 l2f(); 1884 } 1885 break; 1886 1887 case Bytecodes::_l2d: 1888 a = pop_pair(); 1889 b = _gvn.transform( new ConvL2DNode(a)); 1890 // For i486.ad, rounding is always necessary (see _l2f above). 1891 // c = dprecision_rounding(b); 1892 c = _gvn.transform(b); 1893 push_pair(c); 1894 break; 1895 1896 case Bytecodes::_f2l: 1897 a = pop(); 1898 b = _gvn.transform( new ConvF2LNode(a)); 1899 push_pair(b); 1900 break; 1901 1902 case Bytecodes::_d2l: 1903 a = pop_pair(); 1904 b = _gvn.transform( new ConvD2LNode(a)); 1905 push_pair(b); 1906 break; 1907 1908 case Bytecodes::_dsub: 1909 b = pop_pair(); 1910 a = pop_pair(); 1911 c = _gvn.transform( new SubDNode(a,b) ); 1912 d = dprecision_rounding(c); 1913 push_pair( d ); 1914 break; 1915 1916 case Bytecodes::_dadd: 1917 b = pop_pair(); 1918 a = pop_pair(); 1919 c = _gvn.transform( new AddDNode(a,b) ); 1920 d = dprecision_rounding(c); 1921 push_pair( d ); 1922 break; 1923 1924 case Bytecodes::_dmul: 1925 b = pop_pair(); 1926 a = pop_pair(); 1927 c = _gvn.transform( new MulDNode(a,b) ); 1928 d = dprecision_rounding(c); 1929 push_pair( d ); 1930 break; 1931 1932 case Bytecodes::_ddiv: 1933 b = pop_pair(); 1934 a = pop_pair(); 1935 c = _gvn.transform( new DivDNode(0,a,b) ); 1936 d = dprecision_rounding(c); 1937 push_pair( d ); 1938 break; 1939 1940 case Bytecodes::_dneg: 1941 a = pop_pair(); 1942 b = _gvn.transform(new NegDNode (a)); 1943 push_pair(b); 1944 break; 1945 1946 case Bytecodes::_drem: 1947 if (Matcher::has_match_rule(Op_ModD)) { 1948 // Generate a ModD node. 1949 b = pop_pair(); 1950 a = pop_pair(); 1951 // a % b 1952 1953 c = _gvn.transform( new ModDNode(0,a,b) ); 1954 d = dprecision_rounding(c); 1955 push_pair( d ); 1956 } 1957 else { 1958 // Generate a call. 1959 modd(); 1960 } 1961 break; 1962 1963 case Bytecodes::_dcmpl: 1964 b = pop_pair(); 1965 a = pop_pair(); 1966 c = _gvn.transform( new CmpD3Node( a, b)); 1967 push(c); 1968 break; 1969 1970 case Bytecodes::_dcmpg: 1971 b = pop_pair(); 1972 a = pop_pair(); 1973 // Same as dcmpl but need to flip the unordered case. 1974 // Commute the inputs, which negates the result sign except for unordered. 1975 // Flip the unordered as well by using CmpD3 which implements 1976 // unordered-lesser instead of unordered-greater semantics. 1977 // Finally, negate the result bits. Result is same as using a 1978 // CmpD3Greater except we did it with CmpD3 alone. 1979 c = _gvn.transform( new CmpD3Node( b, a)); 1980 c = _gvn.transform( new SubINode(_gvn.intcon(0),c) ); 1981 push(c); 1982 break; 1983 1984 1985 // Note for longs -> lo word is on TOS, hi word is on TOS - 1 1986 case Bytecodes::_land: 1987 b = pop_pair(); 1988 a = pop_pair(); 1989 c = _gvn.transform( new AndLNode(a,b) ); 1990 push_pair(c); 1991 break; 1992 case Bytecodes::_lor: 1993 b = pop_pair(); 1994 a = pop_pair(); 1995 c = _gvn.transform( new OrLNode(a,b) ); 1996 push_pair(c); 1997 break; 1998 case Bytecodes::_lxor: 1999 b = pop_pair(); 2000 a = pop_pair(); 2001 c = _gvn.transform( new XorLNode(a,b) ); 2002 push_pair(c); 2003 break; 2004 2005 case Bytecodes::_lshl: 2006 b = pop(); // the shift count 2007 a = pop_pair(); // value to be shifted 2008 c = _gvn.transform( new LShiftLNode(a,b) ); 2009 push_pair(c); 2010 break; 2011 case Bytecodes::_lshr: 2012 b = pop(); // the shift count 2013 a = pop_pair(); // value to be shifted 2014 c = _gvn.transform( new RShiftLNode(a,b) ); 2015 push_pair(c); 2016 break; 2017 case Bytecodes::_lushr: 2018 b = pop(); // the shift count 2019 a = pop_pair(); // value to be shifted 2020 c = _gvn.transform( new URShiftLNode(a,b) ); 2021 push_pair(c); 2022 break; 2023 case Bytecodes::_lmul: 2024 b = pop_pair(); 2025 a = pop_pair(); 2026 c = _gvn.transform( new MulLNode(a,b) ); 2027 push_pair(c); 2028 break; 2029 2030 case Bytecodes::_lrem: 2031 // Must keep both values on the expression-stack during null-check 2032 assert(peek(0) == top(), "long word order"); 2033 zero_check_long(peek(1)); 2034 // Compile-time detect of null-exception? 2035 if (stopped()) return; 2036 b = pop_pair(); 2037 a = pop_pair(); 2038 c = _gvn.transform( new ModLNode(control(),a,b) ); 2039 push_pair(c); 2040 break; 2041 2042 case Bytecodes::_ldiv: 2043 // Must keep both values on the expression-stack during null-check 2044 assert(peek(0) == top(), "long word order"); 2045 zero_check_long(peek(1)); 2046 // Compile-time detect of null-exception? 2047 if (stopped()) return; 2048 b = pop_pair(); 2049 a = pop_pair(); 2050 c = _gvn.transform( new DivLNode(control(),a,b) ); 2051 push_pair(c); 2052 break; 2053 2054 case Bytecodes::_ladd: 2055 b = pop_pair(); 2056 a = pop_pair(); 2057 c = _gvn.transform( new AddLNode(a,b) ); 2058 push_pair(c); 2059 break; 2060 case Bytecodes::_lsub: 2061 b = pop_pair(); 2062 a = pop_pair(); 2063 c = _gvn.transform( new SubLNode(a,b) ); 2064 push_pair(c); 2065 break; 2066 case Bytecodes::_lcmp: 2067 // Safepoints are now inserted _before_ branches. The long-compare 2068 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a 2069 // slew of control flow. These are usually followed by a CmpI vs zero and 2070 // a branch; this pattern then optimizes to the obvious long-compare and 2071 // branch. However, if the branch is backwards there's a Safepoint 2072 // inserted. The inserted Safepoint captures the JVM state at the 2073 // pre-branch point, i.e. it captures the 3-way value. Thus if a 2074 // long-compare is used to control a loop the debug info will force 2075 // computation of the 3-way value, even though the generated code uses a 2076 // long-compare and branch. We try to rectify the situation by inserting 2077 // a SafePoint here and have it dominate and kill the safepoint added at a 2078 // following backwards branch. At this point the JVM state merely holds 2 2079 // longs but not the 3-way value. 2080 if( UseLoopSafepoints ) { 2081 switch( iter().next_bc() ) { 2082 case Bytecodes::_ifgt: 2083 case Bytecodes::_iflt: 2084 case Bytecodes::_ifge: 2085 case Bytecodes::_ifle: 2086 case Bytecodes::_ifne: 2087 case Bytecodes::_ifeq: 2088 // If this is a backwards branch in the bytecodes, add Safepoint 2089 maybe_add_safepoint(iter().next_get_dest()); 2090 } 2091 } 2092 b = pop_pair(); 2093 a = pop_pair(); 2094 c = _gvn.transform( new CmpL3Node( a, b )); 2095 push(c); 2096 break; 2097 2098 case Bytecodes::_lneg: 2099 a = pop_pair(); 2100 b = _gvn.transform( new SubLNode(longcon(0),a)); 2101 push_pair(b); 2102 break; 2103 case Bytecodes::_l2i: 2104 a = pop_pair(); 2105 push( _gvn.transform( new ConvL2INode(a))); 2106 break; 2107 case Bytecodes::_i2l: 2108 a = pop(); 2109 b = _gvn.transform( new ConvI2LNode(a)); 2110 push_pair(b); 2111 break; 2112 case Bytecodes::_i2b: 2113 // Sign extend 2114 a = pop(); 2115 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(24)) ); 2116 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(24)) ); 2117 push( a ); 2118 break; 2119 case Bytecodes::_i2s: 2120 a = pop(); 2121 a = _gvn.transform( new LShiftINode(a,_gvn.intcon(16)) ); 2122 a = _gvn.transform( new RShiftINode(a,_gvn.intcon(16)) ); 2123 push( a ); 2124 break; 2125 case Bytecodes::_i2c: 2126 a = pop(); 2127 push( _gvn.transform( new AndINode(a,_gvn.intcon(0xFFFF)) ) ); 2128 break; 2129 2130 case Bytecodes::_i2f: 2131 a = pop(); 2132 b = _gvn.transform( new ConvI2FNode(a) ) ; 2133 c = precision_rounding(b); 2134 push (b); 2135 break; 2136 2137 case Bytecodes::_i2d: 2138 a = pop(); 2139 b = _gvn.transform( new ConvI2DNode(a)); 2140 push_pair(b); 2141 break; 2142 2143 case Bytecodes::_iinc: // Increment local 2144 i = iter().get_index(); // Get local index 2145 set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) ); 2146 break; 2147 2148 // Exit points of synchronized methods must have an unlock node 2149 case Bytecodes::_return: 2150 return_current(NULL); 2151 break; 2152 2153 case Bytecodes::_ireturn: 2154 case Bytecodes::_areturn: 2155 case Bytecodes::_freturn: 2156 return_current(pop()); 2157 break; 2158 case Bytecodes::_lreturn: 2159 return_current(pop_pair()); 2160 break; 2161 case Bytecodes::_dreturn: 2162 return_current(pop_pair()); 2163 break; 2164 2165 case Bytecodes::_athrow: 2166 // null exception oop throws NULL pointer exception 2167 null_check(peek()); 2168 if (stopped()) return; 2169 // Hook the thrown exception directly to subsequent handlers. 2170 if (BailoutToInterpreterForThrows) { 2171 // Keep method interpreted from now on. 2172 uncommon_trap(Deoptimization::Reason_unhandled, 2173 Deoptimization::Action_make_not_compilable); 2174 return; 2175 } 2176 if (env()->jvmti_can_post_on_exceptions()) { 2177 // check if we must post exception events, take uncommon trap if so (with must_throw = false) 2178 uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false); 2179 } 2180 // Here if either can_post_on_exceptions or should_post_on_exceptions is false 2181 add_exception_state(make_exception_state(peek())); 2182 break; 2183 2184 case Bytecodes::_goto: // fall through 2185 case Bytecodes::_goto_w: { 2186 int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest(); 2187 2188 // If this is a backwards branch in the bytecodes, add Safepoint 2189 maybe_add_safepoint(target_bci); 2190 2191 // Update method data 2192 profile_taken_branch(target_bci); 2193 2194 // Merge the current control into the target basic block 2195 merge(target_bci); 2196 2197 // See if we can get some profile data and hand it off to the next block 2198 Block *target_block = block()->successor_for_bci(target_bci); 2199 if (target_block->pred_count() != 1) break; 2200 ciMethodData* methodData = method()->method_data(); 2201 if (!methodData->is_mature()) break; 2202 ciProfileData* data = methodData->bci_to_data(bci()); 2203 assert( data->is_JumpData(), "" ); 2204 int taken = ((ciJumpData*)data)->taken(); 2205 taken = method()->scale_count(taken); 2206 target_block->set_count(taken); 2207 break; 2208 } 2209 2210 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null; 2211 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null; 2212 handle_if_null: 2213 // If this is a backwards branch in the bytecodes, add Safepoint 2214 maybe_add_safepoint(iter().get_dest()); 2215 a = null(); 2216 b = pop(); 2217 if (!_gvn.type(b)->speculative_maybe_null() && 2218 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2219 inc_sp(1); 2220 Node* null_ctl = top(); 2221 b = null_check_oop(b, &null_ctl, true, true, true); 2222 assert(null_ctl->is_top(), "no null control here"); 2223 dec_sp(1); 2224 } 2225 c = _gvn.transform( new CmpPNode(b, a) ); 2226 do_ifnull(btest, c); 2227 break; 2228 2229 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp; 2230 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp; 2231 handle_if_acmp: 2232 // If this is a backwards branch in the bytecodes, add Safepoint 2233 maybe_add_safepoint(iter().get_dest()); 2234 a = pop(); 2235 b = pop(); 2236 c = _gvn.transform( new CmpPNode(b, a) ); 2237 c = optimize_cmp_with_klass(c); 2238 do_if(btest, c); 2239 break; 2240 2241 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx; 2242 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx; 2243 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx; 2244 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx; 2245 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx; 2246 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx; 2247 handle_ifxx: 2248 // If this is a backwards branch in the bytecodes, add Safepoint 2249 maybe_add_safepoint(iter().get_dest()); 2250 a = _gvn.intcon(0); 2251 b = pop(); 2252 c = _gvn.transform( new CmpINode(b, a) ); 2253 do_if(btest, c); 2254 break; 2255 2256 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp; 2257 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp; 2258 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp; 2259 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp; 2260 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp; 2261 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp; 2262 handle_if_icmp: 2263 // If this is a backwards branch in the bytecodes, add Safepoint 2264 maybe_add_safepoint(iter().get_dest()); 2265 a = pop(); 2266 b = pop(); 2267 c = _gvn.transform( new CmpINode( b, a ) ); 2268 do_if(btest, c); 2269 break; 2270 2271 case Bytecodes::_tableswitch: 2272 do_tableswitch(); 2273 break; 2274 2275 case Bytecodes::_lookupswitch: 2276 do_lookupswitch(); 2277 break; 2278 2279 case Bytecodes::_invokestatic: 2280 case Bytecodes::_invokedynamic: 2281 case Bytecodes::_invokespecial: 2282 case Bytecodes::_invokevirtual: 2283 case Bytecodes::_invokeinterface: 2284 do_call(); 2285 break; 2286 case Bytecodes::_checkcast: 2287 do_checkcast(); 2288 break; 2289 case Bytecodes::_instanceof: 2290 do_instanceof(); 2291 break; 2292 case Bytecodes::_anewarray: 2293 do_anewarray(); 2294 break; 2295 case Bytecodes::_newarray: 2296 do_newarray((BasicType)iter().get_index()); 2297 break; 2298 case Bytecodes::_multianewarray: 2299 do_multianewarray(); 2300 break; 2301 case Bytecodes::_new: 2302 do_new(); 2303 break; 2304 2305 case Bytecodes::_jsr: 2306 case Bytecodes::_jsr_w: 2307 do_jsr(); 2308 break; 2309 2310 case Bytecodes::_ret: 2311 do_ret(); 2312 break; 2313 2314 2315 case Bytecodes::_monitorenter: 2316 do_monitor_enter(); 2317 break; 2318 2319 case Bytecodes::_monitorexit: 2320 do_monitor_exit(); 2321 break; 2322 2323 case Bytecodes::_breakpoint: 2324 // Breakpoint set concurrently to compile 2325 // %%% use an uncommon trap? 2326 C->record_failure("breakpoint in method"); 2327 return; 2328 2329 default: 2330#ifndef PRODUCT 2331 map()->dump(99); 2332#endif 2333 tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) ); 2334 ShouldNotReachHere(); 2335 } 2336 2337#ifndef PRODUCT 2338 IdealGraphPrinter *printer = IdealGraphPrinter::printer(); 2339 if(printer) { 2340 char buffer[256]; 2341 sprintf(buffer, "Bytecode %d: %s", bci(), Bytecodes::name(bc())); 2342 bool old = printer->traverse_outs(); 2343 printer->set_traverse_outs(true); 2344 printer->print_method(C, buffer, 4); 2345 printer->set_traverse_outs(old); 2346 } 2347#endif 2348} 2349