< prev index next >

src/hotspot/share/opto/graphKit.cpp

Print this page




   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 "ci/ciUtilities.hpp"
  27 #include "compiler/compileLog.hpp"

  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/c2/barrierSetC2.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "opto/addnode.hpp"
  33 #include "opto/castnode.hpp"
  34 #include "opto/convertnode.hpp"
  35 #include "opto/graphKit.hpp"
  36 #include "opto/idealKit.hpp"
  37 #include "opto/intrinsicnode.hpp"
  38 #include "opto/locknode.hpp"
  39 #include "opto/machnode.hpp"

  40 #include "opto/opaquenode.hpp"
  41 #include "opto/parse.hpp"
  42 #include "opto/rootnode.hpp"
  43 #include "opto/runtime.hpp"

  44 #include "runtime/deoptimization.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 
  47 //----------------------------GraphKit-----------------------------------------
  48 // Main utility constructor.
  49 GraphKit::GraphKit(JVMState* jvms)
  50   : Phase(Phase::Parser),
  51     _env(C->env()),
  52     _gvn(*C->initial_gvn()),
  53     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
  54 {

  55   _exceptions = jvms->map()->next_exception();
  56   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);
  57   set_jvms(jvms);







  58 }
  59 
  60 // Private constructor for parser.
  61 GraphKit::GraphKit()
  62   : Phase(Phase::Parser),
  63     _env(C->env()),
  64     _gvn(*C->initial_gvn()),
  65     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
  66 {
  67   _exceptions = NULL;
  68   set_map(NULL);
  69   debug_only(_sp = -99);
  70   debug_only(set_bci(-99));
  71 }
  72 
  73 
  74 
  75 //---------------------------clean_stack---------------------------------------
  76 // Clear away rubbish from the stack area of the JVM state.
  77 // This destroys any arguments that may be waiting on the stack.


 806           tty->print_cr("Zombie local %d: ", local);
 807           jvms->dump();
 808         }
 809         return false;
 810       }
 811     }
 812   }
 813   return true;
 814 }
 815 
 816 #endif //ASSERT
 817 
 818 // Helper function for enforcing certain bytecodes to reexecute if
 819 // deoptimization happens
 820 static bool should_reexecute_implied_by_bytecode(JVMState *jvms, bool is_anewarray) {
 821   ciMethod* cur_method = jvms->method();
 822   int       cur_bci   = jvms->bci();
 823   if (cur_method != NULL && cur_bci != InvocationEntryBci) {
 824     Bytecodes::Code code = cur_method->java_code_at_bci(cur_bci);
 825     return Interpreter::bytecode_should_reexecute(code) ||
 826            (is_anewarray && code == Bytecodes::_multianewarray);
 827     // Reexecute _multianewarray bytecode which was replaced with
 828     // sequence of [a]newarray. See Parse::do_multianewarray().
 829     //
 830     // Note: interpreter should not have it set since this optimization
 831     // is limited by dimensions and guarded by flag so in some cases
 832     // multianewarray() runtime calls will be generated and
 833     // the bytecode should not be reexecutes (stack will not be reset).
 834   } else
 835     return false;

 836 }
 837 
 838 // Helper function for adding JVMState and debug information to node
 839 void GraphKit::add_safepoint_edges(SafePointNode* call, bool must_throw) {
 840   // Add the safepoint edges to the call (or other safepoint).
 841 
 842   // Make sure dead locals are set to top.  This
 843   // should help register allocation time and cut down on the size
 844   // of the deoptimization information.
 845   assert(dead_locals_are_killed(), "garbage in debug info before safepoint");
 846 
 847   // Walk the inline list to fill in the correct set of JVMState's
 848   // Also fill in the associated edges for each JVMState.
 849 
 850   // If the bytecode needs to be reexecuted we need to put
 851   // the arguments back on the stack.
 852   const bool should_reexecute = jvms()->should_reexecute();
 853   JVMState* youngest_jvms = should_reexecute ? sync_jvms_for_reexecute() : sync_jvms();
 854 
 855   // NOTE: set_bci (called from sync_jvms) might reset the reexecute bit to


1059       ciSignature* declared_signature = NULL;
1060       ciMethod* ignored_callee = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1061       assert(declared_signature != NULL, "cannot be null");
1062       inputs   = declared_signature->arg_size_for_bc(code);
1063       int size = declared_signature->return_type()->size();
1064       depth = size - inputs;
1065     }
1066     break;
1067 
1068   case Bytecodes::_multianewarray:
1069     {
1070       ciBytecodeStream iter(method());
1071       iter.reset_to_bci(bci());
1072       iter.next();
1073       inputs = iter.get_dimensions();
1074       assert(rsize == 1, "");
1075       depth = rsize - inputs;
1076     }
1077     break;
1078 









1079   case Bytecodes::_ireturn:
1080   case Bytecodes::_lreturn:
1081   case Bytecodes::_freturn:
1082   case Bytecodes::_dreturn:
1083   case Bytecodes::_areturn:
1084     assert(rsize == -depth, "");
1085     inputs = rsize;
1086     break;
1087 
1088   case Bytecodes::_jsr:
1089   case Bytecodes::_jsr_w:
1090     inputs = 0;
1091     depth  = 1;                  // S.B. depth=1, not zero
1092     break;
1093 
1094   default:
1095     // bytecode produces a typed result
1096     inputs = rsize - depth;
1097     assert(inputs >= 0, "");
1098     break;


