src/share/vm/opto/parse2.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial