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