1184 // the incoming address with NULL casted away.  You are allowed to use the
1185 // not-null value only if you are control dependent on the test.
1186 #ifndef PRODUCT
1187 extern int explicit_null_checks_inserted,
1188            explicit_null_checks_elided;
1189 #endif
1190 Node* GraphKit::null_check_common(Node* value, BasicType type,
1191                                   // optional arguments for variations:
1192                                   bool assert_null,
1193                                   Node* *null_control,
1194                                   bool speculative) {
1195   assert(!assert_null || null_control == NULL, "not both at once");
1196   if (stopped())  return top();
1197   NOT_PRODUCT(explicit_null_checks_inserted++);
1198 
1199   // Construct NULL check
1200   Node *chk = NULL;
1201   switch(type) {
1202     case T_LONG   : chk = new CmpLNode(value, _gvn.zerocon(T_LONG)); break;
1203     case T_INT    : chk = new CmpINode(value, _gvn.intcon(0)); break;

1204     case T_ARRAY  : // fall through
1205       type = T_OBJECT;  // simplify further tests
1206     case T_OBJECT : {
1207       const Type *t = _gvn.type( value );
1208 
1209       const TypeOopPtr* tp = t->isa_oopptr();
1210       if (tp != NULL && tp->klass() != NULL && !tp->klass()->is_loaded()
1211           // Only for do_null_check, not any of its siblings:
1212           && !assert_null && null_control == NULL) {
1213         // Usually, any field access or invocation on an unloaded oop type
1214         // will simply fail to link, since the statically linked class is
1215         // likely also to be unloaded.  However, in -Xcomp mode, sometimes
1216         // the static class is loaded but the sharper oop type is not.
1217         // Rather than checking for this obscure case in lots of places,
1218         // we simply observe that a null check on an unloaded class
1219         // will always be followed by a nonsense operation, so we
1220         // can just issue the uncommon trap here.
1221         // Our access to the unloaded class will only be correct
1222         // after it has been loaded and initialized, which requires
1223         // a trip through the interpreter.


1355   }
1356 
1357   if (assert_null) {
1358     // Cast obj to null on this path.
1359     replace_in_map(value, zerocon(type));
1360     return zerocon(type);
1361   }
1362 
1363   // Cast obj to not-null on this path, if there is no null_control.
1364   // (If there is a null_control, a non-null value may come back to haunt us.)
1365   if (type == T_OBJECT) {
1366     Node* cast = cast_not_null(value, false);
1367     if (null_control == NULL || (*null_control) == top())
1368       replace_in_map(value, cast);
1369     value = cast;
1370   }
1371 
1372   return value;
1373 }
1374 















1375 
1376 //------------------------------cast_not_null----------------------------------
1377 // Cast obj to not-null on this path
1378 Node* GraphKit::cast_not_null(Node* obj, bool do_replace_in_map) {



1379   const Type *t = _gvn.type(obj);
1380   const Type *t_not_null = t->join_speculative(TypePtr::NOTNULL);
1381   // Object is already not-null?
1382   if( t == t_not_null ) return obj;
1383 
1384   Node *cast = new CastPPNode(obj,t_not_null);
1385   cast->init_req(0, control());
1386   cast = _gvn.transform( cast );
1387 
1388   // Scan for instances of 'obj' in the current JVM mapping.
1389   // These instances are known to be not-null after the test.
1390   if (do_replace_in_map)
1391     replace_in_map(obj, cast);
1392 
1393   return cast;                  // Return casted value
1394 }
1395 
1396 // Sometimes in intrinsics, we implicitly know an object is not null
1397 // (there's no actual null check) so we can cast it to not null. In
1398 // the course of optimizations, the input to the cast can become null.


1487                           int adr_idx,
1488                           MemNode::MemOrd mo,
1489                           LoadNode::ControlDependency control_dependency,
1490                           bool require_atomic_access,
1491                           bool unaligned,
1492                           bool mismatched,
1493                           bool unsafe) {
1494   assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
1495   const TypePtr* adr_type = NULL; // debug-mode-only argument
1496   debug_only(adr_type = C->get_adr_type(adr_idx));
1497   Node* mem = memory(adr_idx);
1498   Node* ld;
1499   if (require_atomic_access && bt == T_LONG) {
1500     ld = LoadLNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
1501   } else if (require_atomic_access && bt == T_DOUBLE) {
1502     ld = LoadDNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
1503   } else {
1504     ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt, mo, control_dependency, unaligned, mismatched, unsafe);
1505   }
1506   ld = _gvn.transform(ld);
1507   if (((bt == T_OBJECT) && C->do_escape_analysis()) || C->eliminate_boxing()) {

1508     // Improve graph before escape analysis and boxing elimination.
1509     record_for_igvn(ld);
1510   }
1511   return ld;
1512 }
1513 
1514 Node* GraphKit::store_to_memory(Node* ctl, Node* adr, Node *val, BasicType bt,
1515                                 int adr_idx,
1516                                 MemNode::MemOrd mo,
1517                                 bool require_atomic_access,
1518                                 bool unaligned,
1519                                 bool mismatched,
1520                                 bool unsafe) {
1521   assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
1522   const TypePtr* adr_type = NULL;
1523   debug_only(adr_type = C->get_adr_type(adr_idx));
1524   Node *mem = memory(adr_idx);
1525   Node* st;
1526   if (require_atomic_access && bt == T_LONG) {
1527     st = StoreLNode::make_atomic(ctl, mem, adr, adr_type, val, mo);


1538   }
1539   if (unsafe) {
1540     st->as_Store()->set_unsafe_access();
1541   }
1542   st = _gvn.transform(st);
1543   set_memory(st, adr_idx);
1544   // Back-to-back stores can only remove intermediate store with DU info
1545   // so push on worklist for optimizer.
1546   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1547     record_for_igvn(st);
1548 
1549   return st;
1550 }
1551 
1552 Node* GraphKit::access_store_at(Node* obj,
1553                                 Node* adr,
1554                                 const TypePtr* adr_type,
1555                                 Node* val,
1556                                 const Type* val_type,
1557                                 BasicType bt,
1558                                 DecoratorSet decorators) {


1559   // Transformation of a value which could be NULL pointer (CastPP #NULL)
1560   // could be delayed during Parse (for example, in adjust_map_after_if()).
1561   // Execute transformation here to avoid barrier generation in such case.
1562   if (_gvn.type(val) == TypePtr::NULL_PTR) {
1563     val = _gvn.makecon(TypePtr::NULL_PTR);
1564   }
1565 
1566   if (stopped()) {
1567     return top(); // Dead path ?
1568   }
1569 
1570   assert(val != NULL, "not dead path");




1571 
1572   C2AccessValuePtr addr(adr, adr_type);
1573   C2AccessValue value(val, val_type);
1574   C2ParseAccess access(this, decorators | C2_WRITE_ACCESS, bt, obj, addr);
1575   if (access.is_raw()) {
1576     return _barrier_set->BarrierSetC2::store_at(access, value);
1577   } else {
1578     return _barrier_set->store_at(access, value);
1579   }
1580 }
1581 
1582 Node* GraphKit::access_load_at(Node* obj,   // containing obj
1583                                Node* adr,   // actual adress to store val at
1584                                const TypePtr* adr_type,
1585                                const Type* val_type,
1586                                BasicType bt,
1587                                DecoratorSet decorators) {

1588   if (stopped()) {
1589     return top(); // Dead path ?
1590   }
1591 
1592   C2AccessValuePtr addr(adr, adr_type);
1593   C2ParseAccess access(this, decorators | C2_READ_ACCESS, bt, obj, addr);
1594   if (access.is_raw()) {
1595     return _barrier_set->BarrierSetC2::load_at(access, val_type);
1596   } else {
1597     return _barrier_set->load_at(access, val_type);
1598   }
1599 }
1600 
1601 Node* GraphKit::access_load(Node* adr,   // actual adress to load val at
1602                             const Type* val_type,
1603                             BasicType bt,
1604                             DecoratorSet decorators) {
1605   if (stopped()) {
1606     return top(); // Dead path ?
1607   }
1608 
1609   C2AccessValuePtr addr(adr, NULL);
1610   C2ParseAccess access(this, decorators | C2_READ_ACCESS, bt, NULL, addr);
1611   if (access.is_raw()) {
1612     return _barrier_set->BarrierSetC2::load_at(access, val_type);
1613   } else {


1671   }
1672 }
1673 
1674 Node* GraphKit::access_atomic_add_at(Node* obj,
1675                                      Node* adr,
1676                                      const TypePtr* adr_type,
1677                                      int alias_idx,
1678                                      Node* new_val,
1679                                      const Type* value_type,
1680                                      BasicType bt,
1681                                      DecoratorSet decorators) {
1682   C2AccessValuePtr addr(adr, adr_type);
1683   C2AtomicParseAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS, bt, obj, addr, alias_idx);
1684   if (access.is_raw()) {
1685     return _barrier_set->BarrierSetC2::atomic_add_at(access, new_val, value_type);
1686   } else {
1687     return _barrier_set->atomic_add_at(access, new_val, value_type);
1688   }
1689 }
1690 
1691 void GraphKit::access_clone(Node* src, Node* dst, Node* size, bool is_array) {
1692   return _barrier_set->clone(this, src, dst, size, is_array);
1693 }
1694 
1695 Node* GraphKit::access_resolve(Node* n, DecoratorSet decorators) {
1696   // Use stronger ACCESS_WRITE|ACCESS_READ by default.
1697   if ((decorators & (ACCESS_READ | ACCESS_WRITE)) == 0) {
1698     decorators |= ACCESS_READ | ACCESS_WRITE;
1699   }
1700   return _barrier_set->resolve(this, n, decorators);
1701 }
1702 
1703 //-------------------------array_element_address-------------------------
1704 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,
1705                                       const TypeInt* sizetype, Node* ctrl) {
1706   uint shift  = exact_log2(type2aelembytes(elembt));





1707   uint header = arrayOopDesc::base_offset_in_bytes(elembt);
1708 
1709   // short-circuit a common case (saves lots of confusing waste motion)
1710   jint idx_con = find_int_con(idx, -1);
1711   if (idx_con >= 0) {
1712     intptr_t offset = header + ((intptr_t)idx_con << shift);
1713     return basic_plus_adr(ary, offset);
1714   }
1715 
1716   // must be correct type for alignment purposes
1717   Node* base  = basic_plus_adr(ary, header);
1718   idx = Compile::conv_I2X_index(&_gvn, idx, sizetype, ctrl);
1719   Node* scale = _gvn.transform( new LShiftXNode(idx, intcon(shift)) );
1720   return basic_plus_adr(ary, base, scale);
1721 }
1722 
1723 //-------------------------load_array_element-------------------------
1724 Node* GraphKit::load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype) {
1725   const Type* elemtype = arytype->elem();
1726   BasicType elembt = elemtype->array_element_basic_type();

1727   Node* adr = array_element_address(ary, idx, elembt, arytype->size());
1728   if (elembt == T_NARROWOOP) {
1729     elembt = T_OBJECT; // To satisfy switch in LoadNode::make()
1730   }
1731   Node* ld = make_load(ctl, adr, elemtype, elembt, arytype, MemNode::unordered);
1732   return ld;
1733 }
1734 
1735 //-------------------------set_arguments_for_java_call-------------------------
1736 // Arguments (pre-popped from the stack) are taken from the JVMS.
1737 void GraphKit::set_arguments_for_java_call(CallJavaNode* call) {
1738   // Add the call arguments:
1739   uint nargs = call->method()->arg_size();
1740   for (uint i = 0; i < nargs; i++) {
1741     Node* arg = argument(i);
1742     call->init_req(i + TypeFunc::Parms, arg);




























1743   }
1744 }
1745 
1746 //---------------------------set_edges_for_java_call---------------------------
1747 // Connect a newly created call into the current JVMS.
1748 // A return value node (if any) is returned from set_edges_for_java_call.
1749 void GraphKit::set_edges_for_java_call(CallJavaNode* call, bool must_throw, bool separate_io_proj) {
1750 
1751   // Add the predefined inputs:
1752   call->init_req( TypeFunc::Control, control() );
1753   call->init_req( TypeFunc::I_O    , i_o() );
1754   call->init_req( TypeFunc::Memory , reset_memory() );
1755   call->init_req( TypeFunc::FramePtr, frameptr() );
1756   call->init_req( TypeFunc::ReturnAdr, top() );
1757 
1758   add_safepoint_edges(call, must_throw);
1759 
1760   Node* xcall = _gvn.transform(call);
1761 
1762   if (xcall == top()) {
1763     set_control(top());
1764     return;
1765   }
1766   assert(xcall == call, "call identity is stable");
1767 
1768   // Re-use the current map to produce the result.
1769 
1770   set_control(_gvn.transform(new ProjNode(call, TypeFunc::Control)));
1771   set_i_o(    _gvn.transform(new ProjNode(call, TypeFunc::I_O    , separate_io_proj)));
1772   set_all_memory_call(xcall, separate_io_proj);
1773 
1774   //return xcall;   // no need, caller already has it
1775 }
1776 
1777 Node* GraphKit::set_results_for_java_call(CallJavaNode* call, bool separate_io_proj, bool deoptimize) {
1778   if (stopped())  return top();  // maybe the call folded up?
1779 
1780   // Capture the return value, if any.
1781   Node* ret;
1782   if (call->method() == NULL ||
1783       call->method()->return_type()->basic_type() == T_VOID)
1784         ret = top();
1785   else  ret = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
1786 
1787   // Note:  Since any out-of-line call can produce an exception,
1788   // we always insert an I_O projection from the call into the result.
1789 
1790   make_slow_call_ex(call, env()->Throwable_klass(), separate_io_proj, deoptimize);
1791 
1792   if (separate_io_proj) {
1793     // The caller requested separate projections be used by the fall
1794     // through and exceptional paths, so replace the projections for
1795     // the fall through path.
1796     set_i_o(_gvn.transform( new ProjNode(call, TypeFunc::I_O) ));
1797     set_all_memory(_gvn.transform( new ProjNode(call, TypeFunc::Memory) ));
1798   }



















1799   return ret;
1800 }
1801 
1802 //--------------------set_predefined_input_for_runtime_call--------------------
1803 // Reading and setting the memory state is way conservative here.
1804 // The real problem is that I am not doing real Type analysis on memory,
1805 // so I cannot distinguish card mark stores from other stores.  Across a GC
1806 // point the Store Barrier and the card mark memory has to agree.  I cannot
1807 // have a card mark store and its barrier split across the GC point from
1808 // either above or below.  Here I get that to happen by reading ALL of memory.
1809 // A better answer would be to separate out card marks from other memory.
1810 // For now, return the input memory state, so that it can be reused
1811 // after the call, if this call has restricted memory effects.
1812 Node* GraphKit::set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem) {
1813   // Set fixed predefined input arguments
1814   Node* memory = reset_memory();
1815   Node* m = narrow_mem == NULL ? memory : narrow_mem;
1816   call->init_req( TypeFunc::Control,   control()  );
1817   call->init_req( TypeFunc::I_O,       top()      ); // does no i/o
1818   call->init_req( TypeFunc::Memory,    m          ); // may gc ptrs


1869     if (use->is_MergeMem()) {
1870       wl.push(use);
1871     }
1872   }
1873 }
1874 
1875 // Replace the call with the current state of the kit.
1876 void GraphKit::replace_call(CallNode* call, Node* result, bool do_replaced_nodes) {
1877   JVMState* ejvms = NULL;
1878   if (has_exceptions()) {
1879     ejvms = transfer_exceptions_into_jvms();
1880   }
1881 
1882   ReplacedNodes replaced_nodes = map()->replaced_nodes();
1883   ReplacedNodes replaced_nodes_exception;
1884   Node* ex_ctl = top();
1885 
1886   SafePointNode* final_state = stop();
1887 
1888   // Find all the needed outputs of this call
1889   CallProjections callprojs;
1890   call->extract_projections(&callprojs, true);
1891 
1892   Unique_Node_List wl;
1893   Node* init_mem = call->in(TypeFunc::Memory);
1894   Node* final_mem = final_state->in(TypeFunc::Memory);
1895   Node* final_ctl = final_state->in(TypeFunc::Control);
1896   Node* final_io = final_state->in(TypeFunc::I_O);
1897 
1898   // Replace all the old call edges with the edges from the inlining result
1899   if (callprojs.fallthrough_catchproj != NULL) {
1900     C->gvn_replace_by(callprojs.fallthrough_catchproj, final_ctl);
1901   }
1902   if (callprojs.fallthrough_memproj != NULL) {
1903     if (final_mem->is_MergeMem()) {
1904       // Parser's exits MergeMem was not transformed but may be optimized
1905       final_mem = _gvn.transform(final_mem);
1906     }
1907     C->gvn_replace_by(callprojs.fallthrough_memproj,   final_mem);
1908     add_mergemem_users_to_worklist(wl, final_mem);
1909   }
1910   if (callprojs.fallthrough_ioproj != NULL) {
1911     C->gvn_replace_by(callprojs.fallthrough_ioproj,    final_io);
1912   }
1913 
1914   // Replace the result with the new result if it exists and is used
1915   if (callprojs.resproj != NULL && result != NULL) {
1916     C->gvn_replace_by(callprojs.resproj, result);

1917   }
1918 
1919   if (ejvms == NULL) {
1920     // No exception edges to simply kill off those paths
1921     if (callprojs.catchall_catchproj != NULL) {
1922       C->gvn_replace_by(callprojs.catchall_catchproj, C->top());
1923     }
1924     if (callprojs.catchall_memproj != NULL) {
1925       C->gvn_replace_by(callprojs.catchall_memproj,   C->top());
1926     }
1927     if (callprojs.catchall_ioproj != NULL) {
1928       C->gvn_replace_by(callprojs.catchall_ioproj,    C->top());
1929     }
1930     // Replace the old exception object with top
1931     if (callprojs.exobj != NULL) {
1932       C->gvn_replace_by(callprojs.exobj, C->top());
1933     }
1934   } else {
1935     GraphKit ekit(ejvms);
1936 
1937     // Load my combined exception state into the kit, with all phis transformed:
1938     SafePointNode* ex_map = ekit.combine_and_pop_all_exception_states();
1939     replaced_nodes_exception = ex_map->replaced_nodes();
1940 
1941     Node* ex_oop = ekit.use_exception_state(ex_map);
1942 
1943     if (callprojs.catchall_catchproj != NULL) {
1944       C->gvn_replace_by(callprojs.catchall_catchproj, ekit.control());
1945       ex_ctl = ekit.control();
1946     }
1947     if (callprojs.catchall_memproj != NULL) {
1948       Node* ex_mem = ekit.reset_memory();
1949       C->gvn_replace_by(callprojs.catchall_memproj,   ex_mem);
1950       add_mergemem_users_to_worklist(wl, ex_mem);
1951     }
1952     if (callprojs.catchall_ioproj != NULL) {
1953       C->gvn_replace_by(callprojs.catchall_ioproj,    ekit.i_o());
1954     }
1955 
1956     // Replace the old exception object with the newly created one
1957     if (callprojs.exobj != NULL) {
1958       C->gvn_replace_by(callprojs.exobj, ex_oop);
1959     }
1960   }
1961 
1962   // Disconnect the call from the graph
1963   call->disconnect_inputs(NULL, C);
1964   C->gvn_replace_by(call, C->top());
1965 
1966   // Clean up any MergeMems that feed other MergeMems since the
1967   // optimizer doesn't like that.
1968   while (wl.size() > 0) {
1969     _gvn.transform(wl.pop());
1970   }
1971 
1972   if (callprojs.fallthrough_catchproj != NULL && !final_ctl->is_top() && do_replaced_nodes) {
1973     replaced_nodes.apply(C, final_ctl);
1974   }
1975   if (!ex_ctl->is_top() && do_replaced_nodes) {
1976     replaced_nodes_exception.apply(C, ex_ctl);
1977   }
1978 }
1979 
1980 
1981 //------------------------------increment_counter------------------------------
1982 // for statistics: increment a VM counter by 1
1983 
1984 void GraphKit::increment_counter(address counter_addr) {
1985   Node* adr1 = makecon(TypeRawPtr::make(counter_addr));
1986   increment_counter(adr1);
1987 }
1988 
1989 void GraphKit::increment_counter(Node* counter_addr) {
1990   int adr_type = Compile::AliasIdxRaw;
1991   Node* ctrl = control();
1992   Node* cnt  = make_load(ctrl, counter_addr, TypeInt::INT, T_INT, adr_type, MemNode::unordered);


2129 // it does not require card marks.
2130 Node* GraphKit::just_allocated_object(Node* current_control) {
2131   Node* ctrl = current_control;
2132   // Object::<init> is invoked after allocation, most of invoke nodes
2133   // will be reduced, but a region node is kept in parse time, we check
2134   // the pattern and skip the region node if it degraded to a copy.
2135   if (ctrl != NULL && ctrl->is_Region() && ctrl->req() == 2 &&
2136       ctrl->as_Region()->is_copy()) {
2137     ctrl = ctrl->as_Region()->is_copy();
2138   }
2139   if (C->recent_alloc_ctl() == ctrl) {
2140    return C->recent_alloc_obj();
2141   }
2142   return NULL;
2143 }
2144 
2145 
2146 void GraphKit::round_double_arguments(ciMethod* dest_method) {
2147   // (Note:  TypeFunc::make has a cache that makes this fast.)
2148   const TypeFunc* tf    = TypeFunc::make(dest_method);
2149   int             nargs = tf->domain()->cnt() - TypeFunc::Parms;
2150   for (int j = 0; j < nargs; j++) {
2151     const Type *targ = tf->domain()->field_at(j + TypeFunc::Parms);
2152     if( targ->basic_type() == T_DOUBLE ) {
2153       // If any parameters are doubles, they must be rounded before
2154       // the call, dstore_rounding does gvn.transform
2155       Node *arg = argument(j);
2156       arg = dstore_rounding(arg);
2157       set_argument(j, arg);
2158     }
2159   }
2160 }
2161 
2162 /**
2163  * Record profiling data exact_kls for Node n with the type system so
2164  * that it can propagate it (speculation)
2165  *
2166  * @param n          node that the type applies to
2167  * @param exact_kls  type from profiling
2168  * @param maybe_null did profiling see null?
2169  *
2170  * @return           node with improved type
2171  */


2188     speculative = speculative->with_inline_depth(jvms()->depth());
2189   } else if (current_type->would_improve_ptr(ptr_kind)) {
2190     // Profiling report that null was never seen so we can change the
2191     // speculative type to non null ptr.
2192     if (ptr_kind == ProfileAlwaysNull) {
2193       speculative = TypePtr::NULL_PTR;
2194     } else {
2195       assert(ptr_kind == ProfileNeverNull, "nothing else is an improvement");
2196       const TypePtr* ptr = TypePtr::NOTNULL;
2197       if (speculative != NULL) {
2198         speculative = speculative->cast_to_ptr_type(ptr->ptr())->is_ptr();
2199       } else {
2200         speculative = ptr;
2201       }
2202     }
2203   }
2204 
2205   if (speculative != current_type->speculative()) {
2206     // Build a type with a speculative type (what we think we know
2207     // about the type but will need a guard when we use it)
2208     const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::OffsetBot, TypeOopPtr::InstanceBot, speculative);
2209     // We're changing the type, we need a new CheckCast node to carry
2210     // the new type. The new type depends on the control: what
2211     // profiling tells us is only valid from here as far as we can
2212     // tell.
2213     Node* cast = new CheckCastPPNode(control(), n, current_type->remove_speculative()->join_speculative(spec_type));
2214     cast = _gvn.transform(cast);
2215     replace_in_map(n, cast);
2216     n = cast;
2217   }
2218 
2219   return n;
2220 }
2221 
2222 /**
2223  * Record profiling data from receiver profiling at an invoke with the
2224  * type system so that it can propagate it (speculation)
2225  *
2226  * @param n  receiver node
2227  *
2228  * @return   node with improved type


2253         }
2254         ptr_kind = (i == call->row_limit()) ? ProfileAlwaysNull : ProfileMaybeNull;
2255       }
2256     }
2257   }
2258   return record_profile_for_speculation(n, exact_kls, ptr_kind);
2259 }
2260 
2261 /**
2262  * Record profiling data from argument profiling at an invoke with the
2263  * type system so that it can propagate it (speculation)
2264  *
2265  * @param dest_method  target method for the call
2266  * @param bc           what invoke bytecode is this?
2267  */
2268 void GraphKit::record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc) {
2269   if (!UseTypeSpeculation) {
2270     return;
2271   }
2272   const TypeFunc* tf    = TypeFunc::make(dest_method);
2273   int             nargs = tf->domain()->cnt() - TypeFunc::Parms;
2274   int skip = Bytecodes::has_receiver(bc) ? 1 : 0;
2275   for (int j = skip, i = 0; j < nargs && i < TypeProfileArgsLimit; j++) {
2276     const Type *targ = tf->domain()->field_at(j + TypeFunc::Parms);
2277     if (targ->basic_type() == T_OBJECT || targ->basic_type() == T_ARRAY) {
2278       ProfilePtrKind ptr_kind = ProfileMaybeNull;
2279       ciKlass* better_type = NULL;
2280       if (method()->argument_profiled_type(bci(), i, better_type, ptr_kind)) {
2281         record_profile_for_speculation(argument(j), better_type, ptr_kind);
2282       }
2283       i++;
2284     }
2285   }
2286 }
2287 
2288 /**
2289  * Record profiling data from parameter profiling at an invoke with
2290  * the type system so that it can propagate it (speculation)
2291  */
2292 void GraphKit::record_profiled_parameters_for_speculation() {
2293   if (!UseTypeSpeculation) {
2294     return;
2295   }
2296   for (int i = 0, j = 0; i < method()->arg_size() ; i++) {
2297     if (_gvn.type(local(i))->isa_oopptr()) {


2772   // The decision to inline or out-of-line this final check is platform
2773   // dependent, and is found in the AD file definition of PartialSubtypeCheck.
2774   Node* psc = gvn->transform(
2775     new PartialSubtypeCheckNode(*ctrl, subklass, superklass));
2776 
2777   IfNode *iff4 = gen_subtype_check_compare(*ctrl, psc, gvn->zerocon(T_OBJECT), BoolTest::ne, PROB_FAIR, gvn, T_ADDRESS);
2778   r_not_subtype->init_req(2, gvn->transform(new IfTrueNode (iff4)));
2779   r_ok_subtype ->init_req(3, gvn->transform(new IfFalseNode(iff4)));
2780 
2781   // Return false path; set default control to true path.
2782   *ctrl = gvn->transform(r_ok_subtype);
2783   return gvn->transform(r_not_subtype);
2784 }
2785 
2786 // Profile-driven exact type check:
2787 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
2788                                     float prob,
2789                                     Node* *casted_receiver) {
2790   const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2791   Node* recv_klass = load_object_klass(receiver);
2792   Node* want_klass = makecon(tklass);
2793   Node* cmp = _gvn.transform( new CmpPNode(recv_klass, want_klass) );
2794   Node* bol = _gvn.transform( new BoolNode(cmp, BoolTest::eq) );
2795   IfNode* iff = create_and_xform_if(control(), bol, prob, COUNT_UNKNOWN);
2796   set_control( _gvn.transform( new IfTrueNode (iff) ));
2797   Node* fail = _gvn.transform( new IfFalseNode(iff) );
2798 
2799   const TypeOopPtr* recv_xtype = tklass->as_instance_type();
2800   assert(recv_xtype->klass_is_exact(), "");
2801 
2802   // Subsume downstream occurrences of receiver with a cast to
2803   // recv_xtype, since now we know what the type will be.
2804   Node* cast = new CheckCastPPNode(control(), receiver, recv_xtype);
2805   (*casted_receiver) = _gvn.transform(cast);






2806   // (User must make the replace_in_map call.)
2807 
2808   return fail;
2809 }
2810 











2811 //------------------------------subtype_check_receiver-------------------------
2812 Node* GraphKit::subtype_check_receiver(Node* receiver, ciKlass* klass,
2813                                        Node** casted_receiver) {
2814   const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2815   Node* recv_klass = load_object_klass(receiver);
2816   Node* want_klass = makecon(tklass);
2817 
2818   Node* slow_ctl = gen_subtype_check(recv_klass, want_klass);
2819 
2820   // Cast receiver after successful check
2821   const TypeOopPtr* recv_type = tklass->cast_to_exactness(false)->is_klassptr()->as_instance_type();
2822   Node* cast = new CheckCastPPNode(control(), receiver, recv_type);
2823   (*casted_receiver) = _gvn.transform(cast);
2824 
2825   return slow_ctl;
2826 }
2827 
2828 //------------------------------seems_never_null-------------------------------
2829 // Use null_seen information if it is available from the profile.
2830 // If we see an unexpected null at a type check we record it and force a


3015 // and the reflective instance-of call.
3016 Node* GraphKit::gen_instanceof(Node* obj, Node* superklass, bool safe_for_replace) {
3017   kill_dead_locals();           // Benefit all the uncommon traps
3018   assert( !stopped(), "dead parse path should be checked in callers" );
3019   assert(!TypePtr::NULL_PTR->higher_equal(_gvn.type(superklass)->is_klassptr()),
3020          "must check for not-null not-dead klass in callers");
3021 
3022   // Make the merge point
3023   enum { _obj_path = 1, _fail_path, _null_path, PATH_LIMIT };
3024   RegionNode* region = new RegionNode(PATH_LIMIT);
3025   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
3026   C->set_has_split_ifs(true); // Has chance for split-if optimization
3027 
3028   ciProfileData* data = NULL;
3029   if (java_bc() == Bytecodes::_instanceof) {  // Only for the bytecode
3030     data = method()->method_data()->bci_to_data(bci());
3031   }
3032   bool speculative_not_null = false;
3033   bool never_see_null = (ProfileDynamicTypes  // aggressive use of profile
3034                          && seems_never_null(obj, data, speculative_not_null));

3035 
3036   // Null check; get casted pointer; set region slot 3
3037   Node* null_ctl = top();
3038   Node* not_null_obj = null_check_oop(obj, &null_ctl, never_see_null, safe_for_replace, speculative_not_null);
3039 
3040   // If not_null_obj is dead, only null-path is taken
3041   if (stopped()) {              // Doing instance-of on a NULL?
3042     set_control(null_ctl);
3043     return intcon(0);
3044   }
3045   region->init_req(_null_path, null_ctl);
3046   phi   ->init_req(_null_path, intcon(0)); // Set null path value
3047   if (null_ctl == top()) {
3048     // Do this eagerly, so that pattern matches like is_diamond_phi
3049     // will work even during parsing.
3050     assert(_null_path == PATH_LIMIT-1, "delete last");
3051     region->del_req(_null_path);
3052     phi   ->del_req(_null_path);
3053   }
3054 
3055   // Do we know the type check always succeed?
3056   bool known_statically = false;
3057   if (_gvn.type(superklass)->singleton()) {
3058     ciKlass* superk = _gvn.type(superklass)->is_klassptr()->klass();
3059     ciKlass* subk = _gvn.type(obj)->is_oopptr()->klass();
3060     if (subk != NULL && subk->is_loaded()) {
3061       int static_res = C->static_subtype_check(superk, subk);
3062       known_statically = (static_res == Compile::SSC_always_true || static_res == Compile::SSC_always_false);


3063     }
3064   }
3065 
3066   if (!known_statically) {
3067     const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
3068     // We may not have profiling here or it may not help us. If we
3069     // have a speculative type use it to perform an exact cast.
3070     ciKlass* spec_obj_type = obj_type->speculative_type();
3071     if (spec_obj_type != NULL || (ProfileDynamicTypes && data != NULL)) {
3072       Node* cast_obj = maybe_cast_profiled_receiver(not_null_obj, NULL, spec_obj_type, safe_for_replace);
3073       if (stopped()) {            // Profile disagrees with this path.
3074         set_control(null_ctl);    // Null is the only remaining possibility.
3075         return intcon(0);
3076       }
3077       if (cast_obj != NULL) {
3078         not_null_obj = cast_obj;




3079       }
3080     }
3081   }
3082 
3083   // Load the object's klass
3084   Node* obj_klass = load_object_klass(not_null_obj);





3085 
3086   // Generate the subtype check
3087   Node* not_subtype_ctrl = gen_subtype_check(obj_klass, superklass);
3088 
3089   // Plug in the success path to the general merge in slot 1.
3090   region->init_req(_obj_path, control());
3091   phi   ->init_req(_obj_path, intcon(1));
3092 
3093   // Plug in the failing path to the general merge in slot 2.
3094   region->init_req(_fail_path, not_subtype_ctrl);
3095   phi   ->init_req(_fail_path, intcon(0));
3096 
3097   // Return final merged results
3098   set_control( _gvn.transform(region) );
3099   record_for_igvn(region);
3100 
3101   // If we know the type check always succeeds then we don't use the
3102   // profiling data at this bytecode. Don't lose it, feed it to the
3103   // type system as a speculative type.
3104   if (safe_for_replace) {
3105     Node* casted_obj = record_profiled_receiver_for_speculation(obj);
3106     replace_in_map(obj, casted_obj);
3107   }
3108 
3109   return _gvn.transform(phi);
3110 }
3111 
3112 //-------------------------------gen_checkcast---------------------------------
3113 // Generate a checkcast idiom.  Used by both the checkcast bytecode and the
3114 // array store bytecode.  Stack must be as-if BEFORE doing the bytecode so the
3115 // uncommon-trap paths work.  Adjust stack after this call.
3116 // If failure_control is supplied and not null, it is filled in with
3117 // the control edge for the cast failure.  Otherwise, an appropriate
3118 // uncommon trap or exception is thrown.
3119 Node* GraphKit::gen_checkcast(Node *obj, Node* superklass,
3120                               Node* *failure_control) {
3121   kill_dead_locals();           // Benefit all the uncommon traps
3122   const TypeKlassPtr *tk = _gvn.type(superklass)->is_klassptr();
3123   const Type *toop = TypeOopPtr::make_from_klass(tk->klass());


3124 
3125   // Fast cutout:  Check the case that the cast is vacuously true.
3126   // This detects the common cases where the test will short-circuit
3127   // away completely.  We do this before we perform the null check,
3128   // because if the test is going to turn into zero code, we don't
3129   // want a residual null check left around.  (Causes a slowdown,
3130   // for example, in some objArray manipulations, such as a[i]=a[j].)
3131   if (tk->singleton()) {
3132     const TypeOopPtr* objtp = _gvn.type(obj)->isa_oopptr();
3133     if (objtp != NULL && objtp->klass() != NULL) {
3134       switch (C->static_subtype_check(tk->klass(), objtp->klass())) {








3135       case Compile::SSC_always_true:
3136         // If we know the type check always succeed then we don't use
3137         // the profiling data at this bytecode. Don't lose it, feed it
3138         // to the type system as a speculative type.
3139         return record_profiled_receiver_for_speculation(obj);









3140       case Compile::SSC_always_false:
3141         // It needs a null check because a null will *pass* the cast check.
3142         // A non-null value will always produce an exception.
3143         return null_assert(obj);








3144       }
3145     }
3146   }
3147 
3148   ciProfileData* data = NULL;
3149   bool safe_for_replace = false;
3150   if (failure_control == NULL) {        // use MDO in regular case only
3151     assert(java_bc() == Bytecodes::_aastore ||
3152            java_bc() == Bytecodes::_checkcast,
3153            "interpreter profiles type checks only for these BCs");
3154     data = method()->method_data()->bci_to_data(bci());
3155     safe_for_replace = true;
3156   }
3157 
3158   // Make the merge point
3159   enum { _obj_path = 1, _null_path, PATH_LIMIT };
3160   RegionNode* region = new RegionNode(PATH_LIMIT);
3161   Node*       phi    = new PhiNode(region, toop);



3162   C->set_has_split_ifs(true); // Has chance for split-if optimization
3163 
3164   // Use null-cast information if it is available
3165   bool speculative_not_null = false;
3166   bool never_see_null = ((failure_control == NULL)  // regular case only
3167                          && seems_never_null(obj, data, speculative_not_null));
3168 
3169   // Null check; get casted pointer; set region slot 3
3170   Node* null_ctl = top();
3171   Node* not_null_obj = null_check_oop(obj, &null_ctl, never_see_null, safe_for_replace, speculative_not_null);







3172 
3173   // If not_null_obj is dead, only null-path is taken
3174   if (stopped()) {              // Doing instance-of on a NULL?
3175     set_control(null_ctl);
3176     return null();
3177   }
3178   region->init_req(_null_path, null_ctl);
3179   phi   ->init_req(_null_path, null());  // Set null path value
3180   if (null_ctl == top()) {
3181     // Do this eagerly, so that pattern matches like is_diamond_phi
3182     // will work even during parsing.
3183     assert(_null_path == PATH_LIMIT-1, "delete last");
3184     region->del_req(_null_path);
3185     phi   ->del_req(_null_path);
3186   }
3187 
3188   Node* cast_obj = NULL;
3189   if (tk->klass_is_exact()) {
3190     // The following optimization tries to statically cast the speculative type of the object
3191     // (for example obtained during profiling) to the type of the superklass and then do a
3192     // dynamic check that the type of the object is what we expect. To work correctly
3193     // for checkcast and aastore the type of superklass should be exact.
3194     const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
3195     // We may not have profiling here or it may not help us. If we have
3196     // a speculative type use it to perform an exact cast.
3197     ciKlass* spec_obj_type = obj_type->speculative_type();
3198     if (spec_obj_type != NULL || data != NULL) {
3199       cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace);







3200       if (cast_obj != NULL) {
3201         if (failure_control != NULL) // failure is now impossible
3202           (*failure_control) = top();
3203         // adjust the type of the phi to the exact klass:
3204         phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR));
3205       }
3206     }
3207   }
3208 
3209   if (cast_obj == NULL) {
3210     // Load the object's klass
3211     Node* obj_klass = load_object_klass(not_null_obj);





3212 
3213     // Generate the subtype check
3214     Node* not_subtype_ctrl = gen_subtype_check( obj_klass, superklass );
3215 
3216     // Plug in success path into the merge
3217     cast_obj = _gvn.transform(new CheckCastPPNode(control(), not_null_obj, toop));
3218     // Failure path ends in uncommon trap (or may be dead - failure impossible)
3219     if (failure_control == NULL) {
3220       if (not_subtype_ctrl != top()) { // If failure is possible
3221         PreserveJVMState pjvms(this);
3222         set_control(not_subtype_ctrl);
3223         builtin_throw(Deoptimization::Reason_class_check, obj_klass);
3224       }
3225     } else {
3226       (*failure_control) = not_subtype_ctrl;
3227     }
3228   }
3229 
3230   region->init_req(_obj_path, control());
3231   phi   ->init_req(_obj_path, cast_obj);
3232 
3233   // A merge of NULL or Casted-NotNull obj
3234   Node* res = _gvn.transform(phi);
3235 
3236   // Note I do NOT always 'replace_in_map(obj,result)' here.
3237   //  if( tk->klass()->can_be_primary_super()  )
3238     // This means that if I successfully store an Object into an array-of-String
3239     // I 'forget' that the Object is really now known to be a String.  I have to
3240     // do this because we don't have true union types for interfaces - if I store
3241     // a Baz into an array-of-Interface and then tell the optimizer it's an
3242     // Interface, I forget that it's also a Baz and cannot do Baz-like field
3243     // references to it.  FIX THIS WHEN UNION TYPES APPEAR!
3244   //  replace_in_map( obj, res );
3245 
3246   // Return final merged results
3247   set_control( _gvn.transform(region) );
3248   record_for_igvn(region);
3249 
3250   return record_profiled_receiver_for_speculation(res);













































































































































