annotate src/share/vm/opto/parse2.cpp @ 844:bd02caa94611

6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
author xdono
date Tue, 28 Jul 2009 12:12:40 -0700
parents bf3489cc0aa0
children 148e5441d916
rev   line source
duke@0 1 /*
xdono@844 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 #include "incls/_precompiled.incl"
duke@0 26 #include "incls/_parse2.cpp.incl"
duke@0 27
duke@0 28 extern int explicit_null_checks_inserted,
duke@0 29 explicit_null_checks_elided;
duke@0 30
duke@0 31 //---------------------------------array_load----------------------------------
duke@0 32 void Parse::array_load(BasicType elem_type) {
duke@0 33 const Type* elem = Type::TOP;
duke@0 34 Node* adr = array_addressing(elem_type, 0, &elem);
twisti@605 35 if (stopped()) return; // guaranteed null or range check
duke@0 36 _sp -= 2; // Pop array and index
duke@0 37 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
duke@0 38 Node* ld = make_load(control(), adr, elem, elem_type, adr_type);
duke@0 39 push(ld);
duke@0 40 }
duke@0 41
duke@0 42
duke@0 43 //--------------------------------array_store----------------------------------
duke@0 44 void Parse::array_store(BasicType elem_type) {
duke@0 45 Node* adr = array_addressing(elem_type, 1);
twisti@605 46 if (stopped()) return; // guaranteed null or range check
duke@0 47 Node* val = pop();
duke@0 48 _sp -= 2; // Pop array and index
duke@0 49 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
duke@0 50 store_to_memory(control(), adr, val, elem_type, adr_type);
duke@0 51 }
duke@0 52
duke@0 53
duke@0 54 //------------------------------array_addressing-------------------------------
duke@0 55 // Pull array and index from the stack. Compute pointer-to-element.
duke@0 56 Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) {
duke@0 57 Node *idx = peek(0+vals); // Get from stack without popping
duke@0 58 Node *ary = peek(1+vals); // in case of exception
duke@0 59
duke@0 60 // Null check the array base, with correct stack contents
duke@0 61 ary = do_null_check(ary, T_ARRAY);
duke@0 62 // Compile-time detect of null-exception?
duke@0 63 if (stopped()) return top();
duke@0 64
duke@0 65 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr();
duke@0 66 const TypeInt* sizetype = arytype->size();
duke@0 67 const Type* elemtype = arytype->elem();
duke@0 68
duke@0 69 if (UseUniqueSubclasses && result2 != NULL) {
kvn@221 70 const Type* el = elemtype->make_ptr();
kvn@221 71 if (el && el->isa_instptr()) {
kvn@221 72 const TypeInstPtr* toop = el->is_instptr();
duke@0 73 if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) {
duke@0 74 // If we load from "AbstractClass[]" we must see "ConcreteSubClass".
duke@0 75 const Type* subklass = Type::get_const_type(toop->klass());
coleenp@113 76 elemtype = subklass->join(el);
duke@0 77 }
duke@0 78 }
duke@0 79 }
duke@0 80
duke@0 81 // Check for big class initializers with all constant offsets
duke@0 82 // feeding into a known-size array.
duke@0 83 const TypeInt* idxtype = _gvn.type(idx)->is_int();
duke@0 84 // See if the highest idx value is less than the lowest array bound,
duke@0 85 // and if the idx value cannot be negative:
duke@0 86 bool need_range_check = true;
duke@0 87 if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) {
duke@0 88 need_range_check = false;
duke@0 89 if (C->log() != NULL) C->log()->elem("observe that='!need_range_check'");
duke@0 90 }
duke@0 91
duke@0 92 if (!arytype->klass()->is_loaded()) {
duke@0 93 // Only fails for some -Xcomp runs
duke@0 94 // The class is unloaded. We have to run this bytecode in the interpreter.
duke@0 95 uncommon_trap(Deoptimization::Reason_unloaded,
duke@0 96 Deoptimization::Action_reinterpret,
duke@0 97 arytype->klass(), "!loaded array");
duke@0 98 return top();
duke@0 99 }
duke@0 100
duke@0 101 // Do the range check
duke@0 102 if (GenerateRangeChecks && need_range_check) {
rasbold@129 103 Node* tst;
rasbold@129 104 if (sizetype->_hi <= 0) {
rasbold@366 105 // The greatest array bound is negative, so we can conclude that we're
rasbold@129 106 // compiling unreachable code, but the unsigned compare trick used below
rasbold@129 107 // only works with non-negative lengths. Instead, hack "tst" to be zero so
rasbold@129 108 // the uncommon_trap path will always be taken.
rasbold@129 109 tst = _gvn.intcon(0);
rasbold@129 110 } else {
rasbold@366 111 // Range is constant in array-oop, so we can use the original state of mem
rasbold@366 112 Node* len = load_array_length(ary);
rasbold@366 113
rasbold@129 114 // Test length vs index (standard trick using unsigned compare)
rasbold@129 115 Node* chk = _gvn.transform( new (C, 3) CmpUNode(idx, len) );
rasbold@129 116 BoolTest::mask btest = BoolTest::lt;
rasbold@129 117 tst = _gvn.transform( new (C, 2) BoolNode(chk, btest) );
rasbold@129 118 }
duke@0 119 // Branch to failure if out of bounds
duke@0 120 { BuildCutout unless(this, tst, PROB_MAX);
duke@0 121 if (C->allow_range_check_smearing()) {
duke@0 122 // Do not use builtin_throw, since range checks are sometimes
duke@0 123 // made more stringent by an optimistic transformation.
duke@0 124 // This creates "tentative" range checks at this point,
duke@0 125 // which are not guaranteed to throw exceptions.
duke@0 126 // See IfNode::Ideal, is_range_check, adjust_check.
duke@0 127 uncommon_trap(Deoptimization::Reason_range_check,
duke@0 128 Deoptimization::Action_make_not_entrant,
duke@0 129 NULL, "range_check");
duke@0 130 } else {
duke@0 131 // If we have already recompiled with the range-check-widening
duke@0 132 // heroic optimization turned off, then we must really be throwing
duke@0 133 // range check exceptions.
duke@0 134 builtin_throw(Deoptimization::Reason_range_check, idx);
duke@0 135 }
duke@0 136 }
duke@0 137 }
duke@0 138 // Check for always knowing you are throwing a range-check exception
duke@0 139 if (stopped()) return top();
duke@0 140
rasbold@366 141 Node* ptr = array_element_address(ary, idx, type, sizetype);
duke@0 142
duke@0 143 if (result2 != NULL) *result2 = elemtype;
rasbold@366 144
rasbold@366 145 assert(ptr != top(), "top should go hand-in-hand with stopped");
rasbold@366 146
duke@0 147 return ptr;
duke@0 148 }
duke@0 149
duke@0 150
duke@0 151 // returns IfNode
duke@0 152 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask) {
duke@0 153 Node *cmp = _gvn.transform( new (C, 3) CmpINode( a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
duke@0 154 Node *tst = _gvn.transform( new (C, 2) BoolNode( cmp, mask));
duke@0 155 IfNode *iff = create_and_map_if( control(), tst, ((mask == BoolTest::eq) ? PROB_STATIC_INFREQUENT : PROB_FAIR), COUNT_UNKNOWN );
duke@0 156 return iff;
duke@0 157 }
duke@0 158
duke@0 159 // return Region node
duke@0 160 Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) {
duke@0 161 Node *region = new (C, 3) RegionNode(3); // 2 results
duke@0 162 record_for_igvn(region);
duke@0 163 region->init_req(1, iffalse);
duke@0 164 region->init_req(2, iftrue );
duke@0 165 _gvn.set_type(region, Type::CONTROL);
duke@0 166 region = _gvn.transform(region);
duke@0 167 set_control (region);
duke@0 168 return region;
duke@0 169 }
duke@0 170
duke@0 171
duke@0 172 //------------------------------helper for tableswitch-------------------------
duke@0 173 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) {
duke@0 174 // True branch, use existing map info
duke@0 175 { PreserveJVMState pjvms(this);
duke@0 176 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode (iff) );
duke@0 177 set_control( iftrue );
duke@0 178 profile_switch_case(prof_table_index);
duke@0 179 merge_new_path(dest_bci_if_true);
duke@0 180 }
duke@0 181
duke@0 182 // False branch
duke@0 183 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff) );
duke@0 184 set_control( iffalse );
duke@0 185 }
duke@0 186
duke@0 187 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) {
duke@0 188 // True branch, use existing map info
duke@0 189 { PreserveJVMState pjvms(this);
duke@0 190 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode (iff) );
duke@0 191 set_control( iffalse );
duke@0 192 profile_switch_case(prof_table_index);
duke@0 193 merge_new_path(dest_bci_if_true);
duke@0 194 }
duke@0 195
duke@0 196 // False branch
duke@0 197 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff) );
duke@0 198 set_control( iftrue );
duke@0 199 }
duke@0 200
duke@0 201 void Parse::jump_if_always_fork(int dest_bci, int prof_table_index) {
duke@0 202 // False branch, use existing map and control()
duke@0 203 profile_switch_case(prof_table_index);
duke@0 204 merge_new_path(dest_bci);
duke@0 205 }
duke@0 206
duke@0 207
duke@0 208 extern "C" {
duke@0 209 static int jint_cmp(const void *i, const void *j) {
duke@0 210 int a = *(jint *)i;
duke@0 211 int b = *(jint *)j;
duke@0 212 return a > b ? 1 : a < b ? -1 : 0;
duke@0 213 }
duke@0 214 }
duke@0 215
duke@0 216
duke@0 217 // Default value for methodData switch indexing. Must be a negative value to avoid
duke@0 218 // conflict with any legal switch index.
duke@0 219 #define NullTableIndex -1
duke@0 220
duke@0 221 class SwitchRange : public StackObj {
duke@0 222 // a range of integers coupled with a bci destination
duke@0 223 jint _lo; // inclusive lower limit
duke@0 224 jint _hi; // inclusive upper limit
duke@0 225 int _dest;
duke@0 226 int _table_index; // index into method data table
duke@0 227
duke@0 228 public:
duke@0 229 jint lo() const { return _lo; }
duke@0 230 jint hi() const { return _hi; }
duke@0 231 int dest() const { return _dest; }
duke@0 232 int table_index() const { return _table_index; }
duke@0 233 bool is_singleton() const { return _lo == _hi; }
duke@0 234
duke@0 235 void setRange(jint lo, jint hi, int dest, int table_index) {
duke@0 236 assert(lo <= hi, "must be a non-empty range");
duke@0 237 _lo = lo, _hi = hi; _dest = dest; _table_index = table_index;
duke@0 238 }
duke@0 239 bool adjoinRange(jint lo, jint hi, int dest, int table_index) {
duke@0 240 assert(lo <= hi, "must be a non-empty range");
duke@0 241 if (lo == _hi+1 && dest == _dest && table_index == _table_index) {
duke@0 242 _hi = hi;
duke@0 243 return true;
duke@0 244 }
duke@0 245 return false;
duke@0 246 }
duke@0 247
duke@0 248 void set (jint value, int dest, int table_index) {
duke@0 249 setRange(value, value, dest, table_index);
duke@0 250 }
duke@0 251 bool adjoin(jint value, int dest, int table_index) {
duke@0 252 return adjoinRange(value, value, dest, table_index);
duke@0 253 }
duke@0 254
duke@0 255 void print(ciEnv* env) {
duke@0 256 if (is_singleton())
duke@0 257 tty->print(" {%d}=>%d", lo(), dest());
duke@0 258 else if (lo() == min_jint)
duke@0 259 tty->print(" {..%d}=>%d", hi(), dest());
duke@0 260 else if (hi() == max_jint)
duke@0 261 tty->print(" {%d..}=>%d", lo(), dest());
duke@0 262 else
duke@0 263 tty->print(" {%d..%d}=>%d", lo(), hi(), dest());
duke@0 264 }
duke@0 265 };
duke@0 266
duke@0 267
duke@0 268 //-------------------------------do_tableswitch--------------------------------
duke@0 269 void Parse::do_tableswitch() {
duke@0 270 Node* lookup = pop();
duke@0 271
duke@0 272 // Get information about tableswitch
duke@0 273 int default_dest = iter().get_dest_table(0);
duke@0 274 int lo_index = iter().get_int_table(1);
duke@0 275 int hi_index = iter().get_int_table(2);
duke@0 276 int len = hi_index - lo_index + 1;
duke@0 277
duke@0 278 if (len < 1) {
duke@0 279 // If this is a backward branch, add safepoint
duke@0 280 maybe_add_safepoint(default_dest);
duke@0 281 merge(default_dest);
duke@0 282 return;
duke@0 283 }
duke@0 284
duke@0 285 // generate decision tree, using trichotomy when possible
duke@0 286 int rnum = len+2;
duke@0 287 bool makes_backward_branch = false;
duke@0 288 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
duke@0 289 int rp = -1;
duke@0 290 if (lo_index != min_jint) {
duke@0 291 ranges[++rp].setRange(min_jint, lo_index-1, default_dest, NullTableIndex);
duke@0 292 }
duke@0 293 for (int j = 0; j < len; j++) {
duke@0 294 jint match_int = lo_index+j;
duke@0 295 int dest = iter().get_dest_table(j+3);
duke@0 296 makes_backward_branch |= (dest <= bci());
duke@0 297 int table_index = method_data_update() ? j : NullTableIndex;
duke@0 298 if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index)) {
duke@0 299 ranges[++rp].set(match_int, dest, table_index);
duke@0 300 }
duke@0 301 }
duke@0 302 jint highest = lo_index+(len-1);
duke@0 303 assert(ranges[rp].hi() == highest, "");
duke@0 304 if (highest != max_jint
duke@0 305 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex)) {
duke@0 306 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex);
duke@0 307 }
duke@0 308 assert(rp < len+2, "not too many ranges");
duke@0 309
duke@0 310 // Safepoint in case if backward branch observed
duke@0 311 if( makes_backward_branch && UseLoopSafepoints )
duke@0 312 add_safepoint();
duke@0 313
duke@0 314 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
duke@0 315 }
duke@0 316
duke@0 317
duke@0 318 //------------------------------do_lookupswitch--------------------------------
duke@0 319 void Parse::do_lookupswitch() {
duke@0 320 Node *lookup = pop(); // lookup value
duke@0 321 // Get information about lookupswitch
duke@0 322 int default_dest = iter().get_dest_table(0);
duke@0 323 int len = iter().get_int_table(1);
duke@0 324
duke@0 325 if (len < 1) { // If this is a backward branch, add safepoint
duke@0 326 maybe_add_safepoint(default_dest);
duke@0 327 merge(default_dest);
duke@0 328 return;
duke@0 329 }
duke@0 330
duke@0 331 // generate decision tree, using trichotomy when possible
duke@0 332 jint* table = NEW_RESOURCE_ARRAY(jint, len*2);
duke@0 333 {
duke@0 334 for( int j = 0; j < len; j++ ) {
duke@0 335 table[j+j+0] = iter().get_int_table(2+j+j);
duke@0 336 table[j+j+1] = iter().get_dest_table(2+j+j+1);
duke@0 337 }
duke@0 338 qsort( table, len, 2*sizeof(table[0]), jint_cmp );
duke@0 339 }
duke@0 340
duke@0 341 int rnum = len*2+1;
duke@0 342 bool makes_backward_branch = false;
duke@0 343 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
duke@0 344 int rp = -1;
duke@0 345 for( int j = 0; j < len; j++ ) {
duke@0 346 jint match_int = table[j+j+0];
duke@0 347 int dest = table[j+j+1];
duke@0 348 int next_lo = rp < 0 ? min_jint : ranges[rp].hi()+1;
duke@0 349 int table_index = method_data_update() ? j : NullTableIndex;
duke@0 350 makes_backward_branch |= (dest <= bci());
duke@0 351 if( match_int != next_lo ) {
duke@0 352 ranges[++rp].setRange(next_lo, match_int-1, default_dest, NullTableIndex);
duke@0 353 }
duke@0 354 if( rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index) ) {
duke@0 355 ranges[++rp].set(match_int, dest, table_index);
duke@0 356 }
duke@0 357 }
duke@0 358 jint highest = table[2*(len-1)];
duke@0 359 assert(ranges[rp].hi() == highest, "");
duke@0 360 if( highest != max_jint
duke@0 361 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex) ) {
duke@0 362 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex);
duke@0 363 }
duke@0 364 assert(rp < rnum, "not too many ranges");
duke@0 365
duke@0 366 // Safepoint in case backward branch observed
duke@0 367 if( makes_backward_branch && UseLoopSafepoints )
duke@0 368 add_safepoint();
duke@0 369
duke@0 370 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
duke@0 371 }
duke@0 372
duke@0 373 //----------------------------create_jump_tables-------------------------------
duke@0 374 bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) {
duke@0 375 // Are jumptables enabled
duke@0 376 if (!UseJumpTables) return false;
duke@0 377
duke@0 378 // Are jumptables supported
duke@0 379 if (!Matcher::has_match_rule(Op_Jump)) return false;
duke@0 380
duke@0 381 // Don't make jump table if profiling
duke@0 382 if (method_data_update()) return false;
duke@0 383
duke@0 384 // Decide if a guard is needed to lop off big ranges at either (or
duke@0 385 // both) end(s) of the input set. We'll call this the default target
duke@0 386 // even though we can't be sure that it is the true "default".
duke@0 387
duke@0 388 bool needs_guard = false;
duke@0 389 int default_dest;
duke@0 390 int64 total_outlier_size = 0;
duke@0 391 int64 hi_size = ((int64)hi->hi()) - ((int64)hi->lo()) + 1;
duke@0 392 int64 lo_size = ((int64)lo->hi()) - ((int64)lo->lo()) + 1;
duke@0 393
duke@0 394 if (lo->dest() == hi->dest()) {
duke@0 395 total_outlier_size = hi_size + lo_size;
duke@0 396 default_dest = lo->dest();
duke@0 397 } else if (lo_size > hi_size) {
duke@0 398 total_outlier_size = lo_size;
duke@0 399 default_dest = lo->dest();
duke@0 400 } else {
duke@0 401 total_outlier_size = hi_size;
duke@0 402 default_dest = hi->dest();
duke@0 403 }
duke@0 404
duke@0 405 // If a guard test will eliminate very sparse end ranges, then
duke@0 406 // it is worth the cost of an extra jump.
duke@0 407 if (total_outlier_size > (MaxJumpTableSparseness * 4)) {
duke@0 408 needs_guard = true;
duke@0 409 if (default_dest == lo->dest()) lo++;
duke@0 410 if (default_dest == hi->dest()) hi--;
duke@0 411 }
duke@0 412
duke@0 413 // Find the total number of cases and ranges
duke@0 414 int64 num_cases = ((int64)hi->hi()) - ((int64)lo->lo()) + 1;
duke@0 415 int num_range = hi - lo + 1;
duke@0 416
duke@0 417 // Don't create table if: too large, too small, or too sparse.
duke@0 418 if (num_cases < MinJumpTableSize || num_cases > MaxJumpTableSize)
duke@0 419 return false;
duke@0 420 if (num_cases > (MaxJumpTableSparseness * num_range))
duke@0 421 return false;
duke@0 422
duke@0 423 // Normalize table lookups to zero
duke@0 424 int lowval = lo->lo();
duke@0 425 key_val = _gvn.transform( new (C, 3) SubINode(key_val, _gvn.intcon(lowval)) );
duke@0 426
duke@0 427 // Generate a guard to protect against input keyvals that aren't
duke@0 428 // in the switch domain.
duke@0 429 if (needs_guard) {
duke@0 430 Node* size = _gvn.intcon(num_cases);
duke@0 431 Node* cmp = _gvn.transform( new (C, 3) CmpUNode(key_val, size) );
duke@0 432 Node* tst = _gvn.transform( new (C, 2) BoolNode(cmp, BoolTest::ge) );
duke@0 433 IfNode* iff = create_and_map_if( control(), tst, PROB_FAIR, COUNT_UNKNOWN);
duke@0 434 jump_if_true_fork(iff, default_dest, NullTableIndex);
duke@0 435 }
duke@0 436
duke@0 437 // Create an ideal node JumpTable that has projections
duke@0 438 // of all possible ranges for a switch statement
duke@0 439 // The key_val input must be converted to a pointer offset and scaled.
duke@0 440 // Compare Parse::array_addressing above.
duke@0 441 #ifdef _LP64
duke@0 442 // Clean the 32-bit int into a real 64-bit offset.
duke@0 443 // Otherwise, the jint value 0 might turn into an offset of 0x0800000000.
duke@0 444 const TypeLong* lkeytype = TypeLong::make(CONST64(0), num_cases-1, Type::WidenMin);
duke@0 445 key_val = _gvn.transform( new (C, 2) ConvI2LNode(key_val, lkeytype) );
duke@0 446 #endif
duke@0 447 // Shift the value by wordsize so we have an index into the table, rather
duke@0 448 // than a switch value
duke@0 449 Node *shiftWord = _gvn.MakeConX(wordSize);
duke@0 450 key_val = _gvn.transform( new (C, 3) MulXNode( key_val, shiftWord));
duke@0 451
duke@0 452 // Create the JumpNode
duke@0 453 Node* jtn = _gvn.transform( new (C, 2) JumpNode(control(), key_val, num_cases) );
duke@0 454
duke@0 455 // These are the switch destinations hanging off the jumpnode
duke@0 456 int i = 0;
duke@0 457 for (SwitchRange* r = lo; r <= hi; r++) {
duke@0 458 for (int j = r->lo(); j <= r->hi(); j++, i++) {
duke@0 459 Node* input = _gvn.transform(new (C, 1) JumpProjNode(jtn, i, r->dest(), j - lowval));
duke@0 460 {
duke@0 461 PreserveJVMState pjvms(this);
duke@0 462 set_control(input);
duke@0 463 jump_if_always_fork(r->dest(), r->table_index());
duke@0 464 }
duke@0 465 }
duke@0 466 }
duke@0 467 assert(i == num_cases, "miscount of cases");
duke@0 468 stop_and_kill_map(); // no more uses for this JVMS
duke@0 469 return true;
duke@0 470 }
duke@0 471
duke@0 472 //----------------------------jump_switch_ranges-------------------------------
duke@0 473 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) {
duke@0 474 Block* switch_block = block();
duke@0 475
duke@0 476 if (switch_depth == 0) {
duke@0 477 // Do special processing for the top-level call.
duke@0 478 assert(lo->lo() == min_jint, "initial range must exhaust Type::INT");
duke@0 479 assert(hi->hi() == max_jint, "initial range must exhaust Type::INT");
duke@0 480
duke@0 481 // Decrement pred-numbers for the unique set of nodes.
duke@0 482 #ifdef ASSERT
duke@0 483 // Ensure that the block's successors are a (duplicate-free) set.
duke@0 484 int successors_counted = 0; // block occurrences in [hi..lo]
duke@0 485 int unique_successors = switch_block->num_successors();
duke@0 486 for (int i = 0; i < unique_successors; i++) {
duke@0 487 Block* target = switch_block->successor_at(i);
duke@0 488
duke@0 489 // Check that the set of successors is the same in both places.
duke@0 490 int successors_found = 0;
duke@0 491 for (SwitchRange* p = lo; p <= hi; p++) {
duke@0 492 if (p->dest() == target->start()) successors_found++;
duke@0 493 }
duke@0 494 assert(successors_found > 0, "successor must be known");
duke@0 495 successors_counted += successors_found;
duke@0 496 }
duke@0 497 assert(successors_counted == (hi-lo)+1, "no unexpected successors");
duke@0 498 #endif
duke@0 499
duke@0 500 // Maybe prune the inputs, based on the type of key_val.
duke@0 501 jint min_val = min_jint;
duke@0 502 jint max_val = max_jint;
duke@0 503 const TypeInt* ti = key_val->bottom_type()->isa_int();
duke@0 504 if (ti != NULL) {
duke@0 505 min_val = ti->_lo;
duke@0 506 max_val = ti->_hi;
duke@0 507 assert(min_val <= max_val, "invalid int type");
duke@0 508 }
duke@0 509 while (lo->hi() < min_val) lo++;
duke@0 510 if (lo->lo() < min_val) lo->setRange(min_val, lo->hi(), lo->dest(), lo->table_index());
duke@0 511 while (hi->lo() > max_val) hi--;
duke@0 512 if (hi->hi() > max_val) hi->setRange(hi->lo(), max_val, hi->dest(), hi->table_index());
duke@0 513 }
duke@0 514
duke@0 515 #ifndef PRODUCT
duke@0 516 if (switch_depth == 0) {
duke@0 517 _max_switch_depth = 0;
duke@0 518 _est_switch_depth = log2_intptr((hi-lo+1)-1)+1;
duke@0 519 }
duke@0 520 #endif
duke@0 521
duke@0 522 assert(lo <= hi, "must be a non-empty set of ranges");
duke@0 523 if (lo == hi) {
duke@0 524 jump_if_always_fork(lo->dest(), lo->table_index());
duke@0 525 } else {
duke@0 526 assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges");
duke@0 527 assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges");
duke@0 528
duke@0 529 if (create_jump_tables(key_val, lo, hi)) return;
duke@0 530
duke@0 531 int nr = hi - lo + 1;
duke@0 532
duke@0 533 SwitchRange* mid = lo + nr/2;
duke@0 534 // if there is an easy choice, pivot at a singleton:
duke@0 535 if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton()) mid--;
duke@0 536
duke@0 537 assert(lo < mid && mid <= hi, "good pivot choice");
duke@0 538 assert(nr != 2 || mid == hi, "should pick higher of 2");
duke@0 539 assert(nr != 3 || mid == hi-1, "should pick middle of 3");
duke@0 540
duke@0 541 Node *test_val = _gvn.intcon(mid->lo());
duke@0 542
duke@0 543 if (mid->is_singleton()) {
duke@0 544 IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne);
duke@0 545 jump_if_false_fork(iff_ne, mid->dest(), mid->table_index());
duke@0 546
duke@0 547 // Special Case: If there are exactly three ranges, and the high
duke@0 548 // and low range each go to the same place, omit the "gt" test,
duke@0 549 // since it will not discriminate anything.
duke@0 550 bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest());
duke@0 551 if (eq_test_only) {
duke@0 552 assert(mid == hi-1, "");
duke@0 553 }
duke@0 554
duke@0 555 // if there is a higher range, test for it and process it:
duke@0 556 if (mid < hi && !eq_test_only) {
duke@0 557 // two comparisons of same values--should enable 1 test for 2 branches
duke@0 558 // Use BoolTest::le instead of BoolTest::gt
duke@0 559 IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le);
duke@0 560 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff_le) );
duke@0 561 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff_le) );
duke@0 562 { PreserveJVMState pjvms(this);
duke@0 563 set_control(iffalse);
duke@0 564 jump_switch_ranges(key_val, mid+1, hi, switch_depth+1);
duke@0 565 }
duke@0 566 set_control(iftrue);
duke@0 567 }
duke@0 568
duke@0 569 } else {
duke@0 570 // mid is a range, not a singleton, so treat mid..hi as a unit
duke@0 571 IfNode *iff_ge = jump_if_fork_int(key_val, test_val, BoolTest::ge);
duke@0 572
duke@0 573 // if there is a higher range, test for it and process it:
duke@0 574 if (mid == hi) {
duke@0 575 jump_if_true_fork(iff_ge, mid->dest(), mid->table_index());
duke@0 576 } else {
duke@0 577 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff_ge) );
duke@0 578 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff_ge) );
duke@0 579 { PreserveJVMState pjvms(this);
duke@0 580 set_control(iftrue);
duke@0 581 jump_switch_ranges(key_val, mid, hi, switch_depth+1);
duke@0 582 }
duke@0 583 set_control(iffalse);
duke@0 584 }
duke@0 585 }
duke@0 586
duke@0 587 // in any case, process the lower range
duke@0 588 jump_switch_ranges(key_val, lo, mid-1, switch_depth+1);
duke@0 589 }
duke@0 590
duke@0 591 // Decrease pred_count for each successor after all is done.
duke@0 592 if (switch_depth == 0) {
duke@0 593 int unique_successors = switch_block->num_successors();
duke@0 594 for (int i = 0; i < unique_successors; i++) {
duke@0 595 Block* target = switch_block->successor_at(i);
duke@0 596 // Throw away the pre-allocated path for each unique successor.
duke@0 597 target->next_path_num();
duke@0 598 }
duke@0 599 }
duke@0 600
duke@0 601 #ifndef PRODUCT
duke@0 602 _max_switch_depth = MAX2(switch_depth, _max_switch_depth);
duke@0 603 if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) {
duke@0 604 SwitchRange* r;
duke@0 605 int nsing = 0;
duke@0 606 for( r = lo; r <= hi; r++ ) {
duke@0 607 if( r->is_singleton() ) nsing++;
duke@0 608 }
duke@0 609 tty->print(">>> ");
duke@0 610 _method->print_short_name();
duke@0 611 tty->print_cr(" switch decision tree");
duke@0 612 tty->print_cr(" %d ranges (%d singletons), max_depth=%d, est_depth=%d",
duke@0 613 hi-lo+1, nsing, _max_switch_depth, _est_switch_depth);
duke@0 614 if (_max_switch_depth > _est_switch_depth) {
duke@0 615 tty->print_cr("******** BAD SWITCH DEPTH ********");
duke@0 616 }
duke@0 617 tty->print(" ");
duke@0 618 for( r = lo; r <= hi; r++ ) {
duke@0 619 r->print(env());
duke@0 620 }
duke@0 621 tty->print_cr("");
duke@0 622 }
duke@0 623 #endif
duke@0 624 }
duke@0 625
duke@0 626 void Parse::modf() {
duke@0 627 Node *f2 = pop();
duke@0 628 Node *f1 = pop();
duke@0 629 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(),
duke@0 630 CAST_FROM_FN_PTR(address, SharedRuntime::frem),
duke@0 631 "frem", NULL, //no memory effects
duke@0 632 f1, f2);
duke@0 633 Node* res = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
duke@0 634
duke@0 635 push(res);
duke@0 636 }
duke@0 637
duke@0 638 void Parse::modd() {
duke@0 639 Node *d2 = pop_pair();
duke@0 640 Node *d1 = pop_pair();
duke@0 641 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(),
duke@0 642 CAST_FROM_FN_PTR(address, SharedRuntime::drem),
duke@0 643 "drem", NULL, //no memory effects
duke@0 644 d1, top(), d2, top());
duke@0 645 Node* res_d = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
duke@0 646
duke@0 647 #ifdef ASSERT
duke@0 648 Node* res_top = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 1));
duke@0 649 assert(res_top == top(), "second value must be top");
duke@0 650 #endif
duke@0 651
duke@0 652 push_pair(res_d);
duke@0 653 }
duke@0 654
duke@0 655 void Parse::l2f() {
duke@0 656 Node* f2 = pop();
duke@0 657 Node* f1 = pop();
duke@0 658 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(),
duke@0 659 CAST_FROM_FN_PTR(address, SharedRuntime::l2f),
duke@0 660 "l2f", NULL, //no memory effects
duke@0 661 f1, f2);
duke@0 662 Node* res = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
duke@0 663
duke@0 664 push(res);
duke@0 665 }
duke@0 666
duke@0 667 void Parse::do_irem() {
duke@0 668 // Must keep both values on the expression-stack during null-check
duke@0 669 do_null_check(peek(), T_INT);
duke@0 670 // Compile-time detect of null-exception?
duke@0 671 if (stopped()) return;
duke@0 672
duke@0 673 Node* b = pop();
duke@0 674 Node* a = pop();
duke@0 675
duke@0 676 const Type *t = _gvn.type(b);
duke@0 677 if (t != Type::TOP) {
duke@0 678 const TypeInt *ti = t->is_int();
duke@0 679 if (ti->is_con()) {
duke@0 680 int divisor = ti->get_con();
duke@0 681 // check for positive power of 2
duke@0 682 if (divisor > 0 &&
duke@0 683 (divisor & ~(divisor-1)) == divisor) {
duke@0 684 // yes !
duke@0 685 Node *mask = _gvn.intcon((divisor - 1));
duke@0 686 // Sigh, must handle negative dividends
duke@0 687 Node *zero = _gvn.intcon(0);
duke@0 688 IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt);
duke@0 689 Node *iff = _gvn.transform( new (C, 1) IfFalseNode(ifff) );
duke@0 690 Node *ift = _gvn.transform( new (C, 1) IfTrueNode (ifff) );
duke@0 691 Node *reg = jump_if_join(ift, iff);
duke@0 692 Node *phi = PhiNode::make(reg, NULL, TypeInt::INT);
duke@0 693 // Negative path; negate/and/negate
duke@0 694 Node *neg = _gvn.transform( new (C, 3) SubINode(zero, a) );
duke@0 695 Node *andn= _gvn.transform( new (C, 3) AndINode(neg, mask) );
duke@0 696 Node *negn= _gvn.transform( new (C, 3) SubINode(zero, andn) );
duke@0 697 phi->init_req(1, negn);
duke@0 698 // Fast positive case
duke@0 699 Node *andx = _gvn.transform( new (C, 3) AndINode(a, mask) );
duke@0 700 phi->init_req(2, andx);
duke@0 701 // Push the merge
duke@0 702 push( _gvn.transform(phi) );
duke@0 703 return;
duke@0 704 }
duke@0 705 }
duke@0 706 }
duke@0 707 // Default case
duke@0 708 push( _gvn.transform( new (C, 3) ModINode(control(),a,b) ) );
duke@0 709 }
duke@0 710
duke@0 711 // Handle jsr and jsr_w bytecode
duke@0 712 void Parse::do_jsr() {
duke@0 713 assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode");
duke@0 714
duke@0 715 // Store information about current state, tagged with new _jsr_bci
duke@0 716 int return_bci = iter().next_bci();
duke@0 717 int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest();
duke@0 718
duke@0 719 // Update method data
duke@0 720 profile_taken_branch(jsr_bci);
duke@0 721
duke@0 722 // The way we do things now, there is only one successor block
duke@0 723 // for the jsr, because the target code is cloned by ciTypeFlow.
duke@0 724 Block* target = successor_for_bci(jsr_bci);
duke@0 725
duke@0 726 // What got pushed?
duke@0 727 const Type* ret_addr = target->peek();
duke@0 728 assert(ret_addr->singleton(), "must be a constant (cloned jsr body)");
duke@0 729
duke@0 730 // Effect on jsr on stack
duke@0 731 push(_gvn.makecon(ret_addr));
duke@0 732
duke@0 733 // Flow to the jsr.
duke@0 734 merge(jsr_bci);
duke@0 735 }
duke@0 736
duke@0 737 // Handle ret bytecode
duke@0 738 void Parse::do_ret() {
duke@0 739 // Find to whom we return.
duke@0 740 #if 0 // %%%% MAKE THIS WORK
duke@0 741 Node* con = local();
duke@0 742 const TypePtr* tp = con->bottom_type()->isa_ptr();
duke@0 743 assert(tp && tp->singleton(), "");
duke@0 744 int return_bci = (int) tp->get_con();
duke@0 745 merge(return_bci);
duke@0 746 #else
duke@0 747 assert(block()->num_successors() == 1, "a ret can only go one place now");
duke@0 748 Block* target = block()->successor_at(0);
duke@0 749 assert(!target->is_ready(), "our arrival must be expected");
duke@0 750 profile_ret(target->flow()->start());
duke@0 751 int pnum = target->next_path_num();
duke@0 752 merge_common(target, pnum);
duke@0 753 #endif
duke@0 754 }
duke@0 755
duke@0 756 //--------------------------dynamic_branch_prediction--------------------------
duke@0 757 // Try to gather dynamic branch prediction behavior. Return a probability
duke@0 758 // of the branch being taken and set the "cnt" field. Returns a -1.0
duke@0 759 // if we need to use static prediction for some reason.
duke@0 760 float Parse::dynamic_branch_prediction(float &cnt) {
duke@0 761 ResourceMark rm;
duke@0 762
duke@0 763 cnt = COUNT_UNKNOWN;
duke@0 764
duke@0 765 // Use MethodData information if it is available
duke@0 766 // FIXME: free the ProfileData structure
duke@0 767 ciMethodData* methodData = method()->method_data();
duke@0 768 if (!methodData->is_mature()) return PROB_UNKNOWN;
duke@0 769 ciProfileData* data = methodData->bci_to_data(bci());
duke@0 770 if (!data->is_JumpData()) return PROB_UNKNOWN;
duke@0 771
duke@0 772 // get taken and not taken values
duke@0 773 int taken = data->as_JumpData()->taken();
duke@0 774 int not_taken = 0;
duke@0 775 if (data->is_BranchData()) {
duke@0 776 not_taken = data->as_BranchData()->not_taken();
duke@0 777 }
duke@0 778
duke@0 779 // scale the counts to be commensurate with invocation counts:
duke@0 780 taken = method()->scale_count(taken);
duke@0 781 not_taken = method()->scale_count(not_taken);
duke@0 782
duke@0 783 // Give up if too few counts to be meaningful
duke@0 784 if (taken + not_taken < 40) {
duke@0 785 if (C->log() != NULL) {
duke@0 786 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
duke@0 787 }
duke@0 788 return PROB_UNKNOWN;
duke@0 789 }
duke@0 790
duke@0 791 // Compute frequency that we arrive here
duke@0 792 int sum = taken + not_taken;
duke@0 793 // Adjust, if this block is a cloned private block but the
duke@0 794 // Jump counts are shared. Taken the private counts for
duke@0 795 // just this path instead of the shared counts.
duke@0 796 if( block()->count() > 0 )
duke@0 797 sum = block()->count();
duke@0 798 cnt = (float)sum / (float)FreqCountInvocations;
duke@0 799
duke@0 800 // Pin probability to sane limits
duke@0 801 float prob;
duke@0 802 if( !taken )
duke@0 803 prob = (0+PROB_MIN) / 2;
duke@0 804 else if( !not_taken )
duke@0 805 prob = (1+PROB_MAX) / 2;
duke@0 806 else { // Compute probability of true path
duke@0 807 prob = (float)taken / (float)(taken + not_taken);
duke@0 808 if (prob > PROB_MAX) prob = PROB_MAX;
duke@0 809 if (prob < PROB_MIN) prob = PROB_MIN;
duke@0 810 }
duke@0 811
duke@0 812 assert((cnt > 0.0f) && (prob > 0.0f),
duke@0 813 "Bad frequency assignment in if");
duke@0 814
duke@0 815 if (C->log() != NULL) {
duke@0 816 const char* prob_str = NULL;
duke@0 817 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
duke@0 818 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
duke@0 819 char prob_str_buf[30];
duke@0 820 if (prob_str == NULL) {
duke@0 821 sprintf(prob_str_buf, "%g", prob);
duke@0 822 prob_str = prob_str_buf;
duke@0 823 }
duke@0 824 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
duke@0 825 iter().get_dest(), taken, not_taken, cnt, prob_str);
duke@0 826 }
duke@0 827 return prob;
duke@0 828 }
duke@0 829
duke@0 830 //-----------------------------branch_prediction-------------------------------
duke@0 831 float Parse::branch_prediction(float& cnt,
duke@0 832 BoolTest::mask btest,
duke@0 833 int target_bci) {
duke@0 834 float prob = dynamic_branch_prediction(cnt);
duke@0 835 // If prob is unknown, switch to static prediction
duke@0 836 if (prob != PROB_UNKNOWN) return prob;
duke@0 837
duke@0 838 prob = PROB_FAIR; // Set default value
duke@0 839 if (btest == BoolTest::eq) // Exactly equal test?
duke@0 840 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
duke@0 841 else if (btest == BoolTest::ne)
duke@0 842 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent
duke@0 843
duke@0 844 // If this is a conditional test guarding a backwards branch,
duke@0 845 // assume its a loop-back edge. Make it a likely taken branch.
duke@0 846 if (target_bci < bci()) {
duke@0 847 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt
duke@0 848 // Since it's an OSR, we probably have profile data, but since
duke@0 849 // branch_prediction returned PROB_UNKNOWN, the counts are too small.
duke@0 850 // Let's make a special check here for completely zero counts.
duke@0 851 ciMethodData* methodData = method()->method_data();
duke@0 852 if (!methodData->is_empty()) {
duke@0 853 ciProfileData* data = methodData->bci_to_data(bci());
duke@0 854 // Only stop for truly zero counts, which mean an unknown part
duke@0 855 // of the OSR-ed method, and we want to deopt to gather more stats.
duke@0 856 // If you have ANY counts, then this loop is simply 'cold' relative
duke@0 857 // to the OSR loop.
duke@0 858 if (data->as_BranchData()->taken() +
duke@0 859 data->as_BranchData()->not_taken() == 0 ) {
duke@0 860 // This is the only way to return PROB_UNKNOWN:
duke@0 861 return PROB_UNKNOWN;
duke@0 862 }
duke@0 863 }
duke@0 864 }
duke@0 865 prob = PROB_STATIC_FREQUENT; // Likely to take backwards branch
duke@0 866 }
duke@0 867
duke@0 868 assert(prob != PROB_UNKNOWN, "must have some guess at this point");
duke@0 869 return prob;
duke@0 870 }
duke@0 871
duke@0 872 // The magic constants are chosen so as to match the output of
duke@0 873 // branch_prediction() when the profile reports a zero taken count.
duke@0 874 // It is important to distinguish zero counts unambiguously, because
duke@0 875 // some branches (e.g., _213_javac.Assembler.eliminate) validly produce
duke@0 876 // very small but nonzero probabilities, which if confused with zero
duke@0 877 // counts would keep the program recompiling indefinitely.
duke@0 878 bool Parse::seems_never_taken(float prob) {
duke@0 879 return prob < PROB_MIN;
duke@0 880 }
duke@0 881
rasbold@246 882 //-------------------------------repush_if_args--------------------------------
rasbold@246 883 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
duke@0 884 inline void Parse::repush_if_args() {
duke@0 885 #ifndef PRODUCT
duke@0 886 if (PrintOpto && WizardMode) {
duke@0 887 tty->print("defending against excessive implicit null exceptions on %s @%d in ",
duke@0 888 Bytecodes::name(iter().cur_bc()), iter().cur_bci());
duke@0 889 method()->print_name(); tty->cr();
duke@0 890 }
duke@0 891 #endif
duke@0 892 int bc_depth = - Bytecodes::depth(iter().cur_bc());
duke@0 893 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
duke@0 894 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
duke@0 895 assert(argument(0) != NULL, "must exist");
duke@0 896 assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
duke@0 897 _sp += bc_depth;
duke@0 898 }
duke@0 899
duke@0 900 //----------------------------------do_ifnull----------------------------------
rasbold@248 901 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
duke@0 902 int target_bci = iter().get_dest();
duke@0 903
never@17 904 Block* branch_block = successor_for_bci(target_bci);
never@17 905 Block* next_block = successor_for_bci(iter().next_bci());
never@17 906
duke@0 907 float cnt;
duke@0 908 float prob = branch_prediction(cnt, btest, target_bci);
duke@0 909 if (prob == PROB_UNKNOWN) {
duke@0 910 // (An earlier version of do_ifnull omitted this trap for OSR methods.)
duke@0 911 #ifndef PRODUCT
duke@0 912 if (PrintOpto && Verbose)
rasbold@248 913 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
duke@0 914 #endif
rasbold@248 915 repush_if_args(); // to gather stats on loop
duke@0 916 // We need to mark this branch as taken so that if we recompile we will
duke@0 917 // see that it is possible. In the tiered system the interpreter doesn't
duke@0 918 // do profiling and by the time we get to the lower tier from the interpreter
duke@0 919 // the path may be cold again. Make sure it doesn't look untaken
duke@0 920 profile_taken_branch(target_bci, !ProfileInterpreter);
duke@0 921 uncommon_trap(Deoptimization::Reason_unreached,
duke@0 922 Deoptimization::Action_reinterpret,
duke@0 923 NULL, "cold");
never@17 924 if (EliminateAutoBox) {
never@17 925 // Mark the successor blocks as parsed
never@17 926 branch_block->next_path_num();
never@17 927 next_block->next_path_num();
never@17 928 }
duke@0 929 return;
duke@0 930 }
duke@0 931
duke@0 932 explicit_null_checks_inserted++;
duke@0 933
duke@0 934 // Generate real control flow
duke@0 935 Node *tst = _gvn.transform( new (C, 2) BoolNode( c, btest ) );
duke@0 936
duke@0 937 // Sanity check the probability value
duke@0 938 assert(prob > 0.0f,"Bad probability in Parser");
duke@0 939 // Need xform to put node in hash table
duke@0 940 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt );
duke@0 941 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
duke@0 942 // True branch
duke@0 943 { PreserveJVMState pjvms(this);
duke@0 944 Node* iftrue = _gvn.transform( new (C, 1) IfTrueNode (iff) );
duke@0 945 set_control(iftrue);
duke@0 946
duke@0 947 if (stopped()) { // Path is dead?
duke@0 948 explicit_null_checks_elided++;
never@17 949 if (EliminateAutoBox) {
never@17 950 // Mark the successor block as parsed
never@17 951 branch_block->next_path_num();
never@17 952 }
duke@0 953 } else { // Path is live.
duke@0 954 // Update method data
duke@0 955 profile_taken_branch(target_bci);
duke@0 956 adjust_map_after_if(btest, c, prob, branch_block, next_block);
duke@0 957 if (!stopped())
duke@0 958 merge(target_bci);
duke@0 959 }
duke@0 960 }
duke@0 961
duke@0 962 // False branch
duke@0 963 Node* iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff) );
duke@0 964 set_control(iffalse);
duke@0 965
duke@0 966 if (stopped()) { // Path is dead?
duke@0 967 explicit_null_checks_elided++;
never@17 968 if (EliminateAutoBox) {
never@17 969 // Mark the successor block as parsed
never@17 970 next_block->next_path_num();
never@17 971 }
duke@0 972 } else { // Path is live.
duke@0 973 // Update method data
duke@0 974 profile_not_taken_branch();
duke@0 975 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
duke@0 976 next_block, branch_block);
duke@0 977 }
duke@0 978 }
duke@0 979
duke@0 980 //------------------------------------do_if------------------------------------
duke@0 981 void Parse::do_if(BoolTest::mask btest, Node* c) {
duke@0 982 int target_bci = iter().get_dest();
duke@0 983
never@17 984 Block* branch_block = successor_for_bci(target_bci);
never@17 985 Block* next_block = successor_for_bci(iter().next_bci());
never@17 986
duke@0 987 float cnt;
duke@0 988 float prob = branch_prediction(cnt, btest, target_bci);
duke@0 989 float untaken_prob = 1.0 - prob;
duke@0 990
duke@0 991 if (prob == PROB_UNKNOWN) {
duke@0 992 #ifndef PRODUCT
duke@0 993 if (PrintOpto && Verbose)
rasbold@248 994 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
duke@0 995 #endif
duke@0 996 repush_if_args(); // to gather stats on loop
duke@0 997 // We need to mark this branch as taken so that if we recompile we will
duke@0 998 // see that it is possible. In the tiered system the interpreter doesn't
duke@0 999 // do profiling and by the time we get to the lower tier from the interpreter
duke@0 1000 // the path may be cold again. Make sure it doesn't look untaken
duke@0 1001 profile_taken_branch(target_bci, !ProfileInterpreter);
duke@0 1002 uncommon_trap(Deoptimization::Reason_unreached,
duke@0 1003 Deoptimization::Action_reinterpret,
duke@0 1004 NULL, "cold");
never@17 1005 if (EliminateAutoBox) {
never@17 1006 // Mark the successor blocks as parsed
never@17 1007 branch_block->next_path_num();
never@17 1008 next_block->next_path_num();
never@17 1009 }
duke@0 1010 return;
duke@0 1011 }
duke@0 1012
duke@0 1013 // Sanity check the probability value
duke@0 1014 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser");
duke@0 1015
duke@0 1016 bool taken_if_true = true;
duke@0 1017 // Convert BoolTest to canonical form:
duke@0 1018 if (!BoolTest(btest).is_canonical()) {
duke@0 1019 btest = BoolTest(btest).negate();
duke@0 1020 taken_if_true = false;
duke@0 1021 // prob is NOT updated here; it remains the probability of the taken
duke@0 1022 // path (as opposed to the prob of the path guarded by an 'IfTrueNode').
duke@0 1023 }
duke@0 1024 assert(btest != BoolTest::eq, "!= is the only canonical exact test");
duke@0 1025
duke@0 1026 Node* tst0 = new (C, 2) BoolNode(c, btest);
duke@0 1027 Node* tst = _gvn.transform(tst0);
duke@0 1028 BoolTest::mask taken_btest = BoolTest::illegal;
duke@0 1029 BoolTest::mask untaken_btest = BoolTest::illegal;
kvn@37 1030
kvn@37 1031 if (tst->is_Bool()) {
kvn@37 1032 // Refresh c from the transformed bool node, since it may be
kvn@37 1033 // simpler than the original c. Also re-canonicalize btest.
kvn@37 1034 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)).
kvn@37 1035 // That can arise from statements like: if (x instanceof C) ...
kvn@37 1036 if (tst != tst0) {
kvn@37 1037 // Canonicalize one more time since transform can change it.
kvn@37 1038 btest = tst->as_Bool()->_test._test;
kvn@37 1039 if (!BoolTest(btest).is_canonical()) {
kvn@37 1040 // Reverse edges one more time...
kvn@37 1041 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) );
kvn@37 1042 btest = tst->as_Bool()->_test._test;
kvn@37 1043 assert(BoolTest(btest).is_canonical(), "sanity");
kvn@37 1044 taken_if_true = !taken_if_true;
kvn@37 1045 }
kvn@37 1046 c = tst->in(1);
kvn@37 1047 }
kvn@37 1048 BoolTest::mask neg_btest = BoolTest(btest).negate();
kvn@37 1049 taken_btest = taken_if_true ? btest : neg_btest;
kvn@37 1050 untaken_btest = taken_if_true ? neg_btest : btest;
duke@0 1051 }
duke@0 1052
duke@0 1053 // Generate real control flow
duke@0 1054 float true_prob = (taken_if_true ? prob : untaken_prob);
duke@0 1055 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
duke@0 1056 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
duke@0 1057 Node* taken_branch = new (C, 1) IfTrueNode(iff);
duke@0 1058 Node* untaken_branch = new (C, 1) IfFalseNode(iff);
duke@0 1059 if (!taken_if_true) { // Finish conversion to canonical form
duke@0 1060 Node* tmp = taken_branch;
duke@0 1061 taken_branch = untaken_branch;
duke@0 1062 untaken_branch = tmp;
duke@0 1063 }
duke@0 1064
duke@0 1065 // Branch is taken:
duke@0 1066 { PreserveJVMState pjvms(this);
duke@0 1067 taken_branch = _gvn.transform(taken_branch);
duke@0 1068 set_control(taken_branch);
duke@0 1069
never@17 1070 if (stopped()) {
never@17 1071 if (EliminateAutoBox) {
never@17 1072 // Mark the successor block as parsed
never@17 1073 branch_block->next_path_num();
never@17 1074 }
never@17 1075 } else {
duke@0 1076 // Update method data
duke@0 1077 profile_taken_branch(target_bci);
duke@0 1078 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block);
duke@0 1079 if (!stopped())
duke@0 1080 merge(target_bci);
duke@0 1081 }
duke@0 1082 }
duke@0 1083
duke@0 1084 untaken_branch = _gvn.transform(untaken_branch);
duke@0 1085 set_control(untaken_branch);
duke@0 1086
duke@0 1087 // Branch not taken.
never@17 1088 if (stopped()) {
never@17 1089 if (EliminateAutoBox) {
never@17 1090 // Mark the successor block as parsed
never@17 1091 next_block->next_path_num();
never@17 1092 }
never@17 1093 } else {
duke@0 1094 // Update method data
duke@0 1095 profile_not_taken_branch();
duke@0 1096 adjust_map_after_if(untaken_btest, c, untaken_prob,
duke@0 1097 next_block, branch_block);
duke@0 1098 }
duke@0 1099 }
duke@0 1100
duke@0 1101 //----------------------------adjust_map_after_if------------------------------
duke@0 1102 // Adjust the JVM state to reflect the result of taking this path.
duke@0 1103 // Basically, it means inspecting the CmpNode controlling this
duke@0 1104 // branch, seeing how it constrains a tested value, and then
duke@0 1105 // deciding if it's worth our while to encode this constraint
duke@0 1106 // as graph nodes in the current abstract interpretation map.
duke@0 1107 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob,
duke@0 1108 Block* path, Block* other_path) {
duke@0 1109 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal)
duke@0 1110 return; // nothing to do
duke@0 1111
duke@0 1112 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
duke@0 1113
duke@0 1114 int cop = c->Opcode();
duke@0 1115 if (seems_never_taken(prob) && cop == Op_CmpP && btest == BoolTest::eq) {
duke@0 1116 // (An earlier version of do_if omitted '&& btest == BoolTest::eq'.)
duke@0 1117 //
duke@0 1118 // If this might possibly turn into an implicit null check,
duke@0 1119 // and the null has never yet been seen, we need to generate
duke@0 1120 // an uncommon trap, so as to recompile instead of suffering
duke@0 1121 // with very slow branches. (We'll get the slow branches if
duke@0 1122 // the program ever changes phase and starts seeing nulls here.)
duke@0 1123 //
duke@0 1124 // The tests we worry about are of the form (p == null).
duke@0 1125 // We do not simply inspect for a null constant, since a node may
duke@0 1126 // optimize to 'null' later on.
duke@0 1127 repush_if_args();
duke@0 1128 // We need to mark this branch as taken so that if we recompile we will
duke@0 1129 // see that it is possible. In the tiered system the interpreter doesn't
duke@0 1130 // do profiling and by the time we get to the lower tier from the interpreter
duke@0 1131 // the path may be cold again. Make sure it doesn't look untaken
duke@0 1132 if (is_fallthrough) {
duke@0 1133 profile_not_taken_branch(!ProfileInterpreter);
duke@0 1134 } else {
duke@0 1135 profile_taken_branch(iter().get_dest(), !ProfileInterpreter);
duke@0 1136 }
duke@0 1137 uncommon_trap(Deoptimization::Reason_unreached,
duke@0 1138 Deoptimization::Action_reinterpret,
duke@0 1139 NULL,
duke@0 1140 (is_fallthrough ? "taken always" : "taken never"));
duke@0 1141 return;
duke@0 1142 }
duke@0 1143
duke@0 1144 Node* val = c->in(1);
duke@0 1145 Node* con = c->in(2);
duke@0 1146 const Type* tcon = _gvn.type(con);
duke@0 1147 const Type* tval = _gvn.type(val);
duke@0 1148 bool have_con = tcon->singleton();
duke@0 1149 if (tval->singleton()) {
duke@0 1150 if (!have_con) {
duke@0 1151 // Swap, so constant is in con.
duke@0 1152 con = val;
duke@0 1153 tcon = tval;
duke@0 1154 val = c->in(2);
duke@0 1155 tval = _gvn.type(val);
duke@0 1156 btest = BoolTest(btest).commute();
duke@0 1157 have_con = true;
duke@0 1158 } else {
duke@0 1159 // Do we have two constants? Then leave well enough alone.
duke@0 1160 have_con = false;
duke@0 1161 }
duke@0 1162 }
duke@0 1163 if (!have_con) // remaining adjustments need a con
duke@0 1164 return;
duke@0 1165
duke@0 1166
duke@0 1167 int val_in_map = map()->find_edge(val);
duke@0 1168 if (val_in_map < 0) return; // replace_in_map would be useless
duke@0 1169 {
duke@0 1170 JVMState* jvms = this->jvms();
duke@0 1171 if (!(jvms->is_loc(val_in_map) ||
duke@0 1172 jvms->is_stk(val_in_map)))
duke@0 1173 return; // again, it would be useless
duke@0 1174 }
duke@0 1175
duke@0 1176 // Check for a comparison to a constant, and "know" that the compared
duke@0 1177 // value is constrained on this path.
duke@0 1178 assert(tcon->singleton(), "");
duke@0 1179 ConstraintCastNode* ccast = NULL;
duke@0 1180 Node* cast = NULL;
duke@0 1181
duke@0 1182 switch (btest) {
duke@0 1183 case BoolTest::eq: // Constant test?
duke@0 1184 {
duke@0 1185 const Type* tboth = tcon->join(tval);
duke@0 1186 if (tboth == tval) break; // Nothing to gain.
duke@0 1187 if (tcon->isa_int()) {
duke@0 1188 ccast = new (C, 2) CastIINode(val, tboth);
duke@0 1189 } else if (tcon == TypePtr::NULL_PTR) {
duke@0 1190 // Cast to null, but keep the pointer identity temporarily live.
duke@0 1191 ccast = new (C, 2) CastPPNode(val, tboth);
duke@0 1192 } else {
duke@0 1193 const TypeF* tf = tcon->isa_float_constant();
duke@0 1194 const TypeD* td = tcon->isa_double_constant();
duke@0 1195 // Exclude tests vs float/double 0 as these could be
duke@0 1196 // either +0 or -0. Just because you are equal to +0
duke@0 1197 // doesn't mean you ARE +0!
duke@0 1198 if ((!tf || tf->_f != 0.0) &&
duke@0 1199 (!td || td->_d != 0.0))
duke@0 1200 cast = con; // Replace non-constant val by con.
duke@0 1201 }
duke@0 1202 }
duke@0 1203 break;
duke@0 1204
duke@0 1205 case BoolTest::ne:
duke@0 1206 if (tcon == TypePtr::NULL_PTR) {
duke@0 1207 cast = cast_not_null(val, false);
duke@0 1208 }
duke@0 1209 break;
duke@0 1210
duke@0 1211 default:
duke@0 1212 // (At this point we could record int range types with CastII.)
duke@0 1213 break;
duke@0 1214 }
duke@0 1215
duke@0 1216 if (ccast != NULL) {
duke@0 1217 const Type* tcc = ccast->as_Type()->type();
duke@0 1218 assert(tcc != tval && tcc->higher_equal(tval), "must improve");
duke@0 1219 // Delay transform() call to allow recovery of pre-cast value
duke@0 1220 // at the control merge.
duke@0 1221 ccast->set_req(0, control());
duke@0 1222 _gvn.set_type_bottom(ccast);
duke@0 1223 record_for_igvn(ccast);
duke@0 1224 cast = ccast;
duke@0 1225 }
duke@0 1226
duke@0 1227 if (cast != NULL) { // Here's the payoff.
duke@0 1228 replace_in_map(val, cast);
duke@0 1229 }
duke@0 1230 }
duke@0 1231
duke@0 1232
duke@0 1233 //------------------------------do_one_bytecode--------------------------------
duke@0 1234 // Parse this bytecode, and alter the Parsers JVM->Node mapping
duke@0 1235 void Parse::do_one_bytecode() {
duke@0 1236 Node *a, *b, *c, *d; // Handy temps
duke@0 1237 BoolTest::mask btest;
duke@0 1238 int i;
duke@0 1239
duke@0 1240 assert(!has_exceptions(), "bytecode entry state must be clear of throws");
duke@0 1241
duke@0 1242 if (C->check_node_count(NodeLimitFudgeFactor * 5,
duke@0 1243 "out of nodes parsing method")) {
duke@0 1244 return;
duke@0 1245 }
duke@0 1246
duke@0 1247 #ifdef ASSERT
duke@0 1248 // for setting breakpoints
duke@0 1249 if (TraceOptoParse) {
duke@0 1250 tty->print(" @");
duke@0 1251 dump_bci(bci());
duke@0 1252 }
duke@0 1253 #endif
duke@0 1254
duke@0 1255 switch (bc()) {
duke@0 1256 case Bytecodes::_nop:
duke@0 1257 // do nothing
duke@0 1258 break;
duke@0 1259 case Bytecodes::_lconst_0:
duke@0 1260 push_pair(longcon(0));
duke@0 1261 break;
duke@0 1262
duke@0 1263 case Bytecodes::_lconst_1:
duke@0 1264 push_pair(longcon(1));
duke@0 1265 break;
duke@0 1266
duke@0 1267 case Bytecodes::_fconst_0:
duke@0 1268 push(zerocon(T_FLOAT));
duke@0 1269 break;
duke@0 1270
duke@0 1271 case Bytecodes::_fconst_1:
duke@0 1272 push(makecon(TypeF::ONE));
duke@0 1273 break;
duke@0 1274
duke@0 1275 case Bytecodes::_fconst_2:
duke@0 1276 push(makecon(TypeF::make(2.0f)));
duke@0 1277 break;
duke@0 1278
duke@0 1279 case Bytecodes::_dconst_0:
duke@0 1280 push_pair(zerocon(T_DOUBLE));
duke@0 1281 break;
duke@0 1282
duke@0 1283 case Bytecodes::_dconst_1:
duke@0 1284 push_pair(makecon(TypeD::ONE));
duke@0 1285 break;
duke@0 1286
duke@0 1287 case Bytecodes::_iconst_m1:push(intcon(-1)); break;
duke@0 1288 case Bytecodes::_iconst_0: push(intcon( 0)); break;
duke@0 1289 case Bytecodes::_iconst_1: push(intcon( 1)); break;
duke@0 1290 case Bytecodes::_iconst_2: push(intcon( 2)); break;
duke@0 1291 case Bytecodes::_iconst_3: push(intcon( 3)); break;
duke@0 1292 case Bytecodes::_iconst_4: push(intcon( 4)); break;
duke@0 1293 case Bytecodes::_iconst_5: push(intcon( 5)); break;
duke@0 1294 case Bytecodes::_bipush: push(intcon( iter().get_byte())); break;
duke@0 1295 case Bytecodes::_sipush: push(intcon( iter().get_short())); break;
duke@0 1296 case Bytecodes::_aconst_null: push(null()); break;
duke@0 1297 case Bytecodes::_ldc:
duke@0 1298 case Bytecodes::_ldc_w:
duke@0 1299 case Bytecodes::_ldc2_w:
duke@0 1300 // If the constant is unresolved, run this BC once in the interpreter.
duke@0 1301 if (iter().is_unresolved_string()) {
duke@0 1302 uncommon_trap(Deoptimization::make_trap_request
duke@0 1303 (Deoptimization::Reason_unloaded,
duke@0 1304 Deoptimization::Action_reinterpret,
duke@0 1305 iter().get_constant_index()),
duke@0 1306 NULL, "unresolved_string");
duke@0 1307 break;
duke@0 1308 } else {
duke@0 1309 ciConstant constant = iter().get_constant();
duke@0 1310 if (constant.basic_type() == T_OBJECT) {
duke@0 1311 ciObject* c = constant.as_object();
duke@0 1312 if (c->is_klass()) {
duke@0 1313 // The constant returned for a klass is the ciKlass for the
duke@0 1314 // entry. We want the java_mirror so get it.
duke@0 1315 ciKlass* klass = c->as_klass();
duke@0 1316 if (klass->is_loaded()) {
duke@0 1317 constant = ciConstant(T_OBJECT, klass->java_mirror());
duke@0 1318 } else {
duke@0 1319 uncommon_trap(Deoptimization::make_trap_request
duke@0 1320 (Deoptimization::Reason_unloaded,
duke@0 1321 Deoptimization::Action_reinterpret,
duke@0 1322 iter().get_constant_index()),
duke@0 1323 NULL, "unresolved_klass");
duke@0 1324 break;
duke@0 1325 }
duke@0 1326 }
duke@0 1327 }
duke@0 1328 push_constant(constant);
duke@0 1329 }
duke@0 1330
duke@0 1331 break;
duke@0 1332
duke@0 1333 case Bytecodes::_aload_0:
duke@0 1334 push( local(0) );
duke@0 1335 break;
duke@0 1336 case Bytecodes::_aload_1:
duke@0 1337 push( local(1) );
duke@0 1338 break;
duke@0 1339 case Bytecodes::_aload_2:
duke@0 1340 push( local(2) );
duke@0 1341 break;
duke@0 1342 case Bytecodes::_aload_3:
duke@0 1343 push( local(3) );
duke@0 1344 break;
duke@0 1345 case Bytecodes::_aload:
duke@0 1346 push( local(iter().get_index()) );
duke@0 1347 break;
duke@0 1348
duke@0 1349 case Bytecodes::_fload_0:
duke@0 1350 case Bytecodes::_iload_0:
duke@0 1351 push( local(0) );
duke@0 1352 break;
duke@0 1353 case Bytecodes::_fload_1:
duke@0 1354 case Bytecodes::_iload_1:
duke@0 1355 push( local(1) );
duke@0 1356 break;
duke@0 1357 case Bytecodes::_fload_2:
duke@0 1358 case Bytecodes::_iload_2:
duke@0 1359 push( local(2) );
duke@0 1360 break;
duke@0 1361 case Bytecodes::_fload_3:
duke@0 1362 case Bytecodes::_iload_3:
duke@0 1363 push( local(3) );
duke@0 1364 break;
duke@0 1365 case Bytecodes::_fload:
duke@0 1366 case Bytecodes::_iload:
duke@0 1367 push( local(iter().get_index()) );
duke@0 1368 break;
duke@0 1369 case Bytecodes::_lload_0:
duke@0 1370 push_pair_local( 0 );
duke@0 1371 break;
duke@0 1372 case Bytecodes::_lload_1:
duke@0 1373 push_pair_local( 1 );
duke@0 1374 break;
duke@0 1375 case Bytecodes::_lload_2:
duke@0 1376 push_pair_local( 2 );
duke@0 1377 break;
duke@0 1378 case Bytecodes::_lload_3:
duke@0 1379 push_pair_local( 3 );
duke@0 1380 break;
duke@0 1381 case Bytecodes::_lload:
duke@0 1382 push_pair_local( iter().get_index() );
duke@0 1383 break;
duke@0 1384
duke@0 1385 case Bytecodes::_dload_0:
duke@0 1386 push_pair_local(0);
duke@0 1387 break;
duke@0 1388 case Bytecodes::_dload_1:
duke@0 1389 push_pair_local(1);
duke@0 1390 break;
duke@0 1391 case Bytecodes::_dload_2:
duke@0 1392 push_pair_local(2);
duke@0 1393 break;
duke@0 1394 case Bytecodes::_dload_3:
duke@0 1395 push_pair_local(3);
duke@0 1396 break;
duke@0 1397 case Bytecodes::_dload:
duke@0 1398 push_pair_local(iter().get_index());
duke@0 1399 break;
duke@0 1400 case Bytecodes::_fstore_0:
duke@0 1401 case Bytecodes::_istore_0:
duke@0 1402 case Bytecodes::_astore_0:
duke@0 1403 set_local( 0, pop() );
duke@0 1404 break;
duke@0 1405 case Bytecodes::_fstore_1:
duke@0 1406 case Bytecodes::_istore_1:
duke@0 1407 case Bytecodes::_astore_1:
duke@0 1408 set_local( 1, pop() );
duke@0 1409 break;
duke@0 1410 case Bytecodes::_fstore_2:
duke@0 1411 case Bytecodes::_istore_2:
duke@0 1412 case Bytecodes::_astore_2:
duke@0 1413 set_local( 2, pop() );
duke@0 1414 break;
duke@0 1415 case Bytecodes::_fstore_3:
duke@0 1416 case Bytecodes::_istore_3:
duke@0 1417 case Bytecodes::_astore_3:
duke@0 1418 set_local( 3, pop() );
duke@0 1419 break;
duke@0 1420 case Bytecodes::_fstore:
duke@0 1421 case Bytecodes::_istore:
duke@0 1422 case Bytecodes::_astore:
duke@0 1423 set_local( iter().get_index(), pop() );
duke@0 1424 break;
duke@0 1425 // long stores
duke@0 1426 case Bytecodes::_lstore_0:
duke@0 1427 set_pair_local( 0, pop_pair() );
duke@0 1428 break;
duke@0 1429 case Bytecodes::_lstore_1:
duke@0 1430 set_pair_local( 1, pop_pair() );
duke@0 1431 break;
duke@0 1432 case Bytecodes::_lstore_2:
duke@0 1433 set_pair_local( 2, pop_pair() );
duke@0 1434 break;
duke@0 1435 case Bytecodes::_lstore_3:
duke@0 1436 set_pair_local( 3, pop_pair() );
duke@0 1437 break;
duke@0 1438 case Bytecodes::_lstore:
duke@0 1439 set_pair_local( iter().get_index(), pop_pair() );
duke@0 1440 break;
duke@0 1441
duke@0 1442 // double stores
duke@0 1443 case Bytecodes::_dstore_0:
duke@0 1444 set_pair_local( 0, dstore_rounding(pop_pair()) );
duke@0 1445 break;
duke@0 1446 case Bytecodes::_dstore_1:
duke@0 1447 set_pair_local( 1, dstore_rounding(pop_pair()) );
duke@0 1448 break;
duke@0 1449 case Bytecodes::_dstore_2:
duke@0 1450 set_pair_local( 2, dstore_rounding(pop_pair()) );
duke@0 1451 break;
duke@0 1452 case Bytecodes::_dstore_3:
duke@0 1453 set_pair_local( 3, dstore_rounding(pop_pair()) );
duke@0 1454 break;
duke@0 1455 case Bytecodes::_dstore:
duke@0 1456 set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) );
duke@0 1457 break;
duke@0 1458
duke@0 1459 case Bytecodes::_pop: _sp -= 1; break;
duke@0 1460 case Bytecodes::_pop2: _sp -= 2; break;
duke@0 1461 case Bytecodes::_swap:
duke@0 1462 a = pop();
duke@0 1463 b = pop();
duke@0 1464 push(a);
duke@0 1465 push(b);
duke@0 1466 break;
duke@0 1467 case Bytecodes::_dup:
duke@0 1468 a = pop();
duke@0 1469 push(a);
duke@0 1470 push(a);
duke@0 1471 break;
duke@0 1472 case Bytecodes::_dup_x1:
duke@0 1473 a = pop();
duke@0 1474 b = pop();
duke@0 1475 push( a );
duke@0 1476 push( b );
duke@0 1477 push( a );
duke@0 1478 break;
duke@0 1479 case Bytecodes::_dup_x2:
duke@0 1480 a = pop();
duke@0 1481 b = pop();
duke@0 1482 c = pop();
duke@0 1483 push( a );
duke@0 1484 push( c );
duke@0 1485 push( b );
duke@0 1486 push( a );
duke@0 1487 break;
duke@0 1488 case Bytecodes::_dup2:
duke@0 1489 a = pop();
duke@0 1490 b = pop();
duke@0 1491 push( b );
duke@0 1492 push( a );
duke@0 1493 push( b );
duke@0 1494 push( a );
duke@0 1495 break;
duke@0 1496
duke@0 1497 case Bytecodes::_dup2_x1:
duke@0 1498 // before: .. c, b, a
duke@0 1499 // after: .. b, a, c, b, a
duke@0 1500 // not tested
duke@0 1501 a = pop();
duke@0 1502 b = pop();
duke@0 1503 c = pop();
duke@0 1504 push( b );
duke@0 1505 push( a );
duke@0 1506 push( c );
duke@0 1507 push( b );
duke@0 1508 push( a );
duke@0 1509 break;
duke@0 1510 case Bytecodes::_dup2_x2:
duke@0 1511 // before: .. d, c, b, a
duke@0 1512 // after: .. b, a, d, c, b, a
duke@0 1513 // not tested
duke@0 1514 a = pop();
duke@0 1515 b = pop();
duke@0 1516 c = pop();
duke@0 1517 d = pop();
duke@0 1518 push( b );
duke@0 1519 push( a );
duke@0 1520 push( d );
duke@0 1521 push( c );
duke@0 1522 push( b );
duke@0 1523 push( a );
duke@0 1524 break;
duke@0 1525
duke@0 1526 case Bytecodes::_arraylength: {
duke@0 1527 // Must do null-check with value on expression stack
duke@0 1528 Node *ary = do_null_check(peek(), T_ARRAY);
duke@0 1529 // Compile-time detect of null-exception?
duke@0 1530 if (stopped()) return;
duke@0 1531 a = pop();
duke@0 1532 push(load_array_length(a));
duke@0 1533 break;
duke@0 1534 }
duke@0 1535
duke@0 1536 case Bytecodes::_baload: array_load(T_BYTE); break;
duke@0 1537 case Bytecodes::_caload: array_load(T_CHAR); break;
duke@0 1538 case Bytecodes::_iaload: array_load(T_INT); break;
duke@0 1539 case Bytecodes::_saload: array_load(T_SHORT); break;
duke@0 1540 case Bytecodes::_faload: array_load(T_FLOAT); break;
duke@0 1541 case Bytecodes::_aaload: array_load(T_OBJECT); break;
duke@0 1542 case Bytecodes::_laload: {
duke@0 1543 a = array_addressing(T_LONG, 0);
twisti@605 1544 if (stopped()) return; // guaranteed null or range check
duke@0 1545 _sp -= 2; // Pop array and index
duke@0 1546 push_pair( make_load(control(), a, TypeLong::LONG, T_LONG, TypeAryPtr::LONGS));
duke@0 1547 break;
duke@0 1548 }
duke@0 1549 case Bytecodes::_daload: {
duke@0 1550 a = array_addressing(T_DOUBLE, 0);
twisti@605 1551 if (stopped()) return; // guaranteed null or range check
duke@0 1552 _sp -= 2; // Pop array and index
duke@0 1553 push_pair( make_load(control(), a, Type::DOUBLE, T_DOUBLE, TypeAryPtr::DOUBLES));
duke@0 1554 break;
duke@0 1555 }
duke@0 1556 case Bytecodes::_bastore: array_store(T_BYTE); break;
duke@0 1557 case Bytecodes::_castore: array_store(T_CHAR); break;
duke@0 1558 case Bytecodes::_iastore: array_store(T_INT); break;
duke@0 1559 case Bytecodes::_sastore: array_store(T_SHORT); break;
duke@0 1560 case Bytecodes::_fastore: array_store(T_FLOAT); break;
duke@0 1561 case Bytecodes::_aastore: {
duke@0 1562 d = array_addressing(T_OBJECT, 1);
twisti@605 1563 if (stopped()) return; // guaranteed null or range check
duke@0 1564 array_store_check();
duke@0 1565 c = pop(); // Oop to store
duke@0 1566 b = pop(); // index (already used)
duke@0 1567 a = pop(); // the array itself
never@827 1568 const TypeOopPtr* elemtype = _gvn.type(a)->is_aryptr()->elem()->make_oopptr();
duke@0 1569 const TypeAryPtr* adr_type = TypeAryPtr::OOPS;
duke@0 1570 Node* store = store_oop_to_array(control(), a, d, adr_type, c, elemtype, T_OBJECT);
duke@0 1571 break;
duke@0 1572 }
duke@0 1573 case Bytecodes::_lastore: {
duke@0 1574 a = array_addressing(T_LONG, 2);
twisti@605 1575 if (stopped()) return; // guaranteed null or range check
duke@0 1576 c = pop_pair();
duke@0 1577 _sp -= 2; // Pop array and index
duke@0 1578 store_to_memory(control(), a, c, T_LONG, TypeAryPtr::LONGS);
duke@0 1579 break;
duke@0 1580 }
duke@0 1581 case Bytecodes::_dastore: {
duke@0 1582 a = array_addressing(T_DOUBLE, 2);
twisti@605 1583 if (stopped()) return; // guaranteed null or range check
duke@0 1584 c = pop_pair();
duke@0 1585 _sp -= 2; // Pop array and index
duke@0 1586 c = dstore_rounding(c);
duke@0 1587 store_to_memory(control(), a, c, T_DOUBLE, TypeAryPtr::DOUBLES);
duke@0 1588 break;
duke@0 1589 }
duke@0 1590 case Bytecodes::_getfield:
duke@0 1591 do_getfield();
duke@0 1592 break;
duke@0 1593
duke@0 1594 case Bytecodes::_getstatic:
duke@0 1595 do_getstatic();
duke@0 1596 break;
duke@0 1597
duke@0 1598 case Bytecodes::_putfield:
duke@0 1599 do_putfield();
duke@0 1600 break;
duke@0 1601
duke@0 1602 case Bytecodes::_putstatic:
duke@0 1603 do_putstatic();
duke@0 1604 break;
duke@0 1605
duke@0 1606 case Bytecodes::_irem:
duke@0 1607 do_irem();
duke@0 1608 break;
duke@0 1609 case Bytecodes::_idiv:
duke@0 1610 // Must keep both values on the expression-stack during null-check
duke@0 1611 do_null_check(peek(), T_INT);
duke@0 1612 // Compile-time detect of null-exception?
duke@0 1613 if (stopped()) return;
duke@0 1614 b = pop();
duke@0 1615 a = pop();
duke@0 1616 push( _gvn.transform( new (C, 3) DivINode(control(),a,b) ) );
duke@0 1617 break;
duke@0 1618 case Bytecodes::_imul:
duke@0 1619 b = pop(); a = pop();
duke@0 1620 push( _gvn.transform( new (C, 3) MulINode(a,b) ) );
duke@0 1621 break;
duke@0 1622 case Bytecodes::_iadd:
duke@0 1623 b = pop(); a = pop();
duke@0 1624 push( _gvn.transform( new (C, 3) AddINode(a,b) ) );
duke@0 1625 break;
duke@0 1626 case Bytecodes::_ineg:
duke@0 1627 a = pop();
duke@0 1628 push( _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),a)) );
duke@0 1629 break;
duke@0 1630 case Bytecodes::_isub:
duke@0 1631 b = pop(); a = pop();
duke@0 1632 push( _gvn.transform( new (C, 3) SubINode(a,b) ) );
duke@0 1633 break;
duke@0 1634 case Bytecodes::_iand:
duke@0 1635 b = pop(); a = pop();
duke@0 1636 push( _gvn.transform( new (C, 3) AndINode(a,b) ) );
duke@0 1637 break;
duke@0 1638 case Bytecodes::_ior:
duke@0 1639 b = pop(); a = pop();
duke@0 1640 push( _gvn.transform( new (C, 3) OrINode(a,b) ) );
duke@0 1641 break;
duke@0 1642 case Bytecodes::_ixor:
duke@0 1643 b = pop(); a = pop();
duke@0 1644 push( _gvn.transform( new (C, 3) XorINode(a,b) ) );
duke@0 1645 break;
duke@0 1646 case Bytecodes::_ishl:
duke@0 1647 b = pop(); a = pop();
duke@0 1648 push( _gvn.transform( new (C, 3) LShiftINode(a,b) ) );
duke@0 1649 break;
duke@0 1650 case Bytecodes::_ishr:
duke@0 1651 b = pop(); a = pop();
duke@0 1652 push( _gvn.transform( new (C, 3) RShiftINode(a,b) ) );
duke@0 1653 break;
duke@0 1654 case Bytecodes::_iushr:
duke@0 1655 b = pop(); a = pop();
duke@0 1656 push( _gvn.transform( new (C, 3) URShiftINode(a,b) ) );
duke@0 1657 break;
duke@0 1658
duke@0 1659 case Bytecodes::_fneg:
duke@0 1660 a = pop();
duke@0 1661 b = _gvn.transform(new (C, 2) NegFNode (a));
duke@0 1662 push(b);
duke@0 1663 break;
duke@0 1664
duke@0 1665 case Bytecodes::_fsub:
duke@0 1666 b = pop();
duke@0 1667 a = pop();
duke@0 1668 c = _gvn.transform( new (C, 3) SubFNode(a,b) );
duke@0 1669 d = precision_rounding(c);
duke@0 1670 push( d );
duke@0 1671 break;
duke@0 1672
duke@0 1673 case Bytecodes::_fadd:
duke@0 1674 b = pop();
duke@0 1675 a = pop();
duke@0 1676 c = _gvn.transform( new (C, 3) AddFNode(a,b) );
duke@0 1677 d = precision_rounding(c);
duke@0 1678 push( d );
duke@0 1679 break;
duke@0 1680
duke@0 1681 case Bytecodes::_fmul:
duke@0 1682 b = pop();
duke@0 1683 a = pop();
duke@0 1684 c = _gvn.transform( new (C, 3) MulFNode(a,b) );
duke@0 1685 d = precision_rounding(c);
duke@0 1686 push( d );
duke@0 1687 break;
duke@0 1688
duke@0 1689 case Bytecodes::_fdiv:
duke@0 1690 b = pop();
duke@0 1691 a = pop();
duke@0 1692 c = _gvn.transform( new (C, 3) DivFNode(0,a,b) );
duke@0 1693 d = precision_rounding(c);
duke@0 1694 push( d );
duke@0 1695 break;
duke@0 1696
duke@0 1697 case Bytecodes::_frem:
duke@0 1698 if (Matcher::has_match_rule(Op_ModF)) {
duke@0 1699 // Generate a ModF node.
duke@0 1700 b = pop();
duke@0 1701 a = pop();
duke@0 1702 c = _gvn.transform( new (C, 3) ModFNode(0,a,b) );
duke@0 1703 d = precision_rounding(c);
duke@0 1704 push( d );
duke@0 1705 }
duke@0 1706 else {
duke@0 1707 // Generate a call.
duke@0 1708 modf();
duke@0 1709 }
duke@0 1710 break;
duke@0 1711
duke@0 1712 case Bytecodes::_fcmpl:
duke@0 1713 b = pop();
duke@0 1714 a = pop();
duke@0 1715 c = _gvn.transform( new (C, 3) CmpF3Node( a, b));
duke@0 1716 push(c);
duke@0 1717 break;
duke@0 1718 case Bytecodes::_fcmpg:
duke@0 1719 b = pop();
duke@0 1720 a = pop();
duke@0 1721
duke@0 1722 // Same as fcmpl but need to flip the unordered case. Swap the inputs,
duke@0 1723 // which negates the result sign except for unordered. Flip the unordered
duke@0 1724 // as well by using CmpF3 which implements unordered-lesser instead of
duke@0 1725 // unordered-greater semantics. Finally, commute the result bits. Result
duke@0 1726 // is same as using a CmpF3Greater except we did it with CmpF3 alone.
duke@0 1727 c = _gvn.transform( new (C, 3) CmpF3Node( b, a));
duke@0 1728 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
duke@0 1729 push(c);
duke@0 1730 break;
duke@0 1731
duke@0 1732 case Bytecodes::_f2i:
duke@0 1733 a = pop();
duke@0 1734 push(_gvn.transform(new (C, 2) ConvF2INode(a)));
duke@0 1735 break;
duke@0 1736
duke@0 1737 case Bytecodes::_d2i:
duke@0 1738 a = pop_pair();
duke@0 1739 b = _gvn.transform(new (C, 2) ConvD2INode(a));
duke@0 1740 push( b );
duke@0 1741 break;
duke@0 1742
duke@0 1743 case Bytecodes::_f2d:
duke@0 1744 a = pop();
duke@0 1745 b = _gvn.transform( new (C, 2) ConvF2DNode(a));
duke@0 1746 push_pair( b );
duke@0 1747 break;
duke@0 1748
duke@0 1749 case Bytecodes::_d2f:
duke@0 1750 a = pop_pair();
duke@0 1751 b = _gvn.transform( new (C, 2) ConvD2FNode(a));
duke@0 1752 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed)
duke@0 1753 //b = _gvn.transform(new (C, 2) RoundFloatNode(0, b) );
duke@0 1754 push( b );
duke@0 1755 break;
duke@0 1756
duke@0 1757 case Bytecodes::_l2f:
duke@0 1758 if (Matcher::convL2FSupported()) {
duke@0 1759 a = pop_pair();
duke@0 1760 b = _gvn.transform( new (C, 2) ConvL2FNode(a));
duke@0 1761 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits.
duke@0 1762 // Rather than storing the result into an FP register then pushing
duke@0 1763 // out to memory to round, the machine instruction that implements
duke@0 1764 // ConvL2D is responsible for rounding.
duke@0 1765 // c = precision_rounding(b);
duke@0 1766 c = _gvn.transform(b);
duke@0 1767 push(c);
duke@0 1768 } else {
duke@0 1769 l2f();
duke@0 1770 }
duke@0 1771 break;
duke@0 1772
duke@0 1773 case Bytecodes::_l2d:
duke@0 1774 a = pop_pair();
duke@0 1775 b = _gvn.transform( new (C, 2) ConvL2DNode(a));
duke@0 1776 // For i486.ad, rounding is always necessary (see _l2f above).
duke@0 1777 // c = dprecision_rounding(b);
duke@0 1778 c = _gvn.transform(b);
duke@0 1779 push_pair(c);
duke@0 1780 break;
duke@0 1781
duke@0 1782 case Bytecodes::_f2l:
duke@0 1783 a = pop();
duke@0 1784 b = _gvn.transform( new (C, 2) ConvF2LNode(a));
duke@0 1785 push_pair(b);
duke@0 1786 break;
duke@0 1787
duke@0 1788 case Bytecodes::_d2l:
duke@0 1789 a = pop_pair();
duke@0 1790 b = _gvn.transform( new (C, 2) ConvD2LNode(a));
duke@0 1791 push_pair(b);
duke@0 1792 break;
duke@0 1793
duke@0 1794 case Bytecodes::_dsub:
duke@0 1795 b = pop_pair();
duke@0 1796 a = pop_pair();
duke@0 1797 c = _gvn.transform( new (C, 3) SubDNode(a,b) );
duke@0 1798 d = dprecision_rounding(c);
duke@0 1799 push_pair( d );
duke@0 1800 break;
duke@0 1801
duke@0 1802 case Bytecodes::_dadd:
duke@0 1803 b = pop_pair();
duke@0 1804 a = pop_pair();
duke@0 1805 c = _gvn.transform( new (C, 3) AddDNode(a,b) );
duke@0 1806 d = dprecision_rounding(c);
duke@0 1807 push_pair( d );
duke@0 1808 break;
duke@0 1809
duke@0 1810 case Bytecodes::_dmul:
duke@0 1811 b = pop_pair();
duke@0 1812 a = pop_pair();
duke@0 1813 c = _gvn.transform( new (C, 3) MulDNode(a,b) );
duke@0 1814 d = dprecision_rounding(c);
duke@0 1815 push_pair( d );
duke@0 1816 break;
duke@0 1817
duke@0 1818 case Bytecodes::_ddiv:
duke@0 1819 b = pop_pair();
duke@0 1820 a = pop_pair();
duke@0 1821 c = _gvn.transform( new (C, 3) DivDNode(0,a,b) );
duke@0 1822 d = dprecision_rounding(c);
duke@0 1823 push_pair( d );
duke@0 1824 break;
duke@0 1825
duke@0 1826 case Bytecodes::_dneg:
duke@0 1827 a = pop_pair();
duke@0 1828 b = _gvn.transform(new (C, 2) NegDNode (a));
duke@0 1829 push_pair(b);
duke@0 1830 break;
duke@0 1831
duke@0 1832 case Bytecodes::_drem:
duke@0 1833 if (Matcher::has_match_rule(Op_ModD)) {
duke@0 1834 // Generate a ModD node.
duke@0 1835 b = pop_pair();
duke@0 1836 a = pop_pair();
duke@0 1837 // a % b
duke@0 1838
duke@0 1839 c = _gvn.transform( new (C, 3) ModDNode(0,a,b) );
duke@0 1840 d = dprecision_rounding(c);
duke@0 1841 push_pair( d );
duke@0 1842 }
duke@0 1843 else {
duke@0 1844 // Generate a call.
duke@0 1845 modd();
duke@0 1846 }
duke@0 1847 break;
duke@0 1848
duke@0 1849 case Bytecodes::_dcmpl:
duke@0 1850 b = pop_pair();
duke@0 1851 a = pop_pair();
duke@0 1852 c = _gvn.transform( new (C, 3) CmpD3Node( a, b));
duke@0 1853 push(c);
duke@0 1854 break;
duke@0 1855
duke@0 1856 case Bytecodes::_dcmpg:
duke@0 1857 b = pop_pair();
duke@0 1858 a = pop_pair();
duke@0 1859 // Same as dcmpl but need to flip the unordered case.
duke@0 1860 // Commute the inputs, which negates the result sign except for unordered.
duke@0 1861 // Flip the unordered as well by using CmpD3 which implements
duke@0 1862 // unordered-lesser instead of unordered-greater semantics.
duke@0 1863 // Finally, negate the result bits. Result is same as using a
duke@0 1864 // CmpD3Greater except we did it with CmpD3 alone.
duke@0 1865 c = _gvn.transform( new (C, 3) CmpD3Node( b, a));
duke@0 1866 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
duke@0 1867 push(c);
duke@0 1868 break;
duke@0 1869
duke@0 1870
duke@0 1871 // Note for longs -> lo word is on TOS, hi word is on TOS - 1
duke@0 1872 case Bytecodes::_land:
duke@0 1873 b = pop_pair();
duke@0 1874 a = pop_pair();
duke@0 1875 c = _gvn.transform( new (C, 3) AndLNode(a,b) );
duke@0 1876 push_pair(c);
duke@0 1877 break;
duke@0 1878 case Bytecodes::_lor:
duke@0 1879 b = pop_pair();
duke@0 1880 a = pop_pair();
duke@0 1881 c = _gvn.transform( new (C, 3) OrLNode(a,b) );
duke@0 1882 push_pair(c);
duke@0 1883 break;
duke@0 1884 case Bytecodes::_lxor:
duke@0 1885 b = pop_pair();
duke@0 1886 a = pop_pair();
duke@0 1887 c = _gvn.transform( new (C, 3) XorLNode(a,b) );
duke@0 1888 push_pair(c);
duke@0 1889 break;
duke@0 1890
duke@0 1891 case Bytecodes::_lshl:
duke@0 1892 b = pop(); // the shift count
duke@0 1893 a = pop_pair(); // value to be shifted
duke@0 1894 c = _gvn.transform( new (C, 3) LShiftLNode(a,b) );
duke@0 1895 push_pair(c);
duke@0 1896 break;
duke@0 1897 case Bytecodes::_lshr:
duke@0 1898 b = pop(); // the shift count
duke@0 1899 a = pop_pair(); // value to be shifted
duke@0 1900 c = _gvn.transform( new (C, 3) RShiftLNode(a,b) );
duke@0 1901 push_pair(c);
duke@0 1902 break;
duke@0 1903 case Bytecodes::_lushr:
duke@0 1904 b = pop(); // the shift count
duke@0 1905 a = pop_pair(); // value to be shifted
duke@0 1906 c = _gvn.transform( new (C, 3) URShiftLNode(a,b) );
duke@0 1907 push_pair(c);
duke@0 1908 break;
duke@0 1909 case Bytecodes::_lmul:
duke@0 1910 b = pop_pair();
duke@0 1911 a = pop_pair();
duke@0 1912 c = _gvn.transform( new (C, 3) MulLNode(a,b) );
duke@0 1913 push_pair(c);
duke@0 1914 break;
duke@0 1915
duke@0 1916 case Bytecodes::_lrem:
duke@0 1917 // Must keep both values on the expression-stack during null-check
duke@0 1918 assert(peek(0) == top(), "long word order");
duke@0 1919 do_null_check(peek(1), T_LONG);
duke@0 1920 // Compile-time detect of null-exception?
duke@0 1921 if (stopped()) return;
duke@0 1922 b = pop_pair();
duke@0 1923 a = pop_pair();
duke@0 1924 c = _gvn.transform( new (C, 3) ModLNode(control(),a,b) );
duke@0 1925 push_pair(c);
duke@0 1926 break;
duke@0 1927
duke@0 1928 case Bytecodes::_ldiv:
duke@0 1929 // Must keep both values on the expression-stack during null-check
duke@0 1930 assert(peek(0) == top(), "long word order");
duke@0 1931 do_null_check(peek(1), T_LONG);
duke@0 1932 // Compile-time detect of null-exception?
duke@0 1933 if (stopped()) return;
duke@0 1934 b = pop_pair();
duke@0 1935 a = pop_pair();
duke@0 1936 c = _gvn.transform( new (C, 3) DivLNode(control(),a,b) );
duke@0 1937 push_pair(c);
duke@0 1938 break;
duke@0 1939
duke@0 1940 case Bytecodes::_ladd:
duke@0 1941 b = pop_pair();
duke@0 1942 a = pop_pair();
duke@0 1943 c = _gvn.transform( new (C, 3) AddLNode(a,b) );
duke@0 1944 push_pair(c);
duke@0 1945 break;
duke@0 1946 case Bytecodes::_lsub:
duke@0 1947 b = pop_pair();
duke@0 1948 a = pop_pair();
duke@0 1949 c = _gvn.transform( new (C, 3) SubLNode(a,b) );
duke@0 1950 push_pair(c);
duke@0 1951 break;
duke@0 1952 case Bytecodes::_lcmp:
duke@0 1953 // Safepoints are now inserted _before_ branches. The long-compare
duke@0 1954 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a
duke@0 1955 // slew of control flow. These are usually followed by a CmpI vs zero and
duke@0 1956 // a branch; this pattern then optimizes to the obvious long-compare and
duke@0 1957 // branch. However, if the branch is backwards there's a Safepoint
duke@0 1958 // inserted. The inserted Safepoint captures the JVM state at the
duke@0 1959 // pre-branch point, i.e. it captures the 3-way value. Thus if a
duke@0 1960 // long-compare is used to control a loop the debug info will force
duke@0 1961 // computation of the 3-way value, even though the generated code uses a
duke@0 1962 // long-compare and branch. We try to rectify the situation by inserting
duke@0 1963 // a SafePoint here and have it dominate and kill the safepoint added at a
duke@0 1964 // following backwards branch. At this point the JVM state merely holds 2
duke@0 1965 // longs but not the 3-way value.
duke@0 1966 if( UseLoopSafepoints ) {
duke@0 1967 switch( iter().next_bc() ) {
duke@0 1968 case Bytecodes::_ifgt:
duke@0 1969 case Bytecodes::_iflt:
duke@0 1970 case Bytecodes::_ifge:
duke@0 1971 case Bytecodes::_ifle:
duke@0 1972 case Bytecodes::_ifne:
duke@0 1973 case Bytecodes::_ifeq:
duke@0 1974 // If this is a backwards branch in the bytecodes, add Safepoint
duke@0 1975 maybe_add_safepoint(iter().next_get_dest());
duke@0 1976 }
duke@0 1977 }
duke@0 1978 b = pop_pair();
duke@0 1979 a = pop_pair();
duke@0 1980 c = _gvn.transform( new (C, 3) CmpL3Node( a, b ));
duke@0 1981 push(c);
duke@0 1982 break;
duke@0 1983
duke@0 1984 case Bytecodes::_lneg:
duke@0 1985 a = pop_pair();
duke@0 1986 b = _gvn.transform( new (C, 3) SubLNode(longcon(0),a));
duke@0 1987 push_pair(b);
duke@0 1988 break;
duke@0 1989 case Bytecodes::_l2i:
duke@0 1990 a = pop_pair();
duke@0 1991 push( _gvn.transform( new (C, 2) ConvL2INode(a)));
duke@0 1992 break;
duke@0 1993 case Bytecodes::_i2l:
duke@0 1994 a = pop();
duke@0 1995 b = _gvn.transform( new (C, 2) ConvI2LNode(a));
duke@0 1996 push_pair(b);
duke@0 1997 break;
duke@0 1998 case Bytecodes::_i2b:
duke@0 1999 // Sign extend
duke@0 2000 a = pop();
duke@0 2001 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(24)) );
duke@0 2002 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(24)) );
duke@0 2003 push( a );
duke@0 2004 break;
duke@0 2005 case Bytecodes::_i2s:
duke@0 2006 a = pop();
duke@0 2007 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(16)) );
duke@0 2008 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(16)) );
duke@0 2009 push( a );
duke@0 2010 break;
duke@0 2011 case Bytecodes::_i2c:
duke@0 2012 a = pop();
duke@0 2013 push( _gvn.transform( new (C, 3) AndINode(a,_gvn.intcon(0xFFFF)) ) );
duke@0 2014 break;
duke@0 2015
duke@0 2016 case Bytecodes::_i2f:
duke@0 2017 a = pop();
duke@0 2018 b = _gvn.transform( new (C, 2) ConvI2FNode(a) ) ;
duke@0 2019 c = precision_rounding(b);
duke@0 2020 push (b);
duke@0 2021 break;
duke@0 2022
duke@0 2023 case Bytecodes::_i2d:
duke@0 2024 a = pop();
duke@0 2025 b = _gvn.transform( new (C, 2) ConvI2DNode(a));
duke@0 2026 push_pair(b);
duke@0 2027 break;
duke@0 2028
duke@0 2029 case Bytecodes::_iinc: // Increment local
duke@0 2030 i = iter().get_index(); // Get local index
duke@0 2031 set_local( i, _gvn.transform( new (C, 3) AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
duke@0 2032 break;
duke@0 2033
duke@0 2034 // Exit points of synchronized methods must have an unlock node
duke@0 2035 case Bytecodes::_return:
duke@0 2036 return_current(NULL);
duke@0 2037 break;
duke@0 2038
duke@0 2039 case Bytecodes::_ireturn:
duke@0 2040 case Bytecodes::_areturn:
duke@0 2041 case Bytecodes::_freturn:
duke@0 2042 return_current(pop());
duke@0 2043 break;
duke@0 2044 case Bytecodes::_lreturn:
duke@0 2045 return_current(pop_pair());
duke@0 2046 break;
duke@0 2047 case Bytecodes::_dreturn:
duke@0 2048 return_current(pop_pair());
duke@0 2049 break;
duke@0 2050
duke@0 2051 case Bytecodes::_athrow:
duke@0 2052 // null exception oop throws NULL pointer exception
duke@0 2053 do_null_check(peek(), T_OBJECT);
duke@0 2054 if (stopped()) return;
kvn@780 2055 if (env()->jvmti_can_post_exceptions()) {
duke@0 2056 // "Full-speed throwing" is not necessary here,
duke@0 2057 // since we're notifying the VM on every throw.
duke@0 2058 uncommon_trap(Deoptimization::Reason_unhandled,
duke@0 2059 Deoptimization::Action_none);
duke@0 2060 return;
duke@0 2061 }
duke@0 2062 // Hook the thrown exception directly to subsequent handlers.
duke@0 2063 if (BailoutToInterpreterForThrows) {
duke@0 2064 // Keep method interpreted from now on.
duke@0 2065 uncommon_trap(Deoptimization::Reason_unhandled,
duke@0 2066 Deoptimization::Action_make_not_compilable);
duke@0 2067 return;
duke@0 2068 }
duke@0 2069 add_exception_state(make_exception_state(peek()));
duke@0 2070 break;
duke@0 2071
duke@0 2072 case Bytecodes::_goto: // fall through
duke@0 2073 case Bytecodes::_goto_w: {
duke@0 2074 int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest();
duke@0 2075
duke@0 2076 // If this is a backwards branch in the bytecodes, add Safepoint
duke@0 2077 maybe_add_safepoint(target_bci);
duke@0 2078
duke@0 2079 // Update method data
duke@0 2080 profile_taken_branch(target_bci);
duke@0 2081
duke@0 2082 // Merge the current control into the target basic block
duke@0 2083 merge(target_bci);
duke@0 2084
duke@0 2085 // See if we can get some profile data and hand it off to the next block
duke@0 2086 Block *target_block = block()->successor_for_bci(target_bci);
duke@0 2087 if (target_block->pred_count() != 1) break;
duke@0 2088 ciMethodData* methodData = method()->method_data();
duke@0 2089 if (!methodData->is_mature()) break;
duke@0 2090 ciProfileData* data = methodData->bci_to_data(bci());
duke@0 2091 assert( data->is_JumpData(), "" );
duke@0 2092 int taken = ((ciJumpData*)data)->taken();
duke@0 2093 taken = method()->scale_count(taken);
duke@0 2094 target_block->set_count(taken);
duke@0 2095 break;
duke@0 2096 }
duke@0 2097
rasbold@248 2098 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null;
rasbold@248 2099 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
rasbold@248 2100 handle_if_null:
rasbold@254 2101 // If this is a backwards branch in the bytecodes, add Safepoint
rasbold@254 2102 maybe_add_safepoint(iter().get_dest());
rasbold@248 2103 a = null();
rasbold@248 2104 b = pop();
rasbold@248 2105 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
rasbold@248 2106 do_ifnull(btest, c);
duke@0 2107 break;
duke@0 2108
duke@0 2109 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
duke@0 2110 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
duke@0 2111 handle_if_acmp:
rasbold@254 2112 // If this is a backwards branch in the bytecodes, add Safepoint
rasbold@254 2113 maybe_add_safepoint(iter().get_dest());
duke@0 2114 a = pop();
duke@0 2115 b = pop();
duke@0 2116 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
duke@0 2117 do_if(btest, c);
duke@0 2118 break;
duke@0 2119
duke@0 2120 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
duke@0 2121 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
duke@0 2122 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
duke@0 2123 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
duke@0 2124 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
duke@0 2125 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
duke@0 2126 handle_ifxx:
rasbold@254 2127 // If this is a backwards branch in the bytecodes, add Safepoint
rasbold@254 2128 maybe_add_safepoint(iter().get_dest());
duke@0 2129 a = _gvn.intcon(0);
duke@0 2130 b = pop();
duke@0 2131 c = _gvn.transform( new (C, 3) CmpINode(b, a) );
duke@0 2132 do_if(btest, c);
duke@0 2133 break;
duke@0 2134
duke@0 2135 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
duke@0 2136 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
duke@0 2137 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;
duke@0 2138 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp;
duke@0 2139 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp;
duke@0 2140 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp;
duke@0 2141 handle_if_icmp:
rasbold@254 2142 // If this is a backwards branch in the bytecodes, add Safepoint
rasbold@254 2143 maybe_add_safepoint(iter().get_dest());
duke@0 2144 a = pop();
duke@0 2145 b = pop();
duke@0 2146 c = _gvn.transform( new (C, 3) CmpINode( b, a ) );
duke@0 2147 do_if(btest, c);
duke@0 2148 break;
duke@0 2149
duke@0 2150 case Bytecodes::_tableswitch:
duke@0 2151 do_tableswitch();
duke@0 2152 break;
duke@0 2153
duke@0 2154 case Bytecodes::_lookupswitch:
duke@0 2155 do_lookupswitch();
duke@0 2156 break;
duke@0 2157
duke@0 2158 case Bytecodes::_invokestatic:
jrose@726 2159 case Bytecodes::_invokedynamic:
duke@0 2160 case Bytecodes::_invokespecial:
duke@0 2161 case Bytecodes::_invokevirtual:
duke@0 2162 case Bytecodes::_invokeinterface:
duke@0 2163 do_call();
duke@0 2164 break;
duke@0 2165 case Bytecodes::_checkcast:
duke@0 2166 do_checkcast();
duke@0 2167 break;
duke@0 2168 case Bytecodes::_instanceof:
duke@0 2169 do_instanceof();
duke@0 2170 break;
duke@0 2171 case Bytecodes::_anewarray:
duke@0 2172 do_anewarray();
duke@0 2173 break;
duke@0 2174 case Bytecodes::_newarray:
duke@0 2175 do_newarray((BasicType)iter().get_index());
duke@0 2176 break;
duke@0 2177 case Bytecodes::_multianewarray:
duke@0 2178 do_multianewarray();
duke@0 2179 break;
duke@0 2180 case Bytecodes::_new:
duke@0 2181 do_new();
duke@0 2182 break;
duke@0 2183
duke@0 2184 case Bytecodes::_jsr:
duke@0 2185 case Bytecodes::_jsr_w:
duke@0 2186 do_jsr();
duke@0 2187 break;
duke@0 2188
duke@0 2189 case Bytecodes::_ret:
duke@0 2190 do_ret();
duke@0 2191 break;
duke@0 2192
duke@0 2193
duke@0 2194 case Bytecodes::_monitorenter:
duke@0 2195 do_monitor_enter();
duke@0 2196 break;
duke@0 2197
duke@0 2198 case Bytecodes::_monitorexit:
duke@0 2199 do_monitor_exit();
duke@0 2200 break;
duke@0 2201
duke@0 2202 case Bytecodes::_breakpoint:
duke@0 2203 // Breakpoint set concurrently to compile
duke@0 2204 // %%% use an uncommon trap?
duke@0 2205 C->record_failure("breakpoint in method");
duke@0 2206 return;
duke@0 2207
duke@0 2208 default:
duke@0 2209 #ifndef PRODUCT
duke@0 2210 map()->dump(99);
duke@0 2211 #endif
duke@0 2212 tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) );
duke@0 2213 ShouldNotReachHere();
duke@0 2214 }
duke@0 2215
duke@0 2216 #ifndef PRODUCT
duke@0 2217 IdealGraphPrinter *printer = IdealGraphPrinter::printer();
duke@0 2218 if(printer) {
duke@0 2219 char buffer[256];
duke@0 2220 sprintf(buffer, "Bytecode %d: %s", bci(), Bytecodes::name(bc()));
duke@0 2221 bool old = printer->traverse_outs();
duke@0 2222 printer->set_traverse_outs(true);
never@222 2223 printer->print_method(C, buffer, 4);
duke@0 2224 printer->set_traverse_outs(old);
duke@0 2225 }
duke@0 2226 #endif
duke@0 2227 }