src/share/vm/opto/parse2.cpp

Fri, 16 Oct 2009 02:05:46 -0700

author
ysr
date
Fri, 16 Oct 2009 02:05:46 -0700
changeset 1462
39b01ab7035a
parent 1424
148e5441d916
child 1607
b2b6a9bf6238
permissions
-rw-r--r--

6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
6889757: G1: enable card mark elision for initializing writes from compiled code (ReduceInitialCardMarks)
Summary: Defer the (compiler-elided) card-mark upon a slow-path allocation until after the store and before the next subsequent safepoint; G1 now answers yes to can_elide_tlab_write_barriers().
Reviewed-by: jcoomes, kvn, never

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

mercurial