3251 }
3252 








3253 //------------------------------next_monitor-----------------------------------
3254 // What number should be given to the next monitor?
3255 int GraphKit::next_monitor() {
3256   int current = jvms()->monitor_depth()* C->sync_stack_slots();
3257   int next = current + C->sync_stack_slots();
3258   // Keep the toplevel high water mark current:
3259   if (C->fixed_slots() < next)  C->set_fixed_slots(next);
3260   return current;
3261 }
3262 
3263 //------------------------------insert_mem_bar---------------------------------
3264 // Memory barrier to avoid floating things around
3265 // The membar serves as a pinch point between both control and all memory slices.
3266 Node* GraphKit::insert_mem_bar(int opcode, Node* precedent) {
3267   MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent);
3268   mb->init_req(TypeFunc::Control, control());
3269   mb->init_req(TypeFunc::Memory,  reset_memory());
3270   Node* membar = _gvn.transform(mb);
3271   set_control(_gvn.transform(new ProjNode(membar, TypeFunc::Control)));
3272   set_all_memory_call(membar);


3310   Node* mem = reset_memory();
3311   MemBarNode* mb = MemBarNode::make(C, Op_MemBarVolatile, Compile::AliasIdxRaw);
3312   mb->init_req(TypeFunc::Control, control());
3313   mb->init_req(TypeFunc::Memory, mem);
3314   Node* membar = _gvn.transform(mb);
3315   set_control(_gvn.transform(new ProjNode(membar, TypeFunc::Control)));
3316   Node* newmem = _gvn.transform(new ProjNode(membar, TypeFunc::Memory));
3317   set_all_memory(mem);
3318   set_memory(newmem, Compile::AliasIdxRaw);
3319 }
3320 
3321 //------------------------------shared_lock------------------------------------
3322 // Emit locking code.
3323 FastLockNode* GraphKit::shared_lock(Node* obj) {
3324   // bci is either a monitorenter bc or InvocationEntryBci
3325   // %%% SynchronizationEntryBCI is redundant; use InvocationEntryBci in interfaces
3326   assert(SynchronizationEntryBCI == InvocationEntryBci, "");
3327 
3328   if( !GenerateSynchronizationCode )
3329     return NULL;                // Not locking things?

3330   if (stopped())                // Dead monitor?
3331     return NULL;
3332 
3333   assert(dead_locals_are_killed(), "should kill locals before sync. point");
3334 
3335   obj = access_resolve(obj, ACCESS_READ | ACCESS_WRITE);
3336 
3337   // Box the stack location
3338   Node* box = _gvn.transform(new BoxLockNode(next_monitor()));
3339   Node* mem = reset_memory();
3340 
3341   FastLockNode * flock = _gvn.transform(new FastLockNode(0, obj, box) )->as_FastLock();
3342   if (UseBiasedLocking && PrintPreciseBiasedLockingStatistics) {
3343     // Create the counters for this fast lock.
3344     flock->create_lock_counter(sync_jvms()); // sync_jvms used to get current bci
3345   }
3346 
3347   // Create the rtm counters for this fast lock if needed.
3348   flock->create_rtm_lock_counter(sync_jvms()); // sync_jvms used to get current bci
3349 


3384   }
3385 #endif
3386 
3387   return flock;
3388 }
3389 
3390 
3391 //------------------------------shared_unlock----------------------------------
3392 // Emit unlocking code.
3393 void GraphKit::shared_unlock(Node* box, Node* obj) {
3394   // bci is either a monitorenter bc or InvocationEntryBci
3395   // %%% SynchronizationEntryBCI is redundant; use InvocationEntryBci in interfaces
3396   assert(SynchronizationEntryBCI == InvocationEntryBci, "");
3397 
3398   if( !GenerateSynchronizationCode )
3399     return;
3400   if (stopped()) {               // Dead monitor?
3401     map()->pop_monitor();        // Kill monitor from debug info
3402     return;
3403   }

3404 
3405   // Memory barrier to avoid floating things down past the locked region
3406   insert_mem_bar(Op_MemBarReleaseLock);
3407 
3408   const TypeFunc *tf = OptoRuntime::complete_monitor_exit_Type();
3409   UnlockNode *unlock = new UnlockNode(C, tf);
3410 #ifdef ASSERT
3411   unlock->set_dbg_jvms(sync_jvms());
3412 #endif
3413   uint raw_idx = Compile::AliasIdxRaw;
3414   unlock->init_req( TypeFunc::Control, control() );
3415   unlock->init_req( TypeFunc::Memory , memory(raw_idx) );
3416   unlock->init_req( TypeFunc::I_O    , top() )     ;   // does no i/o
3417   unlock->init_req( TypeFunc::FramePtr, frameptr() );
3418   unlock->init_req( TypeFunc::ReturnAdr, top() );
3419 
3420   unlock->init_req(TypeFunc::Parms + 0, obj);
3421   unlock->init_req(TypeFunc::Parms + 1, box);
3422   unlock = _gvn.transform(unlock)->as_Unlock();
3423 
3424   Node* mem = reset_memory();
3425 
3426   // unlock has no side-effects, sets few values
3427   set_predefined_output_for_runtime_call(unlock, mem, TypeRawPtr::BOTTOM);
3428 
3429   // Kill monitor from debug info
3430   map()->pop_monitor( );
3431 }
3432 
3433 //-------------------------------get_layout_helper-----------------------------
3434 // If the given klass is a constant or known to be an array,
3435 // fetch the constant layout helper value into constant_value
3436 // and return (Node*)NULL.  Otherwise, load the non-constant
3437 // layout helper value, and return the node which represents it.
3438 // This two-faced routine is useful because allocation sites
3439 // almost always feature constant types.
3440 Node* GraphKit::get_layout_helper(Node* klass_node, jint& constant_value) {
3441   const TypeKlassPtr* inst_klass = _gvn.type(klass_node)->isa_klassptr();
3442   if (!StressReflectiveCode && inst_klass != NULL) {
3443     ciKlass* klass = inst_klass->klass();

3444     bool    xklass = inst_klass->klass_is_exact();
3445     if (xklass || klass->is_array_klass()) {





3446       jint lhelper = klass->layout_helper();
3447       if (lhelper != Klass::_lh_neutral_value) {
3448         constant_value = lhelper;
3449         return (Node*) NULL;
3450       }
3451     }
3452   }
3453   constant_value = Klass::_lh_neutral_value;  // put in a known value
3454   Node* lhp = basic_plus_adr(klass_node, klass_node, in_bytes(Klass::layout_helper_offset()));
3455   return make_load(NULL, lhp, TypeInt::INT, T_INT, MemNode::unordered);
3456 }
3457 
3458 // We just put in an allocate/initialize with a big raw-memory effect.
3459 // Hook selected additional alias categories on the initialization.
3460 static void hook_memory_on_init(GraphKit& kit, int alias_idx,
3461                                 MergeMemNode* init_in_merge,
3462                                 Node* init_out_raw) {
3463   DEBUG_ONLY(Node* init_in_raw = init_in_merge->base_memory());
3464   assert(init_in_merge->memory_at(alias_idx) == init_in_raw, "");
3465 


3487 
3488   // a normal slow-call doesn't change i_o, but an allocation does
3489   // we create a separate i_o projection for the normal control path
3490   set_i_o(_gvn.transform( new ProjNode(allocx, TypeFunc::I_O, false) ) );
3491   Node* rawoop = _gvn.transform( new ProjNode(allocx, TypeFunc::Parms) );
3492 
3493   // put in an initialization barrier
3494   InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, rawidx,
3495                                                  rawoop)->as_Initialize();
3496   assert(alloc->initialization() == init,  "2-way macro link must work");
3497   assert(init ->allocation()     == alloc, "2-way macro link must work");
3498   {
3499     // Extract memory strands which may participate in the new object's
3500     // initialization, and source them from the new InitializeNode.
3501     // This will allow us to observe initializations when they occur,
3502     // and link them properly (as a group) to the InitializeNode.
3503     assert(init->in(InitializeNode::Memory) == malloc, "");
3504     MergeMemNode* minit_in = MergeMemNode::make(malloc);
3505     init->set_req(InitializeNode::Memory, minit_in);
3506     record_for_igvn(minit_in); // fold it up later, if possible

3507     Node* minit_out = memory(rawidx);
3508     assert(minit_out->is_Proj() && minit_out->in(0) == init, "");
3509     // Add an edge in the MergeMem for the header fields so an access
3510     // to one of those has correct memory state
3511     set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::mark_offset_in_bytes())));
3512     set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::klass_offset_in_bytes())));
3513     if (oop_type->isa_aryptr()) {
3514       const TypePtr* telemref = oop_type->add_offset(Type::OffsetBot);
3515       int            elemidx  = C->get_alias_index(telemref);
3516       hook_memory_on_init(*this, elemidx, minit_in, minit_out);























3517     } else if (oop_type->isa_instptr()) {

3518       ciInstanceKlass* ik = oop_type->klass()->as_instance_klass();
3519       for (int i = 0, len = ik->nof_nonstatic_fields(); i < len; i++) {
3520         ciField* field = ik->nonstatic_field_at(i);
3521         if (field->offset() >= TrackedInitializationLimit * HeapWordSize)
3522           continue;  // do not bother to track really large numbers of fields
3523         // Find (or create) the alias category for this field:
3524         int fieldidx = C->alias_type(field)->index();
3525         hook_memory_on_init(*this, fieldidx, minit_in, minit_out);
3526       }
3527     }
3528   }
3529 
3530   // Cast raw oop to the real thing...
3531   Node* javaoop = new CheckCastPPNode(control(), rawoop, oop_type);
3532   javaoop = _gvn.transform(javaoop);
3533   C->set_recent_alloc(control(), javaoop);
3534   assert(just_allocated_object(control()) == javaoop, "just allocated");
3535 
3536 #ifdef ASSERT
3537   { // Verify that the AllocateNode::Ideal_allocation recognizers work:


3548       assert(alloc->in(AllocateNode::ALength)->is_top(), "no length, please");
3549     }
3550   }
3551 #endif //ASSERT
3552 
3553   return javaoop;
3554 }
3555 
3556 //---------------------------new_instance--------------------------------------
3557 // This routine takes a klass_node which may be constant (for a static type)
3558 // or may be non-constant (for reflective code).  It will work equally well
3559 // for either, and the graph will fold nicely if the optimizer later reduces
3560 // the type to a constant.
3561 // The optional arguments are for specialized use by intrinsics:
3562 //  - If 'extra_slow_test' if not null is an extra condition for the slow-path.
3563 //  - If 'return_size_val', report the the total object size to the caller.
3564 //  - deoptimize_on_exception controls how Java exceptions are handled (rethrow vs deoptimize)
3565 Node* GraphKit::new_instance(Node* klass_node,
3566                              Node* extra_slow_test,
3567                              Node* *return_size_val,
3568                              bool deoptimize_on_exception) {

3569   // Compute size in doublewords
3570   // The size is always an integral number of doublewords, represented
3571   // as a positive bytewise size stored in the klass's layout_helper.
3572   // The layout_helper also encodes (in a low bit) the need for a slow path.
3573   jint  layout_con = Klass::_lh_neutral_value;
3574   Node* layout_val = get_layout_helper(klass_node, layout_con);
3575   int   layout_is_con = (layout_val == NULL);
3576 
3577   if (extra_slow_test == NULL)  extra_slow_test = intcon(0);
3578   // Generate the initial go-slow test.  It's either ALWAYS (return a
3579   // Node for 1) or NEVER (return a NULL) or perhaps (in the reflective
3580   // case) a computed value derived from the layout_helper.
3581   Node* initial_slow_test = NULL;
3582   if (layout_is_con) {
3583     assert(!StressReflectiveCode, "stress mode does not use these paths");
3584     bool must_go_slow = Klass::layout_helper_needs_slow_path(layout_con);
3585     initial_slow_test = must_go_slow ? intcon(1) : extra_slow_test;
3586   } else {   // reflective case
3587     // This reflective path is used by Unsafe.allocateInstance.
3588     // (It may be stress-tested by specifying StressReflectiveCode.)
3589     // Basically, we want to get into the VM is there's an illegal argument.
3590     Node* bit = intcon(Klass::_lh_instance_slow_path_bit);
3591     initial_slow_test = _gvn.transform( new AndINode(layout_val, bit) );
3592     if (extra_slow_test != intcon(0)) {
3593       initial_slow_test = _gvn.transform( new OrINode(initial_slow_test, extra_slow_test) );
3594     }
3595     // (Macro-expander will further convert this to a Bool, if necessary.)


3606 
3607     // Clear the low bits to extract layout_helper_size_in_bytes:
3608     assert((int)Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
3609     Node* mask = MakeConX(~ (intptr_t)right_n_bits(LogBytesPerLong));
3610     size = _gvn.transform( new AndXNode(size, mask) );
3611   }
3612   if (return_size_val != NULL) {
3613     (*return_size_val) = size;
3614   }
3615 
3616   // This is a precise notnull oop of the klass.
3617   // (Actually, it need not be precise if this is a reflective allocation.)
3618   // It's what we cast the result to.
3619   const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
3620   if (!tklass)  tklass = TypeKlassPtr::OBJECT;
3621   const TypeOopPtr* oop_type = tklass->as_instance_type();
3622 
3623   // Now generate allocation code
3624 
3625   // The entire memory state is needed for slow path of the allocation
3626   // since GC and deoptimization can happened.
3627   Node *mem = reset_memory();
3628   set_all_memory(mem); // Create new memory state
3629 
3630   AllocateNode* alloc = new AllocateNode(C, AllocateNode::alloc_type(Type::TOP),
3631                                          control(), mem, i_o(),
3632                                          size, klass_node,
3633                                          initial_slow_test);
3634 
3635   return set_output_for_allocation(alloc, oop_type, deoptimize_on_exception);
3636 }
3637 








3638 //-------------------------------new_array-------------------------------------
3639 // helper for both newarray and anewarray
3640 // The 'length' parameter is (obviously) the length of the array.
3641 // See comments on new_instance for the meaning of the other arguments.
3642 Node* GraphKit::new_array(Node* klass_node,     // array klass (maybe variable)
3643                           Node* length,         // number of array elements
3644                           int   nargs,          // number of arguments to push back for uncommon trap
3645                           Node* *return_size_val,
3646                           bool deoptimize_on_exception) {

3647   jint  layout_con = Klass::_lh_neutral_value;
3648   Node* layout_val = get_layout_helper(klass_node, layout_con);
3649   int   layout_is_con = (layout_val == NULL);
3650 
3651   if (!layout_is_con && !StressReflectiveCode &&
3652       !too_many_traps(Deoptimization::Reason_class_check)) {
3653     // This is a reflective array creation site.
3654     // Optimistically assume that it is a subtype of Object[],
3655     // so that we can fold up all the address arithmetic.
3656     layout_con = Klass::array_layout_helper(T_OBJECT);
3657     Node* cmp_lh = _gvn.transform( new CmpINode(layout_val, intcon(layout_con)) );
3658     Node* bol_lh = _gvn.transform( new BoolNode(cmp_lh, BoolTest::eq) );
3659     { BuildCutout unless(this, bol_lh, PROB_MAX);
3660       inc_sp(nargs);
3661       uncommon_trap(Deoptimization::Reason_class_check,
3662                     Deoptimization::Action_maybe_recompile);
3663     }
3664     layout_val = NULL;
3665     layout_is_con = true;
3666   }
3667 
3668   // Generate the initial go-slow test.  Make sure we do not overflow
3669   // if length is huge (near 2Gig) or negative!  We do not need
3670   // exact double-words here, just a close approximation of needed
3671   // double-words.  We can't add any offset or rounding bits, lest we
3672   // take a size -1 of bytes and make it positive.  Use an unsigned
3673   // compare, so negative sizes look hugely positive.
3674   int fast_size_limit = FastAllocateSizeLimit;
3675   if (layout_is_con) {
3676     assert(!StressReflectiveCode, "stress mode does not use these paths");
3677     // Increase the size limit if we have exact knowledge of array type.
3678     int log2_esize = Klass::layout_helper_log2_element_size(layout_con);
3679     fast_size_limit <<= (LogBytesPerLong - log2_esize);
3680   }
3681 
3682   Node* initial_slow_cmp  = _gvn.transform( new CmpUNode( length, intcon( fast_size_limit ) ) );
3683   Node* initial_slow_test = _gvn.transform( new BoolNode( initial_slow_cmp, BoolTest::gt ) );
3684 
3685   // --- Size Computation ---
3686   // array_size = round_to_heap(array_header + (length << elem_shift));
3687   // where round_to_heap(x) == align_to(x, MinObjAlignmentInBytes)
3688   // and align_to(x, y) == ((x + y-1) & ~(y-1))
3689   // The rounding mask is strength-reduced, if possible.
3690   int round_mask = MinObjAlignmentInBytes - 1;
3691   Node* header_size = NULL;
3692   int   header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
3693   // (T_BYTE has the weakest alignment and size restrictions...)
3694   if (layout_is_con) {
3695     int       hsize  = Klass::layout_helper_header_size(layout_con);
3696     int       eshift = Klass::layout_helper_log2_element_size(layout_con);
3697     BasicType etype  = Klass::layout_helper_element_type(layout_con);
3698     if ((round_mask & ~right_n_bits(eshift)) == 0)
3699       round_mask = 0;  // strength-reduce it if it goes away completely
3700     assert((hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded");
3701     assert(header_size_min <= hsize, "generic minimum is smallest");
3702     header_size_min = hsize;
3703     header_size = intcon(hsize + round_mask);
3704   } else {
3705     Node* hss   = intcon(Klass::_lh_header_size_shift);
3706     Node* hsm   = intcon(Klass::_lh_header_size_mask);
3707     Node* hsize = _gvn.transform( new URShiftINode(layout_val, hss) );
3708     hsize       = _gvn.transform( new AndINode(hsize, hsm) );
3709     Node* mask  = intcon(round_mask);
3710     header_size = _gvn.transform( new AddINode(hsize, mask) );
3711   }
3712 
3713   Node* elem_shift = NULL;
3714   if (layout_is_con) {
3715     int eshift = Klass::layout_helper_log2_element_size(layout_con);
3716     if (eshift != 0)
3717       elem_shift = intcon(eshift);
3718   } else {
3719     // There is no need to mask or shift this value.
3720     // The semantics of LShiftINode include an implicit mask to 0x1F.


3764   // places, one where the length is sharply limited, and the other
3765   // after a successful allocation.
3766   Node* abody = lengthx;
3767   if (elem_shift != NULL)
3768     abody     = _gvn.transform( new LShiftXNode(lengthx, elem_shift) );
3769   Node* size  = _gvn.transform( new AddXNode(headerx, abody) );
3770   if (round_mask != 0) {
3771     Node* mask = MakeConX(~round_mask);
3772     size       = _gvn.transform( new AndXNode(size, mask) );
3773   }
3774   // else if round_mask == 0, the size computation is self-rounding
3775 
3776   if (return_size_val != NULL) {
3777     // This is the size
3778     (*return_size_val) = size;
3779   }
3780 
3781   // Now generate allocation code
3782 
3783   // The entire memory state is needed for slow path of the allocation
3784   // since GC and deoptimization can happened.
3785   Node *mem = reset_memory();
3786   set_all_memory(mem); // Create new memory state
3787 
3788   if (initial_slow_test->is_Bool()) {
3789     // Hide it behind a CMoveI, or else PhaseIdealLoop::split_up will get sick.
3790     initial_slow_test = initial_slow_test->as_Bool()->as_int_value(&_gvn);
3791   }
3792 




























































































3793   // Create the AllocateArrayNode and its result projections
3794   AllocateArrayNode* alloc
3795     = new AllocateArrayNode(C, AllocateArrayNode::alloc_type(TypeInt::INT),
3796                             control(), mem, i_o(),
3797                             size, klass_node,
3798                             initial_slow_test,
3799                             length);

3800 
3801   // Cast to correct type.  Note that the klass_node may be constant or not,
3802   // and in the latter case the actual array type will be inexact also.
3803   // (This happens via a non-constant argument to inline_native_newArray.)
3804   // In any case, the value of klass_node provides the desired array type.
3805   const TypeInt* length_type = _gvn.find_int_type(length);
3806   const TypeOopPtr* ary_type = _gvn.type(klass_node)->is_klassptr()->as_instance_type();
3807   if (ary_type->isa_aryptr() && length_type != NULL) {
3808     // Try to get a better type than POS for the size
3809     ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
3810   }
3811 
3812   Node* javaoop = set_output_for_allocation(alloc, ary_type, deoptimize_on_exception);
3813 
3814   // Cast length on remaining path to be as narrow as possible
3815   if (map()->find_edge(length) >= 0) {
3816     Node* ccast = alloc->make_ideal_length(ary_type, &_gvn);
3817     if (ccast != length) {
3818       _gvn.set_type_bottom(ccast);
3819       record_for_igvn(ccast);
3820       replace_in_map(length, ccast);
3821     }
3822   }
3823 
3824   return javaoop;
3825 }
3826 


3941   set_all_memory(ideal.merged_memory());
3942   set_i_o(ideal.i_o());
3943   set_control(ideal.ctrl());
3944 }
3945 
3946 void GraphKit::final_sync(IdealKit& ideal) {
3947   // Final sync IdealKit and graphKit.
3948   sync_kit(ideal);
3949 }
3950 
3951 Node* GraphKit::load_String_length(Node* str, bool set_ctrl) {
3952   Node* len = load_array_length(load_String_value(str, set_ctrl));
3953   Node* coder = load_String_coder(str, set_ctrl);
3954   // Divide length by 2 if coder is UTF16
3955   return _gvn.transform(new RShiftINode(len, coder));
3956 }
3957 
3958 Node* GraphKit::load_String_value(Node* str, bool set_ctrl) {
3959   int value_offset = java_lang_String::value_offset_in_bytes();
3960   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3961                                                      false, NULL, 0);
3962   const TypePtr* value_field_type = string_type->add_offset(value_offset);
3963   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,
3964                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS),
3965                                                   ciTypeArrayKlass::make(T_BYTE), true, 0);
3966   Node* p = basic_plus_adr(str, str, value_offset);
3967   Node* load = access_load_at(str, p, value_field_type, value_type, T_OBJECT,
3968                               IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED);
3969   return load;
3970 }
3971 
3972 Node* GraphKit::load_String_coder(Node* str, bool set_ctrl) {
3973   if (!CompactStrings) {
3974     return intcon(java_lang_String::CODER_UTF16);
3975   }
3976   int coder_offset = java_lang_String::coder_offset_in_bytes();
3977   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3978                                                      false, NULL, 0);
3979   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
3980 
3981   Node* p = basic_plus_adr(str, str, coder_offset);
3982   Node* load = access_load_at(str, p, coder_field_type, TypeInt::BYTE, T_BYTE,
3983                               IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED);
3984   return load;
3985 }
3986 
3987 void GraphKit::store_String_value(Node* str, Node* value) {
3988   int value_offset = java_lang_String::value_offset_in_bytes();
3989   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
3990                                                      false, NULL, 0);
3991   const TypePtr* value_field_type = string_type->add_offset(value_offset);
3992 
3993   access_store_at(str,  basic_plus_adr(str, value_offset), value_field_type,
3994                   value, TypeAryPtr::BYTES, T_OBJECT, IN_HEAP | MO_UNORDERED);
3995 }
3996 
3997 void GraphKit::store_String_coder(Node* str, Node* value) {
3998   int coder_offset = java_lang_String::coder_offset_in_bytes();
3999   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4000                                                      false, NULL, 0);
4001   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
4002 
4003   access_store_at(str, basic_plus_adr(str, coder_offset), coder_field_type,
4004                   value, TypeInt::BYTE, T_BYTE, IN_HEAP | MO_UNORDERED);
4005 }
4006 
4007 // Capture src and dst memory state with a MergeMemNode
4008 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) {
4009   if (src_type == dst_type) {
4010     // Types are equal, we don't need a MergeMemNode
4011     return memory(src_type);
4012   }
4013   MergeMemNode* merge = MergeMemNode::make(map()->memory());
4014   record_for_igvn(merge); // fold it up later, if possible
4015   int src_idx = C->get_alias_index(src_type);
4016   int dst_idx = C->get_alias_index(dst_type);
4017   merge->set_memory_at(src_idx, memory(src_idx));
4018   merge->set_memory_at(dst_idx, memory(dst_idx));
4019   return merge;
4020 }


