1 /*
   2  * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm_io.h"
  27 #include "ci/ciMethodData.hpp"
  28 #include "ci/ciSymbols.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "interpreter/linkResolver.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "opto/addnode.hpp"
  36 #include "opto/castnode.hpp"
  37 #include "opto/convertnode.hpp"
  38 #include "opto/divnode.hpp"
  39 #include "opto/idealGraphPrinter.hpp"
  40 #include "opto/idealKit.hpp"
  41 #include "opto/inlinetypenode.hpp"
  42 #include "opto/matcher.hpp"
  43 #include "opto/memnode.hpp"
  44 #include "opto/mulnode.hpp"
  45 #include "opto/opaquenode.hpp"
  46 #include "opto/parse.hpp"
  47 #include "opto/runtime.hpp"
  48 #include "runtime/deoptimization.hpp"
  49 #include "runtime/sharedRuntime.hpp"
  50 
  51 #ifndef PRODUCT
  52 extern int explicit_null_checks_inserted,
  53            explicit_null_checks_elided;
  54 #endif
  55 
  56 Node* Parse::record_profile_for_speculation_at_array_load(Node* ld) {
  57   // Feed unused profile data to type speculation
  58   if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
  59     ciKlass* array_type = NULL;
  60     ciKlass* element_type = NULL;
  61     ProfilePtrKind element_ptr = ProfileMaybeNull;
  62     bool flat_array = true;
  63     bool null_free_array = true;
  64     method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
  65     if (element_type != NULL || element_ptr != ProfileMaybeNull) {
  66       ld = record_profile_for_speculation(ld, element_type, element_ptr);
  67     }
  68   }
  69   return ld;
  70 }
  71 
  72 
  73 //---------------------------------array_load----------------------------------
  74 void Parse::array_load(BasicType bt) {
  75   const Type* elemtype = Type::TOP;
  76   Node* adr = array_addressing(bt, 0, elemtype);
  77   if (stopped())  return;     // guaranteed null or range check
  78 
  79   Node* idx = pop();
  80   Node* ary = pop();
  81 
  82   // Handle inline type arrays
  83   const TypeOopPtr* elemptr = elemtype->make_oopptr();
  84   const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr();
  85   if (ary_t->is_flat()) {
  86     // Load from flattened inline type array
  87     Node* vt = InlineTypeNode::make_from_flattened(this, elemtype->inline_klass(), ary, adr);
  88     push(vt);
  89     return;
  90   } else if (ary_t->is_null_free()) {
  91     // Load from non-flattened inline type array (elements can never be null)
  92     bt = T_INLINE_TYPE;
  93   } else if (!ary_t->is_not_flat()) {
  94     // Cannot statically determine if array is flattened, emit runtime check
  95     assert(UseFlatArray && is_reference_type(bt) && elemptr->can_be_inline_type() && !ary_t->klass_is_exact() && !ary_t->is_not_null_free() &&
  96            (!elemptr->is_inlinetypeptr() || elemptr->inline_klass()->flatten_array()), "array can't be flattened");
  97     IdealKit ideal(this);
  98     IdealVariable res(ideal);
  99     ideal.declarations_done();
 100     ideal.if_then(flat_array_test(ary, /* flat = */ false)); {
 101       // non-flattened
 102       assert(ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
 103       sync_kit(ideal);
 104       const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 105       Node* ld = access_load_at(ary, adr, adr_type, elemptr, bt,
 106                                 IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
 107       if (elemptr->is_inlinetypeptr()) {
 108         assert(elemptr->maybe_null(), "null free array should be handled above");
 109         ld = InlineTypeNode::make_from_oop(this, ld, elemptr->inline_klass(), false);
 110       }
 111       ideal.sync_kit(this);
 112       ideal.set(res, ld);
 113     } ideal.else_(); {
 114       // flattened
 115       sync_kit(ideal);
 116       if (elemptr->is_inlinetypeptr()) {
 117         // Element type is known, cast and load from flattened representation
 118         ciInlineKlass* vk = elemptr->inline_klass();
 119         assert(vk->flatten_array() && elemptr->maybe_null(), "never/always flat - should be optimized");
 120         ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
 121         const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
 122         Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, arytype));
 123         Node* casted_adr = array_element_address(cast, idx, T_INLINE_TYPE, ary_t->size(), control());
 124         // Re-execute flattened array load if buffering triggers deoptimization
 125         PreserveReexecuteState preexecs(this);
 126         jvms()->set_should_reexecute(true);
 127         inc_sp(2);
 128         Node* vt = InlineTypeNode::make_from_flattened(this, vk, cast, casted_adr)->buffer(this, false);
 129         ideal.set(res, vt);
 130         ideal.sync_kit(this);
 131       } else {
 132         // Element type is unknown, emit runtime call
 133 
 134         // Below membars keep this access to an unknown flattened array correctly
 135         // ordered with other unknown and known flattened array accesses.
 136         insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 137 
 138         Node* call = NULL;
 139         {
 140           // Re-execute flattened array load if runtime call triggers deoptimization
 141           PreserveReexecuteState preexecs(this);
 142           jvms()->set_bci(_bci);
 143           jvms()->set_should_reexecute(true);
 144           inc_sp(2);
 145           kill_dead_locals();
 146           call = make_runtime_call(RC_NO_LEAF | RC_NO_IO,
 147                                    OptoRuntime::load_unknown_inline_type(),
 148                                    OptoRuntime::load_unknown_inline_Java(),
 149                                    NULL, TypeRawPtr::BOTTOM,
 150                                    ary, idx);
 151         }
 152         make_slow_call_ex(call, env()->Throwable_klass(), false);
 153         Node* buffer = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 154 
 155         insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 156 
 157         // Keep track of the information that the inline type is flattened in arrays
 158         const Type* unknown_value = elemptr->is_instptr()->cast_to_flatten_array();
 159         buffer = _gvn.transform(new CheckCastPPNode(control(), buffer, unknown_value));
 160 
 161         ideal.sync_kit(this);
 162         ideal.set(res, buffer);
 163       }
 164     } ideal.end_if();
 165     sync_kit(ideal);
 166     Node* ld = _gvn.transform(ideal.value(res));
 167     ld = record_profile_for_speculation_at_array_load(ld);
 168     push_node(bt, ld);
 169     return;
 170   }
 171 
 172   if (elemtype == TypeInt::BOOL) {
 173     bt = T_BOOLEAN;
 174   }
 175   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 176   Node* ld = access_load_at(ary, adr, adr_type, elemtype, bt,
 177                             IN_HEAP | IS_ARRAY | C2_CONTROL_DEPENDENT_LOAD);
 178   ld = record_profile_for_speculation_at_array_load(ld);
 179   // Loading a non-flattened inline type
 180   if (elemptr != NULL && elemptr->is_inlinetypeptr()) {
 181     assert(!ary_t->is_null_free() || !elemptr->maybe_null(), "inline type array elements should never be null");
 182     ld = InlineTypeNode::make_from_oop(this, ld, elemptr->inline_klass(), !elemptr->maybe_null());
 183   }
 184   push_node(bt, ld);
 185 }
 186 
 187 
 188 //--------------------------------array_store----------------------------------
 189 void Parse::array_store(BasicType bt) {
 190   const Type* elemtype = Type::TOP;
 191   Node* adr = array_addressing(bt, type2size[bt], elemtype);
 192   if (stopped())  return;     // guaranteed null or range check
 193   Node* cast_val = NULL;
 194   if (bt == T_OBJECT) {
 195     cast_val = array_store_check(adr, elemtype);
 196     if (stopped()) return;
 197   }
 198   Node* val = pop_node(bt); // Value to store
 199   Node* idx = pop();        // Index in the array
 200   Node* ary = pop();        // The array itself
 201 
 202   const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr();
 203   const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(bt);
 204   assert(adr->as_AddP()->in(AddPNode::Base) == ary, "inconsistent address base");
 205 
 206   if (elemtype == TypeInt::BOOL) {
 207     bt = T_BOOLEAN;
 208   } else if (bt == T_OBJECT) {
 209     elemtype = elemtype->make_oopptr();
 210     const Type* tval = _gvn.type(cast_val);
 211     // We may have lost type information for 'val' here due to the casts
 212     // emitted by the array_store_check code (see JDK-6312651)
 213     // TODO Remove this code once JDK-6312651 is in.
 214     const Type* tval_init = _gvn.type(val);
 215     // Based on the value to be stored, try to determine if the array is not null-free and/or not flat.
 216     // This is only legal for non-null stores because the array_store_check always passes for null, even
 217     // if the array is null-free. Null stores are handled in GraphKit::gen_inline_array_null_guard().
 218     bool not_inline = !tval->isa_inlinetype() &&
 219                       ((!tval_init->maybe_null() && !tval_init->is_oopptr()->can_be_inline_type()) ||
 220                        (!tval->maybe_null() && !tval->is_oopptr()->can_be_inline_type()));
 221     bool not_flattened = not_inline || ((tval_init->is_inlinetypeptr() || tval_init->isa_inlinetype()) && !tval_init->inline_klass()->flatten_array());
 222     if (!ary_t->is_not_null_free() && not_inline) {
 223       // Storing a non-inline type, mark array as not null-free (-> not flat).
 224       ary_t = ary_t->cast_to_not_null_free();
 225       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 226       replace_in_map(ary, cast);
 227       ary = cast;
 228     } else if (!ary_t->is_not_flat() && not_flattened) {
 229       // Storing a non-flattened value, mark array as not flat.
 230       ary_t = ary_t->cast_to_not_flat();
 231       Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
 232       replace_in_map(ary, cast);
 233       ary = cast;
 234     }
 235 
 236     if (ary_t->is_flat()) {
 237       // Store to flattened inline type array
 238       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 239       // Re-execute flattened array store if buffering triggers deoptimization
 240       PreserveReexecuteState preexecs(this);
 241       inc_sp(3);
 242       jvms()->set_should_reexecute(true);
 243       cast_val->as_InlineTypeBase()->store_flattened(this, ary, adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 244       return;
 245     } else if (ary_t->is_null_free()) {
 246       // Store to non-flattened inline type array (elements can never be null)
 247       assert(!tval->maybe_null(), "should be guaranteed by array store check");
 248       if (elemtype->inline_klass()->is_empty()) {
 249         // Ignore empty inline stores, array is already initialized.
 250         return;
 251       }
 252     } else if (!ary_t->is_not_flat() && (tval != TypePtr::NULL_PTR || StressReflectiveCode)) {
 253       // Array might be flattened, emit runtime checks (for NULL, a simple inline_array_null_guard is sufficient).
 254       assert(UseFlatArray && !not_flattened && elemtype->is_oopptr()->can_be_inline_type() &&
 255              !ary_t->klass_is_exact() && !ary_t->is_not_null_free(), "array can't be flattened");
 256       IdealKit ideal(this);
 257       ideal.if_then(flat_array_test(ary, /* flat = */ false)); {
 258         // non-flattened
 259         assert(ideal.ctrl()->in(0)->as_If()->is_flat_array_check(&_gvn), "Should be found");
 260         sync_kit(ideal);
 261         Node* cast_ary = inline_array_null_guard(ary, cast_val, 3);
 262         inc_sp(3);
 263         access_store_at(cast_ary, adr, adr_type, cast_val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY, false);
 264         dec_sp(3);
 265         ideal.sync_kit(this);
 266       } ideal.else_(); {
 267         sync_kit(ideal);
 268         Node* val = cast_val;
 269         // flattened
 270         if (!val->is_InlineType() && tval->maybe_null()) {
 271           // Add null check
 272           Node* null_ctl = top();
 273           val = null_check_oop(val, &null_ctl);
 274           if (null_ctl != top()) {
 275             PreserveJVMState pjvms(this);
 276             inc_sp(3);
 277             set_control(null_ctl);
 278             uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none);
 279             dec_sp(3);
 280           }
 281         }
 282         // Try to determine the inline klass
 283         ciInlineKlass* vk = NULL;
 284         if (tval->isa_inlinetype() || tval->is_inlinetypeptr()) {
 285           vk = tval->inline_klass();
 286         } else if (tval_init->isa_inlinetype() || tval_init->is_inlinetypeptr()) {
 287           vk = tval_init->inline_klass();
 288         } else if (elemtype->is_inlinetypeptr()) {
 289           vk = elemtype->inline_klass();
 290         }
 291         Node* casted_ary = ary;
 292         if (vk != NULL && !stopped()) {
 293           // Element type is known, cast and store to flattened representation
 294           assert(vk->flatten_array() && elemtype->maybe_null(), "never/always flat - should be optimized");
 295           ciArrayKlass* array_klass = ciArrayKlass::make(vk, /* null_free */ true);
 296           const TypeAryPtr* arytype = TypeOopPtr::make_from_klass(array_klass)->isa_aryptr();
 297           casted_ary = _gvn.transform(new CheckCastPPNode(control(), casted_ary, arytype));
 298           Node* casted_adr = array_element_address(casted_ary, idx, T_OBJECT, arytype->size(), control());
 299           if (!val->is_InlineType()) {
 300             assert(!gvn().type(val)->maybe_null(), "inline type array elements should never be null");
 301             val = InlineTypeNode::make_from_oop(this, val, vk);
 302           }
 303           // Re-execute flattened array store if buffering triggers deoptimization
 304           PreserveReexecuteState preexecs(this);
 305           inc_sp(3);
 306           jvms()->set_should_reexecute(true);
 307           val->as_InlineTypeBase()->store_flattened(this, casted_ary, casted_adr, NULL, 0, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 308         } else if (!stopped()) {
 309           // Element type is unknown, emit runtime call
 310 
 311           // Below membars keep this access to an unknown flattened array correctly
 312           // ordered with other unknown and known flattened array accesses.
 313           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 314 
 315           make_runtime_call(RC_LEAF,
 316                             OptoRuntime::store_unknown_inline_type(),
 317                             CAST_FROM_FN_PTR(address, OptoRuntime::store_unknown_inline),
 318                             "store_unknown_inline", TypeRawPtr::BOTTOM,
 319                             val, casted_ary, idx);
 320 
 321           insert_mem_bar_volatile(Op_MemBarCPUOrder, C->get_alias_index(TypeAryPtr::INLINES));
 322         }
 323         ideal.sync_kit(this);
 324       }
 325       ideal.end_if();
 326       sync_kit(ideal);
 327       return;
 328     } else if (!ary_t->is_not_null_free()) {
 329       // Array is not flattened but may be null free
 330       assert(elemtype->is_oopptr()->can_be_inline_type() && !ary_t->klass_is_exact(), "array can't be null-free");
 331       ary = inline_array_null_guard(ary, cast_val, 3, true);
 332     }
 333   }
 334   inc_sp(3);
 335   access_store_at(ary, adr, adr_type, val, elemtype, bt, MO_UNORDERED | IN_HEAP | IS_ARRAY);
 336   dec_sp(3);
 337 }
 338 
 339 
 340 //------------------------------array_addressing-------------------------------
 341 // Pull array and index from the stack.  Compute pointer-to-element.
 342 Node* Parse::array_addressing(BasicType type, int vals, const Type*& elemtype) {
 343   Node *idx   = peek(0+vals);   // Get from stack without popping
 344   Node *ary   = peek(1+vals);   // in case of exception
 345 
 346   // Null check the array base, with correct stack contents
 347   ary = null_check(ary, T_ARRAY);
 348   // Compile-time detect of null-exception?
 349   if (stopped())  return top();
 350 
 351   const TypeAryPtr* arytype  = _gvn.type(ary)->is_aryptr();
 352   const TypeInt*    sizetype = arytype->size();
 353   elemtype = arytype->elem();
 354 
 355   if (UseUniqueSubclasses) {
 356     const Type* el = elemtype->make_ptr();
 357     if (el && el->isa_instptr()) {
 358       const TypeInstPtr* toop = el->is_instptr();
 359       if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) {
 360         // If we load from "AbstractClass[]" we must see "ConcreteSubClass".
 361         const Type* subklass = Type::get_const_type(toop->klass());
 362         elemtype = subklass->join_speculative(el);
 363       }
 364     }
 365   }
 366 
 367   // Check for big class initializers with all constant offsets
 368   // feeding into a known-size array.
 369   const TypeInt* idxtype = _gvn.type(idx)->is_int();
 370   // See if the highest idx value is less than the lowest array bound,
 371   // and if the idx value cannot be negative:
 372   bool need_range_check = true;
 373   if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) {
 374     need_range_check = false;
 375     if (C->log() != NULL)   C->log()->elem("observe that='!need_range_check'");
 376   }
 377 
 378   ciKlass * arytype_klass = arytype->klass();
 379   if ((arytype_klass != NULL) && (!arytype_klass->is_loaded())) {
 380     // Only fails for some -Xcomp runs
 381     // The class is unloaded.  We have to run this bytecode in the interpreter.
 382     uncommon_trap(Deoptimization::Reason_unloaded,
 383                   Deoptimization::Action_reinterpret,
 384                   arytype->klass(), "!loaded array");
 385     return top();
 386   }
 387 
 388   // Do the range check
 389   if (GenerateRangeChecks && need_range_check) {
 390     Node* tst;
 391     if (sizetype->_hi <= 0) {
 392       // The greatest array bound is negative, so we can conclude that we're
 393       // compiling unreachable code, but the unsigned compare trick used below
 394       // only works with non-negative lengths.  Instead, hack "tst" to be zero so
 395       // the uncommon_trap path will always be taken.
 396       tst = _gvn.intcon(0);
 397     } else {
 398       // Range is constant in array-oop, so we can use the original state of mem
 399       Node* len = load_array_length(ary);
 400 
 401       // Test length vs index (standard trick using unsigned compare)
 402       Node* chk = _gvn.transform( new CmpUNode(idx, len) );
 403       BoolTest::mask btest = BoolTest::lt;
 404       tst = _gvn.transform( new BoolNode(chk, btest) );
 405     }
 406     RangeCheckNode* rc = new RangeCheckNode(control(), tst, PROB_MAX, COUNT_UNKNOWN);
 407     _gvn.set_type(rc, rc->Value(&_gvn));
 408     if (!tst->is_Con()) {
 409       record_for_igvn(rc);
 410     }
 411     set_control(_gvn.transform(new IfTrueNode(rc)));
 412     // Branch to failure if out of bounds
 413     {
 414       PreserveJVMState pjvms(this);
 415       set_control(_gvn.transform(new IfFalseNode(rc)));
 416       if (C->allow_range_check_smearing()) {
 417         // Do not use builtin_throw, since range checks are sometimes
 418         // made more stringent by an optimistic transformation.
 419         // This creates "tentative" range checks at this point,
 420         // which are not guaranteed to throw exceptions.
 421         // See IfNode::Ideal, is_range_check, adjust_check.
 422         uncommon_trap(Deoptimization::Reason_range_check,
 423                       Deoptimization::Action_make_not_entrant,
 424                       NULL, "range_check");
 425       } else {
 426         // If we have already recompiled with the range-check-widening
 427         // heroic optimization turned off, then we must really be throwing
 428         // range check exceptions.
 429         builtin_throw(Deoptimization::Reason_range_check, idx);
 430       }
 431     }
 432   }
 433   // Check for always knowing you are throwing a range-check exception
 434   if (stopped())  return top();
 435 
 436   // This could be an access to an inline type array. We can't tell if it's
 437   // flat or not. Knowing the exact type avoids runtime checks and leads to
 438   // a much simpler graph shape. Check profile information.
 439   if (!arytype->is_flat() && !arytype->is_not_flat()) {
 440     // First check the speculative type
 441     Deoptimization::DeoptReason reason = Deoptimization::Reason_speculate_class_check;
 442     ciKlass* array_type = arytype->speculative_type();
 443     if (too_many_traps_or_recompiles(reason) || array_type == NULL) {
 444       // No speculative type, check profile data at this bci
 445       array_type = NULL;
 446       reason = Deoptimization::Reason_class_check;
 447       if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
 448         ciKlass* element_type = NULL;
 449         ProfilePtrKind element_ptr = ProfileMaybeNull;
 450         bool flat_array = true;
 451         bool null_free_array = true;
 452         method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 453       }
 454     }
 455     if (array_type != NULL) {
 456       // Speculate that this array has the exact type reported by profile data
 457       Node* better_ary = NULL;
 458       DEBUG_ONLY(Node* old_control = control();)
 459       Node* slow_ctl = type_check_receiver(ary, array_type, 1.0, &better_ary);
 460       if (stopped()) {
 461         // The check always fails and therefore profile information is incorrect. Don't use it.
 462         assert(old_control == slow_ctl, "type check should have been removed");
 463         set_control(slow_ctl);
 464       } else if (!slow_ctl->is_top()) {
 465         { PreserveJVMState pjvms(this);
 466           set_control(slow_ctl);
 467           uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 468         }
 469         replace_in_map(ary, better_ary);
 470         ary = better_ary;
 471         arytype  = _gvn.type(ary)->is_aryptr();
 472         elemtype = arytype->elem();
 473       }
 474     }
 475   } else if (UseTypeSpeculation && UseArrayLoadStoreProfile) {
 476     // No need to speculate: feed profile data at this bci for the
 477     // array to type speculation
 478     ciKlass* array_type = NULL;
 479     ciKlass* element_type = NULL;
 480     ProfilePtrKind element_ptr = ProfileMaybeNull;
 481     bool flat_array = true;
 482     bool null_free_array = true;
 483     method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 484     if (array_type != NULL) {
 485       ary = record_profile_for_speculation(ary, array_type, ProfileMaybeNull);
 486     }
 487   }
 488 
 489   // We have no exact array type from profile data. Check profile data
 490   // for a non null-free or non flat array. Non null-free implies non
 491   // flat so check this one first. Speculating on a non null-free
 492   // array doesn't help aaload but could be profitable for a
 493   // subsequent aastore.
 494   if (!arytype->is_null_free() && !arytype->is_not_null_free()) {
 495     bool null_free_array = true;
 496     Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
 497     if (arytype->speculative() != NULL &&
 498         arytype->speculative()->is_aryptr()->is_not_null_free() &&
 499         !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
 500       null_free_array = false;
 501       reason = Deoptimization::Reason_speculate_class_check;
 502     } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
 503       ciKlass* array_type = NULL;
 504       ciKlass* element_type = NULL;
 505       ProfilePtrKind element_ptr = ProfileMaybeNull;
 506       bool flat_array = true;
 507       method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 508       reason = Deoptimization::Reason_class_check;
 509     }
 510     if (!null_free_array) {
 511       { // Deoptimize if null-free array
 512         BuildCutout unless(this, null_free_array_test(load_object_klass(ary), /* null_free = */ false), PROB_MAX);
 513         uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 514       }
 515       assert(!stopped(), "null-free array should have been caught earlier");
 516       Node* better_ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype->cast_to_not_null_free()));
 517       replace_in_map(ary, better_ary);
 518       ary = better_ary;
 519       arytype = _gvn.type(ary)->is_aryptr();
 520     }
 521   }
 522 
 523   if (!arytype->is_flat() && !arytype->is_not_flat()) {
 524     bool flat_array = true;
 525     Deoptimization::DeoptReason reason = Deoptimization::Reason_none;
 526     if (arytype->speculative() != NULL &&
 527         arytype->speculative()->is_aryptr()->is_not_flat() &&
 528         !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
 529       flat_array = false;
 530       reason = Deoptimization::Reason_speculate_class_check;
 531     } else if (UseArrayLoadStoreProfile && !too_many_traps_or_recompiles(reason)) {
 532       ciKlass* array_type = NULL;
 533       ciKlass* element_type = NULL;
 534       ProfilePtrKind element_ptr = ProfileMaybeNull;
 535       bool null_free_array = true;
 536       method()->array_access_profiled_type(bci(), array_type, element_type, element_ptr, flat_array, null_free_array);
 537       reason = Deoptimization::Reason_class_check;
 538     }
 539     if (!flat_array) {
 540       { // Deoptimize if flat array
 541         BuildCutout unless(this, flat_array_test(ary, /* flat = */ false), PROB_MAX);
 542         uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
 543       }
 544       assert(!stopped(), "flat array should have been caught earlier");
 545       Node* better_ary = _gvn.transform(new CheckCastPPNode(control(), ary, arytype->cast_to_not_flat()));
 546       replace_in_map(ary, better_ary);
 547       ary = better_ary;
 548       arytype = _gvn.type(ary)->is_aryptr();
 549     }
 550   }
 551 
 552   // Make array address computation control dependent to prevent it
 553   // from floating above the range check during loop optimizations.
 554   Node* ptr = array_element_address(ary, idx, type, sizetype, control());
 555   assert(ptr != top(), "top should go hand-in-hand with stopped");
 556 
 557   return ptr;
 558 }
 559 
 560 
 561 // returns IfNode
 562 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask, float prob, float cnt) {
 563   Node   *cmp = _gvn.transform(new CmpINode(a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
 564   Node   *tst = _gvn.transform(new BoolNode(cmp, mask));
 565   IfNode *iff = create_and_map_if(control(), tst, prob, cnt);
 566   return iff;
 567 }
 568 
 569 
 570 // sentinel value for the target bci to mark never taken branches
 571 // (according to profiling)
 572 static const int never_reached = INT_MAX;
 573 
 574 //------------------------------helper for tableswitch-------------------------
 575 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, bool unc) {
 576   // True branch, use existing map info
 577   { PreserveJVMState pjvms(this);
 578     Node *iftrue  = _gvn.transform( new IfTrueNode (iff) );
 579     set_control( iftrue );
 580     if (unc) {
 581       repush_if_args();
 582       uncommon_trap(Deoptimization::Reason_unstable_if,
 583                     Deoptimization::Action_reinterpret,
 584                     NULL,
 585                     "taken always");
 586     } else {
 587       assert(dest_bci_if_true != never_reached, "inconsistent dest");
 588       merge_new_path(dest_bci_if_true);
 589     }
 590   }
 591 
 592   // False branch
 593   Node *iffalse = _gvn.transform( new IfFalseNode(iff) );
 594   set_control( iffalse );
 595 }
 596 
 597 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, bool unc) {
 598   // True branch, use existing map info
 599   { PreserveJVMState pjvms(this);
 600     Node *iffalse  = _gvn.transform( new IfFalseNode (iff) );
 601     set_control( iffalse );
 602     if (unc) {
 603       repush_if_args();
 604       uncommon_trap(Deoptimization::Reason_unstable_if,
 605                     Deoptimization::Action_reinterpret,
 606                     NULL,
 607                     "taken never");
 608     } else {
 609       assert(dest_bci_if_true != never_reached, "inconsistent dest");
 610       merge_new_path(dest_bci_if_true);
 611     }
 612   }
 613 
 614   // False branch
 615   Node *iftrue = _gvn.transform( new IfTrueNode(iff) );
 616   set_control( iftrue );
 617 }
 618 
 619 void Parse::jump_if_always_fork(int dest_bci, bool unc) {
 620   // False branch, use existing map and control()
 621   if (unc) {
 622     repush_if_args();
 623     uncommon_trap(Deoptimization::Reason_unstable_if,
 624                   Deoptimization::Action_reinterpret,
 625                   NULL,
 626                   "taken never");
 627   } else {
 628     assert(dest_bci != never_reached, "inconsistent dest");
 629     merge_new_path(dest_bci);
 630   }
 631 }
 632 
 633 
 634 extern "C" {
 635   static int jint_cmp(const void *i, const void *j) {
 636     int a = *(jint *)i;
 637     int b = *(jint *)j;
 638     return a > b ? 1 : a < b ? -1 : 0;
 639   }
 640 }
 641 
 642 
 643 class SwitchRange : public StackObj {
 644   // a range of integers coupled with a bci destination
 645   jint _lo;                     // inclusive lower limit
 646   jint _hi;                     // inclusive upper limit
 647   int _dest;
 648   float _cnt;                   // how many times this range was hit according to profiling
 649 
 650 public:
 651   jint lo() const              { return _lo;   }
 652   jint hi() const              { return _hi;   }
 653   int  dest() const            { return _dest; }
 654   bool is_singleton() const    { return _lo == _hi; }
 655   float cnt() const            { return _cnt; }
 656 
 657   void setRange(jint lo, jint hi, int dest, float cnt) {
 658     assert(lo <= hi, "must be a non-empty range");
 659     _lo = lo, _hi = hi; _dest = dest; _cnt = cnt;
 660     assert(_cnt >= 0, "");
 661   }
 662   bool adjoinRange(jint lo, jint hi, int dest, float cnt, bool trim_ranges) {
 663     assert(lo <= hi, "must be a non-empty range");
 664     if (lo == _hi+1) {
 665       // see merge_ranges() comment below
 666       if (trim_ranges) {
 667         if (cnt == 0) {
 668           if (_cnt != 0) {
 669             return false;
 670           }
 671           if (dest != _dest) {
 672             _dest = never_reached;
 673           }
 674         } else {
 675           if (_cnt == 0) {
 676             return false;
 677           }
 678           if (dest != _dest) {
 679             return false;
 680           }
 681         }
 682       } else {
 683         if (dest != _dest) {
 684           return false;
 685         }
 686       }
 687       _hi = hi;
 688       _cnt += cnt;
 689       return true;
 690     }
 691     return false;
 692   }
 693 
 694   void set (jint value, int dest, float cnt) {
 695     setRange(value, value, dest, cnt);
 696   }
 697   bool adjoin(jint value, int dest, float cnt, bool trim_ranges) {
 698     return adjoinRange(value, value, dest, cnt, trim_ranges);
 699   }
 700   bool adjoin(SwitchRange& other) {
 701     return adjoinRange(other._lo, other._hi, other._dest, other._cnt, false);
 702   }
 703 
 704   void print() {
 705     if (is_singleton())
 706       tty->print(" {%d}=>%d (cnt=%f)", lo(), dest(), cnt());
 707     else if (lo() == min_jint)
 708       tty->print(" {..%d}=>%d (cnt=%f)", hi(), dest(), cnt());
 709     else if (hi() == max_jint)
 710       tty->print(" {%d..}=>%d (cnt=%f)", lo(), dest(), cnt());
 711     else
 712       tty->print(" {%d..%d}=>%d (cnt=%f)", lo(), hi(), dest(), cnt());
 713   }
 714 };
 715 
 716 // We try to minimize the number of ranges and the size of the taken
 717 // ones using profiling data. When ranges are created,
 718 // SwitchRange::adjoinRange() only allows 2 adjoining ranges to merge
 719 // if both were never hit or both were hit to build longer unreached
 720 // ranges. Here, we now merge adjoining ranges with the same
 721 // destination and finally set destination of unreached ranges to the
 722 // special value never_reached because it can help minimize the number
 723 // of tests that are necessary.
 724 //
 725 // For instance:
 726 // [0, 1] to target1 sometimes taken
 727 // [1, 2] to target1 never taken
 728 // [2, 3] to target2 never taken
 729 // would lead to:
 730 // [0, 1] to target1 sometimes taken
 731 // [1, 3] never taken
 732 //
 733 // (first 2 ranges to target1 are not merged)
 734 static void merge_ranges(SwitchRange* ranges, int& rp) {
 735   if (rp == 0) {
 736     return;
 737   }
 738   int shift = 0;
 739   for (int j = 0; j < rp; j++) {
 740     SwitchRange& r1 = ranges[j-shift];
 741     SwitchRange& r2 = ranges[j+1];
 742     if (r1.adjoin(r2)) {
 743       shift++;
 744     } else if (shift > 0) {
 745       ranges[j+1-shift] = r2;
 746     }
 747   }
 748   rp -= shift;
 749   for (int j = 0; j <= rp; j++) {
 750     SwitchRange& r = ranges[j];
 751     if (r.cnt() == 0 && r.dest() != never_reached) {
 752       r.setRange(r.lo(), r.hi(), never_reached, r.cnt());
 753     }
 754   }
 755 }
 756 
 757 //-------------------------------do_tableswitch--------------------------------
 758 void Parse::do_tableswitch() {
 759   // Get information about tableswitch
 760   int default_dest = iter().get_dest_table(0);
 761   int lo_index     = iter().get_int_table(1);
 762   int hi_index     = iter().get_int_table(2);
 763   int len          = hi_index - lo_index + 1;
 764 
 765   if (len < 1) {
 766     // If this is a backward branch, add safepoint
 767     maybe_add_safepoint(default_dest);
 768     pop(); // the effect of the instruction execution on the operand stack
 769     merge(default_dest);
 770     return;
 771   }
 772 
 773   ciMethodData* methodData = method()->method_data();
 774   ciMultiBranchData* profile = NULL;
 775   if (methodData->is_mature() && UseSwitchProfiling) {
 776     ciProfileData* data = methodData->bci_to_data(bci());
 777     if (data != NULL && data->is_MultiBranchData()) {
 778       profile = (ciMultiBranchData*)data;
 779     }
 780   }
 781   bool trim_ranges = !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if);
 782 
 783   // generate decision tree, using trichotomy when possible
 784   int rnum = len+2;
 785   bool makes_backward_branch = false;
 786   SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
 787   int rp = -1;
 788   if (lo_index != min_jint) {
 789     uint cnt = 1;
 790     if (profile != NULL) {
 791       cnt = profile->default_count() / (hi_index != max_jint ? 2 : 1);
 792     }
 793     ranges[++rp].setRange(min_jint, lo_index-1, default_dest, cnt);
 794   }
 795   for (int j = 0; j < len; j++) {
 796     jint match_int = lo_index+j;
 797     int  dest      = iter().get_dest_table(j+3);
 798     makes_backward_branch |= (dest <= bci());
 799     uint cnt = 1;
 800     if (profile != NULL) {
 801       cnt = profile->count_at(j);
 802     }
 803     if (rp < 0 || !ranges[rp].adjoin(match_int, dest, cnt, trim_ranges)) {
 804       ranges[++rp].set(match_int, dest, cnt);
 805     }
 806   }
 807   jint highest = lo_index+(len-1);
 808   assert(ranges[rp].hi() == highest, "");
 809   if (highest != max_jint) {
 810     uint cnt = 1;
 811     if (profile != NULL) {
 812       cnt = profile->default_count() / (lo_index != min_jint ? 2 : 1);
 813     }
 814     if (!ranges[rp].adjoinRange(highest+1, max_jint, default_dest, cnt, trim_ranges)) {
 815       ranges[++rp].setRange(highest+1, max_jint, default_dest, cnt);
 816     }
 817   }
 818   assert(rp < len+2, "not too many ranges");
 819 
 820   if (trim_ranges) {
 821     merge_ranges(ranges, rp);
 822   }
 823 
 824   // Safepoint in case if backward branch observed
 825   if (makes_backward_branch) {
 826     add_safepoint();
 827   }
 828 
 829   Node* lookup = pop(); // lookup value
 830   jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
 831 }
 832 
 833 
 834 //------------------------------do_lookupswitch--------------------------------
 835 void Parse::do_lookupswitch() {
 836   // Get information about lookupswitch
 837   int default_dest = iter().get_dest_table(0);
 838   int len          = iter().get_int_table(1);
 839 
 840   if (len < 1) {    // If this is a backward branch, add safepoint
 841     maybe_add_safepoint(default_dest);
 842     pop(); // the effect of the instruction execution on the operand stack
 843     merge(default_dest);
 844     return;
 845   }
 846 
 847   ciMethodData* methodData = method()->method_data();
 848   ciMultiBranchData* profile = NULL;
 849   if (methodData->is_mature() && UseSwitchProfiling) {
 850     ciProfileData* data = methodData->bci_to_data(bci());
 851     if (data != NULL && data->is_MultiBranchData()) {
 852       profile = (ciMultiBranchData*)data;
 853     }
 854   }
 855   bool trim_ranges = !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if);
 856 
 857   // generate decision tree, using trichotomy when possible
 858   jint* table = NEW_RESOURCE_ARRAY(jint, len*3);
 859   {
 860     for (int j = 0; j < len; j++) {
 861       table[3*j+0] = iter().get_int_table(2+2*j);
 862       table[3*j+1] = iter().get_dest_table(2+2*j+1);
 863       // Handle overflow when converting from uint to jint
 864       table[3*j+2] = (profile == NULL) ? 1 : MIN2<uint>(max_jint, profile->count_at(j));
 865     }
 866     qsort(table, len, 3*sizeof(table[0]), jint_cmp);
 867   }
 868 
 869   float defaults = 0;
 870   jint prev = min_jint;
 871   for (int j = 0; j < len; j++) {
 872     jint match_int = table[3*j+0];
 873     if (match_int != prev) {
 874       defaults += (float)match_int - prev;
 875     }
 876     prev = match_int+1;
 877   }
 878   if (prev != min_jint) {
 879     defaults += (float)max_jint - prev + 1;
 880   }
 881   float default_cnt = 1;
 882   if (profile != NULL) {
 883     default_cnt = profile->default_count()/defaults;
 884   }
 885 
 886   int rnum = len*2+1;
 887   bool makes_backward_branch = false;
 888   SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
 889   int rp = -1;
 890   for (int j = 0; j < len; j++) {
 891     jint match_int   = table[3*j+0];
 892     int  dest        = table[3*j+1];
 893     int  cnt         = table[3*j+2];
 894     int  next_lo     = rp < 0 ? min_jint : ranges[rp].hi()+1;
 895     makes_backward_branch |= (dest <= bci());
 896     float c = default_cnt * ((float)match_int - next_lo);
 897     if (match_int != next_lo && (rp < 0 || !ranges[rp].adjoinRange(next_lo, match_int-1, default_dest, c, trim_ranges))) {
 898       assert(default_dest != never_reached, "sentinel value for dead destinations");
 899       ranges[++rp].setRange(next_lo, match_int-1, default_dest, c);
 900     }
 901     if (rp < 0 || !ranges[rp].adjoin(match_int, dest, cnt, trim_ranges)) {
 902       assert(dest != never_reached, "sentinel value for dead destinations");
 903       ranges[++rp].set(match_int, dest, cnt);
 904     }
 905   }
 906   jint highest = table[3*(len-1)];
 907   assert(ranges[rp].hi() == highest, "");
 908   if (highest != max_jint &&
 909       !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, default_cnt * ((float)max_jint - highest), trim_ranges)) {
 910     ranges[++rp].setRange(highest+1, max_jint, default_dest, default_cnt * ((float)max_jint - highest));
 911   }
 912   assert(rp < rnum, "not too many ranges");
 913 
 914   if (trim_ranges) {
 915     merge_ranges(ranges, rp);
 916   }
 917 
 918   // Safepoint in case backward branch observed
 919   if (makes_backward_branch) {
 920     add_safepoint();
 921   }
 922 
 923   Node *lookup = pop(); // lookup value
 924   jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
 925 }
 926 
 927 static float if_prob(float taken_cnt, float total_cnt) {
 928   assert(taken_cnt <= total_cnt, "");
 929   if (total_cnt == 0) {
 930     return PROB_FAIR;
 931   }
 932   float p = taken_cnt / total_cnt;
 933   return clamp(p, PROB_MIN, PROB_MAX);
 934 }
 935 
 936 static float if_cnt(float cnt) {
 937   if (cnt == 0) {
 938     return COUNT_UNKNOWN;
 939   }
 940   return cnt;
 941 }
 942 
 943 static float sum_of_cnts(SwitchRange *lo, SwitchRange *hi) {
 944   float total_cnt = 0;
 945   for (SwitchRange* sr = lo; sr <= hi; sr++) {
 946     total_cnt += sr->cnt();
 947   }
 948   return total_cnt;
 949 }
 950 
 951 class SwitchRanges : public ResourceObj {
 952 public:
 953   SwitchRange* _lo;
 954   SwitchRange* _hi;
 955   SwitchRange* _mid;
 956   float _cost;
 957 
 958   enum {
 959     Start,
 960     LeftDone,
 961     RightDone,
 962     Done
 963   } _state;
 964 
 965   SwitchRanges(SwitchRange *lo, SwitchRange *hi)
 966     : _lo(lo), _hi(hi), _mid(NULL),
 967       _cost(0), _state(Start) {
 968   }
 969 
 970   SwitchRanges()
 971     : _lo(NULL), _hi(NULL), _mid(NULL),
 972       _cost(0), _state(Start) {}
 973 };
 974 
 975 // Estimate cost of performing a binary search on lo..hi
 976 static float compute_tree_cost(SwitchRange *lo, SwitchRange *hi, float total_cnt) {
 977   GrowableArray<SwitchRanges> tree;
 978   SwitchRanges root(lo, hi);
 979   tree.push(root);
 980 
 981   float cost = 0;
 982   do {
 983     SwitchRanges& r = *tree.adr_at(tree.length()-1);
 984     if (r._hi != r._lo) {
 985       if (r._mid == NULL) {
 986         float r_cnt = sum_of_cnts(r._lo, r._hi);
 987 
 988         if (r_cnt == 0) {
 989           tree.pop();
 990           cost = 0;
 991           continue;
 992         }
 993 
 994         SwitchRange* mid = NULL;
 995         mid = r._lo;
 996         for (float cnt = 0; ; ) {
 997           assert(mid <= r._hi, "out of bounds");
 998           cnt += mid->cnt();
 999           if (cnt > r_cnt / 2) {
1000             break;
1001           }
1002           mid++;
1003         }
1004         assert(mid <= r._hi, "out of bounds");
1005         r._mid = mid;
1006         r._cost = r_cnt / total_cnt;
1007       }
1008       r._cost += cost;
1009       if (r._state < SwitchRanges::LeftDone && r._mid > r._lo) {
1010         cost = 0;
1011         r._state = SwitchRanges::LeftDone;
1012         tree.push(SwitchRanges(r._lo, r._mid-1));
1013       } else if (r._state < SwitchRanges::RightDone) {
1014         cost = 0;
1015         r._state = SwitchRanges::RightDone;
1016         tree.push(SwitchRanges(r._mid == r._lo ? r._mid+1 : r._mid, r._hi));
1017       } else {
1018         tree.pop();
1019         cost = r._cost;
1020       }
1021     } else {
1022       tree.pop();
1023       cost = r._cost;
1024     }
1025   } while (tree.length() > 0);
1026 
1027 
1028   return cost;
1029 }
1030 
1031 // It sometimes pays off to test most common ranges before the binary search
1032 void Parse::linear_search_switch_ranges(Node* key_val, SwitchRange*& lo, SwitchRange*& hi) {
1033   uint nr = hi - lo + 1;
1034   float total_cnt = sum_of_cnts(lo, hi);
1035 
1036   float min = compute_tree_cost(lo, hi, total_cnt);
1037   float extra = 1;
1038   float sub = 0;
1039 
1040   SwitchRange* array1 = lo;
1041   SwitchRange* array2 = NEW_RESOURCE_ARRAY(SwitchRange, nr);
1042 
1043   SwitchRange* ranges = NULL;
1044 
1045   while (nr >= 2) {
1046     assert(lo == array1 || lo == array2, "one the 2 already allocated arrays");
1047     ranges = (lo == array1) ? array2 : array1;
1048 
1049     // Find highest frequency range
1050     SwitchRange* candidate = lo;
1051     for (SwitchRange* sr = lo+1; sr <= hi; sr++) {
1052       if (sr->cnt() > candidate->cnt()) {
1053         candidate = sr;
1054       }
1055     }
1056     SwitchRange most_freq = *candidate;
1057     if (most_freq.cnt() == 0) {
1058       break;
1059     }
1060 
1061     // Copy remaining ranges into another array
1062     int shift = 0;
1063     for (uint i = 0; i < nr; i++) {
1064       SwitchRange* sr = &lo[i];
1065       if (sr != candidate) {
1066         ranges[i-shift] = *sr;
1067       } else {
1068         shift++;
1069         if (i > 0 && i < nr-1) {
1070           SwitchRange prev = lo[i-1];
1071           prev.setRange(prev.lo(), sr->hi(), prev.dest(), prev.cnt());
1072           if (prev.adjoin(lo[i+1])) {
1073             shift++;
1074             i++;
1075           }
1076           ranges[i-shift] = prev;
1077         }
1078       }
1079     }
1080     nr -= shift;
1081 
1082     // Evaluate cost of testing the most common range and performing a
1083     // binary search on the other ranges
1084     float cost = extra + compute_tree_cost(&ranges[0], &ranges[nr-1], total_cnt);
1085     if (cost >= min) {
1086       break;
1087     }
1088     // swap arrays
1089     lo = &ranges[0];
1090     hi = &ranges[nr-1];
1091 
1092     // It pays off: emit the test for the most common range
1093     assert(most_freq.cnt() > 0, "must be taken");
1094     Node* val = _gvn.transform(new SubINode(key_val, _gvn.intcon(most_freq.lo())));
1095     Node* cmp = _gvn.transform(new CmpUNode(val, _gvn.intcon(most_freq.hi() - most_freq.lo())));
1096     Node* tst = _gvn.transform(new BoolNode(cmp, BoolTest::le));
1097     IfNode* iff = create_and_map_if(control(), tst, if_prob(most_freq.cnt(), total_cnt), if_cnt(most_freq.cnt()));
1098     jump_if_true_fork(iff, most_freq.dest(), false);
1099 
1100     sub += most_freq.cnt() / total_cnt;
1101     extra += 1 - sub;
1102     min = cost;
1103   }
1104 }
1105 
1106 //----------------------------create_jump_tables-------------------------------
1107 bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) {
1108   // Are jumptables enabled
1109   if (!UseJumpTables)  return false;
1110 
1111   // Are jumptables supported
1112   if (!Matcher::has_match_rule(Op_Jump))  return false;
1113 
1114   bool trim_ranges = !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if);
1115 
1116   // Decide if a guard is needed to lop off big ranges at either (or
1117   // both) end(s) of the input set. We'll call this the default target
1118   // even though we can't be sure that it is the true "default".
1119 
1120   bool needs_guard = false;
1121   int default_dest;
1122   int64_t total_outlier_size = 0;
1123   int64_t hi_size = ((int64_t)hi->hi()) - ((int64_t)hi->lo()) + 1;
1124   int64_t lo_size = ((int64_t)lo->hi()) - ((int64_t)lo->lo()) + 1;
1125 
1126   if (lo->dest() == hi->dest()) {
1127     total_outlier_size = hi_size + lo_size;
1128     default_dest = lo->dest();
1129   } else if (lo_size > hi_size) {
1130     total_outlier_size = lo_size;
1131     default_dest = lo->dest();
1132   } else {
1133     total_outlier_size = hi_size;
1134     default_dest = hi->dest();
1135   }
1136 
1137   float total = sum_of_cnts(lo, hi);
1138   float cost = compute_tree_cost(lo, hi, total);
1139 
1140   // If a guard test will eliminate very sparse end ranges, then
1141   // it is worth the cost of an extra jump.
1142   float trimmed_cnt = 0;
1143   if (total_outlier_size > (MaxJumpTableSparseness * 4)) {
1144     needs_guard = true;
1145     if (default_dest == lo->dest()) {
1146       trimmed_cnt += lo->cnt();
1147       lo++;
1148     }
1149     if (default_dest == hi->dest()) {
1150       trimmed_cnt += hi->cnt();
1151       hi--;
1152     }
1153   }
1154 
1155   // Find the total number of cases and ranges
1156   int64_t num_cases = ((int64_t)hi->hi()) - ((int64_t)lo->lo()) + 1;
1157   int num_range = hi - lo + 1;
1158 
1159   // Don't create table if: too large, too small, or too sparse.
1160   if (num_cases > MaxJumpTableSize)
1161     return false;
1162   if (UseSwitchProfiling) {
1163     // MinJumpTableSize is set so with a well balanced binary tree,
1164     // when the number of ranges is MinJumpTableSize, it's cheaper to
1165     // go through a JumpNode that a tree of IfNodes. Average cost of a
1166     // tree of IfNodes with MinJumpTableSize is
1167     // log2f(MinJumpTableSize) comparisons. So if the cost computed
1168     // from profile data is less than log2f(MinJumpTableSize) then
1169     // going with the binary search is cheaper.
1170     if (cost < log2f(MinJumpTableSize)) {
1171       return false;
1172     }
1173   } else {
1174     if (num_cases < MinJumpTableSize)
1175       return false;
1176   }
1177   if (num_cases > (MaxJumpTableSparseness * num_range))
1178     return false;
1179 
1180   // Normalize table lookups to zero
1181   int lowval = lo->lo();
1182   key_val = _gvn.transform( new SubINode(key_val, _gvn.intcon(lowval)) );
1183 
1184   // Generate a guard to protect against input keyvals that aren't
1185   // in the switch domain.
1186   if (needs_guard) {
1187     Node*   size = _gvn.intcon(num_cases);
1188     Node*   cmp = _gvn.transform(new CmpUNode(key_val, size));
1189     Node*   tst = _gvn.transform(new BoolNode(cmp, BoolTest::ge));
1190     IfNode* iff = create_and_map_if(control(), tst, if_prob(trimmed_cnt, total), if_cnt(trimmed_cnt));
1191     jump_if_true_fork(iff, default_dest, trim_ranges && trimmed_cnt == 0);
1192 
1193     total -= trimmed_cnt;
1194   }
1195 
1196   // Create an ideal node JumpTable that has projections
1197   // of all possible ranges for a switch statement
1198   // The key_val input must be converted to a pointer offset and scaled.
1199   // Compare Parse::array_addressing above.
1200 
1201   // Clean the 32-bit int into a real 64-bit offset.
1202   // Otherwise, the jint value 0 might turn into an offset of 0x0800000000.
1203   // Make I2L conversion control dependent to prevent it from
1204   // floating above the range check during loop optimizations.
1205   // Do not use a narrow int type here to prevent the data path from dying
1206   // while the control path is not removed. This can happen if the type of key_val
1207   // is later known to be out of bounds of [0, num_cases] and therefore a narrow cast
1208   // would be replaced by TOP while C2 is not able to fold the corresponding range checks.
1209   // Set _carry_dependency for the cast to avoid being removed by IGVN.
1210 #ifdef _LP64
1211   key_val = C->constrained_convI2L(&_gvn, key_val, TypeInt::INT, control(), true /* carry_dependency */);
1212 #endif
1213 
1214   // Shift the value by wordsize so we have an index into the table, rather
1215   // than a switch value
1216   Node *shiftWord = _gvn.MakeConX(wordSize);
1217   key_val = _gvn.transform( new MulXNode( key_val, shiftWord));
1218 
1219   // Create the JumpNode
1220   Arena* arena = C->comp_arena();
1221   float* probs = (float*)arena->Amalloc(sizeof(float)*num_cases);
1222   int i = 0;
1223   if (total == 0) {
1224     for (SwitchRange* r = lo; r <= hi; r++) {
1225       for (int64_t j = r->lo(); j <= r->hi(); j++, i++) {
1226         probs[i] = 1.0F / num_cases;
1227       }
1228     }
1229   } else {
1230     for (SwitchRange* r = lo; r <= hi; r++) {
1231       float prob = r->cnt()/total;
1232       for (int64_t j = r->lo(); j <= r->hi(); j++, i++) {
1233         probs[i] = prob / (r->hi() - r->lo() + 1);
1234       }
1235     }
1236   }
1237 
1238   ciMethodData* methodData = method()->method_data();
1239   ciMultiBranchData* profile = NULL;
1240   if (methodData->is_mature()) {
1241     ciProfileData* data = methodData->bci_to_data(bci());
1242     if (data != NULL && data->is_MultiBranchData()) {
1243       profile = (ciMultiBranchData*)data;
1244     }
1245   }
1246 
1247   Node* jtn = _gvn.transform(new JumpNode(control(), key_val, num_cases, probs, profile == NULL ? COUNT_UNKNOWN : total));
1248 
1249   // These are the switch destinations hanging off the jumpnode
1250   i = 0;
1251   for (SwitchRange* r = lo; r <= hi; r++) {
1252     for (int64_t j = r->lo(); j <= r->hi(); j++, i++) {
1253       Node* input = _gvn.transform(new JumpProjNode(jtn, i, r->dest(), (int)(j - lowval)));
1254       {
1255         PreserveJVMState pjvms(this);
1256         set_control(input);
1257         jump_if_always_fork(r->dest(), trim_ranges && r->cnt() == 0);
1258       }
1259     }
1260   }
1261   assert(i == num_cases, "miscount of cases");
1262   stop_and_kill_map();  // no more uses for this JVMS
1263   return true;
1264 }
1265 
1266 //----------------------------jump_switch_ranges-------------------------------
1267 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) {
1268   Block* switch_block = block();
1269   bool trim_ranges = !C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if);
1270 
1271   if (switch_depth == 0) {
1272     // Do special processing for the top-level call.
1273     assert(lo->lo() == min_jint, "initial range must exhaust Type::INT");
1274     assert(hi->hi() == max_jint, "initial range must exhaust Type::INT");
1275 
1276     // Decrement pred-numbers for the unique set of nodes.
1277 #ifdef ASSERT
1278     if (!trim_ranges) {
1279       // Ensure that the block's successors are a (duplicate-free) set.
1280       int successors_counted = 0;  // block occurrences in [hi..lo]
1281       int unique_successors = switch_block->num_successors();
1282       for (int i = 0; i < unique_successors; i++) {
1283         Block* target = switch_block->successor_at(i);
1284 
1285         // Check that the set of successors is the same in both places.
1286         int successors_found = 0;
1287         for (SwitchRange* p = lo; p <= hi; p++) {
1288           if (p->dest() == target->start())  successors_found++;
1289         }
1290         assert(successors_found > 0, "successor must be known");
1291         successors_counted += successors_found;
1292       }
1293       assert(successors_counted == (hi-lo)+1, "no unexpected successors");
1294     }
1295 #endif
1296 
1297     // Maybe prune the inputs, based on the type of key_val.
1298     jint min_val = min_jint;
1299     jint max_val = max_jint;
1300     const TypeInt* ti = key_val->bottom_type()->isa_int();
1301     if (ti != NULL) {
1302       min_val = ti->_lo;
1303       max_val = ti->_hi;
1304       assert(min_val <= max_val, "invalid int type");
1305     }
1306     while (lo->hi() < min_val) {
1307       lo++;
1308     }
1309     if (lo->lo() < min_val)  {
1310       lo->setRange(min_val, lo->hi(), lo->dest(), lo->cnt());
1311     }
1312     while (hi->lo() > max_val) {
1313       hi--;
1314     }
1315     if (hi->hi() > max_val) {
1316       hi->setRange(hi->lo(), max_val, hi->dest(), hi->cnt());
1317     }
1318 
1319     linear_search_switch_ranges(key_val, lo, hi);
1320   }
1321 
1322 #ifndef PRODUCT
1323   if (switch_depth == 0) {
1324     _max_switch_depth = 0;
1325     _est_switch_depth = log2i_graceful((hi - lo + 1) - 1) + 1;
1326   }
1327 #endif
1328 
1329   assert(lo <= hi, "must be a non-empty set of ranges");
1330   if (lo == hi) {
1331     jump_if_always_fork(lo->dest(), trim_ranges && lo->cnt() == 0);
1332   } else {
1333     assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges");
1334     assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges");
1335 
1336     if (create_jump_tables(key_val, lo, hi)) return;
1337 
1338     SwitchRange* mid = NULL;
1339     float total_cnt = sum_of_cnts(lo, hi);
1340 
1341     int nr = hi - lo + 1;
1342     if (UseSwitchProfiling) {
1343       // Don't keep the binary search tree balanced: pick up mid point
1344       // that split frequencies in half.
1345       float cnt = 0;
1346       for (SwitchRange* sr = lo; sr <= hi; sr++) {
1347         cnt += sr->cnt();
1348         if (cnt >= total_cnt / 2) {
1349           mid = sr;
1350           break;
1351         }
1352       }
1353     } else {
1354       mid = lo + nr/2;
1355 
1356       // if there is an easy choice, pivot at a singleton:
1357       if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton())  mid--;
1358 
1359       assert(lo < mid && mid <= hi, "good pivot choice");
1360       assert(nr != 2 || mid == hi,   "should pick higher of 2");
1361       assert(nr != 3 || mid == hi-1, "should pick middle of 3");
1362     }
1363 
1364 
1365     Node *test_val = _gvn.intcon(mid == lo ? mid->hi() : mid->lo());
1366 
1367     if (mid->is_singleton()) {
1368       IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne, 1-if_prob(mid->cnt(), total_cnt), if_cnt(mid->cnt()));
1369       jump_if_false_fork(iff_ne, mid->dest(), trim_ranges && mid->cnt() == 0);
1370 
1371       // Special Case:  If there are exactly three ranges, and the high
1372       // and low range each go to the same place, omit the "gt" test,
1373       // since it will not discriminate anything.
1374       bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest() && mid == hi-1) || mid == lo;
1375 
1376       // if there is a higher range, test for it and process it:
1377       if (mid < hi && !eq_test_only) {
1378         // two comparisons of same values--should enable 1 test for 2 branches
1379         // Use BoolTest::lt instead of BoolTest::gt
1380         float cnt = sum_of_cnts(lo, mid-1);
1381         IfNode *iff_lt  = jump_if_fork_int(key_val, test_val, BoolTest::lt, if_prob(cnt, total_cnt), if_cnt(cnt));
1382         Node   *iftrue  = _gvn.transform( new IfTrueNode(iff_lt) );
1383         Node   *iffalse = _gvn.transform( new IfFalseNode(iff_lt) );
1384         { PreserveJVMState pjvms(this);
1385           set_control(iffalse);
1386           jump_switch_ranges(key_val, mid+1, hi, switch_depth+1);
1387         }
1388         set_control(iftrue);
1389       }
1390 
1391     } else {
1392       // mid is a range, not a singleton, so treat mid..hi as a unit
1393       float cnt = sum_of_cnts(mid == lo ? mid+1 : mid, hi);
1394       IfNode *iff_ge = jump_if_fork_int(key_val, test_val, mid == lo ? BoolTest::gt : BoolTest::ge, if_prob(cnt, total_cnt), if_cnt(cnt));
1395 
1396       // if there is a higher range, test for it and process it:
1397       if (mid == hi) {
1398         jump_if_true_fork(iff_ge, mid->dest(), trim_ranges && cnt == 0);
1399       } else {
1400         Node *iftrue  = _gvn.transform( new IfTrueNode(iff_ge) );
1401         Node *iffalse = _gvn.transform( new IfFalseNode(iff_ge) );
1402         { PreserveJVMState pjvms(this);
1403           set_control(iftrue);
1404           jump_switch_ranges(key_val, mid == lo ? mid+1 : mid, hi, switch_depth+1);
1405         }
1406         set_control(iffalse);
1407       }
1408     }
1409 
1410     // in any case, process the lower range
1411     if (mid == lo) {
1412       if (mid->is_singleton()) {
1413         jump_switch_ranges(key_val, lo+1, hi, switch_depth+1);
1414       } else {
1415         jump_if_always_fork(lo->dest(), trim_ranges && lo->cnt() == 0);
1416       }
1417     } else {
1418       jump_switch_ranges(key_val, lo, mid-1, switch_depth+1);
1419     }
1420   }
1421 
1422   // Decrease pred_count for each successor after all is done.
1423   if (switch_depth == 0) {
1424     int unique_successors = switch_block->num_successors();
1425     for (int i = 0; i < unique_successors; i++) {
1426       Block* target = switch_block->successor_at(i);
1427       // Throw away the pre-allocated path for each unique successor.
1428       target->next_path_num();
1429     }
1430   }
1431 
1432 #ifndef PRODUCT
1433   _max_switch_depth = MAX2(switch_depth, _max_switch_depth);
1434   if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) {
1435     SwitchRange* r;
1436     int nsing = 0;
1437     for( r = lo; r <= hi; r++ ) {
1438       if( r->is_singleton() )  nsing++;
1439     }
1440     tty->print(">>> ");
1441     _method->print_short_name();
1442     tty->print_cr(" switch decision tree");
1443     tty->print_cr("    %d ranges (%d singletons), max_depth=%d, est_depth=%d",
1444                   (int) (hi-lo+1), nsing, _max_switch_depth, _est_switch_depth);
1445     if (_max_switch_depth > _est_switch_depth) {
1446       tty->print_cr("******** BAD SWITCH DEPTH ********");
1447     }
1448     tty->print("   ");
1449     for( r = lo; r <= hi; r++ ) {
1450       r->print();
1451     }
1452     tty->cr();
1453   }
1454 #endif
1455 }
1456 
1457 void Parse::modf() {
1458   Node *f2 = pop();
1459   Node *f1 = pop();
1460   Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(),
1461                               CAST_FROM_FN_PTR(address, SharedRuntime::frem),
1462                               "frem", NULL, //no memory effects
1463                               f1, f2);
1464   Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0));
1465 
1466   push(res);
1467 }
1468 
1469 void Parse::modd() {
1470   Node *d2 = pop_pair();
1471   Node *d1 = pop_pair();
1472   Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(),
1473                               CAST_FROM_FN_PTR(address, SharedRuntime::drem),
1474                               "drem", NULL, //no memory effects
1475                               d1, top(), d2, top());
1476   Node* res_d   = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0));
1477 
1478 #ifdef ASSERT
1479   Node* res_top = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 1));
1480   assert(res_top == top(), "second value must be top");
1481 #endif
1482 
1483   push_pair(res_d);
1484 }
1485 
1486 void Parse::l2f() {
1487   Node* f2 = pop();
1488   Node* f1 = pop();
1489   Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(),
1490                               CAST_FROM_FN_PTR(address, SharedRuntime::l2f),
1491                               "l2f", NULL, //no memory effects
1492                               f1, f2);
1493   Node* res = _gvn.transform(new ProjNode(c, TypeFunc::Parms + 0));
1494 
1495   push(res);
1496 }
1497 
1498 // Handle jsr and jsr_w bytecode
1499 void Parse::do_jsr() {
1500   assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode");
1501 
1502   // Store information about current state, tagged with new _jsr_bci
1503   int return_bci = iter().next_bci();
1504   int jsr_bci    = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest();
1505 
1506   // The way we do things now, there is only one successor block
1507   // for the jsr, because the target code is cloned by ciTypeFlow.
1508   Block* target = successor_for_bci(jsr_bci);
1509 
1510   // What got pushed?
1511   const Type* ret_addr = target->peek();
1512   assert(ret_addr->singleton(), "must be a constant (cloned jsr body)");
1513 
1514   // Effect on jsr on stack
1515   push(_gvn.makecon(ret_addr));
1516 
1517   // Flow to the jsr.
1518   merge(jsr_bci);
1519 }
1520 
1521 // Handle ret bytecode
1522 void Parse::do_ret() {
1523   // Find to whom we return.
1524   assert(block()->num_successors() == 1, "a ret can only go one place now");
1525   Block* target = block()->successor_at(0);
1526   assert(!target->is_ready(), "our arrival must be expected");
1527   int pnum = target->next_path_num();
1528   merge_common(target, pnum);
1529 }
1530 
1531 static bool has_injected_profile(BoolTest::mask btest, Node* test, int& taken, int& not_taken) {
1532   if (btest != BoolTest::eq && btest != BoolTest::ne) {
1533     // Only ::eq and ::ne are supported for profile injection.
1534     return false;
1535   }
1536   if (test->is_Cmp() &&
1537       test->in(1)->Opcode() == Op_ProfileBoolean) {
1538     ProfileBooleanNode* profile = (ProfileBooleanNode*)test->in(1);
1539     int false_cnt = profile->false_count();
1540     int  true_cnt = profile->true_count();
1541 
1542     // Counts matching depends on the actual test operation (::eq or ::ne).
1543     // No need to scale the counts because profile injection was designed
1544     // to feed exact counts into VM.
1545     taken     = (btest == BoolTest::eq) ? false_cnt :  true_cnt;
1546     not_taken = (btest == BoolTest::eq) ?  true_cnt : false_cnt;
1547 
1548     profile->consume();
1549     return true;
1550   }
1551   return false;
1552 }
1553 //--------------------------dynamic_branch_prediction--------------------------
1554 // Try to gather dynamic branch prediction behavior.  Return a probability
1555 // of the branch being taken and set the "cnt" field.  Returns a -1.0
1556 // if we need to use static prediction for some reason.
1557 float Parse::dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test) {
1558   ResourceMark rm;
1559 
1560   cnt  = COUNT_UNKNOWN;
1561 
1562   int     taken = 0;
1563   int not_taken = 0;
1564 
1565   bool use_mdo = !has_injected_profile(btest, test, taken, not_taken);
1566 
1567   if (use_mdo) {
1568     // Use MethodData information if it is available
1569     // FIXME: free the ProfileData structure
1570     ciMethodData* methodData = method()->method_data();
1571     if (!methodData->is_mature())  return PROB_UNKNOWN;
1572     ciProfileData* data = methodData->bci_to_data(bci());
1573     if (data == NULL) {
1574       return PROB_UNKNOWN;
1575     }
1576     if (!data->is_JumpData())  return PROB_UNKNOWN;
1577 
1578     // get taken and not taken values
1579     taken = data->as_JumpData()->taken();
1580     not_taken = 0;
1581     if (data->is_BranchData()) {
1582       not_taken = data->as_BranchData()->not_taken();
1583     }
1584 
1585     // scale the counts to be commensurate with invocation counts:
1586     taken = method()->scale_count(taken);
1587     not_taken = method()->scale_count(not_taken);
1588   }
1589 
1590   // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
1591   // We also check that individual counters are positive first, otherwise the sum can become positive.
1592   if (taken < 0 || not_taken < 0 || taken + not_taken < 40) {
1593     if (C->log() != NULL) {
1594       C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
1595     }
1596     return PROB_UNKNOWN;
1597   }
1598 
1599   // Compute frequency that we arrive here
1600   float sum = taken + not_taken;
1601   // Adjust, if this block is a cloned private block but the
1602   // Jump counts are shared.  Taken the private counts for
1603   // just this path instead of the shared counts.
1604   if( block()->count() > 0 )
1605     sum = block()->count();
1606   cnt = sum / FreqCountInvocations;
1607 
1608   // Pin probability to sane limits
1609   float prob;
1610   if( !taken )
1611     prob = (0+PROB_MIN) / 2;
1612   else if( !not_taken )
1613     prob = (1+PROB_MAX) / 2;
1614   else {                         // Compute probability of true path
1615     prob = (float)taken / (float)(taken + not_taken);
1616     if (prob > PROB_MAX)  prob = PROB_MAX;
1617     if (prob < PROB_MIN)   prob = PROB_MIN;
1618   }
1619 
1620   assert((cnt > 0.0f) && (prob > 0.0f),
1621          "Bad frequency assignment in if");
1622 
1623   if (C->log() != NULL) {
1624     const char* prob_str = NULL;
1625     if (prob >= PROB_MAX)  prob_str = (prob == PROB_MAX) ? "max" : "always";
1626     if (prob <= PROB_MIN)  prob_str = (prob == PROB_MIN) ? "min" : "never";
1627     char prob_str_buf[30];
1628     if (prob_str == NULL) {
1629       jio_snprintf(prob_str_buf, sizeof(prob_str_buf), "%20.2f", prob);
1630       prob_str = prob_str_buf;
1631     }
1632     C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%f' prob='%s'",
1633                    iter().get_dest(), taken, not_taken, cnt, prob_str);
1634   }
1635   return prob;
1636 }
1637 
1638 //-----------------------------branch_prediction-------------------------------
1639 float Parse::branch_prediction(float& cnt,
1640                                BoolTest::mask btest,
1641                                int target_bci,
1642                                Node* test) {
1643   float prob = dynamic_branch_prediction(cnt, btest, test);
1644   // If prob is unknown, switch to static prediction
1645   if (prob != PROB_UNKNOWN)  return prob;
1646 
1647   prob = PROB_FAIR;                   // Set default value
1648   if (btest == BoolTest::eq)          // Exactly equal test?
1649     prob = PROB_STATIC_INFREQUENT;    // Assume its relatively infrequent
1650   else if (btest == BoolTest::ne)
1651     prob = PROB_STATIC_FREQUENT;      // Assume its relatively frequent
1652 
1653   // If this is a conditional test guarding a backwards branch,
1654   // assume its a loop-back edge.  Make it a likely taken branch.
1655   if (target_bci < bci()) {
1656     if (is_osr_parse()) {    // Could be a hot OSR'd loop; force deopt
1657       // Since it's an OSR, we probably have profile data, but since
1658       // branch_prediction returned PROB_UNKNOWN, the counts are too small.
1659       // Let's make a special check here for completely zero counts.
1660       ciMethodData* methodData = method()->method_data();
1661       if (!methodData->is_empty()) {
1662         ciProfileData* data = methodData->bci_to_data(bci());
1663         // Only stop for truly zero counts, which mean an unknown part
1664         // of the OSR-ed method, and we want to deopt to gather more stats.
1665         // If you have ANY counts, then this loop is simply 'cold' relative
1666         // to the OSR loop.
1667         if (data == NULL ||
1668             (data->as_BranchData()->taken() +  data->as_BranchData()->not_taken() == 0)) {
1669           // This is the only way to return PROB_UNKNOWN:
1670           return PROB_UNKNOWN;
1671         }
1672       }
1673     }
1674     prob = PROB_STATIC_FREQUENT;     // Likely to take backwards branch
1675   }
1676 
1677   assert(prob != PROB_UNKNOWN, "must have some guess at this point");
1678   return prob;
1679 }
1680 
1681 // The magic constants are chosen so as to match the output of
1682 // branch_prediction() when the profile reports a zero taken count.
1683 // It is important to distinguish zero counts unambiguously, because
1684 // some branches (e.g., _213_javac.Assembler.eliminate) validly produce
1685 // very small but nonzero probabilities, which if confused with zero
1686 // counts would keep the program recompiling indefinitely.
1687 bool Parse::seems_never_taken(float prob) const {
1688   return prob < PROB_MIN;
1689 }
1690 
1691 // True if the comparison seems to be the kind that will not change its
1692 // statistics from true to false.  See comments in adjust_map_after_if.
1693 // This question is only asked along paths which are already
1694 // classifed as untaken (by seems_never_taken), so really,
1695 // if a path is never taken, its controlling comparison is
1696 // already acting in a stable fashion.  If the comparison
1697 // seems stable, we will put an expensive uncommon trap
1698 // on the untaken path.
1699 bool Parse::seems_stable_comparison() const {
1700   if (C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if)) {
1701     return false;
1702   }
1703   return true;
1704 }
1705 
1706 //-------------------------------repush_if_args--------------------------------
1707 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
1708 inline int Parse::repush_if_args() {
1709   if (PrintOpto && WizardMode) {
1710     tty->print("defending against excessive implicit null exceptions on %s @%d in ",
1711                Bytecodes::name(iter().cur_bc()), iter().cur_bci());
1712     method()->print_name(); tty->cr();
1713   }
1714   int bc_depth = - Bytecodes::depth(iter().cur_bc());
1715   assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
1716   DEBUG_ONLY(sync_jvms());   // argument(n) requires a synced jvms
1717   assert(argument(0) != NULL, "must exist");
1718   assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
1719   inc_sp(bc_depth);
1720   return bc_depth;
1721 }
1722 
1723 //----------------------------------do_ifnull----------------------------------
1724 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
1725   int target_bci = iter().get_dest();
1726 
1727   Block* branch_block = successor_for_bci(target_bci);
1728   Block* next_block   = successor_for_bci(iter().next_bci());
1729 
1730   float cnt;
1731   float prob = branch_prediction(cnt, btest, target_bci, c);
1732   if (prob == PROB_UNKNOWN) {
1733     // (An earlier version of do_ifnull omitted this trap for OSR methods.)
1734     if (PrintOpto && Verbose) {
1735       tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1736     }
1737     repush_if_args(); // to gather stats on loop
1738     uncommon_trap(Deoptimization::Reason_unreached,
1739                   Deoptimization::Action_reinterpret,
1740                   NULL, "cold");
1741     if (C->eliminate_boxing()) {
1742       // Mark the successor blocks as parsed
1743       branch_block->next_path_num();
1744       next_block->next_path_num();
1745     }
1746     return;
1747   }
1748 
1749   NOT_PRODUCT(explicit_null_checks_inserted++);
1750 
1751   // Generate real control flow
1752   Node   *tst = _gvn.transform( new BoolNode( c, btest ) );
1753 
1754   // Sanity check the probability value
1755   assert(prob > 0.0f,"Bad probability in Parser");
1756  // Need xform to put node in hash table
1757   IfNode *iff = create_and_xform_if( control(), tst, prob, cnt );
1758   assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1759   // True branch
1760   { PreserveJVMState pjvms(this);
1761     Node* iftrue  = _gvn.transform( new IfTrueNode (iff) );
1762     set_control(iftrue);
1763 
1764     if (stopped()) {            // Path is dead?
1765       NOT_PRODUCT(explicit_null_checks_elided++);
1766       if (C->eliminate_boxing()) {
1767         // Mark the successor block as parsed
1768         branch_block->next_path_num();
1769       }
1770     } else {                    // Path is live.
1771       adjust_map_after_if(btest, c, prob, branch_block);
1772       if (!stopped()) {
1773         merge(target_bci);
1774       }
1775     }
1776   }
1777 
1778   // False branch
1779   Node* iffalse = _gvn.transform( new IfFalseNode(iff) );
1780   set_control(iffalse);
1781 
1782   if (stopped()) {              // Path is dead?
1783     NOT_PRODUCT(explicit_null_checks_elided++);
1784     if (C->eliminate_boxing()) {
1785       // Mark the successor block as parsed
1786       next_block->next_path_num();
1787     }
1788   } else  {                     // Path is live.
1789     adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob, next_block);
1790   }
1791 }
1792 
1793 //------------------------------------do_if------------------------------------
1794 void Parse::do_if(BoolTest::mask btest, Node* c, bool new_path, Node** ctrl_taken) {
1795   int target_bci = iter().get_dest();
1796 
1797   Block* branch_block = successor_for_bci(target_bci);
1798   Block* next_block   = successor_for_bci(iter().next_bci());
1799 
1800   float cnt;
1801   float prob = branch_prediction(cnt, btest, target_bci, c);
1802   float untaken_prob = 1.0 - prob;
1803 
1804   if (prob == PROB_UNKNOWN) {
1805     if (PrintOpto && Verbose) {
1806       tty->print_cr("Never-taken edge stops compilation at bci %d", bci());
1807     }
1808     repush_if_args(); // to gather stats on loop
1809     uncommon_trap(Deoptimization::Reason_unreached,
1810                   Deoptimization::Action_reinterpret,
1811                   NULL, "cold");
1812     if (C->eliminate_boxing()) {
1813       // Mark the successor blocks as parsed
1814       branch_block->next_path_num();
1815       next_block->next_path_num();
1816     }
1817     return;
1818   }
1819 
1820   // Sanity check the probability value
1821   assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser");
1822 
1823   bool taken_if_true = true;
1824   // Convert BoolTest to canonical form:
1825   if (!BoolTest(btest).is_canonical()) {
1826     btest         = BoolTest(btest).negate();
1827     taken_if_true = false;
1828     // prob is NOT updated here; it remains the probability of the taken
1829     // path (as opposed to the prob of the path guarded by an 'IfTrueNode').
1830   }
1831   assert(btest != BoolTest::eq, "!= is the only canonical exact test");
1832 
1833   Node* tst0 = new BoolNode(c, btest);
1834   Node* tst = _gvn.transform(tst0);
1835   BoolTest::mask taken_btest   = BoolTest::illegal;
1836   BoolTest::mask untaken_btest = BoolTest::illegal;
1837 
1838   if (tst->is_Bool()) {
1839     // Refresh c from the transformed bool node, since it may be
1840     // simpler than the original c.  Also re-canonicalize btest.
1841     // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)).
1842     // That can arise from statements like: if (x instanceof C) ...
1843     if (tst != tst0) {
1844       // Canonicalize one more time since transform can change it.
1845       btest = tst->as_Bool()->_test._test;
1846       if (!BoolTest(btest).is_canonical()) {
1847         // Reverse edges one more time...
1848         tst   = _gvn.transform( tst->as_Bool()->negate(&_gvn) );
1849         btest = tst->as_Bool()->_test._test;
1850         assert(BoolTest(btest).is_canonical(), "sanity");
1851         taken_if_true = !taken_if_true;
1852       }
1853       c = tst->in(1);
1854     }
1855     BoolTest::mask neg_btest = BoolTest(btest).negate();
1856     taken_btest   = taken_if_true ?     btest : neg_btest;
1857     untaken_btest = taken_if_true ? neg_btest :     btest;
1858   }
1859 
1860   // Generate real control flow
1861   float true_prob = (taken_if_true ? prob : untaken_prob);
1862   IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1863   assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1864   Node* taken_branch   = new IfTrueNode(iff);
1865   Node* untaken_branch = new IfFalseNode(iff);
1866   if (!taken_if_true) {  // Finish conversion to canonical form
1867     Node* tmp      = taken_branch;
1868     taken_branch   = untaken_branch;
1869     untaken_branch = tmp;
1870   }
1871 
1872   // Branch is taken:
1873   { PreserveJVMState pjvms(this);
1874     taken_branch = _gvn.transform(taken_branch);
1875     set_control(taken_branch);
1876 
1877     if (stopped()) {
1878       if (C->eliminate_boxing() && !new_path) {
1879         // Mark the successor block as parsed (if we haven't created a new path)
1880         branch_block->next_path_num();
1881       }
1882     } else {
1883       adjust_map_after_if(taken_btest, c, prob, branch_block);
1884       if (!stopped()) {
1885         if (new_path) {
1886           // Merge by using a new path
1887           merge_new_path(target_bci);
1888         } else if (ctrl_taken != NULL) {
1889           // Don't merge but save taken branch to be wired by caller
1890           *ctrl_taken = control();
1891         } else {
1892           merge(target_bci);
1893         }
1894       }
1895     }
1896   }
1897 
1898   untaken_branch = _gvn.transform(untaken_branch);
1899   set_control(untaken_branch);
1900 
1901   // Branch not taken.
1902   if (stopped() && ctrl_taken == NULL) {
1903     if (C->eliminate_boxing()) {
1904       // Mark the successor block as parsed (if caller does not re-wire control flow)
1905       next_block->next_path_num();
1906     }
1907   } else {
1908     adjust_map_after_if(untaken_btest, c, untaken_prob, next_block);
1909   }
1910 }
1911 
1912 
1913 static ProfilePtrKind speculative_ptr_kind(const TypeOopPtr* t) {
1914   if (t->speculative() == NULL) {
1915     return ProfileUnknownNull;
1916   }
1917   if (t->speculative_always_null()) {
1918     return ProfileAlwaysNull;
1919   }
1920   if (t->speculative_maybe_null()) {
1921     return ProfileMaybeNull;
1922   }
1923   return ProfileNeverNull;
1924 }
1925 
1926 void Parse::acmp_always_null_input(Node* input, const TypeOopPtr* tinput, BoolTest::mask btest, Node* eq_region) {
1927   inc_sp(2);
1928   Node* cast = null_check_common(input, T_OBJECT, true, NULL,
1929                                  !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check) &&
1930                                  speculative_ptr_kind(tinput) == ProfileAlwaysNull);
1931   dec_sp(2);
1932   if (btest == BoolTest::ne) {
1933     {
1934       PreserveJVMState pjvms(this);
1935       replace_in_map(input, cast);
1936       int target_bci = iter().get_dest();
1937       merge(target_bci);
1938     }
1939     record_for_igvn(eq_region);
1940     set_control(_gvn.transform(eq_region));
1941   } else {
1942     replace_in_map(input, cast);
1943   }
1944 }
1945 
1946 Node* Parse::acmp_null_check(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, Node*& null_ctl) {
1947   inc_sp(2);
1948   null_ctl = top();
1949   Node* cast = null_check_oop(input, &null_ctl,
1950                               input_ptr == ProfileNeverNull || (input_ptr == ProfileUnknownNull && !too_many_traps_or_recompiles(Deoptimization::Reason_null_check)),
1951                               false,
1952                               speculative_ptr_kind(tinput) == ProfileNeverNull &&
1953                               !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check));
1954   dec_sp(2);
1955   assert(!stopped(), "null input should have been caught earlier");
1956   if (cast->is_InlineType()) {
1957     cast = cast->as_InlineType()->get_oop();
1958   }
1959   return cast;
1960 }
1961 
1962 void Parse::acmp_known_non_inline_type_input(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, ciKlass* input_type, BoolTest::mask btest, Node* eq_region) {
1963   Node* ne_region = new RegionNode(1);
1964   Node* null_ctl;
1965   Node* cast = acmp_null_check(input, tinput, input_ptr, null_ctl);
1966   ne_region->add_req(null_ctl);
1967 
1968   Node* slow_ctl = type_check_receiver(cast, input_type, 1.0, &cast);
1969   {
1970     PreserveJVMState pjvms(this);
1971     inc_sp(2);
1972     set_control(slow_ctl);
1973     Deoptimization::DeoptReason reason;
1974     if (tinput->speculative_type() != NULL && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
1975       reason = Deoptimization::Reason_speculate_class_check;
1976     } else {
1977       reason = Deoptimization::Reason_class_check;
1978     }
1979     uncommon_trap_exact(reason, Deoptimization::Action_maybe_recompile);
1980   }
1981   ne_region->add_req(control());
1982 
1983   record_for_igvn(ne_region);
1984   set_control(_gvn.transform(ne_region));
1985   if (btest == BoolTest::ne) {
1986     {
1987       PreserveJVMState pjvms(this);
1988       if (null_ctl == top()) {
1989         replace_in_map(input, cast);
1990       }
1991       int target_bci = iter().get_dest();
1992       merge(target_bci);
1993     }
1994     record_for_igvn(eq_region);
1995     set_control(_gvn.transform(eq_region));
1996   } else {
1997     if (null_ctl == top()) {
1998       replace_in_map(input, cast);
1999     }
2000     set_control(_gvn.transform(ne_region));
2001   }
2002 }
2003 
2004 void Parse::acmp_unknown_non_inline_type_input(Node* input, const TypeOopPtr* tinput, ProfilePtrKind input_ptr, BoolTest::mask btest, Node* eq_region) {
2005   Node* ne_region = new RegionNode(1);
2006   Node* null_ctl;
2007   Node* cast = acmp_null_check(input, tinput, input_ptr, null_ctl);
2008   ne_region->add_req(null_ctl);
2009 
2010   {
2011     BuildCutout unless(this, inline_type_test(cast, /* is_inline = */ false), PROB_MAX);
2012     inc_sp(2);
2013     uncommon_trap_exact(Deoptimization::Reason_class_check, Deoptimization::Action_maybe_recompile);
2014   }
2015 
2016   ne_region->add_req(control());
2017 
2018   record_for_igvn(ne_region);
2019   set_control(_gvn.transform(ne_region));
2020   if (btest == BoolTest::ne) {
2021     {
2022       PreserveJVMState pjvms(this);
2023       if (null_ctl == top()) {
2024         replace_in_map(input, cast);
2025       }
2026       int target_bci = iter().get_dest();
2027       merge(target_bci);
2028     }
2029     record_for_igvn(eq_region);
2030     set_control(_gvn.transform(eq_region));
2031   } else {
2032     if (null_ctl == top()) {
2033       replace_in_map(input, cast);
2034     }
2035     set_control(_gvn.transform(ne_region));
2036   }
2037 }
2038 
2039 void Parse::do_acmp(BoolTest::mask btest, Node* left, Node* right) {
2040   ciKlass* left_type = NULL;
2041   ciKlass* right_type = NULL;
2042   ProfilePtrKind left_ptr = ProfileUnknownNull;
2043   ProfilePtrKind right_ptr = ProfileUnknownNull;
2044   bool left_inline_type = true;
2045   bool right_inline_type = true;
2046 
2047   // Leverage profiling at acmp
2048   if (UseACmpProfile) {
2049     method()->acmp_profiled_type(bci(), left_type, right_type, left_ptr, right_ptr, left_inline_type, right_inline_type);
2050     if (too_many_traps_or_recompiles(Deoptimization::Reason_class_check)) {
2051       left_type = NULL;
2052       right_type = NULL;
2053       left_inline_type = true;
2054       right_inline_type = true;
2055     }
2056     if (too_many_traps_or_recompiles(Deoptimization::Reason_null_check)) {
2057       left_ptr = ProfileUnknownNull;
2058       right_ptr = ProfileUnknownNull;
2059     }
2060   }
2061 
2062   if (UseTypeSpeculation) {
2063     record_profile_for_speculation(left, left_type, left_ptr);
2064     record_profile_for_speculation(right, right_type, right_ptr);
2065   }
2066 
2067   if (!EnableValhalla) {
2068     Node* cmp = CmpP(left, right);
2069     cmp = optimize_cmp_with_klass(cmp);
2070     do_if(btest, cmp);
2071     return;
2072   }
2073 
2074   // Check for equality before potentially allocating
2075   if (left == right) {
2076     do_if(btest, makecon(TypeInt::CC_EQ));
2077     return;
2078   }
2079 
2080   // Allocate inline type operands and re-execute on deoptimization
2081   if (left->is_InlineType()) {
2082     PreserveReexecuteState preexecs(this);
2083     inc_sp(2);
2084     jvms()->set_should_reexecute(true);
2085     left = left->as_InlineType()->buffer(this)->get_oop();
2086   }
2087   if (right->is_InlineType()) {
2088     PreserveReexecuteState preexecs(this);
2089     inc_sp(2);
2090     jvms()->set_should_reexecute(true);
2091     right = right->as_InlineType()->buffer(this)->get_oop();
2092   }
2093 
2094   // First, do a normal pointer comparison
2095   const TypeOopPtr* tleft = _gvn.type(left)->isa_oopptr();
2096   const TypeOopPtr* tright = _gvn.type(right)->isa_oopptr();
2097   Node* cmp = CmpP(left, right);
2098   cmp = optimize_cmp_with_klass(cmp);
2099   if (tleft == NULL || !tleft->can_be_inline_type() ||
2100       tright == NULL || !tright->can_be_inline_type()) {
2101     // This is sufficient, if one of the operands can't be an inline type
2102     do_if(btest, cmp);
2103     return;
2104   }
2105   Node* eq_region = NULL;
2106   if (btest == BoolTest::eq) {
2107     do_if(btest, cmp, true);
2108     if (stopped()) {
2109       return;
2110     }
2111   } else {
2112     assert(btest == BoolTest::ne, "only eq or ne");
2113     Node* is_not_equal = NULL;
2114     eq_region = new RegionNode(3);
2115     {
2116       PreserveJVMState pjvms(this);
2117       do_if(btest, cmp, false, &is_not_equal);
2118       if (!stopped()) {
2119         eq_region->init_req(1, control());
2120       }
2121     }
2122     if (is_not_equal == NULL || is_not_equal->is_top()) {
2123       record_for_igvn(eq_region);
2124       set_control(_gvn.transform(eq_region));
2125       return;
2126     }
2127     set_control(is_not_equal);
2128   }
2129 
2130   // Prefer speculative types if available
2131   if (!too_many_traps_or_recompiles(Deoptimization::Reason_speculate_class_check)) {
2132     if (tleft->speculative_type() != NULL) {
2133       left_type = tleft->speculative_type();
2134     }
2135     if (tright->speculative_type() != NULL) {
2136       right_type = tright->speculative_type();
2137     }
2138   }
2139 
2140   if (speculative_ptr_kind(tleft) != ProfileMaybeNull && speculative_ptr_kind(tleft) != ProfileUnknownNull) {
2141     ProfilePtrKind speculative_left_ptr = speculative_ptr_kind(tleft);
2142     if (speculative_left_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2143       left_ptr = speculative_left_ptr;
2144     } else if (speculative_left_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2145       left_ptr = speculative_left_ptr;
2146     }
2147   }
2148   if (speculative_ptr_kind(tright) != ProfileMaybeNull && speculative_ptr_kind(tright) != ProfileUnknownNull) {
2149     ProfilePtrKind speculative_right_ptr = speculative_ptr_kind(tright);
2150     if (speculative_right_ptr == ProfileAlwaysNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_assert)) {
2151       right_ptr = speculative_right_ptr;
2152     } else if (speculative_right_ptr == ProfileNeverNull && !too_many_traps_or_recompiles(Deoptimization::Reason_speculate_null_check)) {
2153       right_ptr = speculative_right_ptr;
2154     }
2155   }
2156 
2157   if (left_ptr == ProfileAlwaysNull) {
2158     // Comparison with null. Assert the input is indeed null and we're done.
2159     acmp_always_null_input(left, tleft, btest, eq_region);
2160     return;
2161   }
2162   if (right_ptr == ProfileAlwaysNull) {
2163     // Comparison with null. Assert the input is indeed null and we're done.
2164     acmp_always_null_input(right, tright, btest, eq_region);
2165     return;
2166   }
2167   if (left_type != NULL && !left_type->is_inlinetype()) {
2168     // Comparison with an object of known type
2169     acmp_known_non_inline_type_input(left, tleft, left_ptr, left_type, btest, eq_region);
2170     return;
2171   }
2172   if (right_type != NULL && !right_type->is_inlinetype()) {
2173     // Comparison with an object of known type
2174     acmp_known_non_inline_type_input(right, tright, right_ptr, right_type, btest, eq_region);
2175     return;
2176   }
2177   if (!left_inline_type) {
2178     // Comparison with an object known not to be an inline type
2179     acmp_unknown_non_inline_type_input(left, tleft, left_ptr, btest, eq_region);
2180     return;
2181   }
2182   if (!right_inline_type) {
2183     // Comparison with an object known not to be an inline type
2184     acmp_unknown_non_inline_type_input(right, tright, right_ptr, btest, eq_region);
2185     return;
2186   }
2187 
2188   // Pointers are not equal, check if first operand is non-null
2189   Node* ne_region = new RegionNode(6);
2190   Node* null_ctl;
2191   Node* not_null_right = acmp_null_check(right, tright, right_ptr, null_ctl);
2192   ne_region->init_req(1, null_ctl);
2193 
2194   // First operand is non-null, check if it is an inline type
2195   Node* is_value = inline_type_test(not_null_right);
2196   IfNode* is_value_iff = create_and_map_if(control(), is_value, PROB_FAIR, COUNT_UNKNOWN);
2197   Node* not_value = _gvn.transform(new IfFalseNode(is_value_iff));
2198   ne_region->init_req(2, not_value);
2199   set_control(_gvn.transform(new IfTrueNode(is_value_iff)));
2200 
2201   // The first operand is an inline type, check if the second operand is non-null
2202   Node* not_null_left = acmp_null_check(left, tleft, left_ptr, null_ctl);
2203   ne_region->init_req(3, null_ctl);
2204 
2205   // Check if both operands are of the same class.
2206   Node* kls_left = load_object_klass(not_null_left);
2207   Node* kls_right = load_object_klass(not_null_right);
2208   Node* kls_cmp = CmpP(kls_left, kls_right);
2209   Node* kls_bol = _gvn.transform(new BoolNode(kls_cmp, BoolTest::ne));
2210   IfNode* kls_iff = create_and_map_if(control(), kls_bol, PROB_FAIR, COUNT_UNKNOWN);
2211   Node* kls_ne = _gvn.transform(new IfTrueNode(kls_iff));
2212   set_control(_gvn.transform(new IfFalseNode(kls_iff)));
2213   ne_region->init_req(4, kls_ne);
2214 
2215   if (stopped()) {
2216     record_for_igvn(ne_region);
2217     set_control(_gvn.transform(ne_region));
2218     if (btest == BoolTest::ne) {
2219       {
2220         PreserveJVMState pjvms(this);
2221         int target_bci = iter().get_dest();
2222         merge(target_bci);
2223       }
2224       record_for_igvn(eq_region);
2225       set_control(_gvn.transform(eq_region));
2226     }
2227     return;
2228   }
2229 
2230   // Both operands are values types of the same class, we need to perform a
2231   // substitutability test. Delegate to PrimitiveObjectMethods::isSubstitutable().
2232   Node* ne_io_phi = PhiNode::make(ne_region, i_o());
2233   Node* mem = reset_memory();
2234   Node* ne_mem_phi = PhiNode::make(ne_region, mem);
2235 
2236   Node* eq_io_phi = NULL;
2237   Node* eq_mem_phi = NULL;
2238   if (eq_region != NULL) {
2239     eq_io_phi = PhiNode::make(eq_region, i_o());
2240     eq_mem_phi = PhiNode::make(eq_region, mem);
2241   }
2242 
2243   set_all_memory(mem);
2244 
2245   kill_dead_locals();
2246   ciMethod* subst_method = ciEnv::current()->PrimitiveObjectMethods_klass()->find_method(ciSymbols::isSubstitutable_name(), ciSymbols::object_object_boolean_signature());
2247   CallStaticJavaNode *call = new CallStaticJavaNode(C, TypeFunc::make(subst_method), SharedRuntime::get_resolve_static_call_stub(), subst_method);
2248   call->set_override_symbolic_info(true);
2249   call->init_req(TypeFunc::Parms, not_null_left);
2250   call->init_req(TypeFunc::Parms+1, not_null_right);
2251   inc_sp(2);
2252   set_edges_for_java_call(call, false, false);
2253   Node* ret = set_results_for_java_call(call, false, true);
2254   dec_sp(2);
2255 
2256   // Test the return value of PrimitiveObjectMethods::isSubstitutable()
2257   Node* subst_cmp = _gvn.transform(new CmpINode(ret, intcon(1)));
2258   Node* ctl = C->top();
2259   if (btest == BoolTest::eq) {
2260     PreserveJVMState pjvms(this);
2261     do_if(btest, subst_cmp);
2262     if (!stopped()) {
2263       ctl = control();
2264     }
2265   } else {
2266     assert(btest == BoolTest::ne, "only eq or ne");
2267     PreserveJVMState pjvms(this);
2268     do_if(btest, subst_cmp, false, &ctl);
2269     if (!stopped()) {
2270       eq_region->init_req(2, control());
2271       eq_io_phi->init_req(2, i_o());
2272       eq_mem_phi->init_req(2, reset_memory());
2273     }
2274   }
2275   ne_region->init_req(5, ctl);
2276   ne_io_phi->init_req(5, i_o());
2277   ne_mem_phi->init_req(5, reset_memory());
2278 
2279   record_for_igvn(ne_region);
2280   set_control(_gvn.transform(ne_region));
2281   set_i_o(_gvn.transform(ne_io_phi));
2282   set_all_memory(_gvn.transform(ne_mem_phi));
2283 
2284   if (btest == BoolTest::ne) {
2285     {
2286       PreserveJVMState pjvms(this);
2287       int target_bci = iter().get_dest();
2288       merge(target_bci);
2289     }
2290 
2291     record_for_igvn(eq_region);
2292     set_control(_gvn.transform(eq_region));
2293     set_i_o(_gvn.transform(eq_io_phi));
2294     set_all_memory(_gvn.transform(eq_mem_phi));
2295   }
2296 }
2297 
2298 bool Parse::path_is_suitable_for_uncommon_trap(float prob) const {
2299   // Don't want to speculate on uncommon traps when running with -Xcomp
2300   if (!UseInterpreter) {
2301     return false;
2302   }
2303   return (seems_never_taken(prob) && seems_stable_comparison());
2304 }
2305 
2306 void Parse::maybe_add_predicate_after_if(Block* path) {
2307   if (path->is_SEL_head() && path->preds_parsed() == 0) {
2308     // Add predicates at bci of if dominating the loop so traps can be
2309     // recorded on the if's profile data
2310     int bc_depth = repush_if_args();
2311     add_empty_predicates();
2312     dec_sp(bc_depth);
2313     path->set_has_predicates();
2314   }
2315 }
2316 
2317 
2318 //----------------------------adjust_map_after_if------------------------------
2319 // Adjust the JVM state to reflect the result of taking this path.
2320 // Basically, it means inspecting the CmpNode controlling this
2321 // branch, seeing how it constrains a tested value, and then
2322 // deciding if it's worth our while to encode this constraint
2323 // as graph nodes in the current abstract interpretation map.
2324 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob, Block* path) {
2325   if (!c->is_Cmp()) {
2326     maybe_add_predicate_after_if(path);
2327     return;
2328   }
2329 
2330   if (stopped() || btest == BoolTest::illegal) {
2331     return;                             // nothing to do
2332   }
2333 
2334   bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
2335 
2336   if (path_is_suitable_for_uncommon_trap(prob)) {
2337     repush_if_args();
2338     uncommon_trap(Deoptimization::Reason_unstable_if,
2339                   Deoptimization::Action_reinterpret,
2340                   NULL,
2341                   (is_fallthrough ? "taken always" : "taken never"));
2342     return;
2343   }
2344 
2345   Node* val = c->in(1);
2346   Node* con = c->in(2);
2347   const Type* tcon = _gvn.type(con);
2348   const Type* tval = _gvn.type(val);
2349   bool have_con = tcon->singleton();
2350   if (tval->singleton()) {
2351     if (!have_con) {
2352       // Swap, so constant is in con.
2353       con  = val;
2354       tcon = tval;
2355       val  = c->in(2);
2356       tval = _gvn.type(val);
2357       btest = BoolTest(btest).commute();
2358       have_con = true;
2359     } else {
2360       // Do we have two constants?  Then leave well enough alone.
2361       have_con = false;
2362     }
2363   }
2364   if (!have_con) {                        // remaining adjustments need a con
2365     maybe_add_predicate_after_if(path);
2366     return;
2367   }
2368 
2369   sharpen_type_after_if(btest, con, tcon, val, tval);
2370   maybe_add_predicate_after_if(path);
2371 }
2372 
2373 
2374 static Node* extract_obj_from_klass_load(PhaseGVN* gvn, Node* n) {
2375   Node* ldk;
2376   if (n->is_DecodeNKlass()) {
2377     if (n->in(1)->Opcode() != Op_LoadNKlass) {
2378       return NULL;
2379     } else {
2380       ldk = n->in(1);
2381     }
2382   } else if (n->Opcode() != Op_LoadKlass) {
2383     return NULL;
2384   } else {
2385     ldk = n;
2386   }
2387   assert(ldk != NULL && ldk->is_Load(), "should have found a LoadKlass or LoadNKlass node");
2388 
2389   Node* adr = ldk->in(MemNode::Address);
2390   intptr_t off = 0;
2391   Node* obj = AddPNode::Ideal_base_and_offset(adr, gvn, off);
2392   if (obj == NULL || off != oopDesc::klass_offset_in_bytes()) // loading oopDesc::_klass?
2393     return NULL;
2394   const TypePtr* tp = gvn->type(obj)->is_ptr();
2395   if (tp == NULL || !(tp->isa_instptr() || tp->isa_aryptr())) // is obj a Java object ptr?
2396     return NULL;
2397 
2398   return obj;
2399 }
2400 
2401 void Parse::sharpen_type_after_if(BoolTest::mask btest,
2402                                   Node* con, const Type* tcon,
2403                                   Node* val, const Type* tval) {
2404   // Look for opportunities to sharpen the type of a node
2405   // whose klass is compared with a constant klass.
2406   if (btest == BoolTest::eq && tcon->isa_klassptr()) {
2407     Node* obj = extract_obj_from_klass_load(&_gvn, val);
2408     const TypeOopPtr* con_type = tcon->isa_klassptr()->as_instance_type();
2409     if (obj != NULL && (con_type->isa_instptr() || con_type->isa_aryptr())) {
2410        // Found:
2411        //   Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq])
2412        // or the narrowOop equivalent.
2413        const Type* obj_type = _gvn.type(obj);
2414        const TypeOopPtr* tboth = obj_type->join_speculative(con_type)->isa_oopptr();
2415        if (tboth != NULL && tboth->klass_is_exact() && tboth != obj_type &&
2416            tboth->higher_equal(obj_type)) {
2417           // obj has to be of the exact type Foo if the CmpP succeeds.
2418           int obj_in_map = map()->find_edge(obj);
2419           JVMState* jvms = this->jvms();
2420           if (obj_in_map >= 0 &&
2421               (jvms->is_loc(obj_in_map) || jvms->is_stk(obj_in_map))) {
2422             TypeNode* ccast = new CheckCastPPNode(control(), obj, tboth);
2423             const Type* tcc = ccast->as_Type()->type();
2424             assert(tcc != obj_type && tcc->higher_equal(obj_type), "must improve");
2425             // Delay transform() call to allow recovery of pre-cast value
2426             // at the control merge.
2427             _gvn.set_type_bottom(ccast);
2428             record_for_igvn(ccast);
2429             // Here's the payoff.
2430             replace_in_map(obj, ccast);
2431           }
2432        }
2433     }
2434   }
2435 
2436   int val_in_map = map()->find_edge(val);
2437   if (val_in_map < 0)  return;          // replace_in_map would be useless
2438   {
2439     JVMState* jvms = this->jvms();
2440     if (!(jvms->is_loc(val_in_map) ||
2441           jvms->is_stk(val_in_map)))
2442       return;                           // again, it would be useless
2443   }
2444 
2445   // Check for a comparison to a constant, and "know" that the compared
2446   // value is constrained on this path.
2447   assert(tcon->singleton(), "");
2448   ConstraintCastNode* ccast = NULL;
2449   Node* cast = NULL;
2450 
2451   switch (btest) {
2452   case BoolTest::eq:                    // Constant test?
2453     {
2454       const Type* tboth = tcon->join_speculative(tval);
2455       if (tboth == tval)  break;        // Nothing to gain.
2456       if (tcon->isa_int()) {
2457         ccast = new CastIINode(val, tboth);
2458       } else if (tcon == TypePtr::NULL_PTR) {
2459         // Cast to null, but keep the pointer identity temporarily live.
2460         ccast = new CastPPNode(val, tboth);
2461       } else {
2462         const TypeF* tf = tcon->isa_float_constant();
2463         const TypeD* td = tcon->isa_double_constant();
2464         // Exclude tests vs float/double 0 as these could be
2465         // either +0 or -0.  Just because you are equal to +0
2466         // doesn't mean you ARE +0!
2467         // Note, following code also replaces Long and Oop values.
2468         if ((!tf || tf->_f != 0.0) &&
2469             (!td || td->_d != 0.0))
2470           cast = con;                   // Replace non-constant val by con.
2471       }
2472     }
2473     break;
2474 
2475   case BoolTest::ne:
2476     if (tcon == TypePtr::NULL_PTR) {
2477       cast = cast_not_null(val, false);
2478     }
2479     break;
2480 
2481   default:
2482     // (At this point we could record int range types with CastII.)
2483     break;
2484   }
2485 
2486   if (ccast != NULL) {
2487     const Type* tcc = ccast->as_Type()->type();
2488     assert(tcc != tval && tcc->higher_equal(tval), "must improve");
2489     // Delay transform() call to allow recovery of pre-cast value
2490     // at the control merge.
2491     ccast->set_req(0, control());
2492     _gvn.set_type_bottom(ccast);
2493     record_for_igvn(ccast);
2494     cast = ccast;
2495   }
2496 
2497   if (cast != NULL) {                   // Here's the payoff.
2498     replace_in_map(val, cast);
2499   }
2500 }
2501 
2502 /**
2503  * Use speculative type to optimize CmpP node: if comparison is
2504  * against the low level class, cast the object to the speculative
2505  * type if any. CmpP should then go away.
2506  *
2507  * @param c  expected CmpP node
2508  * @return   result of CmpP on object casted to speculative type
2509  *
2510  */
2511 Node* Parse::optimize_cmp_with_klass(Node* c) {
2512   // If this is transformed by the _gvn to a comparison with the low
2513   // level klass then we may be able to use speculation
2514   if (c->Opcode() == Op_CmpP &&
2515       (c->in(1)->Opcode() == Op_LoadKlass || c->in(1)->Opcode() == Op_DecodeNKlass) &&
2516       c->in(2)->is_Con()) {
2517     Node* load_klass = NULL;
2518     Node* decode = NULL;
2519     if (c->in(1)->Opcode() == Op_DecodeNKlass) {
2520       decode = c->in(1);
2521       load_klass = c->in(1)->in(1);
2522     } else {
2523       load_klass = c->in(1);
2524     }
2525     if (load_klass->in(2)->is_AddP()) {
2526       Node* addp = load_klass->in(2);
2527       Node* obj = addp->in(AddPNode::Address);
2528       const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
2529       if (obj_type->speculative_type_not_null() != NULL) {
2530         ciKlass* k = obj_type->speculative_type();
2531         inc_sp(2);
2532         obj = maybe_cast_profiled_obj(obj, k);
2533         dec_sp(2);
2534         if (obj->is_InlineType()) {
2535           assert(obj->as_InlineType()->is_allocated(&_gvn), "must be allocated");
2536           obj = obj->as_InlineType()->get_oop();
2537         }
2538         // Make the CmpP use the casted obj
2539         addp = basic_plus_adr(obj, addp->in(AddPNode::Offset));
2540         load_klass = load_klass->clone();
2541         load_klass->set_req(2, addp);
2542         load_klass = _gvn.transform(load_klass);
2543         if (decode != NULL) {
2544           decode = decode->clone();
2545           decode->set_req(1, load_klass);
2546           load_klass = _gvn.transform(decode);
2547         }
2548         c = c->clone();
2549         c->set_req(1, load_klass);
2550         c = _gvn.transform(c);
2551       }
2552     }
2553   }
2554   return c;
2555 }
2556 
2557 //------------------------------do_one_bytecode--------------------------------
2558 // Parse this bytecode, and alter the Parsers JVM->Node mapping
2559 void Parse::do_one_bytecode() {
2560   Node *a, *b, *c, *d;          // Handy temps
2561   BoolTest::mask btest;
2562   int i;
2563 
2564   assert(!has_exceptions(), "bytecode entry state must be clear of throws");
2565 
2566   if (C->check_node_count(NodeLimitFudgeFactor * 5,
2567                           "out of nodes parsing method")) {
2568     return;
2569   }
2570 
2571 #ifdef ASSERT
2572   // for setting breakpoints
2573   if (TraceOptoParse) {
2574     tty->print(" @");
2575     dump_bci(bci());
2576     tty->cr();
2577   }
2578 #endif
2579 
2580   switch (bc()) {
2581   case Bytecodes::_nop:
2582     // do nothing
2583     break;
2584   case Bytecodes::_lconst_0:
2585     push_pair(longcon(0));
2586     break;
2587 
2588   case Bytecodes::_lconst_1:
2589     push_pair(longcon(1));
2590     break;
2591 
2592   case Bytecodes::_fconst_0:
2593     push(zerocon(T_FLOAT));
2594     break;
2595 
2596   case Bytecodes::_fconst_1:
2597     push(makecon(TypeF::ONE));
2598     break;
2599 
2600   case Bytecodes::_fconst_2:
2601     push(makecon(TypeF::make(2.0f)));
2602     break;
2603 
2604   case Bytecodes::_dconst_0:
2605     push_pair(zerocon(T_DOUBLE));
2606     break;
2607 
2608   case Bytecodes::_dconst_1:
2609     push_pair(makecon(TypeD::ONE));
2610     break;
2611 
2612   case Bytecodes::_iconst_m1:push(intcon(-1)); break;
2613   case Bytecodes::_iconst_0: push(intcon( 0)); break;
2614   case Bytecodes::_iconst_1: push(intcon( 1)); break;
2615   case Bytecodes::_iconst_2: push(intcon( 2)); break;
2616   case Bytecodes::_iconst_3: push(intcon( 3)); break;
2617   case Bytecodes::_iconst_4: push(intcon( 4)); break;
2618   case Bytecodes::_iconst_5: push(intcon( 5)); break;
2619   case Bytecodes::_bipush:   push(intcon(iter().get_constant_u1())); break;
2620   case Bytecodes::_sipush:   push(intcon(iter().get_constant_u2())); break;
2621   case Bytecodes::_aconst_null: push(null());  break;
2622   case Bytecodes::_ldc:
2623   case Bytecodes::_ldc_w:
2624   case Bytecodes::_ldc2_w:
2625     // If the constant is unresolved, run this BC once in the interpreter.
2626     {
2627       ciConstant constant = iter().get_constant();
2628       if (!constant.is_valid() ||
2629           (constant.basic_type() == T_OBJECT &&
2630            !constant.as_object()->is_loaded())) {
2631         int index = iter().get_constant_pool_index();
2632         constantTag tag = iter().get_constant_pool_tag(index);
2633         uncommon_trap(Deoptimization::make_trap_request
2634                       (Deoptimization::Reason_unloaded,
2635                        Deoptimization::Action_reinterpret,
2636                        index),
2637                       NULL, tag.internal_name());
2638         break;
2639       }
2640       assert(constant.basic_type() != T_OBJECT || constant.as_object()->is_instance(),
2641              "must be java_mirror of klass");
2642       const Type* con_type = Type::make_from_constant(constant);
2643       if (con_type != NULL) {
2644         push_node(con_type->basic_type(), makecon(con_type));
2645       }
2646     }
2647 
2648     break;
2649 
2650   case Bytecodes::_aload_0:
2651     push( local(0) );
2652     break;
2653   case Bytecodes::_aload_1:
2654     push( local(1) );
2655     break;
2656   case Bytecodes::_aload_2:
2657     push( local(2) );
2658     break;
2659   case Bytecodes::_aload_3:
2660     push( local(3) );
2661     break;
2662   case Bytecodes::_aload:
2663     push( local(iter().get_index()) );
2664     break;
2665 
2666   case Bytecodes::_fload_0:
2667   case Bytecodes::_iload_0:
2668     push( local(0) );
2669     break;
2670   case Bytecodes::_fload_1:
2671   case Bytecodes::_iload_1:
2672     push( local(1) );
2673     break;
2674   case Bytecodes::_fload_2:
2675   case Bytecodes::_iload_2:
2676     push( local(2) );
2677     break;
2678   case Bytecodes::_fload_3:
2679   case Bytecodes::_iload_3:
2680     push( local(3) );
2681     break;
2682   case Bytecodes::_fload:
2683   case Bytecodes::_iload:
2684     push( local(iter().get_index()) );
2685     break;
2686   case Bytecodes::_lload_0:
2687     push_pair_local( 0 );
2688     break;
2689   case Bytecodes::_lload_1:
2690     push_pair_local( 1 );
2691     break;
2692   case Bytecodes::_lload_2:
2693     push_pair_local( 2 );
2694     break;
2695   case Bytecodes::_lload_3:
2696     push_pair_local( 3 );
2697     break;
2698   case Bytecodes::_lload:
2699     push_pair_local( iter().get_index() );
2700     break;
2701 
2702   case Bytecodes::_dload_0:
2703     push_pair_local(0);
2704     break;
2705   case Bytecodes::_dload_1:
2706     push_pair_local(1);
2707     break;
2708   case Bytecodes::_dload_2:
2709     push_pair_local(2);
2710     break;
2711   case Bytecodes::_dload_3:
2712     push_pair_local(3);
2713     break;
2714   case Bytecodes::_dload:
2715     push_pair_local(iter().get_index());
2716     break;
2717   case Bytecodes::_fstore_0:
2718   case Bytecodes::_istore_0:
2719   case Bytecodes::_astore_0:
2720     set_local( 0, pop() );
2721     break;
2722   case Bytecodes::_fstore_1:
2723   case Bytecodes::_istore_1:
2724   case Bytecodes::_astore_1:
2725     set_local( 1, pop() );
2726     break;
2727   case Bytecodes::_fstore_2:
2728   case Bytecodes::_istore_2:
2729   case Bytecodes::_astore_2:
2730     set_local( 2, pop() );
2731     break;
2732   case Bytecodes::_fstore_3:
2733   case Bytecodes::_istore_3:
2734   case Bytecodes::_astore_3:
2735     set_local( 3, pop() );
2736     break;
2737   case Bytecodes::_fstore:
2738   case Bytecodes::_istore:
2739   case Bytecodes::_astore:
2740     set_local( iter().get_index(), pop() );
2741     break;
2742   // long stores
2743   case Bytecodes::_lstore_0:
2744     set_pair_local( 0, pop_pair() );
2745     break;
2746   case Bytecodes::_lstore_1:
2747     set_pair_local( 1, pop_pair() );
2748     break;
2749   case Bytecodes::_lstore_2:
2750     set_pair_local( 2, pop_pair() );
2751     break;
2752   case Bytecodes::_lstore_3:
2753     set_pair_local( 3, pop_pair() );
2754     break;
2755   case Bytecodes::_lstore:
2756     set_pair_local( iter().get_index(), pop_pair() );
2757     break;
2758 
2759   // double stores
2760   case Bytecodes::_dstore_0:
2761     set_pair_local( 0, dstore_rounding(pop_pair()) );
2762     break;
2763   case Bytecodes::_dstore_1:
2764     set_pair_local( 1, dstore_rounding(pop_pair()) );
2765     break;
2766   case Bytecodes::_dstore_2:
2767     set_pair_local( 2, dstore_rounding(pop_pair()) );
2768     break;
2769   case Bytecodes::_dstore_3:
2770     set_pair_local( 3, dstore_rounding(pop_pair()) );
2771     break;
2772   case Bytecodes::_dstore:
2773     set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) );
2774     break;
2775 
2776   case Bytecodes::_pop:  dec_sp(1);   break;
2777   case Bytecodes::_pop2: dec_sp(2);   break;
2778   case Bytecodes::_swap:
2779     a = pop();
2780     b = pop();
2781     push(a);
2782     push(b);
2783     break;
2784   case Bytecodes::_dup:
2785     a = pop();
2786     push(a);
2787     push(a);
2788     break;
2789   case Bytecodes::_dup_x1:
2790     a = pop();
2791     b = pop();
2792     push( a );
2793     push( b );
2794     push( a );
2795     break;
2796   case Bytecodes::_dup_x2:
2797     a = pop();
2798     b = pop();
2799     c = pop();
2800     push( a );
2801     push( c );
2802     push( b );
2803     push( a );
2804     break;
2805   case Bytecodes::_dup2:
2806     a = pop();
2807     b = pop();
2808     push( b );
2809     push( a );
2810     push( b );
2811     push( a );
2812     break;
2813 
2814   case Bytecodes::_dup2_x1:
2815     // before: .. c, b, a
2816     // after:  .. b, a, c, b, a
2817     // not tested
2818     a = pop();
2819     b = pop();
2820     c = pop();
2821     push( b );
2822     push( a );
2823     push( c );
2824     push( b );
2825     push( a );
2826     break;
2827   case Bytecodes::_dup2_x2:
2828     // before: .. d, c, b, a
2829     // after:  .. b, a, d, c, b, a
2830     // not tested
2831     a = pop();
2832     b = pop();
2833     c = pop();
2834     d = pop();
2835     push( b );
2836     push( a );
2837     push( d );
2838     push( c );
2839     push( b );
2840     push( a );
2841     break;
2842 
2843   case Bytecodes::_arraylength: {
2844     // Must do null-check with value on expression stack
2845     Node *ary = null_check(peek(), T_ARRAY);
2846     // Compile-time detect of null-exception?
2847     if (stopped())  return;
2848     a = pop();
2849     push(load_array_length(a));
2850     break;
2851   }
2852 
2853   case Bytecodes::_baload:  array_load(T_BYTE);    break;
2854   case Bytecodes::_caload:  array_load(T_CHAR);    break;
2855   case Bytecodes::_iaload:  array_load(T_INT);     break;
2856   case Bytecodes::_saload:  array_load(T_SHORT);   break;
2857   case Bytecodes::_faload:  array_load(T_FLOAT);   break;
2858   case Bytecodes::_aaload:  array_load(T_OBJECT);  break;
2859   case Bytecodes::_laload:  array_load(T_LONG);    break;
2860   case Bytecodes::_daload:  array_load(T_DOUBLE);  break;
2861   case Bytecodes::_bastore: array_store(T_BYTE);   break;
2862   case Bytecodes::_castore: array_store(T_CHAR);   break;
2863   case Bytecodes::_iastore: array_store(T_INT);    break;
2864   case Bytecodes::_sastore: array_store(T_SHORT);  break;
2865   case Bytecodes::_fastore: array_store(T_FLOAT);  break;
2866   case Bytecodes::_aastore: array_store(T_OBJECT); break;
2867   case Bytecodes::_lastore: array_store(T_LONG);   break;
2868   case Bytecodes::_dastore: array_store(T_DOUBLE); break;
2869 
2870   case Bytecodes::_getfield:
2871     do_getfield();
2872     break;
2873 
2874   case Bytecodes::_getstatic:
2875     do_getstatic();
2876     break;
2877 
2878   case Bytecodes::_putfield:
2879     do_putfield();
2880     break;
2881 
2882   case Bytecodes::_putstatic:
2883     do_putstatic();
2884     break;
2885 
2886   case Bytecodes::_irem:
2887     // Must keep both values on the expression-stack during null-check
2888     zero_check_int(peek());
2889     // Compile-time detect of null-exception?
2890     if (stopped())  return;
2891     b = pop();
2892     a = pop();
2893     push(_gvn.transform(new ModINode(control(), a, b)));
2894     break;
2895   case Bytecodes::_idiv:
2896     // Must keep both values on the expression-stack during null-check
2897     zero_check_int(peek());
2898     // Compile-time detect of null-exception?
2899     if (stopped())  return;
2900     b = pop();
2901     a = pop();
2902     push( _gvn.transform( new DivINode(control(),a,b) ) );
2903     break;
2904   case Bytecodes::_imul:
2905     b = pop(); a = pop();
2906     push( _gvn.transform( new MulINode(a,b) ) );
2907     break;
2908   case Bytecodes::_iadd:
2909     b = pop(); a = pop();
2910     push( _gvn.transform( new AddINode(a,b) ) );
2911     break;
2912   case Bytecodes::_ineg:
2913     a = pop();
2914     push( _gvn.transform( new SubINode(_gvn.intcon(0),a)) );
2915     break;
2916   case Bytecodes::_isub:
2917     b = pop(); a = pop();
2918     push( _gvn.transform( new SubINode(a,b) ) );
2919     break;
2920   case Bytecodes::_iand:
2921     b = pop(); a = pop();
2922     push( _gvn.transform( new AndINode(a,b) ) );
2923     break;
2924   case Bytecodes::_ior:
2925     b = pop(); a = pop();
2926     push( _gvn.transform( new OrINode(a,b) ) );
2927     break;
2928   case Bytecodes::_ixor:
2929     b = pop(); a = pop();
2930     push( _gvn.transform( new XorINode(a,b) ) );
2931     break;
2932   case Bytecodes::_ishl:
2933     b = pop(); a = pop();
2934     push( _gvn.transform( new LShiftINode(a,b) ) );
2935     break;
2936   case Bytecodes::_ishr:
2937     b = pop(); a = pop();
2938     push( _gvn.transform( new RShiftINode(a,b) ) );
2939     break;
2940   case Bytecodes::_iushr:
2941     b = pop(); a = pop();
2942     push( _gvn.transform( new URShiftINode(a,b) ) );
2943     break;
2944 
2945   case Bytecodes::_fneg:
2946     a = pop();
2947     b = _gvn.transform(new NegFNode (a));
2948     push(b);
2949     break;
2950 
2951   case Bytecodes::_fsub:
2952     b = pop();
2953     a = pop();
2954     c = _gvn.transform( new SubFNode(a,b) );
2955     d = precision_rounding(c);
2956     push( d );
2957     break;
2958 
2959   case Bytecodes::_fadd:
2960     b = pop();
2961     a = pop();
2962     c = _gvn.transform( new AddFNode(a,b) );
2963     d = precision_rounding(c);
2964     push( d );
2965     break;
2966 
2967   case Bytecodes::_fmul:
2968     b = pop();
2969     a = pop();
2970     c = _gvn.transform( new MulFNode(a,b) );
2971     d = precision_rounding(c);
2972     push( d );
2973     break;
2974 
2975   case Bytecodes::_fdiv:
2976     b = pop();
2977     a = pop();
2978     c = _gvn.transform( new DivFNode(0,a,b) );
2979     d = precision_rounding(c);
2980     push( d );
2981     break;
2982 
2983   case Bytecodes::_frem:
2984     if (Matcher::has_match_rule(Op_ModF)) {
2985       // Generate a ModF node.
2986       b = pop();
2987       a = pop();
2988       c = _gvn.transform( new ModFNode(0,a,b) );
2989       d = precision_rounding(c);
2990       push( d );
2991     }
2992     else {
2993       // Generate a call.
2994       modf();
2995     }
2996     break;
2997 
2998   case Bytecodes::_fcmpl:
2999     b = pop();
3000     a = pop();
3001     c = _gvn.transform( new CmpF3Node( a, b));
3002     push(c);
3003     break;
3004   case Bytecodes::_fcmpg:
3005     b = pop();
3006     a = pop();
3007 
3008     // Same as fcmpl but need to flip the unordered case.  Swap the inputs,
3009     // which negates the result sign except for unordered.  Flip the unordered
3010     // as well by using CmpF3 which implements unordered-lesser instead of
3011     // unordered-greater semantics.  Finally, commute the result bits.  Result
3012     // is same as using a CmpF3Greater except we did it with CmpF3 alone.
3013     c = _gvn.transform( new CmpF3Node( b, a));
3014     c = _gvn.transform( new SubINode(_gvn.intcon(0),c) );
3015     push(c);
3016     break;
3017 
3018   case Bytecodes::_f2i:
3019     a = pop();
3020     push(_gvn.transform(new ConvF2INode(a)));
3021     break;
3022 
3023   case Bytecodes::_d2i:
3024     a = pop_pair();
3025     b = _gvn.transform(new ConvD2INode(a));
3026     push( b );
3027     break;
3028 
3029   case Bytecodes::_f2d:
3030     a = pop();
3031     b = _gvn.transform( new ConvF2DNode(a));
3032     push_pair( b );
3033     break;
3034 
3035   case Bytecodes::_d2f:
3036     a = pop_pair();
3037     b = _gvn.transform( new ConvD2FNode(a));
3038     // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed)
3039     //b = _gvn.transform(new RoundFloatNode(0, b) );
3040     push( b );
3041     break;
3042 
3043   case Bytecodes::_l2f:
3044     if (Matcher::convL2FSupported()) {
3045       a = pop_pair();
3046       b = _gvn.transform( new ConvL2FNode(a));
3047       // For x86_32.ad, FILD doesn't restrict precision to 24 or 53 bits.
3048       // Rather than storing the result into an FP register then pushing
3049       // out to memory to round, the machine instruction that implements
3050       // ConvL2D is responsible for rounding.
3051       // c = precision_rounding(b);
3052       c = _gvn.transform(b);
3053       push(c);
3054     } else {
3055       l2f();
3056     }
3057     break;
3058 
3059   case Bytecodes::_l2d:
3060     a = pop_pair();
3061     b = _gvn.transform( new ConvL2DNode(a));
3062     // For x86_32.ad, rounding is always necessary (see _l2f above).
3063     // c = dprecision_rounding(b);
3064     c = _gvn.transform(b);
3065     push_pair(c);
3066     break;
3067 
3068   case Bytecodes::_f2l:
3069     a = pop();
3070     b = _gvn.transform( new ConvF2LNode(a));
3071     push_pair(b);
3072     break;
3073 
3074   case Bytecodes::_d2l:
3075     a = pop_pair();
3076     b = _gvn.transform( new ConvD2LNode(a));
3077     push_pair(b);
3078     break;
3079 
3080   case Bytecodes::_dsub:
3081     b = pop_pair();
3082     a = pop_pair();
3083     c = _gvn.transform( new SubDNode(a,b) );
3084     d = dprecision_rounding(c);
3085     push_pair( d );
3086     break;
3087 
3088   case Bytecodes::_dadd:
3089     b = pop_pair();
3090     a = pop_pair();
3091     c = _gvn.transform( new AddDNode(a,b) );
3092     d = dprecision_rounding(c);
3093     push_pair( d );
3094     break;
3095 
3096   case Bytecodes::_dmul:
3097     b = pop_pair();
3098     a = pop_pair();
3099     c = _gvn.transform( new MulDNode(a,b) );
3100     d = dprecision_rounding(c);
3101     push_pair( d );
3102     break;
3103 
3104   case Bytecodes::_ddiv:
3105     b = pop_pair();
3106     a = pop_pair();
3107     c = _gvn.transform( new DivDNode(0,a,b) );
3108     d = dprecision_rounding(c);
3109     push_pair( d );
3110     break;
3111 
3112   case Bytecodes::_dneg:
3113     a = pop_pair();
3114     b = _gvn.transform(new NegDNode (a));
3115     push_pair(b);
3116     break;
3117 
3118   case Bytecodes::_drem:
3119     if (Matcher::has_match_rule(Op_ModD)) {
3120       // Generate a ModD node.
3121       b = pop_pair();
3122       a = pop_pair();
3123       // a % b
3124 
3125       c = _gvn.transform( new ModDNode(0,a,b) );
3126       d = dprecision_rounding(c);
3127       push_pair( d );
3128     }
3129     else {
3130       // Generate a call.
3131       modd();
3132     }
3133     break;
3134 
3135   case Bytecodes::_dcmpl:
3136     b = pop_pair();
3137     a = pop_pair();
3138     c = _gvn.transform( new CmpD3Node( a, b));
3139     push(c);
3140     break;
3141 
3142   case Bytecodes::_dcmpg:
3143     b = pop_pair();
3144     a = pop_pair();
3145     // Same as dcmpl but need to flip the unordered case.
3146     // Commute the inputs, which negates the result sign except for unordered.
3147     // Flip the unordered as well by using CmpD3 which implements
3148     // unordered-lesser instead of unordered-greater semantics.
3149     // Finally, negate the result bits.  Result is same as using a
3150     // CmpD3Greater except we did it with CmpD3 alone.
3151     c = _gvn.transform( new CmpD3Node( b, a));
3152     c = _gvn.transform( new SubINode(_gvn.intcon(0),c) );
3153     push(c);
3154     break;
3155 
3156 
3157     // Note for longs -> lo word is on TOS, hi word is on TOS - 1
3158   case Bytecodes::_land:
3159     b = pop_pair();
3160     a = pop_pair();
3161     c = _gvn.transform( new AndLNode(a,b) );
3162     push_pair(c);
3163     break;
3164   case Bytecodes::_lor:
3165     b = pop_pair();
3166     a = pop_pair();
3167     c = _gvn.transform( new OrLNode(a,b) );
3168     push_pair(c);
3169     break;
3170   case Bytecodes::_lxor:
3171     b = pop_pair();
3172     a = pop_pair();
3173     c = _gvn.transform( new XorLNode(a,b) );
3174     push_pair(c);
3175     break;
3176 
3177   case Bytecodes::_lshl:
3178     b = pop();                  // the shift count
3179     a = pop_pair();             // value to be shifted
3180     c = _gvn.transform( new LShiftLNode(a,b) );
3181     push_pair(c);
3182     break;
3183   case Bytecodes::_lshr:
3184     b = pop();                  // the shift count
3185     a = pop_pair();             // value to be shifted
3186     c = _gvn.transform( new RShiftLNode(a,b) );
3187     push_pair(c);
3188     break;
3189   case Bytecodes::_lushr:
3190     b = pop();                  // the shift count
3191     a = pop_pair();             // value to be shifted
3192     c = _gvn.transform( new URShiftLNode(a,b) );
3193     push_pair(c);
3194     break;
3195   case Bytecodes::_lmul:
3196     b = pop_pair();
3197     a = pop_pair();
3198     c = _gvn.transform( new MulLNode(a,b) );
3199     push_pair(c);
3200     break;
3201 
3202   case Bytecodes::_lrem:
3203     // Must keep both values on the expression-stack during null-check
3204     assert(peek(0) == top(), "long word order");
3205     zero_check_long(peek(1));
3206     // Compile-time detect of null-exception?
3207     if (stopped())  return;
3208     b = pop_pair();
3209     a = pop_pair();
3210     c = _gvn.transform( new ModLNode(control(),a,b) );
3211     push_pair(c);
3212     break;
3213 
3214   case Bytecodes::_ldiv:
3215     // Must keep both values on the expression-stack during null-check
3216     assert(peek(0) == top(), "long word order");
3217     zero_check_long(peek(1));
3218     // Compile-time detect of null-exception?
3219     if (stopped())  return;
3220     b = pop_pair();
3221     a = pop_pair();
3222     c = _gvn.transform( new DivLNode(control(),a,b) );
3223     push_pair(c);
3224     break;
3225 
3226   case Bytecodes::_ladd:
3227     b = pop_pair();
3228     a = pop_pair();
3229     c = _gvn.transform( new AddLNode(a,b) );
3230     push_pair(c);
3231     break;
3232   case Bytecodes::_lsub:
3233     b = pop_pair();
3234     a = pop_pair();
3235     c = _gvn.transform( new SubLNode(a,b) );
3236     push_pair(c);
3237     break;
3238   case Bytecodes::_lcmp:
3239     // Safepoints are now inserted _before_ branches.  The long-compare
3240     // bytecode painfully produces a 3-way value (-1,0,+1) which requires a
3241     // slew of control flow.  These are usually followed by a CmpI vs zero and
3242     // a branch; this pattern then optimizes to the obvious long-compare and
3243     // branch.  However, if the branch is backwards there's a Safepoint
3244     // inserted.  The inserted Safepoint captures the JVM state at the
3245     // pre-branch point, i.e. it captures the 3-way value.  Thus if a
3246     // long-compare is used to control a loop the debug info will force
3247     // computation of the 3-way value, even though the generated code uses a
3248     // long-compare and branch.  We try to rectify the situation by inserting
3249     // a SafePoint here and have it dominate and kill the safepoint added at a
3250     // following backwards branch.  At this point the JVM state merely holds 2
3251     // longs but not the 3-way value.
3252     switch (iter().next_bc()) {
3253       case Bytecodes::_ifgt:
3254       case Bytecodes::_iflt:
3255       case Bytecodes::_ifge:
3256       case Bytecodes::_ifle:
3257       case Bytecodes::_ifne:
3258       case Bytecodes::_ifeq:
3259         // If this is a backwards branch in the bytecodes, add Safepoint
3260         maybe_add_safepoint(iter().next_get_dest());
3261       default:
3262         break;
3263     }
3264     b = pop_pair();
3265     a = pop_pair();
3266     c = _gvn.transform( new CmpL3Node( a, b ));
3267     push(c);
3268     break;
3269 
3270   case Bytecodes::_lneg:
3271     a = pop_pair();
3272     b = _gvn.transform( new SubLNode(longcon(0),a));
3273     push_pair(b);
3274     break;
3275   case Bytecodes::_l2i:
3276     a = pop_pair();
3277     push( _gvn.transform( new ConvL2INode(a)));
3278     break;
3279   case Bytecodes::_i2l:
3280     a = pop();
3281     b = _gvn.transform( new ConvI2LNode(a));
3282     push_pair(b);
3283     break;
3284   case Bytecodes::_i2b:
3285     // Sign extend
3286     a = pop();
3287     a = Compile::narrow_value(T_BYTE, a, NULL, &_gvn, true);
3288     push(a);
3289     break;
3290   case Bytecodes::_i2s:
3291     a = pop();
3292     a = Compile::narrow_value(T_SHORT, a, NULL, &_gvn, true);
3293     push(a);
3294     break;
3295   case Bytecodes::_i2c:
3296     a = pop();
3297     a = Compile::narrow_value(T_CHAR, a, NULL, &_gvn, true);
3298     push(a);
3299     break;
3300 
3301   case Bytecodes::_i2f:
3302     a = pop();
3303     b = _gvn.transform( new ConvI2FNode(a) ) ;
3304     c = precision_rounding(b);
3305     push (b);
3306     break;
3307 
3308   case Bytecodes::_i2d:
3309     a = pop();
3310     b = _gvn.transform( new ConvI2DNode(a));
3311     push_pair(b);
3312     break;
3313 
3314   case Bytecodes::_iinc:        // Increment local
3315     i = iter().get_index();     // Get local index
3316     set_local( i, _gvn.transform( new AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
3317     break;
3318 
3319   // Exit points of synchronized methods must have an unlock node
3320   case Bytecodes::_return:
3321     return_current(NULL);
3322     break;
3323 
3324   case Bytecodes::_ireturn:
3325   case Bytecodes::_areturn:
3326   case Bytecodes::_freturn:
3327     return_current(pop());
3328     break;
3329   case Bytecodes::_lreturn:
3330     return_current(pop_pair());
3331     break;
3332   case Bytecodes::_dreturn:
3333     return_current(pop_pair());
3334     break;
3335 
3336   case Bytecodes::_athrow:
3337     // null exception oop throws NULL pointer exception
3338     null_check(peek());
3339     if (stopped())  return;
3340     // Hook the thrown exception directly to subsequent handlers.
3341     if (BailoutToInterpreterForThrows) {
3342       // Keep method interpreted from now on.
3343       uncommon_trap(Deoptimization::Reason_unhandled,
3344                     Deoptimization::Action_make_not_compilable);
3345       return;
3346     }
3347     if (env()->jvmti_can_post_on_exceptions()) {
3348       // check if we must post exception events, take uncommon trap if so (with must_throw = false)
3349       uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false);
3350     }
3351     // Here if either can_post_on_exceptions or should_post_on_exceptions is false
3352     add_exception_state(make_exception_state(peek()));
3353     break;
3354 
3355   case Bytecodes::_goto:   // fall through
3356   case Bytecodes::_goto_w: {
3357     int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest();
3358 
3359     // If this is a backwards branch in the bytecodes, add Safepoint
3360     maybe_add_safepoint(target_bci);
3361 
3362     // Merge the current control into the target basic block
3363     merge(target_bci);
3364 
3365     // See if we can get some profile data and hand it off to the next block
3366     Block *target_block = block()->successor_for_bci(target_bci);
3367     if (target_block->pred_count() != 1)  break;
3368     ciMethodData* methodData = method()->method_data();
3369     if (!methodData->is_mature())  break;
3370     ciProfileData* data = methodData->bci_to_data(bci());
3371     assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch");
3372     int taken = ((ciJumpData*)data)->taken();
3373     taken = method()->scale_count(taken);
3374     target_block->set_count(taken);
3375     break;
3376   }
3377 
3378   case Bytecodes::_ifnull:    btest = BoolTest::eq; goto handle_if_null;
3379   case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
3380   handle_if_null:
3381     // If this is a backwards branch in the bytecodes, add Safepoint
3382     maybe_add_safepoint(iter().get_dest());
3383     a = null();
3384     b = pop();
3385     if (b->is_InlineType()) {
3386       // Return constant false because 'b' is always non-null
3387       c = _gvn.makecon(TypeInt::CC_GT);
3388     } else {
3389       if (!_gvn.type(b)->speculative_maybe_null() &&
3390           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
3391         inc_sp(1);
3392         Node* null_ctl = top();
3393         b = null_check_oop(b, &null_ctl, true, true, true);
3394         assert(null_ctl->is_top(), "no null control here");
3395         dec_sp(1);
3396       } else if (_gvn.type(b)->speculative_always_null() &&
3397                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
3398         inc_sp(1);
3399         b = null_assert(b);
3400         dec_sp(1);
3401       }
3402       c = _gvn.transform( new CmpPNode(b, a) );
3403     }
3404     do_ifnull(btest, c);
3405     break;
3406 
3407   case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
3408   case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
3409   handle_if_acmp:
3410     // If this is a backwards branch in the bytecodes, add Safepoint
3411     maybe_add_safepoint(iter().get_dest());
3412     a = pop();
3413     b = pop();
3414     do_acmp(btest, b, a);
3415     break;
3416 
3417   case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
3418   case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
3419   case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
3420   case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
3421   case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
3422   case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
3423   handle_ifxx:
3424     // If this is a backwards branch in the bytecodes, add Safepoint
3425     maybe_add_safepoint(iter().get_dest());
3426     a = _gvn.intcon(0);
3427     b = pop();
3428     c = _gvn.transform( new CmpINode(b, a) );
3429     do_if(btest, c);
3430     break;
3431 
3432   case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
3433   case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
3434   case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;
3435   case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp;
3436   case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp;
3437   case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp;
3438   handle_if_icmp:
3439     // If this is a backwards branch in the bytecodes, add Safepoint
3440     maybe_add_safepoint(iter().get_dest());
3441     a = pop();
3442     b = pop();
3443     c = _gvn.transform( new CmpINode( b, a ) );
3444     do_if(btest, c);
3445     break;
3446 
3447   case Bytecodes::_tableswitch:
3448     do_tableswitch();
3449     break;
3450 
3451   case Bytecodes::_lookupswitch:
3452     do_lookupswitch();
3453     break;
3454 
3455   case Bytecodes::_invokestatic:
3456   case Bytecodes::_invokedynamic:
3457   case Bytecodes::_invokespecial:
3458   case Bytecodes::_invokevirtual:
3459   case Bytecodes::_invokeinterface:
3460     do_call();
3461     break;
3462   case Bytecodes::_checkcast:
3463     do_checkcast();
3464     break;
3465   case Bytecodes::_instanceof:
3466     do_instanceof();
3467     break;
3468   case Bytecodes::_anewarray:
3469     do_newarray();
3470     break;
3471   case Bytecodes::_newarray:
3472     do_newarray((BasicType)iter().get_index());
3473     break;
3474   case Bytecodes::_multianewarray:
3475     do_multianewarray();
3476     break;
3477   case Bytecodes::_new:
3478     do_new();
3479     break;
3480   case Bytecodes::_defaultvalue:
3481     do_defaultvalue();
3482     break;
3483   case Bytecodes::_withfield:
3484     do_withfield();
3485     break;
3486 
3487   case Bytecodes::_jsr:
3488   case Bytecodes::_jsr_w:
3489     do_jsr();
3490     break;
3491 
3492   case Bytecodes::_ret:
3493     do_ret();
3494     break;
3495 
3496 
3497   case Bytecodes::_monitorenter:
3498     do_monitor_enter();
3499     break;
3500 
3501   case Bytecodes::_monitorexit:
3502     do_monitor_exit();
3503     break;
3504 
3505   case Bytecodes::_breakpoint:
3506     // Breakpoint set concurrently to compile
3507     // %%% use an uncommon trap?
3508     C->record_failure("breakpoint in method");
3509     return;
3510 
3511   default:
3512 #ifndef PRODUCT
3513     map()->dump(99);
3514 #endif
3515     tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) );
3516     ShouldNotReachHere();
3517   }
3518 
3519 #ifndef PRODUCT
3520   if (C->should_print(1)) {
3521     IdealGraphPrinter* printer = C->printer();
3522     char buffer[256];
3523     jio_snprintf(buffer, sizeof(buffer), "Bytecode %d: %s", bci(), Bytecodes::name(bc()));
3524     bool old = printer->traverse_outs();
3525     printer->set_traverse_outs(true);
3526     printer->print_method(buffer, 4);
3527     printer->set_traverse_outs(old);
3528   }
3529 #endif
3530 }