src/share/vm/opto/parse2.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8415
d109bda16490
parent 7994
04ff2f6cd0eb
child 9041
95a08233f46c
permissions
-rw-r--r--

Merge

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

mercurial