4093   i_char->init_req(2, AddI(i_char, intcon(2)));
4094 
4095   set_control(IfFalse(iff));
4096   set_memory(st, TypeAryPtr::BYTES);
4097 }
4098 
4099 Node* GraphKit::make_constant_from_field(ciField* field, Node* obj) {
4100   if (!field->is_constant()) {
4101     return NULL; // Field not marked as constant.
4102   }
4103   ciInstance* holder = NULL;
4104   if (!field->is_static()) {
4105     ciObject* const_oop = obj->bottom_type()->is_oopptr()->const_oop();
4106     if (const_oop != NULL && const_oop->is_instance()) {
4107       holder = const_oop->as_instance();
4108     }
4109   }
4110   const Type* con_type = Type::make_constant_from_field(field, holder, field->layout_type(),
4111                                                         /*is_unsigned_load=*/false);
4112   if (con_type != NULL) {
4113     return makecon(con_type);





4114   }
4115   return NULL;









4116 }


   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 "ci/ciUtilities.hpp"
  27 #include "compiler/compileLog.hpp"
  28 #include "ci/ciValueKlass.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "gc/shared/c2/barrierSetC2.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "opto/addnode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/convertnode.hpp"
  36 #include "opto/graphKit.hpp"
  37 #include "opto/idealKit.hpp"
  38 #include "opto/intrinsicnode.hpp"
  39 #include "opto/locknode.hpp"
  40 #include "opto/machnode.hpp"
  41 #include "opto/narrowptrnode.hpp"
  42 #include "opto/opaquenode.hpp"
  43 #include "opto/parse.hpp"
  44 #include "opto/rootnode.hpp"
  45 #include "opto/runtime.hpp"
  46 #include "opto/valuetypenode.hpp"
  47 #include "runtime/deoptimization.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 
  50 //----------------------------GraphKit-----------------------------------------
  51 // Main utility constructor.
  52 GraphKit::GraphKit(JVMState* jvms, PhaseGVN* gvn)
  53   : Phase(Phase::Parser),
  54     _env(C->env()),
  55     _gvn((gvn != NULL) ? *gvn : *C->initial_gvn()),
  56     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
  57 {
  58   assert(gvn == NULL || !gvn->is_IterGVN() || gvn->is_IterGVN()->delay_transform(), "delay transform should be enabled");
  59   _exceptions = jvms->map()->next_exception();
  60   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);
  61   set_jvms(jvms);
  62 #ifdef ASSERT
  63   if (_gvn.is_IterGVN() != NULL) {
  64     assert(_gvn.is_IterGVN()->delay_transform(), "Transformation must be delayed if IterGVN is used");
  65     // Save the initial size of _for_igvn worklist for verification (see ~GraphKit)
  66     _worklist_size = _gvn.C->for_igvn()->size();
  67   }
  68 #endif
  69 }
  70 
  71 // Private constructor for parser.
  72 GraphKit::GraphKit()
  73   : Phase(Phase::Parser),
  74     _env(C->env()),
  75     _gvn(*C->initial_gvn()),
  76     _barrier_set(BarrierSet::barrier_set()->barrier_set_c2())
  77 {
  78   _exceptions = NULL;
  79   set_map(NULL);
  80   debug_only(_sp = -99);
  81   debug_only(set_bci(-99));
  82 }
  83 
  84 
  85 
  86 //---------------------------clean_stack---------------------------------------
  87 // Clear away rubbish from the stack area of the JVM state.
  88 // This destroys any arguments that may be waiting on the stack.


 817           tty->print_cr("Zombie local %d: ", local);
 818           jvms->dump();
 819         }
 820         return false;
 821       }
 822     }
 823   }
 824   return true;
 825 }
 826 
 827 #endif //ASSERT
 828 
 829 // Helper function for enforcing certain bytecodes to reexecute if
 830 // deoptimization happens
 831 static bool should_reexecute_implied_by_bytecode(JVMState *jvms, bool is_anewarray) {
 832   ciMethod* cur_method = jvms->method();
 833   int       cur_bci   = jvms->bci();
 834   if (cur_method != NULL && cur_bci != InvocationEntryBci) {
 835     Bytecodes::Code code = cur_method->java_code_at_bci(cur_bci);
 836     return Interpreter::bytecode_should_reexecute(code) ||
 837            (is_anewarray && (code == Bytecodes::_multianewarray));
 838     // Reexecute _multianewarray bytecode which was replaced with
 839     // sequence of [a]newarray. See Parse::do_multianewarray().
 840     //
 841     // Note: interpreter should not have it set since this optimization
 842     // is limited by dimensions and guarded by flag so in some cases
 843     // multianewarray() runtime calls will be generated and
 844     // the bytecode should not be reexecutes (stack will not be reset).
 845   } else {
 846     return false;
 847   }
 848 }
 849 
 850 // Helper function for adding JVMState and debug information to node
 851 void GraphKit::add_safepoint_edges(SafePointNode* call, bool must_throw) {
 852   // Add the safepoint edges to the call (or other safepoint).
 853 
 854   // Make sure dead locals are set to top.  This
 855   // should help register allocation time and cut down on the size
 856   // of the deoptimization information.
 857   assert(dead_locals_are_killed(), "garbage in debug info before safepoint");
 858 
 859   // Walk the inline list to fill in the correct set of JVMState's
 860   // Also fill in the associated edges for each JVMState.
 861 
 862   // If the bytecode needs to be reexecuted we need to put
 863   // the arguments back on the stack.
 864   const bool should_reexecute = jvms()->should_reexecute();
 865   JVMState* youngest_jvms = should_reexecute ? sync_jvms_for_reexecute() : sync_jvms();
 866 
 867   // NOTE: set_bci (called from sync_jvms) might reset the reexecute bit to


1071       ciSignature* declared_signature = NULL;
1072       ciMethod* ignored_callee = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
1073       assert(declared_signature != NULL, "cannot be null");
1074       inputs   = declared_signature->arg_size_for_bc(code);
1075       int size = declared_signature->return_type()->size();
1076       depth = size - inputs;
1077     }
1078     break;
1079 
1080   case Bytecodes::_multianewarray:
1081     {
1082       ciBytecodeStream iter(method());
1083       iter.reset_to_bci(bci());
1084       iter.next();
1085       inputs = iter.get_dimensions();
1086       assert(rsize == 1, "");
1087       depth = rsize - inputs;
1088     }
1089     break;
1090 
1091   case Bytecodes::_withfield: {
1092     bool ignored_will_link;
1093     ciField* field = method()->get_field_at_bci(bci(), ignored_will_link);
1094     int      size  = field->type()->size();
1095     inputs = size+1;
1096     depth = rsize - inputs;
1097     break;
1098   }
1099 
1100   case Bytecodes::_ireturn:
1101   case Bytecodes::_lreturn:
1102   case Bytecodes::_freturn:
1103   case Bytecodes::_dreturn:
1104   case Bytecodes::_areturn:
1105     assert(rsize == -depth, "");
1106     inputs = rsize;
1107     break;
1108 
1109   case Bytecodes::_jsr:
1110   case Bytecodes::_jsr_w:
1111     inputs = 0;
1112     depth  = 1;                  // S.B. depth=1, not zero
1113     break;
1114 
1115   default:
1116     // bytecode produces a typed result
1117     inputs = rsize - depth;
1118     assert(inputs >= 0, "");
1119     break;


1205 // the incoming address with NULL casted away.  You are allowed to use the
1206 // not-null value only if you are control dependent on the test.
1207 #ifndef PRODUCT
1208 extern int explicit_null_checks_inserted,
1209            explicit_null_checks_elided;
1210 #endif
1211 Node* GraphKit::null_check_common(Node* value, BasicType type,
1212                                   // optional arguments for variations:
1213                                   bool assert_null,
1214                                   Node* *null_control,
1215                                   bool speculative) {
1216   assert(!assert_null || null_control == NULL, "not both at once");
1217   if (stopped())  return top();
1218   NOT_PRODUCT(explicit_null_checks_inserted++);
1219 
1220   // Construct NULL check
1221   Node *chk = NULL;
1222   switch(type) {
1223     case T_LONG   : chk = new CmpLNode(value, _gvn.zerocon(T_LONG)); break;
1224     case T_INT    : chk = new CmpINode(value, _gvn.intcon(0)); break;
1225     case T_VALUETYPE : // fall through
1226     case T_ARRAY  : // fall through
1227       type = T_OBJECT;  // simplify further tests
1228     case T_OBJECT : {
1229       const Type *t = _gvn.type( value );
1230 
1231       const TypeOopPtr* tp = t->isa_oopptr();
1232       if (tp != NULL && tp->klass() != NULL && !tp->klass()->is_loaded()
1233           // Only for do_null_check, not any of its siblings:
1234           && !assert_null && null_control == NULL) {
1235         // Usually, any field access or invocation on an unloaded oop type
1236         // will simply fail to link, since the statically linked class is
1237         // likely also to be unloaded.  However, in -Xcomp mode, sometimes
1238         // the static class is loaded but the sharper oop type is not.
1239         // Rather than checking for this obscure case in lots of places,
1240         // we simply observe that a null check on an unloaded class
1241         // will always be followed by a nonsense operation, so we
1242         // can just issue the uncommon trap here.
1243         // Our access to the unloaded class will only be correct
1244         // after it has been loaded and initialized, which requires
1245         // a trip through the interpreter.


1377   }
1378 
1379   if (assert_null) {
1380     // Cast obj to null on this path.
1381     replace_in_map(value, zerocon(type));
1382     return zerocon(type);
1383   }
1384 
1385   // Cast obj to not-null on this path, if there is no null_control.
1386   // (If there is a null_control, a non-null value may come back to haunt us.)
1387   if (type == T_OBJECT) {
1388     Node* cast = cast_not_null(value, false);
1389     if (null_control == NULL || (*null_control) == top())
1390       replace_in_map(value, cast);
1391     value = cast;
1392   }
1393 
1394   return value;
1395 }
1396 
1397 Node* GraphKit::null2default(Node* value, ciValueKlass* vk) {
1398   Node* null_ctl = top();
1399   value = null_check_oop(value, &null_ctl);
1400   if (!null_ctl->is_top()) {
1401     // Return default value if oop is null
1402     Node* region = new RegionNode(3);
1403     region->init_req(1, control());
1404     region->init_req(2, null_ctl);
1405     value = PhiNode::make(region, value, TypeInstPtr::make(TypePtr::BotPTR, vk));
1406     value->set_req(2, ValueTypeNode::default_oop(gvn(), vk));
1407     set_control(gvn().transform(region));
1408     value = gvn().transform(value);
1409   }
1410   return value;
1411 }
1412 
1413 //------------------------------cast_not_null----------------------------------
1414 // Cast obj to not-null on this path
1415 Node* GraphKit::cast_not_null(Node* obj, bool do_replace_in_map) {
1416   if (obj->is_ValueType()) {
1417     return obj;
1418   }
1419   const Type *t = _gvn.type(obj);
1420   const Type *t_not_null = t->join_speculative(TypePtr::NOTNULL);
1421   // Object is already not-null?
1422   if( t == t_not_null ) return obj;
1423 
1424   Node *cast = new CastPPNode(obj,t_not_null);
1425   cast->init_req(0, control());
1426   cast = _gvn.transform( cast );
1427 
1428   // Scan for instances of 'obj' in the current JVM mapping.
1429   // These instances are known to be not-null after the test.
1430   if (do_replace_in_map)
1431     replace_in_map(obj, cast);
1432 
1433   return cast;                  // Return casted value
1434 }
1435 
1436 // Sometimes in intrinsics, we implicitly know an object is not null
1437 // (there's no actual null check) so we can cast it to not null. In
1438 // the course of optimizations, the input to the cast can become null.


1527                           int adr_idx,
1528                           MemNode::MemOrd mo,
1529                           LoadNode::ControlDependency control_dependency,
1530                           bool require_atomic_access,
1531                           bool unaligned,
1532                           bool mismatched,
1533                           bool unsafe) {
1534   assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
1535   const TypePtr* adr_type = NULL; // debug-mode-only argument
1536   debug_only(adr_type = C->get_adr_type(adr_idx));
1537   Node* mem = memory(adr_idx);
1538   Node* ld;
1539   if (require_atomic_access && bt == T_LONG) {
1540     ld = LoadLNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
1541   } else if (require_atomic_access && bt == T_DOUBLE) {
1542     ld = LoadDNode::make_atomic(ctl, mem, adr, adr_type, t, mo, control_dependency, unaligned, mismatched, unsafe);
1543   } else {
1544     ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt, mo, control_dependency, unaligned, mismatched, unsafe);
1545   }
1546   ld = _gvn.transform(ld);
1547 
1548   if (((bt == T_OBJECT || bt == T_VALUETYPE) && C->do_escape_analysis()) || C->eliminate_boxing()) {
1549     // Improve graph before escape analysis and boxing elimination.
1550     record_for_igvn(ld);
1551   }
1552   return ld;
1553 }
1554 
1555 Node* GraphKit::store_to_memory(Node* ctl, Node* adr, Node *val, BasicType bt,
1556                                 int adr_idx,
1557                                 MemNode::MemOrd mo,
1558                                 bool require_atomic_access,
1559                                 bool unaligned,
1560                                 bool mismatched,
1561                                 bool unsafe) {
1562   assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
1563   const TypePtr* adr_type = NULL;
1564   debug_only(adr_type = C->get_adr_type(adr_idx));
1565   Node *mem = memory(adr_idx);
1566   Node* st;
1567   if (require_atomic_access && bt == T_LONG) {
1568     st = StoreLNode::make_atomic(ctl, mem, adr, adr_type, val, mo);


1579   }
1580   if (unsafe) {
1581     st->as_Store()->set_unsafe_access();
1582   }
1583   st = _gvn.transform(st);
1584   set_memory(st, adr_idx);
1585   // Back-to-back stores can only remove intermediate store with DU info
1586   // so push on worklist for optimizer.
1587   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1588     record_for_igvn(st);
1589 
1590   return st;
1591 }
1592 
1593 Node* GraphKit::access_store_at(Node* obj,
1594                                 Node* adr,
1595                                 const TypePtr* adr_type,
1596                                 Node* val,
1597                                 const Type* val_type,
1598                                 BasicType bt,
1599                                 DecoratorSet decorators,
1600                                 bool deoptimize_on_exception,
1601                                 bool safe_for_replace) {
1602   // Transformation of a value which could be NULL pointer (CastPP #NULL)
1603   // could be delayed during Parse (for example, in adjust_map_after_if()).
1604   // Execute transformation here to avoid barrier generation in such case.
1605   if (_gvn.type(val) == TypePtr::NULL_PTR) {
1606     val = _gvn.makecon(TypePtr::NULL_PTR);
1607   }
1608 
1609   if (stopped()) {
1610     return top(); // Dead path ?
1611   }
1612 
1613   assert(val != NULL, "not dead path");
1614   if (val->is_ValueType()) {
1615     // Allocate value type and get oop
1616     val = val->as_ValueType()->allocate(this, deoptimize_on_exception, safe_for_replace)->get_oop();
1617   }
1618 
1619   C2AccessValuePtr addr(adr, adr_type);
1620   C2AccessValue value(val, val_type);
1621   C2ParseAccess access(this, decorators | C2_WRITE_ACCESS, bt, obj, addr);
1622   if (access.is_raw()) {
1623     return _barrier_set->BarrierSetC2::store_at(access, value);
1624   } else {
1625     return _barrier_set->store_at(access, value);
1626   }
1627 }
1628 
1629 Node* GraphKit::access_load_at(Node* obj,   // containing obj
1630                                Node* adr,   // actual adress to store val at
1631                                const TypePtr* adr_type,
1632                                const Type* val_type,
1633                                BasicType bt,
1634                                DecoratorSet decorators,
1635                                Node* ctl) {
1636   if (stopped()) {
1637     return top(); // Dead path ?
1638   }
1639 
1640   C2AccessValuePtr addr(adr, adr_type);
1641   C2ParseAccess access(this, decorators | C2_READ_ACCESS, bt, obj, addr, ctl);
1642   if (access.is_raw()) {
1643     return _barrier_set->BarrierSetC2::load_at(access, val_type);
1644   } else {
1645     return _barrier_set->load_at(access, val_type);
1646   }
1647 }
1648 
1649 Node* GraphKit::access_load(Node* adr,   // actual adress to load val at
1650                             const Type* val_type,
1651                             BasicType bt,
1652                             DecoratorSet decorators) {
1653   if (stopped()) {
1654     return top(); // Dead path ?
1655   }
1656 
1657   C2AccessValuePtr addr(adr, NULL);
1658   C2ParseAccess access(this, decorators | C2_READ_ACCESS, bt, NULL, addr);
1659   if (access.is_raw()) {
1660     return _barrier_set->BarrierSetC2::load_at(access, val_type);
1661   } else {


1719   }
1720 }
1721 
1722 Node* GraphKit::access_atomic_add_at(Node* obj,
1723                                      Node* adr,
1724                                      const TypePtr* adr_type,
1725                                      int alias_idx,
1726                                      Node* new_val,
1727                                      const Type* value_type,
1728                                      BasicType bt,
1729                                      DecoratorSet decorators) {
1730   C2AccessValuePtr addr(adr, adr_type);
1731   C2AtomicParseAccess access(this, decorators | C2_READ_ACCESS | C2_WRITE_ACCESS, bt, obj, addr, alias_idx);
1732   if (access.is_raw()) {
1733     return _barrier_set->BarrierSetC2::atomic_add_at(access, new_val, value_type);
1734   } else {
1735     return _barrier_set->atomic_add_at(access, new_val, value_type);
1736   }
1737 }
1738 
1739 void GraphKit::access_clone(Node* src_base, Node* dst_base, Node* countx, bool is_array) {
1740   return _barrier_set->clone(this, src_base, dst_base, countx, is_array);
1741 }
1742 
1743 Node* GraphKit::access_resolve(Node* n, DecoratorSet decorators) {
1744   // Use stronger ACCESS_WRITE|ACCESS_READ by default.
1745   if ((decorators & (ACCESS_READ | ACCESS_WRITE)) == 0) {
1746     decorators |= ACCESS_READ | ACCESS_WRITE;
1747   }
1748   return _barrier_set->resolve(this, n, decorators);
1749 }
1750 
1751 //-------------------------array_element_address-------------------------
1752 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,
1753                                       const TypeInt* sizetype, Node* ctrl) {
1754   uint shift  = exact_log2(type2aelembytes(elembt));
1755   ciKlass* arytype_klass = _gvn.type(ary)->is_aryptr()->klass();
1756   if (arytype_klass != NULL && arytype_klass->is_value_array_klass()) {
1757     ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
1758     shift = vak->log2_element_size();
1759   }
1760   uint header = arrayOopDesc::base_offset_in_bytes(elembt);
1761 
1762   // short-circuit a common case (saves lots of confusing waste motion)
1763   jint idx_con = find_int_con(idx, -1);
1764   if (idx_con >= 0) {
1765     intptr_t offset = header + ((intptr_t)idx_con << shift);
1766     return basic_plus_adr(ary, offset);
1767   }
1768 
1769   // must be correct type for alignment purposes
1770   Node* base  = basic_plus_adr(ary, header);
1771   idx = Compile::conv_I2X_index(&_gvn, idx, sizetype, ctrl);
1772   Node* scale = _gvn.transform( new LShiftXNode(idx, intcon(shift)) );
1773   return basic_plus_adr(ary, base, scale);
1774 }
1775 
1776 //-------------------------load_array_element-------------------------
1777 Node* GraphKit::load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype) {
1778   const Type* elemtype = arytype->elem();
1779   BasicType elembt = elemtype->array_element_basic_type();
1780   assert(elembt != T_VALUETYPE, "value types are not supported by this method");
1781   Node* adr = array_element_address(ary, idx, elembt, arytype->size());
1782   if (elembt == T_NARROWOOP) {
1783     elembt = T_OBJECT; // To satisfy switch in LoadNode::make()
1784   }
1785   Node* ld = make_load(ctl, adr, elemtype, elembt, arytype, MemNode::unordered);
1786   return ld;
1787 }
1788 
1789 //-------------------------set_arguments_for_java_call-------------------------
1790 // Arguments (pre-popped from the stack) are taken from the JVMS.
1791 void GraphKit::set_arguments_for_java_call(CallJavaNode* call, bool incremental_inlining) {
1792   // Add the call arguments:
1793   const TypeTuple* domain = call->tf()->domain_sig();
1794   ExtendedSignature sig_cc = ExtendedSignature(call->method()->get_sig_cc(), SigEntryFilter());
1795   uint nargs = domain->cnt();
1796   for (uint i = TypeFunc::Parms, idx = TypeFunc::Parms; i < nargs; i++) {
1797     Node* arg = argument(i-TypeFunc::Parms);
1798     const Type* t = domain->field_at(i);
1799     if (call->method()->has_scalarized_args() && t->is_valuetypeptr() && !t->maybe_null()) {
1800       // We don't pass value type arguments by reference but instead pass each field of the value type
1801       ValueTypeNode* vt = arg->as_ValueType();
1802       vt->pass_fields(this, call, sig_cc, idx);
1803       // If a value type argument is passed as fields, attach the Method* to the call site
1804       // to be able to access the extended signature later via attached_method_before_pc().
1805       // For example, see CompiledMethod::preserve_callee_argument_oops().
1806       call->set_override_symbolic_info(true);
1807       continue;
1808     } else if (arg->is_ValueType()) {
1809       // Pass value type argument via oop to callee
1810       if (!incremental_inlining) {
1811         arg = arg->as_ValueType()->allocate(this)->get_oop();
1812       } else {
1813         arg = ValueTypePtrNode::make_from_value_type(this, arg->as_ValueType());
1814       }
1815     }
1816     call->init_req(idx++, arg);
1817     // Skip reserved arguments
1818     BasicType bt = t->basic_type();
1819     while (SigEntry::next_is_reserved(sig_cc, bt, true)) {
1820       call->init_req(idx++, top());
1821       if (type2size[bt] == 2) {
1822         call->init_req(idx++, top());
1823       }
1824     }
1825   }
1826 }
1827 
1828 //---------------------------set_edges_for_java_call---------------------------
1829 // Connect a newly created call into the current JVMS.
1830 // A return value node (if any) is returned from set_edges_for_java_call.
1831 void GraphKit::set_edges_for_java_call(CallJavaNode* call, bool must_throw, bool separate_io_proj) {
1832 
1833   // Add the predefined inputs:
1834   call->init_req( TypeFunc::Control, control() );
1835   call->init_req( TypeFunc::I_O    , i_o() );
1836   call->init_req( TypeFunc::Memory , reset_memory() );
1837   call->init_req( TypeFunc::FramePtr, frameptr() );
1838   call->init_req( TypeFunc::ReturnAdr, top() );
1839 
1840   add_safepoint_edges(call, must_throw);
1841 
1842   Node* xcall = _gvn.transform(call);
1843 
1844   if (xcall == top()) {
1845     set_control(top());
1846     return;
1847   }
1848   assert(xcall == call, "call identity is stable");
1849 
1850   // Re-use the current map to produce the result.
1851 
1852   set_control(_gvn.transform(new ProjNode(call, TypeFunc::Control)));
1853   set_i_o(    _gvn.transform(new ProjNode(call, TypeFunc::I_O    , separate_io_proj)));
1854   set_all_memory_call(xcall, separate_io_proj);
1855 
1856   //return xcall;   // no need, caller already has it
1857 }
1858 
1859 Node* GraphKit::set_results_for_java_call(CallJavaNode* call, bool separate_io_proj, bool deoptimize) {
1860   if (stopped())  return top();  // maybe the call folded up?
1861 







1862   // Note:  Since any out-of-line call can produce an exception,
1863   // we always insert an I_O projection from the call into the result.
1864 
1865   make_slow_call_ex(call, env()->Throwable_klass(), separate_io_proj, deoptimize);
1866 
1867   if (separate_io_proj) {
1868     // The caller requested separate projections be used by the fall
1869     // through and exceptional paths, so replace the projections for
1870     // the fall through path.
1871     set_i_o(_gvn.transform( new ProjNode(call, TypeFunc::I_O) ));
1872     set_all_memory(_gvn.transform( new ProjNode(call, TypeFunc::Memory) ));
1873   }
1874 
1875   // Capture the return value, if any.
1876   Node* ret;
1877   if (call->method() == NULL || call->method()->return_type()->basic_type() == T_VOID) {
1878     ret = top();
1879   } else if (call->tf()->returns_value_type_as_fields()) {
1880     // Return of multiple values (value type fields): we create a
1881     // ValueType node, each field is a projection from the call.
1882     ciValueKlass* vk = call->method()->return_type()->as_value_klass();
1883     const Array<SigEntry>* sig_array = vk->extended_sig();
1884     GrowableArray<SigEntry> sig = GrowableArray<SigEntry>(sig_array->length());
1885     sig.appendAll(sig_array);
1886     ExtendedSignature sig_cc = ExtendedSignature(&sig, SigEntryFilter());
1887     uint base_input = TypeFunc::Parms + 1;
1888     ret = ValueTypeNode::make_from_multi(this, call, sig_cc, vk, base_input, false);
1889   } else {
1890     ret = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
1891   }
1892 
1893   return ret;
1894 }
1895 
1896 //--------------------set_predefined_input_for_runtime_call--------------------
1897 // Reading and setting the memory state is way conservative here.
1898 // The real problem is that I am not doing real Type analysis on memory,
1899 // so I cannot distinguish card mark stores from other stores.  Across a GC
1900 // point the Store Barrier and the card mark memory has to agree.  I cannot
1901 // have a card mark store and its barrier split across the GC point from
1902 // either above or below.  Here I get that to happen by reading ALL of memory.
1903 // A better answer would be to separate out card marks from other memory.
1904 // For now, return the input memory state, so that it can be reused
1905 // after the call, if this call has restricted memory effects.
1906 Node* GraphKit::set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem) {
1907   // Set fixed predefined input arguments
1908   Node* memory = reset_memory();
1909   Node* m = narrow_mem == NULL ? memory : narrow_mem;
1910   call->init_req( TypeFunc::Control,   control()  );
1911   call->init_req( TypeFunc::I_O,       top()      ); // does no i/o
1912   call->init_req( TypeFunc::Memory,    m          ); // may gc ptrs


1963     if (use->is_MergeMem()) {
1964       wl.push(use);
1965     }
1966   }
1967 }
1968 
1969 // Replace the call with the current state of the kit.
1970 void GraphKit::replace_call(CallNode* call, Node* result, bool do_replaced_nodes) {
1971   JVMState* ejvms = NULL;
1972   if (has_exceptions()) {
1973     ejvms = transfer_exceptions_into_jvms();
1974   }
1975 
1976   ReplacedNodes replaced_nodes = map()->replaced_nodes();
1977   ReplacedNodes replaced_nodes_exception;
1978   Node* ex_ctl = top();
1979 
1980   SafePointNode* final_state = stop();
1981 
1982   // Find all the needed outputs of this call
1983   CallProjections* callprojs = call->extract_projections(true);

1984 
1985   Unique_Node_List wl;
1986   Node* init_mem = call->in(TypeFunc::Memory);
1987   Node* final_mem = final_state->in(TypeFunc::Memory);
1988   Node* final_ctl = final_state->in(TypeFunc::Control);
1989   Node* final_io = final_state->in(TypeFunc::I_O);
1990 
1991   // Replace all the old call edges with the edges from the inlining result
1992   if (callprojs->fallthrough_catchproj != NULL) {
1993     C->gvn_replace_by(callprojs->fallthrough_catchproj, final_ctl);
1994   }
1995   if (callprojs->fallthrough_memproj != NULL) {
1996     if (final_mem->is_MergeMem()) {
1997       // Parser's exits MergeMem was not transformed but may be optimized
1998       final_mem = _gvn.transform(final_mem);
1999     }
2000     C->gvn_replace_by(callprojs->fallthrough_memproj,   final_mem);
2001     add_mergemem_users_to_worklist(wl, final_mem);
2002   }
2003   if (callprojs->fallthrough_ioproj != NULL) {
2004     C->gvn_replace_by(callprojs->fallthrough_ioproj,    final_io);
2005   }
2006 
2007   // Replace the result with the new result if it exists and is used
2008   if (callprojs->resproj[0] != NULL && result != NULL) {
2009     assert(callprojs->nb_resproj == 1, "unexpected number of results");
2010     C->gvn_replace_by(callprojs->resproj[0], result);
2011   }
2012 
2013   if (ejvms == NULL) {
2014     // No exception edges to simply kill off those paths
2015     if (callprojs->catchall_catchproj != NULL) {
2016       C->gvn_replace_by(callprojs->catchall_catchproj, C->top());
2017     }
2018     if (callprojs->catchall_memproj != NULL) {
2019       C->gvn_replace_by(callprojs->catchall_memproj,   C->top());
2020     }
2021     if (callprojs->catchall_ioproj != NULL) {
2022       C->gvn_replace_by(callprojs->catchall_ioproj,    C->top());
2023     }
2024     // Replace the old exception object with top
2025     if (callprojs->exobj != NULL) {
2026       C->gvn_replace_by(callprojs->exobj, C->top());
2027     }
2028   } else {
2029     GraphKit ekit(ejvms);
2030 
2031     // Load my combined exception state into the kit, with all phis transformed:
2032     SafePointNode* ex_map = ekit.combine_and_pop_all_exception_states();
2033     replaced_nodes_exception = ex_map->replaced_nodes();
2034 
2035     Node* ex_oop = ekit.use_exception_state(ex_map);
2036 
2037     if (callprojs->catchall_catchproj != NULL) {
2038       C->gvn_replace_by(callprojs->catchall_catchproj, ekit.control());
2039       ex_ctl = ekit.control();
2040     }
2041     if (callprojs->catchall_memproj != NULL) {
2042       Node* ex_mem = ekit.reset_memory();
2043       C->gvn_replace_by(callprojs->catchall_memproj,   ex_mem);
2044       add_mergemem_users_to_worklist(wl, ex_mem);
2045     }
2046     if (callprojs->catchall_ioproj != NULL) {
2047       C->gvn_replace_by(callprojs->catchall_ioproj,    ekit.i_o());
2048     }
2049 
2050     // Replace the old exception object with the newly created one
2051     if (callprojs->exobj != NULL) {
2052       C->gvn_replace_by(callprojs->exobj, ex_oop);
2053     }
2054   }
2055 
2056   // Disconnect the call from the graph
2057   call->disconnect_inputs(NULL, C);
2058   C->gvn_replace_by(call, C->top());
2059 
2060   // Clean up any MergeMems that feed other MergeMems since the
2061   // optimizer doesn't like that.
2062   while (wl.size() > 0) {
2063     _gvn.transform(wl.pop());
2064   }
2065 
2066   if (callprojs->fallthrough_catchproj != NULL && !final_ctl->is_top() && do_replaced_nodes) {
2067     replaced_nodes.apply(C, final_ctl);
2068   }
2069   if (!ex_ctl->is_top() && do_replaced_nodes) {
2070     replaced_nodes_exception.apply(C, ex_ctl);
2071   }
2072 }
2073 
2074 
2075 //------------------------------increment_counter------------------------------
2076 // for statistics: increment a VM counter by 1
2077 
2078 void GraphKit::increment_counter(address counter_addr) {
2079   Node* adr1 = makecon(TypeRawPtr::make(counter_addr));
2080   increment_counter(adr1);
2081 }
2082 
2083 void GraphKit::increment_counter(Node* counter_addr) {
2084   int adr_type = Compile::AliasIdxRaw;
2085   Node* ctrl = control();
2086   Node* cnt  = make_load(ctrl, counter_addr, TypeInt::INT, T_INT, adr_type, MemNode::unordered);


2223 // it does not require card marks.
2224 Node* GraphKit::just_allocated_object(Node* current_control) {
2225   Node* ctrl = current_control;
2226   // Object::<init> is invoked after allocation, most of invoke nodes
2227   // will be reduced, but a region node is kept in parse time, we check
2228   // the pattern and skip the region node if it degraded to a copy.
2229   if (ctrl != NULL && ctrl->is_Region() && ctrl->req() == 2 &&
2230       ctrl->as_Region()->is_copy()) {
2231     ctrl = ctrl->as_Region()->is_copy();
2232   }
2233   if (C->recent_alloc_ctl() == ctrl) {
2234    return C->recent_alloc_obj();
2235   }
2236   return NULL;
2237 }
2238 
2239 
2240 void GraphKit::round_double_arguments(ciMethod* dest_method) {
2241   // (Note:  TypeFunc::make has a cache that makes this fast.)
2242   const TypeFunc* tf    = TypeFunc::make(dest_method);
2243   int             nargs = tf->domain_sig()->cnt() - TypeFunc::Parms;
2244   for (int j = 0; j < nargs; j++) {
2245     const Type *targ = tf->domain_sig()->field_at(j + TypeFunc::Parms);
2246     if( targ->basic_type() == T_DOUBLE ) {
2247       // If any parameters are doubles, they must be rounded before
2248       // the call, dstore_rounding does gvn.transform
2249       Node *arg = argument(j);
2250       arg = dstore_rounding(arg);
2251       set_argument(j, arg);
2252     }
2253   }
2254 }
2255 
2256 /**
2257  * Record profiling data exact_kls for Node n with the type system so
2258  * that it can propagate it (speculation)
2259  *
2260  * @param n          node that the type applies to
2261  * @param exact_kls  type from profiling
2262  * @param maybe_null did profiling see null?
2263  *
2264  * @return           node with improved type
2265  */


2282     speculative = speculative->with_inline_depth(jvms()->depth());
2283   } else if (current_type->would_improve_ptr(ptr_kind)) {
2284     // Profiling report that null was never seen so we can change the
2285     // speculative type to non null ptr.
2286     if (ptr_kind == ProfileAlwaysNull) {
2287       speculative = TypePtr::NULL_PTR;
2288     } else {
2289       assert(ptr_kind == ProfileNeverNull, "nothing else is an improvement");
2290       const TypePtr* ptr = TypePtr::NOTNULL;
2291       if (speculative != NULL) {
2292         speculative = speculative->cast_to_ptr_type(ptr->ptr())->is_ptr();
2293       } else {
2294         speculative = ptr;
2295       }
2296     }
2297   }
2298 
2299   if (speculative != current_type->speculative()) {
2300     // Build a type with a speculative type (what we think we know
2301     // about the type but will need a guard when we use it)
2302     const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::Offset::bottom, TypeOopPtr::InstanceBot, speculative);
2303     // We're changing the type, we need a new CheckCast node to carry
2304     // the new type. The new type depends on the control: what
2305     // profiling tells us is only valid from here as far as we can
2306     // tell.
2307     Node* cast = new CheckCastPPNode(control(), n, current_type->remove_speculative()->join_speculative(spec_type));
2308     cast = _gvn.transform(cast);
2309     replace_in_map(n, cast);
2310     n = cast;
2311   }
2312 
2313   return n;
2314 }
2315 
2316 /**
2317  * Record profiling data from receiver profiling at an invoke with the
2318  * type system so that it can propagate it (speculation)
2319  *
2320  * @param n  receiver node
2321  *
2322  * @return   node with improved type


2347         }
2348         ptr_kind = (i == call->row_limit()) ? ProfileAlwaysNull : ProfileMaybeNull;
2349       }
2350     }
2351   }
2352   return record_profile_for_speculation(n, exact_kls, ptr_kind);
2353 }
2354 
2355 /**
2356  * Record profiling data from argument profiling at an invoke with the
2357  * type system so that it can propagate it (speculation)
2358  *
2359  * @param dest_method  target method for the call
2360  * @param bc           what invoke bytecode is this?
2361  */
2362 void GraphKit::record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc) {
2363   if (!UseTypeSpeculation) {
2364     return;
2365   }
2366   const TypeFunc* tf    = TypeFunc::make(dest_method);
2367   int             nargs = tf->domain_sig()->cnt() - TypeFunc::Parms;
2368   int skip = Bytecodes::has_receiver(bc) ? 1 : 0;
2369   for (int j = skip, i = 0; j < nargs && i < TypeProfileArgsLimit; j++) {
2370     const Type *targ = tf->domain_sig()->field_at(j + TypeFunc::Parms);
2371     if (targ->isa_oopptr()) {
2372       ProfilePtrKind ptr_kind = ProfileMaybeNull;
2373       ciKlass* better_type = NULL;
2374       if (method()->argument_profiled_type(bci(), i, better_type, ptr_kind)) {
2375         record_profile_for_speculation(argument(j), better_type, ptr_kind);
2376       }
2377       i++;
2378     }
2379   }
2380 }
2381 
2382 /**
2383  * Record profiling data from parameter profiling at an invoke with
2384  * the type system so that it can propagate it (speculation)
2385  */
2386 void GraphKit::record_profiled_parameters_for_speculation() {
2387   if (!UseTypeSpeculation) {
2388     return;
2389   }
2390   for (int i = 0, j = 0; i < method()->arg_size() ; i++) {
2391     if (_gvn.type(local(i))->isa_oopptr()) {


2866   // The decision to inline or out-of-line this final check is platform
2867   // dependent, and is found in the AD file definition of PartialSubtypeCheck.
2868   Node* psc = gvn->transform(
2869     new PartialSubtypeCheckNode(*ctrl, subklass, superklass));
2870 
2871   IfNode *iff4 = gen_subtype_check_compare(*ctrl, psc, gvn->zerocon(T_OBJECT), BoolTest::ne, PROB_FAIR, gvn, T_ADDRESS);
2872   r_not_subtype->init_req(2, gvn->transform(new IfTrueNode (iff4)));
2873   r_ok_subtype ->init_req(3, gvn->transform(new IfFalseNode(iff4)));
2874 
2875   // Return false path; set default control to true path.
2876   *ctrl = gvn->transform(r_ok_subtype);
2877   return gvn->transform(r_not_subtype);
2878 }
2879 
2880 // Profile-driven exact type check:
2881 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
2882                                     float prob,
2883                                     Node* *casted_receiver) {
2884   const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2885   Node* recv_klass = load_object_klass(receiver);
2886   Node* fail = type_check(recv_klass, tklass, prob);






2887   const TypeOopPtr* recv_xtype = tklass->as_instance_type();
2888   assert(recv_xtype->klass_is_exact(), "");
2889 
2890   // Subsume downstream occurrences of receiver with a cast to
2891   // recv_xtype, since now we know what the type will be.
2892   Node* cast = new CheckCastPPNode(control(), receiver, recv_xtype);
2893   Node* res = _gvn.transform(cast);
2894   if (recv_xtype->is_valuetypeptr() && recv_xtype->value_klass()->is_scalarizable()) {
2895     assert(!gvn().type(res)->maybe_null(), "receiver should never be null");
2896     res = ValueTypeNode::make_from_oop(this, res, recv_xtype->value_klass());
2897   }
2898 
2899   (*casted_receiver) = res;
2900   // (User must make the replace_in_map call.)
2901 
2902   return fail;
2903 }
2904 
2905 Node* GraphKit::type_check(Node* recv_klass, const TypeKlassPtr* tklass,
2906                            float prob) {
2907   Node* want_klass = makecon(tklass);
2908   Node* cmp = _gvn.transform( new CmpPNode(recv_klass, want_klass));
2909   Node* bol = _gvn.transform( new BoolNode(cmp, BoolTest::eq) );
2910   IfNode* iff = create_and_xform_if(control(), bol, prob, COUNT_UNKNOWN);
2911   set_control(  _gvn.transform( new IfTrueNode (iff)));
2912   Node* fail = _gvn.transform( new IfFalseNode(iff));
2913   return fail;
2914 }
2915 
2916 //------------------------------subtype_check_receiver-------------------------
2917 Node* GraphKit::subtype_check_receiver(Node* receiver, ciKlass* klass,
2918                                        Node** casted_receiver) {
2919   const TypeKlassPtr* tklass = TypeKlassPtr::make(klass);
2920   Node* recv_klass = load_object_klass(receiver);
2921   Node* want_klass = makecon(tklass);
2922 
2923   Node* slow_ctl = gen_subtype_check(recv_klass, want_klass);
2924 
2925   // Cast receiver after successful check
2926   const TypeOopPtr* recv_type = tklass->cast_to_exactness(false)->is_klassptr()->as_instance_type();
2927   Node* cast = new CheckCastPPNode(control(), receiver, recv_type);
2928   (*casted_receiver) = _gvn.transform(cast);
2929 
2930   return slow_ctl;
2931 }
2932 
2933 //------------------------------seems_never_null-------------------------------
2934 // Use null_seen information if it is available from the profile.
2935 // If we see an unexpected null at a type check we record it and force a


3120 // and the reflective instance-of call.
3121 Node* GraphKit::gen_instanceof(Node* obj, Node* superklass, bool safe_for_replace) {
3122   kill_dead_locals();           // Benefit all the uncommon traps
3123   assert( !stopped(), "dead parse path should be checked in callers" );
3124   assert(!TypePtr::NULL_PTR->higher_equal(_gvn.type(superklass)->is_klassptr()),
3125          "must check for not-null not-dead klass in callers");
3126 
3127   // Make the merge point
3128   enum { _obj_path = 1, _fail_path, _null_path, PATH_LIMIT };
3129   RegionNode* region = new RegionNode(PATH_LIMIT);
3130   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
3131   C->set_has_split_ifs(true); // Has chance for split-if optimization
3132 
3133   ciProfileData* data = NULL;
3134   if (java_bc() == Bytecodes::_instanceof) {  // Only for the bytecode
3135     data = method()->method_data()->bci_to_data(bci());
3136   }
3137   bool speculative_not_null = false;
3138   bool never_see_null = (ProfileDynamicTypes  // aggressive use of profile
3139                          && seems_never_null(obj, data, speculative_not_null));
3140   bool is_value = obj->is_ValueType();
3141 
3142   // Null check; get casted pointer; set region slot 3
3143   Node* null_ctl = top();
3144   Node* not_null_obj = is_value ? obj : null_check_oop(obj, &null_ctl, never_see_null, safe_for_replace, speculative_not_null);
3145 
3146   // If not_null_obj is dead, only null-path is taken
3147   if (stopped()) {              // Doing instance-of on a NULL?
3148     set_control(null_ctl);
3149     return intcon(0);
3150   }
3151   region->init_req(_null_path, null_ctl);
3152   phi   ->init_req(_null_path, intcon(0)); // Set null path value
3153   if (null_ctl == top()) {
3154     // Do this eagerly, so that pattern matches like is_diamond_phi
3155     // will work even during parsing.
3156     assert(_null_path == PATH_LIMIT-1, "delete last");
3157     region->del_req(_null_path);
3158     phi   ->del_req(_null_path);
3159   }
3160 
3161   // Do we know the type check always succeed?
3162   if (!is_value) {
3163     bool known_statically = false;
3164     if (_gvn.type(superklass)->singleton()) {
3165       ciKlass* superk = _gvn.type(superklass)->is_klassptr()->klass();
3166       ciKlass* subk = _gvn.type(obj)->is_oopptr()->klass();
3167       if (subk != NULL && subk->is_loaded()) {
3168         int static_res = C->static_subtype_check(superk, subk);
3169         known_statically = (static_res == Compile::SSC_always_true || static_res == Compile::SSC_always_false);
3170       }
3171     }

3172 
3173     if (!known_statically) {
3174       const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
3175       // We may not have profiling here or it may not help us. If we
3176       // have a speculative type use it to perform an exact cast.
3177       ciKlass* spec_obj_type = obj_type->speculative_type();
3178       if (spec_obj_type != NULL || (ProfileDynamicTypes && data != NULL)) {
3179         Node* cast_obj = maybe_cast_profiled_receiver(not_null_obj, NULL, spec_obj_type, safe_for_replace);
3180         if (stopped()) {            // Profile disagrees with this path.
3181           set_control(null_ctl);    // Null is the only remaining possibility.
3182           return intcon(0);
3183         }
3184         if (cast_obj != NULL &&
3185             // A value that's sometimes null is not something we can optimize well
3186             !(cast_obj->is_ValueType() && null_ctl != top())) {
3187           not_null_obj = cast_obj;
3188           is_value = not_null_obj->is_ValueType();
3189         }
3190       }
3191     }
3192   }
3193 
3194   // Load the object's klass
3195   Node* obj_klass = NULL;
3196   if (is_value) {
3197     obj_klass = makecon(TypeKlassPtr::make(_gvn.type(not_null_obj)->value_klass()));
3198   } else {
3199     obj_klass = load_object_klass(not_null_obj);
3200   }
3201 
3202   // Generate the subtype check
3203   Node* not_subtype_ctrl = gen_subtype_check(obj_klass, superklass);
3204 
3205   // Plug in the success path to the general merge in slot 1.
3206   region->init_req(_obj_path, control());
3207   phi   ->init_req(_obj_path, intcon(1));
3208 
3209   // Plug in the failing path to the general merge in slot 2.
3210   region->init_req(_fail_path, not_subtype_ctrl);
3211   phi   ->init_req(_fail_path, intcon(0));
3212 
3213   // Return final merged results
3214   set_control( _gvn.transform(region) );
3215   record_for_igvn(region);
3216 
3217   // If we know the type check always succeeds then we don't use the
3218   // profiling data at this bytecode. Don't lose it, feed it to the
3219   // type system as a speculative type.
3220   if (safe_for_replace && !is_value) {
3221     Node* casted_obj = record_profiled_receiver_for_speculation(obj);
3222     replace_in_map(obj, casted_obj);
3223   }
3224 
3225   return _gvn.transform(phi);
3226 }
3227 
3228 //-------------------------------gen_checkcast---------------------------------
3229 // Generate a checkcast idiom.  Used by both the checkcast bytecode and the
3230 // array store bytecode.  Stack must be as-if BEFORE doing the bytecode so the
3231 // uncommon-trap paths work.  Adjust stack after this call.
3232 // If failure_control is supplied and not null, it is filled in with
3233 // the control edge for the cast failure.  Otherwise, an appropriate
3234 // uncommon trap or exception is thrown.
3235 Node* GraphKit::gen_checkcast(Node *obj, Node* superklass, Node* *failure_control, bool never_null) {

3236   kill_dead_locals();           // Benefit all the uncommon traps
3237   const TypeKlassPtr* tk = _gvn.type(superklass)->is_klassptr();
3238   const TypeOopPtr* toop = TypeOopPtr::make_from_klass(tk->klass());
3239   assert(!never_null || toop->is_valuetypeptr(), "must be a value type pointer");
3240   bool is_value = obj->is_ValueType();
3241 
3242   // Fast cutout:  Check the case that the cast is vacuously true.
3243   // This detects the common cases where the test will short-circuit
3244   // away completely.  We do this before we perform the null check,
3245   // because if the test is going to turn into zero code, we don't
3246   // want a residual null check left around.  (Causes a slowdown,
3247   // for example, in some objArray manipulations, such as a[i]=a[j].)
3248   if (tk->singleton()) {
3249     ciKlass* klass = NULL;
3250     if (is_value) {
3251       klass = _gvn.type(obj)->value_klass();
3252     } else {
3253       const TypeOopPtr* objtp = _gvn.type(obj)->isa_oopptr();
3254       if (objtp != NULL) {
3255         klass = objtp->klass();
3256       }
3257     }
3258     if (klass != NULL) {
3259       switch (C->static_subtype_check(tk->klass(), klass)) {
3260       case Compile::SSC_always_true:
3261         // If we know the type check always succeed then we don't use
3262         // the profiling data at this bytecode. Don't lose it, feed it
3263         // to the type system as a speculative type.
3264         if (!is_value) {
3265           obj = record_profiled_receiver_for_speculation(obj);
3266           if (never_null) {
3267             obj = null_check(obj);
3268           }
3269           if (toop->is_valuetypeptr() && toop->value_klass()->is_scalarizable() && !gvn().type(obj)->maybe_null()) {
3270             obj = ValueTypeNode::make_from_oop(this, obj, toop->value_klass());
3271           }
3272         }
3273         return obj;
3274       case Compile::SSC_always_false:
3275         if (is_value || never_null) {
3276           if (!is_value) {
3277             null_check(obj);
3278           }
3279           // Value type is never null. Always throw an exception.
3280           builtin_throw(Deoptimization::Reason_class_check, makecon(TypeKlassPtr::make(klass)));
3281           return top();
3282         } else {
3283           // It needs a null check because a null will *pass* the cast check.
3284           return null_assert(obj);
3285         }
3286       }
3287     }
3288   }
3289 
3290   ciProfileData* data = NULL;
3291   bool safe_for_replace = false;
3292   if (failure_control == NULL) {        // use MDO in regular case only
3293     assert(java_bc() == Bytecodes::_aastore ||
3294            java_bc() == Bytecodes::_checkcast,
3295            "interpreter profiles type checks only for these BCs");
3296     data = method()->method_data()->bci_to_data(bci());
3297     safe_for_replace = true;
3298   }
3299 
3300   // Make the merge point
3301   enum { _obj_path = 1, _null_path, PATH_LIMIT };
3302   RegionNode* region = new RegionNode(PATH_LIMIT);
3303   Node*       phi    = new PhiNode(region, toop);
3304   _gvn.set_type(region, Type::CONTROL);
3305   _gvn.set_type(phi, toop);
3306 
3307   C->set_has_split_ifs(true); // Has chance for split-if optimization
3308 
3309   // Use null-cast information if it is available
3310   bool speculative_not_null = false;
3311   bool never_see_null = ((failure_control == NULL)  // regular case only
3312                          && seems_never_null(obj, data, speculative_not_null));
3313 
3314   // Null check; get casted pointer; set region slot 3
3315   Node* null_ctl = top();
3316   Node* not_null_obj = NULL;
3317   if (is_value) {
3318     not_null_obj = obj;
3319   } else if (never_null) {
3320     not_null_obj = null_check(obj);
3321   } else {
3322     not_null_obj = null_check_oop(obj, &null_ctl, never_see_null, safe_for_replace, speculative_not_null);
3323   }
3324 
3325   // If not_null_obj is dead, only null-path is taken
3326   if (stopped()) {              // Doing instance-of on a NULL?
3327     set_control(null_ctl);
3328     return null();
3329   }
3330   region->init_req(_null_path, null_ctl);
3331   phi   ->init_req(_null_path, null());  // Set null path value
3332   if (null_ctl == top()) {
3333     // Do this eagerly, so that pattern matches like is_diamond_phi
3334     // will work even during parsing.
3335     assert(_null_path == PATH_LIMIT-1, "delete last");
3336     region->del_req(_null_path);
3337     phi   ->del_req(_null_path);
3338   }
3339 
3340   Node* cast_obj = NULL;
3341   if (!is_value && tk->klass_is_exact()) {
3342     // The following optimization tries to statically cast the speculative type of the object
3343     // (for example obtained during profiling) to the type of the superklass and then do a
3344     // dynamic check that the type of the object is what we expect. To work correctly
3345     // for checkcast and aastore the type of superklass should be exact.
3346     const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
3347     // We may not have profiling here or it may not help us. If we have
3348     // a speculative type use it to perform an exact cast.
3349     ciKlass* spec_obj_type = obj_type->speculative_type();
3350     if (spec_obj_type != NULL || data != NULL) {
3351       cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace);
3352       if (cast_obj != NULL && cast_obj->is_ValueType()) {
3353         if (null_ctl != top()) {
3354           cast_obj = NULL; // A value that's sometimes null is not something we can optimize well
3355         } else {
3356           return cast_obj;
3357         }
3358       }
3359       if (cast_obj != NULL) {
3360         if (failure_control != NULL) // failure is now impossible
3361           (*failure_control) = top();
3362         // adjust the type of the phi to the exact klass:
3363         phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR));
3364       }
3365     }
3366   }
3367 
3368   if (cast_obj == NULL) {
3369     // Load the object's klass
3370     Node* obj_klass = NULL;
3371     if (is_value) {
3372       obj_klass = makecon(TypeKlassPtr::make(_gvn.type(not_null_obj)->value_klass()));
3373     } else {
3374       obj_klass = load_object_klass(not_null_obj);
3375     }
3376 
3377     // Generate the subtype check
3378     Node* not_subtype_ctrl = gen_subtype_check( obj_klass, superklass );
3379 
3380     // Plug in success path into the merge
3381     cast_obj = is_value ? not_null_obj : _gvn.transform(new CheckCastPPNode(control(), not_null_obj, toop));
3382     // Failure path ends in uncommon trap (or may be dead - failure impossible)
3383     if (failure_control == NULL) {
3384       if (not_subtype_ctrl != top()) { // If failure is possible
3385         PreserveJVMState pjvms(this);
3386         set_control(not_subtype_ctrl);
3387         builtin_throw(Deoptimization::Reason_class_check, obj_klass);
3388       }
3389     } else {
3390       (*failure_control) = not_subtype_ctrl;
3391     }
3392   }
3393 
3394   region->init_req(_obj_path, control());
3395   phi   ->init_req(_obj_path, cast_obj);
3396 
3397   // A merge of NULL or Casted-NotNull obj
3398   Node* res = _gvn.transform(phi);
3399 
3400   // Note I do NOT always 'replace_in_map(obj,result)' here.
3401   //  if( tk->klass()->can_be_primary_super()  )
3402     // This means that if I successfully store an Object into an array-of-String
3403     // I 'forget' that the Object is really now known to be a String.  I have to
3404     // do this because we don't have true union types for interfaces - if I store
3405     // a Baz into an array-of-Interface and then tell the optimizer it's an
3406     // Interface, I forget that it's also a Baz and cannot do Baz-like field
3407     // references to it.  FIX THIS WHEN UNION TYPES APPEAR!
3408   //  replace_in_map( obj, res );
3409 
3410   // Return final merged results
3411   set_control( _gvn.transform(region) );
3412   record_for_igvn(region);
3413 
3414   bool not_null_free = !toop->can_be_value_type();
3415   bool not_flattenable = !ValueArrayFlatten || not_null_free || (toop->is_valuetypeptr() && !toop->value_klass()->flatten_array());
3416   if (EnableValhalla && not_flattenable) {
3417     // Check if obj has been loaded from an array
3418     obj = obj->isa_DecodeN() ? obj->in(1) : obj;
3419     Node* array = NULL;
3420     if (obj->isa_Load()) {
3421       Node* address = obj->in(MemNode::Address);
3422       if (address->isa_AddP()) {
3423         array = address->as_AddP()->in(AddPNode::Base);
3424       }
3425     } else if (obj->is_Phi()) {
3426       Node* region = obj->in(0);
3427       if (region->req() == 3 && region->in(2) != NULL) {
3428         IfNode* iff = region->in(2)->in(0)->isa_If();
3429         if (iff != NULL) {
3430           iff->is_flattened_array_check(&_gvn, array);
3431         }
3432       }
3433     }
3434     if (array != NULL) {
3435       const TypeAryPtr* ary_t = _gvn.type(array)->isa_aryptr();
3436       if (ary_t != NULL) {
3437         if (!ary_t->is_not_null_free() && not_null_free) {
3438           // Casting array element to a non-inline-type, mark array as not null-free.
3439           Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_null_free()));
3440           replace_in_map(array, cast);
3441         } else if (!ary_t->is_not_flat()) {
3442           // Casting array element to a non-flattenable type, mark array as not flat.
3443           Node* cast = _gvn.transform(new CheckCastPPNode(control(), array, ary_t->cast_to_not_flat()));
3444           replace_in_map(array, cast);
3445         }
3446       }
3447     }
3448   }
3449 
3450   if (!is_value) {
3451     res = record_profiled_receiver_for_speculation(res);
3452     if (toop->is_valuetypeptr() && toop->value_klass()->is_scalarizable() && !gvn().type(res)->maybe_null()) {
3453       res = ValueTypeNode::make_from_oop(this, res, toop->value_klass());
3454     }
3455   }
3456   return res;
3457 }
3458 
3459 Node* GraphKit::is_always_locked(Node* obj) {
3460   Node* mark_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
3461   Node* mark = make_load(NULL, mark_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
3462   Node* value_mask = _gvn.MakeConX(markOopDesc::always_locked_pattern);
3463   return _gvn.transform(new AndXNode(mark, value_mask));
3464 }
3465 
3466 Node* GraphKit::is_value_mirror(Node* mirror) {
3467   Node* p = basic_plus_adr(mirror, java_lang_Class::inline_mirror_offset_in_bytes());
3468   Node* inline_mirror = access_load_at(mirror, p, _gvn.type(p)->is_ptr(), TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR), T_OBJECT, IN_HEAP);
3469   Node* cmp = _gvn.transform(new CmpPNode(mirror, inline_mirror));
3470   return _gvn.transform(new BoolNode(cmp, BoolTest::eq));
3471 }
3472 
3473 // Deoptimize if 'obj' is a value type
3474 void GraphKit::gen_value_type_guard(Node* obj, int nargs) {
3475   assert(EnableValhalla, "should only be used if value types are enabled");
3476   Node* bol = NULL;
3477   if (obj->is_ValueTypeBase()) {
3478     bol = intcon(0);
3479   } else {
3480     Node* is_value = is_always_locked(obj);
3481     Node* value_mask = _gvn.MakeConX(markOopDesc::always_locked_pattern);
3482     Node* cmp = _gvn.transform(new CmpXNode(is_value, value_mask));
3483     bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
3484   }
3485   { BuildCutout unless(this, bol, PROB_MAX);
3486     inc_sp(nargs);
3487     uncommon_trap(Deoptimization::Reason_class_check,
3488                   Deoptimization::Action_none);
3489   }
3490 }
3491 
3492 // Check if 'ary' is a null-free value type array
3493 Node* GraphKit::gen_null_free_array_check(Node* ary) {
3494   assert(EnableValhalla, "should only be used if value types are enabled");
3495   // Extract null free property from klass pointer
3496   Node* k_adr = basic_plus_adr(ary, oopDesc::klass_offset_in_bytes());
3497   const TypePtr* k_adr_type = k_adr->bottom_type()->isa_ptr();
3498   Node* klass = NULL;
3499   if (k_adr_type->is_ptr_to_narrowklass()) {
3500     klass = _gvn.transform(new LoadNKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT->make_narrowklass(), MemNode::unordered));
3501   } else {
3502     klass = _gvn.transform(new LoadKlassNode(NULL, immutable_memory(), k_adr, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT, MemNode::unordered));
3503   }
3504   Node* null_free = _gvn.transform(new GetNullFreePropertyNode(klass));
3505   Node* cmp = NULL;
3506   if (_gvn.type(klass)->isa_klassptr()) {
3507     cmp = _gvn.transform(new CmpLNode(null_free, zerocon(T_LONG)));
3508   } else {
3509     cmp = _gvn.transform(new CmpINode(null_free, zerocon(T_INT)));
3510   }
3511   return _gvn.transform(new BoolNode(cmp, BoolTest::eq));
3512 }
3513 
3514 // Deoptimize if 'ary' is a null-free value type array and 'val' is null
3515 Node* GraphKit::gen_value_array_null_guard(Node* ary, Node* val, int nargs, bool safe_for_replace) {
3516   const Type* val_t = _gvn.type(val);
3517   if (val->is_ValueType() || !TypePtr::NULL_PTR->higher_equal(val_t)) {
3518     return ary; // Never null
3519   }
3520   RegionNode* region = new RegionNode(3);
3521   Node* null_ctl = top();
3522   null_check_oop(val, &null_ctl);
3523   if (null_ctl != top()) {
3524     PreserveJVMState pjvms(this);
3525     set_control(null_ctl);
3526     // Deoptimize if null-free array
3527     Node* bol = gen_null_free_array_check(ary);
3528     { BuildCutout unless(this, bol, PROB_MAX);
3529       inc_sp(nargs);
3530       uncommon_trap(Deoptimization::Reason_null_check,
3531                     Deoptimization::Action_none);
3532     }
3533     region->init_req(1, control());
3534   }
3535   region->init_req(2, control());
3536   set_control(_gvn.transform(region));
3537   record_for_igvn(region);
3538   const TypeAryPtr* ary_t = _gvn.type(ary)->is_aryptr();
3539   if (val_t == TypePtr::NULL_PTR && !ary_t->is_not_null_free()) {
3540     // Since we were just successfully storing null, the array can't be null free.
3541     ary_t = ary_t->cast_to_not_null_free();
3542     Node* cast = _gvn.transform(new CheckCastPPNode(control(), ary, ary_t));
3543     if (safe_for_replace) {
3544       replace_in_map(ary, cast);
3545     }
3546     ary = cast;
3547   }
3548   return ary;
3549 }
3550 
3551 Node* GraphKit::load_lh_array_tag(Node* kls) {
3552   Node* lhp = basic_plus_adr(kls, in_bytes(Klass::layout_helper_offset()));
3553   Node* layout_val = _gvn.transform(LoadNode::make(_gvn, NULL, immutable_memory(), lhp, lhp->bottom_type()->is_ptr(), TypeInt::INT, T_INT, MemNode::unordered));
3554 
3555   return _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
3556 }
3557 
3558 
3559 Node* GraphKit::gen_lh_array_test(Node* kls, unsigned int lh_value) {
3560   Node* layout_val = load_lh_array_tag(kls);
3561   Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(lh_value)));
3562   return cmp;
3563 }
3564 
3565 
3566 //------------------------------next_monitor-----------------------------------
3567 // What number should be given to the next monitor?
3568 int GraphKit::next_monitor() {
3569   int current = jvms()->monitor_depth()* C->sync_stack_slots();
3570   int next = current + C->sync_stack_slots();
3571   // Keep the toplevel high water mark current:
3572   if (C->fixed_slots() < next)  C->set_fixed_slots(next);
3573   return current;
3574 }
3575 
3576 //------------------------------insert_mem_bar---------------------------------
3577 // Memory barrier to avoid floating things around
3578 // The membar serves as a pinch point between both control and all memory slices.
3579 Node* GraphKit::insert_mem_bar(int opcode, Node* precedent) {
3580   MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent);
3581   mb->init_req(TypeFunc::Control, control());
3582   mb->init_req(TypeFunc::Memory,  reset_memory());
3583   Node* membar = _gvn.transform(mb);
3584   set_control(_gvn.transform(new ProjNode(membar, TypeFunc::Control)));
3585   set_all_memory_call(membar);


3623   Node* mem = reset_memory();
3624   MemBarNode* mb = MemBarNode::make(C, Op_MemBarVolatile, Compile::AliasIdxRaw);
3625   mb->init_req(TypeFunc::Control, control());
3626   mb->init_req(TypeFunc::Memory, mem);
3627   Node* membar = _gvn.transform(mb);
3628   set_control(_gvn.transform(new ProjNode(membar, TypeFunc::Control)));
3629   Node* newmem = _gvn.transform(new ProjNode(membar, TypeFunc::Memory));
3630   set_all_memory(mem);
3631   set_memory(newmem, Compile::AliasIdxRaw);
3632 }
3633 
3634 //------------------------------shared_lock------------------------------------
3635 // Emit locking code.
3636 FastLockNode* GraphKit::shared_lock(Node* obj) {
3637   // bci is either a monitorenter bc or InvocationEntryBci
3638   // %%% SynchronizationEntryBCI is redundant; use InvocationEntryBci in interfaces
3639   assert(SynchronizationEntryBCI == InvocationEntryBci, "");
3640 
3641   if( !GenerateSynchronizationCode )
3642     return NULL;                // Not locking things?
3643 
3644   if (stopped())                // Dead monitor?
3645     return NULL;
3646 
3647   assert(dead_locals_are_killed(), "should kill locals before sync. point");
3648 
3649   obj = access_resolve(obj, ACCESS_READ | ACCESS_WRITE);
3650 
3651   // Box the stack location
3652   Node* box = _gvn.transform(new BoxLockNode(next_monitor()));
3653   Node* mem = reset_memory();
3654 
3655   FastLockNode * flock = _gvn.transform(new FastLockNode(0, obj, box) )->as_FastLock();
3656   if (UseBiasedLocking && PrintPreciseBiasedLockingStatistics) {
3657     // Create the counters for this fast lock.
3658     flock->create_lock_counter(sync_jvms()); // sync_jvms used to get current bci
3659   }
3660 
3661   // Create the rtm counters for this fast lock if needed.
3662   flock->create_rtm_lock_counter(sync_jvms()); // sync_jvms used to get current bci
3663 


3698   }
3699 #endif
3700 
3701   return flock;
3702 }
3703 
3704 
3705 //------------------------------shared_unlock----------------------------------
3706 // Emit unlocking code.
3707 void GraphKit::shared_unlock(Node* box, Node* obj) {
3708   // bci is either a monitorenter bc or InvocationEntryBci
3709   // %%% SynchronizationEntryBCI is redundant; use InvocationEntryBci in interfaces
3710   assert(SynchronizationEntryBCI == InvocationEntryBci, "");
3711 
3712   if( !GenerateSynchronizationCode )
3713     return;
3714   if (stopped()) {               // Dead monitor?
3715     map()->pop_monitor();        // Kill monitor from debug info
3716     return;
3717   }
3718   assert(!obj->is_ValueTypeBase(), "should not unlock on value type");
3719 
3720   // Memory barrier to avoid floating things down past the locked region
3721   insert_mem_bar(Op_MemBarReleaseLock);
3722 
3723   const TypeFunc *tf = OptoRuntime::complete_monitor_exit_Type();
3724   UnlockNode *unlock = new UnlockNode(C, tf);
3725 #ifdef ASSERT
3726   unlock->set_dbg_jvms(sync_jvms());
3727 #endif
3728   uint raw_idx = Compile::AliasIdxRaw;
3729   unlock->init_req( TypeFunc::Control, control() );
3730   unlock->init_req( TypeFunc::Memory , memory(raw_idx) );
3731   unlock->init_req( TypeFunc::I_O    , top() )     ;   // does no i/o
3732   unlock->init_req( TypeFunc::FramePtr, frameptr() );
3733   unlock->init_req( TypeFunc::ReturnAdr, top() );
3734 
3735   unlock->init_req(TypeFunc::Parms + 0, obj);
3736   unlock->init_req(TypeFunc::Parms + 1, box);
3737   unlock = _gvn.transform(unlock)->as_Unlock();
3738 
3739   Node* mem = reset_memory();
3740 
3741   // unlock has no side-effects, sets few values
3742   set_predefined_output_for_runtime_call(unlock, mem, TypeRawPtr::BOTTOM);
3743 
3744   // Kill monitor from debug info
3745   map()->pop_monitor( );
3746 }
3747 
3748 //-------------------------------get_layout_helper-----------------------------
3749 // If the given klass is a constant or known to be an array,
3750 // fetch the constant layout helper value into constant_value
3751 // and return (Node*)NULL.  Otherwise, load the non-constant
3752 // layout helper value, and return the node which represents it.
3753 // This two-faced routine is useful because allocation sites
3754 // almost always feature constant types.
3755 Node* GraphKit::get_layout_helper(Node* klass_node, jint& constant_value) {
3756   const TypeKlassPtr* inst_klass = _gvn.type(klass_node)->isa_klassptr();
3757   if (!StressReflectiveCode && inst_klass != NULL) {
3758     ciKlass* klass = inst_klass->klass();
3759     assert(klass != NULL, "klass should not be NULL");
3760     bool    xklass = inst_klass->klass_is_exact();
3761     bool can_be_flattened = false;
3762     if (ValueArrayFlatten && klass->is_obj_array_klass()) {
3763       ciKlass* elem = klass->as_obj_array_klass()->element_klass();
3764       can_be_flattened = elem->is_java_lang_Object() || elem->is_interface() || (elem->is_valuetype() && !klass->as_array_klass()->storage_properties().is_null_free());
3765     }
3766     if (xklass || (klass->is_array_klass() && !can_be_flattened)) {
3767       jint lhelper = klass->layout_helper();
3768       if (lhelper != Klass::_lh_neutral_value) {
3769         constant_value = lhelper;
3770         return (Node*) NULL;
3771       }
3772     }
3773   }
3774   constant_value = Klass::_lh_neutral_value;  // put in a known value
3775   Node* lhp = basic_plus_adr(klass_node, klass_node, in_bytes(Klass::layout_helper_offset()));
3776   return make_load(NULL, lhp, TypeInt::INT, T_INT, MemNode::unordered);
3777 }
3778 
3779 // We just put in an allocate/initialize with a big raw-memory effect.
3780 // Hook selected additional alias categories on the initialization.
3781 static void hook_memory_on_init(GraphKit& kit, int alias_idx,
3782                                 MergeMemNode* init_in_merge,
3783                                 Node* init_out_raw) {
3784   DEBUG_ONLY(Node* init_in_raw = init_in_merge->base_memory());
3785   assert(init_in_merge->memory_at(alias_idx) == init_in_raw, "");
3786 


3808 
3809   // a normal slow-call doesn't change i_o, but an allocation does
3810   // we create a separate i_o projection for the normal control path
3811   set_i_o(_gvn.transform( new ProjNode(allocx, TypeFunc::I_O, false) ) );
3812   Node* rawoop = _gvn.transform( new ProjNode(allocx, TypeFunc::Parms) );
3813 
3814   // put in an initialization barrier
3815   InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, rawidx,
3816                                                  rawoop)->as_Initialize();
3817   assert(alloc->initialization() == init,  "2-way macro link must work");
3818   assert(init ->allocation()     == alloc, "2-way macro link must work");
3819   {
3820     // Extract memory strands which may participate in the new object's
3821     // initialization, and source them from the new InitializeNode.
3822     // This will allow us to observe initializations when they occur,
3823     // and link them properly (as a group) to the InitializeNode.
3824     assert(init->in(InitializeNode::Memory) == malloc, "");
3825     MergeMemNode* minit_in = MergeMemNode::make(malloc);
3826     init->set_req(InitializeNode::Memory, minit_in);
3827     record_for_igvn(minit_in); // fold it up later, if possible
3828     _gvn.set_type(minit_in, Type::MEMORY);
3829     Node* minit_out = memory(rawidx);
3830     assert(minit_out->is_Proj() && minit_out->in(0) == init, "");
3831     // Add an edge in the MergeMem for the header fields so an access
3832     // to one of those has correct memory state
3833     set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::mark_offset_in_bytes())));
3834     set_memory(minit_out, C->get_alias_index(oop_type->add_offset(oopDesc::klass_offset_in_bytes())));
3835     if (oop_type->isa_aryptr()) {
3836       const TypeAryPtr* arytype = oop_type->is_aryptr();
3837       if (arytype->klass()->is_value_array_klass()) {
3838         // Initially all flattened array accesses share a single slice
3839         // but that changes after parsing. Prepare the memory graph so
3840         // it can optimize flattened array accesses properly once they
3841         // don't share a single slice.
3842         assert(C->flattened_accesses_share_alias(), "should be set at parse time");
3843         C->set_flattened_accesses_share_alias(false);
3844         ciValueArrayKlass* vak = arytype->klass()->as_value_array_klass();
3845         ciValueKlass* vk = vak->element_klass()->as_value_klass();
3846         for (int i = 0, len = vk->nof_nonstatic_fields(); i < len; i++) {
3847           ciField* field = vk->nonstatic_field_at(i);
3848           if (field->offset() >= TrackedInitializationLimit * HeapWordSize)
3849             continue;  // do not bother to track really large numbers of fields
3850           int off_in_vt = field->offset() - vk->first_field_offset();
3851           const TypePtr* adr_type = arytype->with_field_offset(off_in_vt)->add_offset(Type::OffsetBot);
3852           int fieldidx = C->get_alias_index(adr_type, true);
3853           hook_memory_on_init(*this, fieldidx, minit_in, minit_out);
3854         }
3855         C->set_flattened_accesses_share_alias(true);
3856         hook_memory_on_init(*this, C->get_alias_index(TypeAryPtr::VALUES), minit_in, minit_out);
3857       } else {
3858         const TypePtr* telemref = oop_type->add_offset(Type::OffsetBot);
3859         int            elemidx  = C->get_alias_index(telemref);
3860         hook_memory_on_init(*this, elemidx, minit_in, minit_out);
3861       }
3862     } else if (oop_type->isa_instptr()) {
3863       set_memory(minit_out, C->get_alias_index(oop_type)); // mark word
3864       ciInstanceKlass* ik = oop_type->klass()->as_instance_klass();
3865       for (int i = 0, len = ik->nof_nonstatic_fields(); i < len; i++) {
3866         ciField* field = ik->nonstatic_field_at(i);
3867         if (field->offset() >= TrackedInitializationLimit * HeapWordSize)
3868           continue;  // do not bother to track really large numbers of fields
3869         // Find (or create) the alias category for this field:
3870         int fieldidx = C->alias_type(field)->index();
3871         hook_memory_on_init(*this, fieldidx, minit_in, minit_out);
3872       }
3873     }
3874   }
3875 
3876   // Cast raw oop to the real thing...
3877   Node* javaoop = new CheckCastPPNode(control(), rawoop, oop_type);
3878   javaoop = _gvn.transform(javaoop);
3879   C->set_recent_alloc(control(), javaoop);
3880   assert(just_allocated_object(control()) == javaoop, "just allocated");
3881 
3882 #ifdef ASSERT
3883   { // Verify that the AllocateNode::Ideal_allocation recognizers work:


3894       assert(alloc->in(AllocateNode::ALength)->is_top(), "no length, please");
3895     }
3896   }
3897 #endif //ASSERT
3898 
3899   return javaoop;
3900 }
3901 
3902 //---------------------------new_instance--------------------------------------
3903 // This routine takes a klass_node which may be constant (for a static type)
3904 // or may be non-constant (for reflective code).  It will work equally well
3905 // for either, and the graph will fold nicely if the optimizer later reduces
3906 // the type to a constant.
3907 // The optional arguments are for specialized use by intrinsics:
3908 //  - If 'extra_slow_test' if not null is an extra condition for the slow-path.
3909 //  - If 'return_size_val', report the the total object size to the caller.
3910 //  - deoptimize_on_exception controls how Java exceptions are handled (rethrow vs deoptimize)
3911 Node* GraphKit::new_instance(Node* klass_node,
3912                              Node* extra_slow_test,
3913                              Node* *return_size_val,
3914                              bool deoptimize_on_exception,
3915                              ValueTypeBaseNode* value_node) {
3916   // Compute size in doublewords
3917   // The size is always an integral number of doublewords, represented
3918   // as a positive bytewise size stored in the klass's layout_helper.
3919   // The layout_helper also encodes (in a low bit) the need for a slow path.
3920   jint  layout_con = Klass::_lh_neutral_value;
3921   Node* layout_val = get_layout_helper(klass_node, layout_con);
3922   bool  layout_is_con = (layout_val == NULL);
3923 
3924   if (extra_slow_test == NULL)  extra_slow_test = intcon(0);
3925   // Generate the initial go-slow test.  It's either ALWAYS (return a
3926   // Node for 1) or NEVER (return a NULL) or perhaps (in the reflective
3927   // case) a computed value derived from the layout_helper.
3928   Node* initial_slow_test = NULL;
3929   if (layout_is_con) {
3930     assert(!StressReflectiveCode, "stress mode does not use these paths");
3931     bool must_go_slow = Klass::layout_helper_needs_slow_path(layout_con);
3932     initial_slow_test = must_go_slow ? intcon(1) : extra_slow_test;
3933   } else {   // reflective case
3934     // This reflective path is used by Unsafe.allocateInstance.
3935     // (It may be stress-tested by specifying StressReflectiveCode.)
3936     // Basically, we want to get into the VM is there's an illegal argument.
3937     Node* bit = intcon(Klass::_lh_instance_slow_path_bit);
3938     initial_slow_test = _gvn.transform( new AndINode(layout_val, bit) );
3939     if (extra_slow_test != intcon(0)) {
3940       initial_slow_test = _gvn.transform( new OrINode(initial_slow_test, extra_slow_test) );
3941     }
3942     // (Macro-expander will further convert this to a Bool, if necessary.)


3953 
3954     // Clear the low bits to extract layout_helper_size_in_bytes:
3955     assert((int)Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
3956     Node* mask = MakeConX(~ (intptr_t)right_n_bits(LogBytesPerLong));
3957     size = _gvn.transform( new AndXNode(size, mask) );
3958   }
3959   if (return_size_val != NULL) {
3960     (*return_size_val) = size;
3961   }
3962 
3963   // This is a precise notnull oop of the klass.
3964   // (Actually, it need not be precise if this is a reflective allocation.)
3965   // It's what we cast the result to.
3966   const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
3967   if (!tklass)  tklass = TypeKlassPtr::OBJECT;
3968   const TypeOopPtr* oop_type = tklass->as_instance_type();
3969 
3970   // Now generate allocation code
3971 
3972   // The entire memory state is needed for slow path of the allocation
3973   // since GC and deoptimization can happen.
3974   Node *mem = reset_memory();
3975   set_all_memory(mem); // Create new memory state
3976 
3977   AllocateNode* alloc = new AllocateNode(C, AllocateNode::alloc_type(Type::TOP),
3978                                          control(), mem, i_o(),
3979                                          size, klass_node,
3980                                          initial_slow_test, value_node);
3981 
3982   return set_output_for_allocation(alloc, oop_type, deoptimize_on_exception);
3983 }
3984 
3985 // With compressed oops, the 64 bit init value for non flattened value
3986 // arrays is built from 2 32 bit compressed oops
3987 static Node* raw_default_for_coops(Node* default_value, GraphKit& kit) {
3988   Node* lower = kit.gvn().transform(new CastP2XNode(kit.control(), default_value));
3989   Node* upper = kit.gvn().transform(new LShiftLNode(lower, kit.intcon(32)));
3990   return kit.gvn().transform(new OrLNode(lower, upper));
3991 }
3992 
3993 //-------------------------------new_array-------------------------------------
3994 // helper for newarray and anewarray
3995 // The 'length' parameter is (obviously) the length of the array.
3996 // See comments on new_instance for the meaning of the other arguments.
3997 Node* GraphKit::new_array(Node* klass_node,     // array klass (maybe variable)
3998                           Node* length,         // number of array elements
3999                           int   nargs,          // number of arguments to push back for uncommon trap
4000                           Node* *return_size_val,
4001                           bool deoptimize_on_exception,
4002                           Node* elem_mirror) {
4003   jint  layout_con = Klass::_lh_neutral_value;
4004   Node* layout_val = get_layout_helper(klass_node, layout_con);
4005   bool  layout_is_con = (layout_val == NULL);
4006 
4007   if (!layout_is_con && !StressReflectiveCode &&
4008       !too_many_traps(Deoptimization::Reason_class_check)) {
4009     // This is a reflective array creation site.
4010     // Optimistically assume that it is a subtype of Object[],
4011     // so that we can fold up all the address arithmetic.
4012     layout_con = Klass::array_layout_helper(T_OBJECT);
4013     Node* cmp_lh = _gvn.transform( new CmpINode(layout_val, intcon(layout_con)) );
4014     Node* bol_lh = _gvn.transform( new BoolNode(cmp_lh, BoolTest::eq) );
4015     { BuildCutout unless(this, bol_lh, PROB_MAX);
4016       inc_sp(nargs);
4017       uncommon_trap(Deoptimization::Reason_class_check,
4018                     Deoptimization::Action_maybe_recompile);
4019     }
4020     layout_val = NULL;
4021     layout_is_con = true;
4022   }
4023 
4024   // Generate the initial go-slow test.  Make sure we do not overflow
4025   // if length is huge (near 2Gig) or negative!  We do not need
4026   // exact double-words here, just a close approximation of needed
4027   // double-words.  We can't add any offset or rounding bits, lest we
4028   // take a size -1 of bytes and make it positive.  Use an unsigned
4029   // compare, so negative sizes look hugely positive.
4030   int fast_size_limit = FastAllocateSizeLimit;
4031   if (layout_is_con) {
4032     assert(!StressReflectiveCode, "stress mode does not use these paths");
4033     // Increase the size limit if we have exact knowledge of array type.
4034     int log2_esize = Klass::layout_helper_log2_element_size(layout_con);
4035     fast_size_limit <<= MAX2(LogBytesPerLong - log2_esize, 0);
4036   }
4037 
4038   Node* initial_slow_cmp  = _gvn.transform( new CmpUNode( length, intcon( fast_size_limit ) ) );
4039   Node* initial_slow_test = _gvn.transform( new BoolNode( initial_slow_cmp, BoolTest::gt ) );
4040 
4041   // --- Size Computation ---
4042   // array_size = round_to_heap(array_header + (length << elem_shift));
4043   // where round_to_heap(x) == align_to(x, MinObjAlignmentInBytes)
4044   // and align_to(x, y) == ((x + y-1) & ~(y-1))
4045   // The rounding mask is strength-reduced, if possible.
4046   int round_mask = MinObjAlignmentInBytes - 1;
4047   Node* header_size = NULL;
4048   int   header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
4049   // (T_BYTE has the weakest alignment and size restrictions...)
4050   if (layout_is_con) {
4051     int       hsize  = Klass::layout_helper_header_size(layout_con);
4052     int       eshift = Klass::layout_helper_log2_element_size(layout_con);
4053     bool is_value_array = Klass::layout_helper_is_valueArray(layout_con);
4054     if ((round_mask & ~right_n_bits(eshift)) == 0)
4055       round_mask = 0;  // strength-reduce it if it goes away completely
4056     assert(is_value_array || (hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded");
4057     assert(header_size_min <= hsize, "generic minimum is smallest");
4058     header_size_min = hsize;
4059     header_size = intcon(hsize + round_mask);
4060   } else {
4061     Node* hss   = intcon(Klass::_lh_header_size_shift);
4062     Node* hsm   = intcon(Klass::_lh_header_size_mask);
4063     Node* hsize = _gvn.transform( new URShiftINode(layout_val, hss) );
4064     hsize       = _gvn.transform( new AndINode(hsize, hsm) );
4065     Node* mask  = intcon(round_mask);
4066     header_size = _gvn.transform( new AddINode(hsize, mask) );
4067   }
4068 
4069   Node* elem_shift = NULL;
4070   if (layout_is_con) {
4071     int eshift = Klass::layout_helper_log2_element_size(layout_con);
4072     if (eshift != 0)
4073       elem_shift = intcon(eshift);
4074   } else {
4075     // There is no need to mask or shift this value.
4076     // The semantics of LShiftINode include an implicit mask to 0x1F.


4120   // places, one where the length is sharply limited, and the other
4121   // after a successful allocation.
4122   Node* abody = lengthx;
4123   if (elem_shift != NULL)
4124     abody     = _gvn.transform( new LShiftXNode(lengthx, elem_shift) );
4125   Node* size  = _gvn.transform( new AddXNode(headerx, abody) );
4126   if (round_mask != 0) {
4127     Node* mask = MakeConX(~round_mask);
4128     size       = _gvn.transform( new AndXNode(size, mask) );
4129   }
4130   // else if round_mask == 0, the size computation is self-rounding
4131 
4132   if (return_size_val != NULL) {
4133     // This is the size
4134     (*return_size_val) = size;
4135   }
4136 
4137   // Now generate allocation code
4138 
4139   // The entire memory state is needed for slow path of the allocation
4140   // since GC and deoptimization can happen.
4141   Node *mem = reset_memory();
4142   set_all_memory(mem); // Create new memory state
4143 
4144   if (initial_slow_test->is_Bool()) {
4145     // Hide it behind a CMoveI, or else PhaseIdealLoop::split_up will get sick.
4146     initial_slow_test = initial_slow_test->as_Bool()->as_int_value(&_gvn);
4147   }
4148 
4149   const TypeOopPtr* ary_type = _gvn.type(klass_node)->is_klassptr()->as_instance_type();
4150   const TypeAryPtr* ary_ptr = ary_type->isa_aryptr();
4151   const Type* elem = NULL;
4152   ciKlass* elem_klass = NULL;
4153 
4154   // Compute default value and storage properties for value type arrays:
4155   // - null-ok:              MyValue.box[] (ciObjArrayKlass "[LMyValue")
4156   // - null-free:            MyValue.val[] (ciObjArrayKlass "[QMyValue")
4157   // - null-free, flattened: MyValue.val[] (ciValueArrayKlass "[QMyValue")
4158   Node* storage_properties = NULL;
4159   Node* default_value = NULL;
4160   Node* raw_default_value = NULL;
4161   int props_shift = UseCompressedClassPointers ? oopDesc::narrow_storage_props_shift : oopDesc::wide_storage_props_shift;
4162   if (ary_ptr != NULL && ary_ptr->klass_is_exact()) {
4163     // Array type is known
4164     elem = ary_ptr->elem();
4165     ciArrayKlass* ary_klass = ary_ptr->klass()->as_array_klass();
4166     elem_klass = ary_klass->element_klass();
4167 
4168     ArrayStorageProperties props = ary_klass->storage_properties();
4169     if (!props.is_empty() && elem_klass->is_valuetype()) {
4170       if (props.is_null_free() && !props.is_flattened()) {
4171         default_value = ValueTypeNode::default_oop(gvn(), elem_klass->as_value_klass());
4172         if (elem->isa_narrowoop()) {
4173           default_value = _gvn.transform(new EncodePNode(default_value, elem));
4174           raw_default_value = raw_default_for_coops(default_value, *this);
4175         } else {
4176           raw_default_value = _gvn.transform(new CastP2XNode(control(), default_value));
4177         }
4178       }
4179       storage_properties = MakeConX(props.encode<NOT_LP64(jint) LP64_ONLY(jlong)>(props_shift));
4180     }
4181   }
4182 
4183   if (EnableValhalla && (elem == NULL || (elem_klass != NULL && (elem_klass->is_java_lang_Object() || elem_klass->is_valuetype()) &&
4184                                           !ary_type->klass_is_exact()))) {
4185     // Array type is not known, compute default value and storage properties for initialization.
4186     assert(default_value == NULL && raw_default_value == NULL && storage_properties == NULL, "shouldn't be set yet");
4187     assert(elem_mirror != NULL, "should not be null");
4188 
4189     Node* r = new RegionNode(4);
4190     default_value = new PhiNode(r, TypeInstPtr::BOTTOM);
4191     storage_properties = new PhiNode(r, TypeX_X);
4192 
4193     Node* empty     = MakeConX(ArrayStorageProperties::empty.encode<NOT_LP64(jint) LP64_ONLY(jlong)>(props_shift));
4194     Node* null_free = MakeConX(ArrayStorageProperties::null_free.encode<NOT_LP64(jint) LP64_ONLY(jlong)>(props_shift));
4195     Node* flat      = MakeConX(ArrayStorageProperties::flattened_and_null_free.encode<NOT_LP64(jint) LP64_ONLY(jlong)>(props_shift));
4196 
4197     // Check if element mirror is a value mirror
4198     IfNode* iff = create_and_map_if(control(), is_value_mirror(elem_mirror), PROB_FAIR, COUNT_UNKNOWN);
4199 
4200     // Not a value mirror but a box mirror or not a value type array, initialize with all zero
4201     r->init_req(1, _gvn.transform(new IfFalseNode(iff)));
4202     default_value->init_req(1, null());
4203     storage_properties->init_req(1, empty);
4204 
4205     // Value mirror (= null-free), check if flattened
4206     set_control(_gvn.transform(new IfTrueNode(iff)));
4207     Node* cmp = gen_lh_array_test(klass_node, Klass::_lh_array_tag_vt_value);
4208     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
4209     iff = create_and_map_if(control(), bol, PROB_FAIR, COUNT_UNKNOWN);
4210 
4211     // Flattened, initialize with all zero
4212     r->init_req(2, _gvn.transform(new IfTrueNode(iff)));
4213     default_value->init_req(2, null());
4214     storage_properties->init_req(2, flat);
4215 
4216     // Non-flattened, initialize with the default value
4217     set_control(_gvn.transform(new IfFalseNode(iff)));
4218     Node* p = basic_plus_adr(klass_node, in_bytes(ArrayKlass::element_klass_offset()));
4219     Node* eklass = _gvn.transform(LoadKlassNode::make(_gvn, control(), immutable_memory(), p, TypeInstPtr::KLASS));
4220     Node* adr_fixed_block_addr = basic_plus_adr(eklass, in_bytes(InstanceKlass::adr_valueklass_fixed_block_offset()));
4221     Node* adr_fixed_block = make_load(control(), adr_fixed_block_addr, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
4222     Node* default_value_offset_addr = basic_plus_adr(adr_fixed_block, in_bytes(ValueKlass::default_value_offset_offset()));
4223     Node* default_value_offset = make_load(control(), default_value_offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
4224     Node* default_value_addr = basic_plus_adr(elem_mirror, ConvI2X(default_value_offset));
4225     Node* val = access_load_at(elem_mirror, default_value_addr, _gvn.type(default_value_addr)->is_ptr(), TypeInstPtr::BOTTOM, T_OBJECT, IN_HEAP);
4226     r->init_req(3, control());
4227     default_value->init_req(3, val);
4228     storage_properties->init_req(3, null_free);
4229 
4230     set_control(_gvn.transform(r));
4231     default_value = _gvn.transform(default_value);
4232     storage_properties = _gvn.transform(storage_properties);
4233     if (UseCompressedOops) {
4234       default_value = _gvn.transform(new EncodePNode(default_value, default_value->bottom_type()->make_narrowoop()));
4235       raw_default_value = raw_default_for_coops(default_value, *this);
4236     } else {
4237       raw_default_value = _gvn.transform(new CastP2XNode(control(), default_value));
4238     }
4239   }
4240 
4241   // Create the AllocateArrayNode and its result projections
4242   AllocateArrayNode* alloc = new AllocateArrayNode(C, AllocateArrayNode::alloc_type(TypeInt::INT),
4243                                                    control(), mem, i_o(),
4244                                                    size, klass_node,
4245                                                    initial_slow_test,
4246                                                    length, default_value,
4247                                                    raw_default_value,
4248                                                    storage_properties);
4249 
4250   // Cast to correct type.  Note that the klass_node may be constant or not,
4251   // and in the latter case the actual array type will be inexact also.
4252   // (This happens via a non-constant argument to inline_native_newArray.)
4253   // In any case, the value of klass_node provides the desired array type.
4254   const TypeInt* length_type = _gvn.find_int_type(length);

4255   if (ary_type->isa_aryptr() && length_type != NULL) {
4256     // Try to get a better type than POS for the size
4257     ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
4258   }
4259 
4260   Node* javaoop = set_output_for_allocation(alloc, ary_type, deoptimize_on_exception);
4261 
4262   // Cast length on remaining path to be as narrow as possible
4263   if (map()->find_edge(length) >= 0) {
4264     Node* ccast = alloc->make_ideal_length(ary_type, &_gvn);
4265     if (ccast != length) {
4266       _gvn.set_type_bottom(ccast);
4267       record_for_igvn(ccast);
4268       replace_in_map(length, ccast);
4269     }
4270   }
4271 
4272   return javaoop;
4273 }
4274 


4389   set_all_memory(ideal.merged_memory());
4390   set_i_o(ideal.i_o());
4391   set_control(ideal.ctrl());
4392 }
4393 
4394 void GraphKit::final_sync(IdealKit& ideal) {
4395   // Final sync IdealKit and graphKit.
4396   sync_kit(ideal);
4397 }
4398 
4399 Node* GraphKit::load_String_length(Node* str, bool set_ctrl) {
4400   Node* len = load_array_length(load_String_value(str, set_ctrl));
4401   Node* coder = load_String_coder(str, set_ctrl);
4402   // Divide length by 2 if coder is UTF16
4403   return _gvn.transform(new RShiftINode(len, coder));
4404 }
4405 
4406 Node* GraphKit::load_String_value(Node* str, bool set_ctrl) {
4407   int value_offset = java_lang_String::value_offset_in_bytes();
4408   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4409                                                      false, NULL, Type::Offset(0));
4410   const TypePtr* value_field_type = string_type->add_offset(value_offset);
4411   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,
4412                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS, false, true, true),
4413                                                   ciTypeArrayKlass::make(T_BYTE), true, Type::Offset(0));
4414   Node* p = basic_plus_adr(str, str, value_offset);
4415   Node* load = access_load_at(str, p, value_field_type, value_type, T_OBJECT,
4416                               IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED);
4417   return load;
4418 }
4419 
4420 Node* GraphKit::load_String_coder(Node* str, bool set_ctrl) {
4421   if (!CompactStrings) {
4422     return intcon(java_lang_String::CODER_UTF16);
4423   }
4424   int coder_offset = java_lang_String::coder_offset_in_bytes();
4425   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4426                                                      false, NULL, Type::Offset(0));
4427   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
4428 
4429   Node* p = basic_plus_adr(str, str, coder_offset);
4430   Node* load = access_load_at(str, p, coder_field_type, TypeInt::BYTE, T_BYTE,
4431                               IN_HEAP | (set_ctrl ? C2_CONTROL_DEPENDENT_LOAD : 0) | MO_UNORDERED);
4432   return load;
4433 }
4434 
4435 void GraphKit::store_String_value(Node* str, Node* value) {
4436   int value_offset = java_lang_String::value_offset_in_bytes();
4437   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4438                                                      false, NULL, Type::Offset(0));
4439   const TypePtr* value_field_type = string_type->add_offset(value_offset);
4440 
4441   access_store_at(str,  basic_plus_adr(str, value_offset), value_field_type,
4442                   value, TypeAryPtr::BYTES, T_OBJECT, IN_HEAP | MO_UNORDERED);
4443 }
4444 
4445 void GraphKit::store_String_coder(Node* str, Node* value) {
4446   int coder_offset = java_lang_String::coder_offset_in_bytes();
4447   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4448                                                      false, NULL, Type::Offset(0));
4449   const TypePtr* coder_field_type = string_type->add_offset(coder_offset);
4450 
4451   access_store_at(str, basic_plus_adr(str, coder_offset), coder_field_type,
4452                   value, TypeInt::BYTE, T_BYTE, IN_HEAP | MO_UNORDERED);
4453 }
4454 
4455 // Capture src and dst memory state with a MergeMemNode
4456 Node* GraphKit::capture_memory(const TypePtr* src_type, const TypePtr* dst_type) {
4457   if (src_type == dst_type) {
4458     // Types are equal, we don't need a MergeMemNode
4459     return memory(src_type);
4460   }
4461   MergeMemNode* merge = MergeMemNode::make(map()->memory());
4462   record_for_igvn(merge); // fold it up later, if possible
4463   int src_idx = C->get_alias_index(src_type);
4464   int dst_idx = C->get_alias_index(dst_type);
4465   merge->set_memory_at(src_idx, memory(src_idx));
4466   merge->set_memory_at(dst_idx, memory(dst_idx));
4467   return merge;
4468 }


4541   i_char->init_req(2, AddI(i_char, intcon(2)));
4542 
4543   set_control(IfFalse(iff));
4544   set_memory(st, TypeAryPtr::BYTES);
4545 }
4546 
4547 Node* GraphKit::make_constant_from_field(ciField* field, Node* obj) {
4548   if (!field->is_constant()) {
4549     return NULL; // Field not marked as constant.
4550   }
4551   ciInstance* holder = NULL;
4552   if (!field->is_static()) {
4553     ciObject* const_oop = obj->bottom_type()->is_oopptr()->const_oop();
4554     if (const_oop != NULL && const_oop->is_instance()) {
4555       holder = const_oop->as_instance();
4556     }
4557   }
4558   const Type* con_type = Type::make_constant_from_field(field, holder, field->layout_type(),
4559                                                         /*is_unsigned_load=*/false);
4560   if (con_type != NULL) {
4561     Node* con = makecon(con_type);
4562     if (field->layout_type() == T_VALUETYPE && field->type()->as_value_klass()->is_scalarizable() && !con_type->maybe_null()) {
4563       // Load value type from constant oop
4564       con = ValueTypeNode::make_from_oop(this, con, field->type()->as_value_klass());
4565     }
4566     return con;
4567   }
4568   return NULL;
4569 }
4570 
4571 //---------------------------load_mirror_from_klass----------------------------
4572 // Given a klass oop, load its java mirror (a java.lang.Class oop).
4573 Node* GraphKit::load_mirror_from_klass(Node* klass) {
4574   Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset()));
4575   Node* load = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
4576   // mirror = ((OopHandle)mirror)->resolve();
4577   return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE);
4578 }
< prev index next >