< prev index next >

src/hotspot/share/opto/library_call.cpp

Print this page




  40 #include "opto/castnode.hpp"
  41 #include "opto/cfgnode.hpp"
  42 #include "opto/convertnode.hpp"
  43 #include "opto/countbitsnode.hpp"
  44 #include "opto/intrinsicnode.hpp"
  45 #include "opto/idealKit.hpp"
  46 #include "opto/mathexactnode.hpp"
  47 #include "opto/movenode.hpp"
  48 #include "opto/mulnode.hpp"
  49 #include "opto/narrowptrnode.hpp"
  50 #include "opto/opaquenode.hpp"
  51 #include "opto/parse.hpp"
  52 #include "opto/runtime.hpp"
  53 #include "opto/rootnode.hpp"
  54 #include "opto/subnode.hpp"
  55 #include "prims/nativeLookup.hpp"
  56 #include "prims/unsafe.hpp"
  57 #include "runtime/objectMonitor.hpp"
  58 #include "runtime/sharedRuntime.hpp"
  59 #include "utilities/macros.hpp"




  60 
  61 
  62 class LibraryIntrinsic : public InlineCallGenerator {
  63   // Extend the set of intrinsics known to the runtime:
  64  public:
  65  private:
  66   bool             _is_virtual;
  67   bool             _does_virtual_dispatch;
  68   int8_t           _predicates_count;  // Intrinsic is predicated by several conditions
  69   int8_t           _last_predicate; // Last generated predicate
  70   vmIntrinsics::ID _intrinsic_id;
  71 
  72  public:
  73   LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
  74     : InlineCallGenerator(m),
  75       _is_virtual(is_virtual),
  76       _does_virtual_dispatch(does_virtual_dispatch),
  77       _predicates_count((int8_t)predicates_count),
  78       _last_predicate((int8_t)-1),
  79       _intrinsic_id(id)


 227   bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName);
 228   bool inline_math_native(vmIntrinsics::ID id);
 229   bool inline_math(vmIntrinsics::ID id);
 230   template <typename OverflowOp>
 231   bool inline_math_overflow(Node* arg1, Node* arg2);
 232   void inline_math_mathExact(Node* math, Node* test);
 233   bool inline_math_addExactI(bool is_increment);
 234   bool inline_math_addExactL(bool is_increment);
 235   bool inline_math_multiplyExactI();
 236   bool inline_math_multiplyExactL();
 237   bool inline_math_multiplyHigh();
 238   bool inline_math_negateExactI();
 239   bool inline_math_negateExactL();
 240   bool inline_math_subtractExactI(bool is_decrement);
 241   bool inline_math_subtractExactL(bool is_decrement);
 242   bool inline_min_max(vmIntrinsics::ID id);
 243   bool inline_notify(vmIntrinsics::ID id);
 244   Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
 245   // This returns Type::AnyPtr, RawPtr, or OopPtr.
 246   int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
 247   Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false);
 248 
 249   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
 250   DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
 251   bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
 252   static bool klass_needs_init_guard(Node* kls);
 253   bool inline_unsafe_allocate();
 254   bool inline_unsafe_newArray(bool uninitialized);
 255   bool inline_unsafe_copyMemory();
 256   bool inline_native_currentThread();
 257 
 258   bool inline_native_time_funcs(address method, const char* funcName);
 259 #ifdef JFR_HAVE_INTRINSICS
 260   bool inline_native_classID();
 261   bool inline_native_getEventWriter();
 262 #endif
 263   bool inline_native_isInterrupted();
 264   bool inline_native_Class_query(vmIntrinsics::ID id);
 265   bool inline_native_subtype_check();
 266   bool inline_native_getLength();
 267   bool inline_array_copyOf(bool is_copyOfRange);


 318   bool inline_updateByteBufferAdler32();
 319   bool inline_multiplyToLen();
 320   bool inline_hasNegatives();
 321   bool inline_squareToLen();
 322   bool inline_mulAdd();
 323   bool inline_montgomeryMultiply();
 324   bool inline_montgomerySquare();
 325   bool inline_vectorizedMismatch();
 326   bool inline_fma(vmIntrinsics::ID id);
 327   bool inline_character_compare(vmIntrinsics::ID id);
 328 
 329   bool inline_profileBoolean();
 330   bool inline_isCompileConstant();
 331   void clear_upper_avx() {
 332 #ifdef X86
 333     if (UseAVX >= 2) {
 334       C->set_clear_upper_avx(true);
 335     }
 336 #endif
 337   }




 338 };
 339 
 340 //---------------------------make_vm_intrinsic----------------------------
 341 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
 342   vmIntrinsics::ID id = m->intrinsic_id();
 343   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 344 
 345   if (!m->is_loaded()) {
 346     // Do not attempt to inline unloaded methods.
 347     return NULL;
 348   }
 349 
 350   C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
 351   bool is_available = false;
 352 
 353   {
 354     // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
 355     // the compiler must transition to '_thread_in_vm' state because both
 356     // methods access VM-internal data.
 357     VM_ENTRY_MARK;


1090     result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES),
1091                                str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae);
1092     break;
1093   default:
1094     ShouldNotReachHere();
1095     return NULL;
1096   }
1097 
1098   // All these intrinsics have checks.
1099   C->set_has_split_ifs(true); // Has chance for split-if optimization
1100   clear_upper_avx();
1101 
1102   return _gvn.transform(result);
1103 }
1104 
1105 //------------------------------inline_string_compareTo------------------------
1106 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) {
1107   Node* arg1 = argument(0);
1108   Node* arg2 = argument(1);
1109 






1110   // Get start addr and length of first argument
1111   Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
1112   Node* arg1_cnt    = load_array_length(arg1);
1113 
1114   // Get start addr and length of second argument
1115   Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
1116   Node* arg2_cnt    = load_array_length(arg2);
1117 
1118   Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
1119   set_result(result);
1120   return true;
1121 }
1122 
1123 //------------------------------inline_string_equals------------------------
1124 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) {
1125   Node* arg1 = argument(0);
1126   Node* arg2 = argument(1);
1127 
1128   // paths (plus control) merge
1129   RegionNode* region = new RegionNode(3);
1130   Node* phi = new PhiNode(region, TypeInt::BOOL);
1131 
1132   if (!stopped()) {
1133     // Get start addr and length of first argument







1134     Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
1135     Node* arg1_cnt    = load_array_length(arg1);
1136 
1137     // Get start addr and length of second argument
1138     Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
1139     Node* arg2_cnt    = load_array_length(arg2);
1140 
1141     // Check for arg1_cnt != arg2_cnt
1142     Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt));
1143     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
1144     Node* if_ne = generate_slow_guard(bol, NULL);
1145     if (if_ne != NULL) {
1146       phi->init_req(2, intcon(0));
1147       region->init_req(2, if_ne);
1148     }
1149 
1150     // Check for count == 0 is done by assembler code for StrEquals.
1151 
1152     if (!stopped()) {
1153       Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
1154       phi->init_req(1, equals);
1155       region->init_req(1, control());
1156     }
1157   }
1158 
1159   // post merge
1160   set_control(_gvn.transform(region));
1161   record_for_igvn(region);
1162 
1163   set_result(_gvn.transform(phi));
1164   return true;
1165 }
1166 
1167 //------------------------------inline_array_equals----------------------------
1168 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
1169   assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types");
1170   Node* arg1 = argument(0);
1171   Node* arg2 = argument(1);
1172 



1173   const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES;
1174   set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae)));
1175   clear_upper_avx();
1176 
1177   return true;
1178 }
1179 
1180 //------------------------------inline_hasNegatives------------------------------
1181 bool LibraryCallKit::inline_hasNegatives() {
1182   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1183     return false;
1184   }
1185 
1186   assert(callee()->signature()->size() == 3, "hasNegatives has 3 parameters");
1187   // no receiver since it is static method
1188   Node* ba         = argument(0);
1189   Node* offset     = argument(1);
1190   Node* len        = argument(2);
1191 


1192   // Range checks
1193   generate_string_range_check(ba, offset, len, false);
1194   if (stopped()) {
1195     return true;
1196   }



1197   Node* ba_start = array_element_address(ba, offset, T_BYTE);
1198   Node* result = new HasNegativesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len);
1199   set_result(_gvn.transform(result));
1200   return true;
1201 }
1202 
1203 bool LibraryCallKit::inline_preconditions_checkIndex() {
1204   Node* index = argument(0);
1205   Node* length = argument(1);
1206   if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) {
1207     return false;
1208   }
1209 
1210   Node* len_pos_cmp = _gvn.transform(new CmpINode(length, intcon(0)));
1211   Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge));
1212 
1213   {
1214     BuildCutout unless(this, len_pos_bol, PROB_MAX);
1215     uncommon_trap(Deoptimization::Reason_intrinsic,
1216                   Deoptimization::Action_make_not_entrant);


1244   result->set_req(0, control());
1245   result = _gvn.transform(result);
1246   set_result(result);
1247   replace_in_map(index, result);
1248   clear_upper_avx();
1249   return true;
1250 }
1251 
1252 //------------------------------inline_string_indexOf------------------------
1253 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) {
1254   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
1255     return false;
1256   }
1257   Node* src = argument(0);
1258   Node* tgt = argument(1);
1259 
1260   // Make the merge point
1261   RegionNode* result_rgn = new RegionNode(4);
1262   Node*       result_phi = new PhiNode(result_rgn, TypeInt::INT);
1263 






1264   // Get start addr and length of source string
1265   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
1266   Node* src_count = load_array_length(src);
1267 
1268   // Get start addr and length of substring
1269   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
1270   Node* tgt_count = load_array_length(tgt);
1271 
1272   if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) {
1273     // Divide src size by 2 if String is UTF16 encoded
1274     src_count = _gvn.transform(new RShiftINode(src_count, intcon(1)));
1275   }
1276   if (ae == StrIntrinsicNode::UU) {
1277     // Divide substring size by 2 if String is UTF16 encoded
1278     tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1)));
1279   }
1280 
1281   Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, result_rgn, result_phi, ae);
1282   if (result != NULL) {
1283     result_phi->init_req(3, result);


1288   set_result(_gvn.transform(result_phi));
1289 
1290   return true;
1291 }
1292 
1293 //-----------------------------inline_string_indexOf-----------------------
1294 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) {
1295   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1296     return false;
1297   }
1298   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
1299     return false;
1300   }
1301   assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments");
1302   Node* src         = argument(0); // byte[]
1303   Node* src_count   = argument(1); // char count
1304   Node* tgt         = argument(2); // byte[]
1305   Node* tgt_count   = argument(3); // char count
1306   Node* from_index  = argument(4); // char index
1307 






1308   // Multiply byte array index by 2 if String is UTF16 encoded
1309   Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
1310   src_count = _gvn.transform(new SubINode(src_count, from_index));
1311   Node* src_start = array_element_address(src, src_offset, T_BYTE);
1312   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
1313 
1314   // Range checks
1315   generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL);
1316   generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU);
1317   if (stopped()) {
1318     return true;
1319   }
1320 
1321   RegionNode* region = new RegionNode(5);
1322   Node* phi = new PhiNode(region, TypeInt::INT);
1323 
1324   Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, region, phi, ae);
1325   if (result != NULL) {
1326     // The result is index relative to from_index if substring was found, -1 otherwise.
1327     // Generate code which will fold into cmove.


1373   if (!stopped()) {
1374     return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae);
1375   }
1376   return NULL;
1377 }
1378 
1379 //-----------------------------inline_string_indexOfChar-----------------------
1380 bool LibraryCallKit::inline_string_indexOfChar() {
1381   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1382     return false;
1383   }
1384   if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) {
1385     return false;
1386   }
1387   assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments");
1388   Node* src         = argument(0); // byte[]
1389   Node* tgt         = argument(1); // tgt is int ch
1390   Node* from_index  = argument(2);
1391   Node* max         = argument(3);
1392 



1393   Node* src_offset = _gvn.transform(new LShiftINode(from_index, intcon(1)));
1394   Node* src_start = array_element_address(src, src_offset, T_BYTE);
1395   Node* src_count = _gvn.transform(new SubINode(max, from_index));
1396 
1397   // Range checks
1398   generate_string_range_check(src, src_offset, src_count, true);
1399   if (stopped()) {
1400     return true;
1401   }
1402 
1403   RegionNode* region = new RegionNode(3);
1404   Node* phi = new PhiNode(region, TypeInt::INT);
1405 
1406   Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, tgt, StrIntrinsicNode::none);
1407   C->set_has_split_ifs(true); // Has chance for split-if optimization
1408   _gvn.transform(result);
1409 
1410   Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
1411   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
1412 


1443 
1444   Node* src         = argument(0);
1445   Node* src_offset  = argument(1);
1446   Node* dst         = argument(2);
1447   Node* dst_offset  = argument(3);
1448   Node* length      = argument(4);
1449 
1450   // Check for allocation before we add nodes that would confuse
1451   // tightly_coupled_allocation()
1452   AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL);
1453 
1454   // Figure out the size and type of the elements we will be copying.
1455   const Type* src_type = src->Value(&_gvn);
1456   const Type* dst_type = dst->Value(&_gvn);
1457   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
1458   BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
1459   assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) ||
1460          (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)),
1461          "Unsupported array types for inline_string_copy");
1462 



1463   // Convert char[] offsets to byte[] offsets
1464   bool convert_src = (compress && src_elem == T_BYTE);
1465   bool convert_dst = (!compress && dst_elem == T_BYTE);
1466   if (convert_src) {
1467     src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1)));
1468   } else if (convert_dst) {
1469     dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1)));
1470   }
1471 
1472   // Range checks
1473   generate_string_range_check(src, src_offset, length, convert_src);
1474   generate_string_range_check(dst, dst_offset, length, convert_dst);
1475   if (stopped()) {
1476     return true;
1477   }
1478 



1479   Node* src_start = array_element_address(src, src_offset, src_elem);
1480   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
1481   // 'src_start' points to src array + scaled offset
1482   // 'dst_start' points to dst array + scaled offset
1483   Node* count = NULL;
1484   if (compress) {
1485     count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length);
1486   } else {
1487     inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length);
1488   }
1489 
1490   if (alloc != NULL) {
1491     if (alloc->maybe_set_complete(&_gvn)) {
1492       // "You break it, you buy it."
1493       InitializeNode* init = alloc->initialization();
1494       assert(init->is_complete(), "we just did this");
1495       init->set_complete_with_arraycopy();
1496       assert(dst->is_CheckCastPP(), "sanity");
1497       assert(dst->in(0)->in(0) == init, "dest pinned");
1498     }


1549     generate_limit_guard(offset, length, load_array_length(value), bailout);
1550     // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE
1551     generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout);
1552 
1553     if (bailout->req() > 1) {
1554       PreserveJVMState pjvms(this);
1555       set_control(_gvn.transform(bailout));
1556       uncommon_trap(Deoptimization::Reason_intrinsic,
1557                     Deoptimization::Action_maybe_recompile);
1558     }
1559     if (stopped()) {
1560       return true;
1561     }
1562 
1563     Node* size = _gvn.transform(new LShiftINode(length, intcon(1)));
1564     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE)));
1565     newcopy = new_array(klass_node, size, 0);  // no arguments to push
1566     AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy, NULL);
1567 
1568     // Calculate starting addresses.


1569     Node* src_start = array_element_address(value, offset, T_CHAR);
1570     Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1571 
1572     // Check if src array address is aligned to HeapWordSize (dst is always aligned)
1573     const TypeInt* toffset = gvn().type(offset)->is_int();
1574     bool aligned = toffset->is_con() && ((toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
1575 
1576     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
1577     const char* copyfunc_name = "arraycopy";
1578     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
1579     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
1580                       OptoRuntime::fast_arraycopy_Type(),
1581                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
1582                       src_start, dst_start, ConvI2X(length) XTOP);
1583     // Do not let reads from the cloned object float above the arraycopy.
1584     if (alloc != NULL) {
1585       if (alloc->maybe_set_complete(&_gvn)) {
1586         // "You break it, you buy it."
1587         InitializeNode* init = alloc->initialization();
1588         assert(init->is_complete(), "we just did this");


1632 
1633   // Check if a null path was taken unconditionally.
1634   src = null_check(src);
1635   dst = null_check(dst);
1636   if (stopped()) {
1637     return true;
1638   }
1639 
1640   // Get length and convert char[] offset to byte[] offset
1641   Node* length = _gvn.transform(new SubINode(src_end, src_begin));
1642   src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1)));
1643 
1644   // Range checks
1645   generate_string_range_check(src, src_begin, length, true);
1646   generate_string_range_check(dst, dst_begin, length, false);
1647   if (stopped()) {
1648     return true;
1649   }
1650 
1651   if (!stopped()) {




1652     // Calculate starting addresses.
1653     Node* src_start = array_element_address(src, src_begin, T_BYTE);
1654     Node* dst_start = array_element_address(dst, dst_begin, T_CHAR);
1655 
1656     // Check if array addresses are aligned to HeapWordSize
1657     const TypeInt* tsrc = gvn().type(src_begin)->is_int();
1658     const TypeInt* tdst = gvn().type(dst_begin)->is_int();
1659     bool aligned = tsrc->is_con() && ((tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) &&
1660                    tdst->is_con() && ((tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
1661 
1662     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
1663     const char* copyfunc_name = "arraycopy";
1664     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
1665     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
1666                       OptoRuntime::fast_arraycopy_Type(),
1667                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
1668                       src_start, dst_start, ConvI2X(length) XTOP);
1669     // Do not let reads from the cloned object float above the arraycopy.
1670     if (alloc != NULL) {
1671       if (alloc->maybe_set_complete(&_gvn)) {


1699 // static char StringUTF16.getChar(byte[] val, int index)
1700 bool LibraryCallKit::inline_string_char_access(bool is_store) {
1701   Node* value  = argument(0);
1702   Node* index  = argument(1);
1703   Node* ch = is_store ? argument(2) : NULL;
1704 
1705   // This intrinsic accesses byte[] array as char[] array. Computing the offsets
1706   // correctly requires matched array shapes.
1707   assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE),
1708           "sanity: byte[] and char[] bases agree");
1709   assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2,
1710           "sanity: byte[] and char[] scales agree");
1711 
1712   // Bail when getChar over constants is requested: constant folding would
1713   // reject folding mismatched char access over byte[]. A normal inlining for getChar
1714   // Java method would constant fold nicely instead.
1715   if (!is_store && value->is_Con() && index->is_Con()) {
1716     return false;
1717   }
1718 








1719   Node* adr = array_element_address(value, index, T_CHAR);
1720   if (adr->is_top()) {
1721     return false;
1722   }
1723   if (is_store) {
1724     (void) store_to_memory(control(), adr, ch, T_CHAR, TypeAryPtr::BYTES, MemNode::unordered,
1725                            false, false, true /* mismatched */);
1726   } else {
1727     ch = make_load(control(), adr, TypeInt::CHAR, T_CHAR, TypeAryPtr::BYTES, MemNode::unordered,
1728                    LoadNode::DependsOnlyOnTest, false, false, true /* mismatched */);
1729     set_result(ch);
1730   }
1731   return true;
1732 }
1733 
1734 //--------------------------round_double_node--------------------------------
1735 // Round a double node if necessary.
1736 Node* LibraryCallKit::round_double_node(Node* n) {
1737   if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1)
1738     n = _gvn.transform(new RoundDoubleNode(0, n));


2136     // Offset is small => always a heap address.
2137     const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
2138     if (offset_type != NULL &&
2139         base_type->offset() == 0 &&     // (should always be?)
2140         offset_type->_lo >= 0 &&
2141         !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
2142       return Type::OopPtr;
2143     } else if (type == T_OBJECT) {
2144       // off heap access to an oop doesn't make any sense. Has to be on
2145       // heap.
2146       return Type::OopPtr;
2147     }
2148     // Otherwise, it might either be oop+off or NULL+addr.
2149     return Type::AnyPtr;
2150   } else {
2151     // No information:
2152     return Type::AnyPtr;
2153   }
2154 }
2155 
2156 inline Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, BasicType type, bool can_cast) {
2157   Node* uncasted_base = base;
2158   int kind = classify_unsafe_addr(uncasted_base, offset, type);
2159   if (kind == Type::RawPtr) {
2160     return basic_plus_adr(top(), uncasted_base, offset);
2161   } else if (kind == Type::AnyPtr) {
2162     assert(base == uncasted_base, "unexpected base change");
2163     if (can_cast) {
2164       if (!_gvn.type(base)->speculative_maybe_null() &&
2165           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
2166         // According to profiling, this access is always on
2167         // heap. Casting the base to not null and thus avoiding membars
2168         // around the access should allow better optimizations
2169         Node* null_ctl = top();
2170         base = null_check_oop(base, &null_ctl, true, true, true);
2171         assert(null_ctl->is_top(), "no null control here");
2172         return basic_plus_adr(base, offset);











2173       } else if (_gvn.type(base)->speculative_always_null() &&
2174                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
2175         // According to profiling, this access is always off
2176         // heap.
2177         base = null_assert(base);
2178         Node* raw_base = _gvn.transform(new CastX2PNode(offset));
2179         offset = MakeConX(0);
2180         return basic_plus_adr(top(), raw_base, offset);
2181       }
2182     }
2183     // We don't know if it's an on heap or off heap access. Fall back
2184     // to raw memory access.
2185     Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM));











2186     return basic_plus_adr(top(), raw, offset);
2187   } else {
2188     assert(base == uncasted_base, "unexpected base change");
2189     // We know it's an on heap access so base can't be null
2190     if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) {
2191       base = must_be_not_null(base, true);
2192     }
2193     return basic_plus_adr(base, offset);











2194   }
2195 }
2196 
2197 //--------------------------inline_number_methods-----------------------------
2198 // inline int     Integer.numberOfLeadingZeros(int)
2199 // inline int        Long.numberOfLeadingZeros(long)
2200 //
2201 // inline int     Integer.numberOfTrailingZeros(int)
2202 // inline int        Long.numberOfTrailingZeros(long)
2203 //
2204 // inline int     Integer.bitCount(int)
2205 // inline int        Long.bitCount(long)
2206 //
2207 // inline char  Character.reverseBytes(char)
2208 // inline short     Short.reverseBytes(short)
2209 // inline int     Integer.reverseBytes(int)
2210 // inline long       Long.reverseBytes(long)
2211 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) {
2212   Node* arg = argument(0);
2213   Node* n = NULL;


2331 
2332   Node* receiver = argument(0);  // type: oop
2333 
2334   // Build address expression.
2335   Node* adr;
2336   Node* heap_base_oop = top();
2337   Node* offset = top();
2338   Node* val;
2339 
2340   // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2341   Node* base = argument(1);  // type: oop
2342   // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2343   offset = argument(2);  // type: long
2344   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2345   // to be plain byte offsets, which are also the same as those accepted
2346   // by oopDesc::field_addr.
2347   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2348          "fieldOffset must be byte-scaled");
2349   // 32-bit machines ignore the high half!
2350   offset = ConvL2X(offset);
2351   adr = make_unsafe_address(base, offset, type, kind == Relaxed);
2352 
2353   if (_gvn.type(base)->isa_ptr() != TypePtr::NULL_PTR) {
2354     heap_base_oop = base;
2355   } else if (type == T_OBJECT) {
2356     return false; // off-heap oop accesses are not supported
2357   }
2358 
2359   // Can base be NULL? Otherwise, always on-heap access.
2360   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base));
2361 
2362   if (!can_access_non_heap) {
2363     decorators |= IN_HEAP;
2364   }
2365 
2366   val = is_store ? argument(4) : NULL;
2367 
2368   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2369 
2370   // Try to categorize the address.
2371   Compile::AliasType* alias_type = C->alias_type(adr_type);
2372   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");


2615     case LS_get_add:
2616     case LS_get_set: {
2617       receiver = argument(0);  // type: oop
2618       base     = argument(1);  // type: oop
2619       offset   = argument(2);  // type: long
2620       oldval   = NULL;
2621       newval   = argument(4);  // type: oop, int, or long
2622       break;
2623     }
2624     default:
2625       ShouldNotReachHere();
2626   }
2627 
2628   // Build field offset expression.
2629   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2630   // to be plain byte offsets, which are also the same as those accepted
2631   // by oopDesc::field_addr.
2632   assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
2633   // 32-bit machines ignore the high half of long offsets
2634   offset = ConvL2X(offset);
2635   Node* adr = make_unsafe_address(base, offset, type, false);
2636   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2637 
2638   Compile::AliasType* alias_type = C->alias_type(adr_type);
2639   BasicType bt = alias_type->basic_type();
2640   if (bt != T_ILLEGAL &&
2641       ((bt == T_OBJECT || bt == T_ARRAY) != (type == T_OBJECT))) {
2642     // Don't intrinsify mismatched object accesses.
2643     return false;
2644   }
2645 
2646   // For CAS, unlike inline_unsafe_access, there seems no point in
2647   // trying to refine types. Just use the coarse types here.
2648   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2649   const Type *value_type = Type::get_const_basic_type(type);
2650 
2651   switch (kind) {
2652     case LS_get_set:
2653     case LS_cmp_exchange: {
2654       if (type == T_OBJECT) {
2655         const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);


2910     no_int_result_path   = 1, // t == Thread.current() && !TLS._osthread._interrupted
2911     no_clear_result_path = 2, // t == Thread.current() &&  TLS._osthread._interrupted && !clear_int
2912     slow_result_path     = 3, // slow path: t.isInterrupted(clear_int)
2913     PATH_LIMIT
2914   };
2915 
2916   // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag
2917   // out of the function.
2918   insert_mem_bar(Op_MemBarCPUOrder);
2919 
2920   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
2921   PhiNode*    result_val = new PhiNode(result_rgn, TypeInt::BOOL);
2922 
2923   RegionNode* slow_region = new RegionNode(1);
2924   record_for_igvn(slow_region);
2925 
2926   // (a) Receiving thread must be the current thread.
2927   Node* rec_thr = argument(0);
2928   Node* tls_ptr = NULL;
2929   Node* cur_thr = generate_current_thread(tls_ptr);



2930   Node* cmp_thr = _gvn.transform(new CmpPNode(cur_thr, rec_thr));
2931   Node* bol_thr = _gvn.transform(new BoolNode(cmp_thr, BoolTest::ne));
2932 
2933   generate_slow_guard(bol_thr, slow_region);
2934 
2935   // (b) Interrupt bit on TLS must be false.
2936   Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
2937   Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
2938   p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
2939 
2940   // Set the control input on the field _interrupted read to prevent it floating up.
2941   Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered);
2942   Node* cmp_bit = _gvn.transform(new CmpINode(int_bit, intcon(0)));
2943   Node* bol_bit = _gvn.transform(new BoolNode(cmp_bit, BoolTest::ne));
2944 
2945   IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
2946 
2947   // First fast path:  if (!TLS._interrupted) return false;
2948   Node* false_bit = _gvn.transform(new IfFalseNode(iff_bit));
2949   result_rgn->init_req(no_int_result_path, false_bit);


3325   // Pull both arguments off the stack.
3326   Node* args[2];                // two java.lang.Class mirrors: superc, subc
3327   args[0] = argument(0);
3328   args[1] = argument(1);
3329   Node* klasses[2];             // corresponding Klasses: superk, subk
3330   klasses[0] = klasses[1] = top();
3331 
3332   enum {
3333     // A full decision tree on {superc is prim, subc is prim}:
3334     _prim_0_path = 1,           // {P,N} => false
3335                                 // {P,P} & superc!=subc => false
3336     _prim_same_path,            // {P,P} & superc==subc => true
3337     _prim_1_path,               // {N,P} => false
3338     _ref_subtype_path,          // {N,N} & subtype check wins => true
3339     _both_ref_path,             // {N,N} & subtype check loses => false
3340     PATH_LIMIT
3341   };
3342 
3343   RegionNode* region = new RegionNode(PATH_LIMIT);
3344   Node*       phi    = new PhiNode(region, TypeInt::BOOL);

3345   record_for_igvn(region);

3346 
3347   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
3348   const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3349   int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
3350 
3351   // First null-check both mirrors and load each mirror's klass metaobject.
3352   int which_arg;
3353   for (which_arg = 0; which_arg <= 1; which_arg++) {
3354     Node* arg = args[which_arg];
3355     arg = null_check(arg);
3356     if (stopped())  break;
3357     args[which_arg] = arg;
3358 
3359     Node* p = basic_plus_adr(arg, class_klass_offset);
3360     Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type);
3361     klasses[which_arg] = _gvn.transform(kls);
3362   }
3363 



3364   // Having loaded both klasses, test each for null.
3365   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3366   for (which_arg = 0; which_arg <= 1; which_arg++) {
3367     Node* kls = klasses[which_arg];
3368     Node* null_ctl = top();
3369     kls = null_check_oop(kls, &null_ctl, never_see_null);
3370     int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path);
3371     region->init_req(prim_path, null_ctl);
3372     if (stopped())  break;
3373     klasses[which_arg] = kls;
3374   }
3375 
3376   if (!stopped()) {
3377     // now we have two reference types, in klasses[0..1]
3378     Node* subk   = klasses[1];  // the argument to isAssignableFrom
3379     Node* superk = klasses[0];  // the receiver
3380     region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
3381     // now we have a successful reference subtype check
3382     region->set_req(_ref_subtype_path, control());
3383   }


3388   set_control(region->in(_prim_0_path)); // go back to first null check
3389   if (!stopped()) {
3390     // Since superc is primitive, make a guard for the superc==subc case.
3391     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
3392     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
3393     generate_guard(bol_eq, region, PROB_FAIR);
3394     if (region->req() == PATH_LIMIT+1) {
3395       // A guard was added.  If the added guard is taken, superc==subc.
3396       region->swap_edges(PATH_LIMIT, _prim_same_path);
3397       region->del_req(PATH_LIMIT);
3398     }
3399     region->set_req(_prim_0_path, control()); // Not equal after all.
3400   }
3401 
3402   // these are the only paths that produce 'true':
3403   phi->set_req(_prim_same_path,   intcon(1));
3404   phi->set_req(_ref_subtype_path, intcon(1));
3405 
3406   // pull together the cases:
3407   assert(region->req() == PATH_LIMIT, "sane region");

3408   for (uint i = 1; i < region->req(); i++) {
3409     Node* ctl = region->in(i);
3410     if (ctl == NULL || ctl == top()) {
3411       region->set_req(i, top());
3412       phi   ->set_req(i, top());
3413     } else if (phi->in(i) == NULL) {
3414       phi->set_req(i, intcon(0)); // all other paths produce 'false'




3415     }
3416   }
3417 
3418   set_control(_gvn.transform(region));
3419   set_result(_gvn.transform(phi));

3420   return true;
3421 }
3422 
3423 //---------------------generate_array_guard_common------------------------
3424 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
3425                                                   bool obj_array, bool not_array) {
3426 
3427   if (stopped()) {
3428     return NULL;
3429   }
3430 
3431   // If obj_array/non_array==false/false:
3432   // Branch around if the given klass is in fact an array (either obj or prim).
3433   // If obj_array/non_array==false/true:
3434   // Branch around if the given klass is not an array klass of any kind.
3435   // If obj_array/non_array==true/true:
3436   // Branch around if the kls is not an oop array (kls is int[], String, etc.)
3437   // If obj_array/non_array==true/false:
3438   // Branch around if the kls is an oop array (Object[] or subtype)
3439   //


3629 
3630     // Bail out if length is negative.
3631     // Without this the new_array would throw
3632     // NegativeArraySizeException but IllegalArgumentException is what
3633     // should be thrown
3634     generate_negative_guard(length, bailout, &length);
3635 
3636     if (bailout->req() > 1) {
3637       PreserveJVMState pjvms(this);
3638       set_control(_gvn.transform(bailout));
3639       uncommon_trap(Deoptimization::Reason_intrinsic,
3640                     Deoptimization::Action_maybe_recompile);
3641     }
3642 
3643     if (!stopped()) {
3644       // How many elements will we copy from the original?
3645       // The answer is MinI(orig_length - start, length).
3646       Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
3647       Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length);
3648 


3649       // Generate a direct call to the right arraycopy function(s).
3650       // We know the copy is disjoint but we might not know if the
3651       // oop stores need checking.
3652       // Extreme case:  Arrays.copyOf((Integer[])x, 10, String[].class).
3653       // This will fail a store-check if x contains any non-nulls.
3654 
3655       // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
3656       // loads/stores but it is legal only if we're sure the
3657       // Arrays.copyOf would succeed. So we need all input arguments
3658       // to the copyOf to be validated, including that the copy to the
3659       // new array won't trigger an ArrayStoreException. That subtype
3660       // check can be optimized if we know something on the type of
3661       // the input array from type speculation.
3662       if (_gvn.type(klass_node)->singleton()) {
3663         ciKlass* subk   = _gvn.type(load_object_klass(original))->is_klassptr()->klass();
3664         ciKlass* superk = _gvn.type(klass_node)->is_klassptr()->klass();
3665 
3666         int test = C->static_subtype_check(superk, subk);
3667         if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) {
3668           const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr();


3684           set_control(not_subtype_ctrl);
3685           uncommon_trap(Deoptimization::Reason_class_check,
3686                         Deoptimization::Action_make_not_entrant);
3687           assert(stopped(), "Should be stopped");
3688         }
3689         validated = true;
3690       }
3691 
3692       if (!stopped()) {
3693         newcopy = new_array(klass_node, length, 0);  // no arguments to push
3694 
3695         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false,
3696                                                 load_object_klass(original), klass_node);
3697         if (!is_copyOfRange) {
3698           ac->set_copyof(validated);
3699         } else {
3700           ac->set_copyofrange(validated);
3701         }
3702         Node* n = _gvn.transform(ac);
3703         if (n == ac) {



3704           ac->connect_outputs(this);
3705         } else {
3706           assert(validated, "shouldn't transform if all arguments not validated");
3707           set_all_memory(n);
3708         }
3709       }
3710     }
3711   } // original reexecute is set back here
3712 
3713   C->set_has_split_ifs(true); // Has chance for split-if optimization
3714   if (!stopped()) {
3715     set_result(newcopy);
3716   }
3717   return true;
3718 }
3719 
3720 
3721 //----------------------generate_virtual_guard---------------------------
3722 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
3723 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,


4119 }
4120 
4121 //----------------------inline_unsafe_copyMemory-------------------------
4122 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
4123 bool LibraryCallKit::inline_unsafe_copyMemory() {
4124   if (callee()->is_static())  return false;  // caller must have the capability!
4125   null_check_receiver();  // null-check receiver
4126   if (stopped())  return true;
4127 
4128   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
4129 
4130   Node* src_ptr =         argument(1);   // type: oop
4131   Node* src_off = ConvL2X(argument(2));  // type: long
4132   Node* dst_ptr =         argument(4);   // type: oop
4133   Node* dst_off = ConvL2X(argument(5));  // type: long
4134   Node* size    = ConvL2X(argument(7));  // type: long
4135 
4136   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
4137          "fieldOffset must be byte-scaled");
4138 
4139   Node* src = make_unsafe_address(src_ptr, src_off);
4140   Node* dst = make_unsafe_address(dst_ptr, dst_off);
4141 
4142   // Conservatively insert a memory barrier on all memory slices.
4143   // Do not let writes of the copy source or destination float below the copy.
4144   insert_mem_bar(Op_MemBarCPUOrder);
4145 
4146   // Call it.  Note that the length argument is not scaled.
4147   make_runtime_call(RC_LEAF|RC_NO_FP,
4148                     OptoRuntime::fast_arraycopy_Type(),
4149                     StubRoutines::unsafe_arraycopy(),
4150                     "unsafe_arraycopy",
4151                     TypeRawPtr::BOTTOM,
4152                     src, dst, size XTOP);
4153 
4154   // Do not let reads of the copy destination float above the copy.
4155   insert_mem_bar(Op_MemBarCPUOrder);
4156 
4157   return true;
4158 }
4159 
4160 //------------------------clone_coping-----------------------------------
4161 // Helper function for inline_native_clone.
4162 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) {
4163   assert(obj_size != NULL, "");
4164   Node* raw_obj = alloc_obj->in(1);
4165   assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), "");
4166 


4167   AllocateNode* alloc = NULL;
4168   if (ReduceBulkZeroing) {
4169     // We will be completely responsible for initializing this object -
4170     // mark Initialize node as complete.
4171     alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn);
4172     // The object was just allocated - there should be no any stores!
4173     guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), "");
4174     // Mark as complete_with_arraycopy so that on AllocateNode
4175     // expansion, we know this AllocateNode is initialized by an array
4176     // copy and a StoreStore barrier exists after the array copy.
4177     alloc->initialization()->set_complete_with_arraycopy();
4178   }
4179 
4180   // Copy the fastest available way.
4181   // TODO: generate fields copies for small objects instead.
4182   Node* size = _gvn.transform(obj_size);
4183 
4184   access_clone(control(), obj, alloc_obj, size, is_array);
4185 
4186   // Do not let reads from the cloned object float above the arraycopy.


4271     PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
4272     record_for_igvn(result_reg);
4273 
4274     Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL);
4275     if (array_ctl != NULL) {
4276       // It's an array.
4277       PreserveJVMState pjvms(this);
4278       set_control(array_ctl);
4279       Node* obj_length = load_array_length(obj);
4280       Node* obj_size  = NULL;
4281       Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size);  // no arguments to push
4282 
4283       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
4284       if (bs->array_copy_requires_gc_barriers(T_OBJECT)) {
4285         // If it is an oop array, it requires very special treatment,
4286         // because gc barriers are required when accessing the array.
4287         Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);
4288         if (is_obja != NULL) {
4289           PreserveJVMState pjvms2(this);
4290           set_control(is_obja);



4291           // Generate a direct call to the right arraycopy function(s).
4292           Node* alloc = tightly_coupled_allocation(alloc_obj, NULL);
4293           ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false);
4294           ac->set_cloneoop();
4295           Node* n = _gvn.transform(ac);
4296           assert(n == ac, "cannot disappear");



4297           ac->connect_outputs(this);
4298 
4299           result_reg->init_req(_objArray_path, control());
4300           result_val->init_req(_objArray_path, alloc_obj);
4301           result_i_o ->set_req(_objArray_path, i_o());
4302           result_mem ->set_req(_objArray_path, reset_memory());
4303         }
4304       }
4305       // Otherwise, there are no barriers to worry about.
4306       // (We can dispense with card marks if we know the allocation
4307       //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
4308       //  causes the non-eden paths to take compensating steps to
4309       //  simulate a fresh allocation, so that no further
4310       //  card marks are required in compiled code to initialize
4311       //  the object.)
4312 
4313       if (!stopped()) {
4314         copy_to_clone(obj, alloc_obj, obj_size, true);
4315 
4316         // Present the results of the copy.


4396 // we set the JVM state for uncommon traps between the allocation and
4397 // the arraycopy to the state before the allocation so, in case of
4398 // deoptimization, we'll reexecute the allocation and the
4399 // initialization.
4400 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) {
4401   if (alloc != NULL) {
4402     ciMethod* trap_method = alloc->jvms()->method();
4403     int trap_bci = alloc->jvms()->bci();
4404 
4405     if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &
4406           !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) {
4407       // Make sure there's no store between the allocation and the
4408       // arraycopy otherwise visible side effects could be rexecuted
4409       // in case of deoptimization and cause incorrect execution.
4410       bool no_interfering_store = true;
4411       Node* mem = alloc->in(TypeFunc::Memory);
4412       if (mem->is_MergeMem()) {
4413         for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) {
4414           Node* n = mms.memory();
4415           if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
4416             assert(n->is_Store(), "what else?");
4417             no_interfering_store = false;
4418             break;
4419           }
4420         }
4421       } else {
4422         for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) {
4423           Node* n = mms.memory();
4424           if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
4425             assert(n->is_Store(), "what else?");
4426             no_interfering_store = false;
4427             break;
4428           }
4429         }
4430       }
4431 
4432       if (no_interfering_store) {
4433         JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
4434         uint size = alloc->req();
4435         SafePointNode* sfpt = new SafePointNode(size, old_jvms);
4436         old_jvms->set_map(sfpt);
4437         for (uint i = 0; i < size; i++) {
4438           sfpt->init_req(i, alloc->in(i));
4439         }
4440         // re-push array length for deoptimization
4441         sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), alloc->in(AllocateNode::ALength));
4442         old_jvms->set_sp(old_jvms->sp()+1);
4443         old_jvms->set_monoff(old_jvms->monoff()+1);
4444         old_jvms->set_scloff(old_jvms->scloff()+1);
4445         old_jvms->set_endoff(old_jvms->endoff()+1);


4746     }
4747     {
4748       PreserveJVMState pjvms(this);
4749       set_control(_gvn.transform(slow_region));
4750       uncommon_trap(Deoptimization::Reason_intrinsic,
4751                     Deoptimization::Action_make_not_entrant);
4752       assert(stopped(), "Should be stopped");
4753     }
4754 
4755     const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr();
4756     const Type *toop = TypeOopPtr::make_from_klass(dest_klass_t->klass());
4757     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
4758   }
4759 
4760   arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx);
4761 
4762   if (stopped()) {
4763     return true;
4764   }
4765 
4766   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != NULL, negative_length_guard_generated,



4767                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
4768                                           // so the compiler has a chance to eliminate them: during macro expansion,
4769                                           // we have to set their control (CastPP nodes are eliminated).
4770                                           load_object_klass(src), load_object_klass(dest),
4771                                           load_array_length(src), load_array_length(dest));
4772 
4773   ac->set_arraycopy(validated);
4774 
4775   Node* n = _gvn.transform(ac);
4776   if (n == ac) {



4777     ac->connect_outputs(this);
4778   } else {
4779     assert(validated, "shouldn't transform if all arguments not validated");
4780     set_all_memory(n);
4781   }
4782   clear_upper_avx();
4783 
4784 
4785   return true;
4786 }
4787 
4788 
4789 // Helper function which determines if an arraycopy immediately follows
4790 // an allocation, with no intervening tests or other escapes for the object.
4791 AllocateArrayNode*
4792 LibraryCallKit::tightly_coupled_allocation(Node* ptr,
4793                                            RegionNode* slow_region) {
4794   if (stopped())             return NULL;  // no fast path
4795   if (C->AliasLevel() == 0)  return NULL;  // no MergeMems around
4796 




4797   AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn);
4798   if (alloc == NULL)  return NULL;
4799 
4800   Node* rawmem = memory(Compile::AliasIdxRaw);
4801   // Is the allocation's memory state untouched?
4802   if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) {
4803     // Bail out if there have been raw-memory effects since the allocation.
4804     // (Example:  There might have been a call or safepoint.)
4805     return NULL;
4806   }
4807   rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw);
4808   if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) {
4809     return NULL;
4810   }
4811 
4812   // There must be no unexpected observers of this allocation.
4813   for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) {
4814     Node* obs = ptr->fast_out(i);
4815     if (obs != this->map()) {
4816       return NULL;


4856 
4857   // If we get this far, we have an allocation which immediately
4858   // precedes the arraycopy, and we can take over zeroing the new object.
4859   // The arraycopy will finish the initialization, and provide
4860   // a new control state to which we will anchor the destination pointer.
4861 
4862   return alloc;
4863 }
4864 
4865 //-------------inline_encodeISOArray-----------------------------------
4866 // encode char[] to byte[] in ISO_8859_1
4867 bool LibraryCallKit::inline_encodeISOArray() {
4868   assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters");
4869   // no receiver since it is static method
4870   Node *src         = argument(0);
4871   Node *src_offset  = argument(1);
4872   Node *dst         = argument(2);
4873   Node *dst_offset  = argument(3);
4874   Node *length      = argument(4);
4875 






4876   const Type* src_type = src->Value(&_gvn);
4877   const Type* dst_type = dst->Value(&_gvn);
4878   const TypeAryPtr* top_src = src_type->isa_aryptr();
4879   const TypeAryPtr* top_dest = dst_type->isa_aryptr();
4880   if (top_src  == NULL || top_src->klass()  == NULL ||
4881       top_dest == NULL || top_dest->klass() == NULL) {
4882     // failed array check
4883     return false;
4884   }
4885 
4886   // Figure out the size and type of the elements we will be copying.
4887   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
4888   BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
4889   if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) {
4890     return false;
4891   }
4892 
4893   Node* src_start = array_element_address(src, src_offset, T_CHAR);
4894   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
4895   // 'src_start' points to src array + scaled offset


4908 
4909 //-------------inline_multiplyToLen-----------------------------------
4910 bool LibraryCallKit::inline_multiplyToLen() {
4911   assert(UseMultiplyToLenIntrinsic, "not implemented on this platform");
4912 
4913   address stubAddr = StubRoutines::multiplyToLen();
4914   if (stubAddr == NULL) {
4915     return false; // Intrinsic's stub is not implemented on this platform
4916   }
4917   const char* stubName = "multiplyToLen";
4918 
4919   assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters");
4920 
4921   // no receiver because it is a static method
4922   Node* x    = argument(0);
4923   Node* xlen = argument(1);
4924   Node* y    = argument(2);
4925   Node* ylen = argument(3);
4926   Node* z    = argument(4);
4927 






4928   const Type* x_type = x->Value(&_gvn);
4929   const Type* y_type = y->Value(&_gvn);
4930   const TypeAryPtr* top_x = x_type->isa_aryptr();
4931   const TypeAryPtr* top_y = y_type->isa_aryptr();
4932   if (top_x  == NULL || top_x->klass()  == NULL ||
4933       top_y == NULL || top_y->klass() == NULL) {
4934     // failed array check
4935     return false;
4936   }
4937 
4938   BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
4939   BasicType y_elem = y_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
4940   if (x_elem != T_INT || y_elem != T_INT) {
4941     return false;
4942   }
4943 
4944   // Set the original stack and the reexecute bit for the interpreter to reexecute
4945   // the bytecode that invokes BigInteger.multiplyToLen() if deoptimization happens
4946   // on the return from z array allocation in runtime.
4947   { PreserveReexecuteState preexecs(this);


4953     // 'y_start' points to y array + scaled ylen
4954 
4955     // Allocate the result array
4956     Node* zlen = _gvn.transform(new AddINode(xlen, ylen));
4957     ciKlass* klass = ciTypeArrayKlass::make(T_INT);
4958     Node* klass_node = makecon(TypeKlassPtr::make(klass));
4959 
4960     IdealKit ideal(this);
4961 
4962 #define __ ideal.
4963      Node* one = __ ConI(1);
4964      Node* zero = __ ConI(0);
4965      IdealVariable need_alloc(ideal), z_alloc(ideal);  __ declarations_done();
4966      __ set(need_alloc, zero);
4967      __ set(z_alloc, z);
4968      __ if_then(z, BoolTest::eq, null()); {
4969        __ increment (need_alloc, one);
4970      } __ else_(); {
4971        // Update graphKit memory and control from IdealKit.
4972        sync_kit(ideal);
4973        Node* zlen_arg = load_array_length(z);










4974        // Update IdealKit memory and control from graphKit.
4975        __ sync_kit(this);
4976        __ if_then(zlen_arg, BoolTest::lt, zlen); {
4977          __ increment (need_alloc, one);
4978        } __ end_if();
4979      } __ end_if();
4980 
4981      __ if_then(__ value(need_alloc), BoolTest::ne, zero); {
4982        // Update graphKit memory and control from IdealKit.
4983        sync_kit(ideal);
4984        Node * narr = new_array(klass_node, zlen, 1);
4985        // Update IdealKit memory and control from graphKit.
4986        __ sync_kit(this);
4987        __ set(z_alloc, narr);
4988      } __ end_if();
4989 
4990      sync_kit(ideal);
4991      z = __ value(z_alloc);
4992      // Can't use TypeAryPtr::INTS which uses Bottom offset.
4993      _gvn.set_type(z, TypeOopPtr::make_from_klass(klass));


5008   return true;
5009 }
5010 
5011 //-------------inline_squareToLen------------------------------------
5012 bool LibraryCallKit::inline_squareToLen() {
5013   assert(UseSquareToLenIntrinsic, "not implemented on this platform");
5014 
5015   address stubAddr = StubRoutines::squareToLen();
5016   if (stubAddr == NULL) {
5017     return false; // Intrinsic's stub is not implemented on this platform
5018   }
5019   const char* stubName = "squareToLen";
5020 
5021   assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters");
5022 
5023   Node* x    = argument(0);
5024   Node* len  = argument(1);
5025   Node* z    = argument(2);
5026   Node* zlen = argument(3);
5027 





5028   const Type* x_type = x->Value(&_gvn);
5029   const Type* z_type = z->Value(&_gvn);
5030   const TypeAryPtr* top_x = x_type->isa_aryptr();
5031   const TypeAryPtr* top_z = z_type->isa_aryptr();
5032   if (top_x  == NULL || top_x->klass()  == NULL ||
5033       top_z  == NULL || top_z->klass()  == NULL) {
5034     // failed array check
5035     return false;
5036   }
5037 
5038   BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5039   BasicType z_elem = z_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5040   if (x_elem != T_INT || z_elem != T_INT) {
5041     return false;
5042   }
5043 
5044 
5045   Node* x_start = array_element_address(x, intcon(0), x_elem);
5046   Node* z_start = array_element_address(z, intcon(0), z_elem);
5047 


5055 }
5056 
5057 //-------------inline_mulAdd------------------------------------------
5058 bool LibraryCallKit::inline_mulAdd() {
5059   assert(UseMulAddIntrinsic, "not implemented on this platform");
5060 
5061   address stubAddr = StubRoutines::mulAdd();
5062   if (stubAddr == NULL) {
5063     return false; // Intrinsic's stub is not implemented on this platform
5064   }
5065   const char* stubName = "mulAdd";
5066 
5067   assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters");
5068 
5069   Node* out      = argument(0);
5070   Node* in       = argument(1);
5071   Node* offset   = argument(2);
5072   Node* len      = argument(3);
5073   Node* k        = argument(4);
5074 




5075   const Type* out_type = out->Value(&_gvn);
5076   const Type* in_type = in->Value(&_gvn);
5077   const TypeAryPtr* top_out = out_type->isa_aryptr();
5078   const TypeAryPtr* top_in = in_type->isa_aryptr();
5079   if (top_out  == NULL || top_out->klass()  == NULL ||
5080       top_in == NULL || top_in->klass() == NULL) {
5081     // failed array check
5082     return false;
5083   }
5084 
5085   BasicType out_elem = out_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5086   BasicType in_elem = in_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5087   if (out_elem != T_INT || in_elem != T_INT) {
5088     return false;
5089   }
5090 
5091   Node* outlen = load_array_length(out);
5092   Node* new_offset = _gvn.transform(new SubINode(outlen, offset));
5093   Node* out_start = array_element_address(out, intcon(0), out_elem);
5094   Node* in_start = array_element_address(in, intcon(0), in_elem);


5104 
5105 //-------------inline_montgomeryMultiply-----------------------------------
5106 bool LibraryCallKit::inline_montgomeryMultiply() {
5107   address stubAddr = StubRoutines::montgomeryMultiply();
5108   if (stubAddr == NULL) {
5109     return false; // Intrinsic's stub is not implemented on this platform
5110   }
5111 
5112   assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform");
5113   const char* stubName = "montgomery_multiply";
5114 
5115   assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters");
5116 
5117   Node* a    = argument(0);
5118   Node* b    = argument(1);
5119   Node* n    = argument(2);
5120   Node* len  = argument(3);
5121   Node* inv  = argument(4);
5122   Node* m    = argument(6);
5123 





5124   const Type* a_type = a->Value(&_gvn);
5125   const TypeAryPtr* top_a = a_type->isa_aryptr();
5126   const Type* b_type = b->Value(&_gvn);
5127   const TypeAryPtr* top_b = b_type->isa_aryptr();
5128   const Type* n_type = a->Value(&_gvn);
5129   const TypeAryPtr* top_n = n_type->isa_aryptr();
5130   const Type* m_type = a->Value(&_gvn);
5131   const TypeAryPtr* top_m = m_type->isa_aryptr();
5132   if (top_a  == NULL || top_a->klass()  == NULL ||
5133       top_b == NULL || top_b->klass()  == NULL ||
5134       top_n == NULL || top_n->klass()  == NULL ||
5135       top_m == NULL || top_m->klass()  == NULL) {
5136     // failed array check
5137     return false;
5138   }
5139 
5140   BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5141   BasicType b_elem = b_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5142   BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5143   BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();


5163   return true;
5164 }
5165 
5166 bool LibraryCallKit::inline_montgomerySquare() {
5167   address stubAddr = StubRoutines::montgomerySquare();
5168   if (stubAddr == NULL) {
5169     return false; // Intrinsic's stub is not implemented on this platform
5170   }
5171 
5172   assert(UseMontgomerySquareIntrinsic, "not implemented on this platform");
5173   const char* stubName = "montgomery_square";
5174 
5175   assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters");
5176 
5177   Node* a    = argument(0);
5178   Node* n    = argument(1);
5179   Node* len  = argument(2);
5180   Node* inv  = argument(3);
5181   Node* m    = argument(5);
5182 




5183   const Type* a_type = a->Value(&_gvn);
5184   const TypeAryPtr* top_a = a_type->isa_aryptr();
5185   const Type* n_type = a->Value(&_gvn);
5186   const TypeAryPtr* top_n = n_type->isa_aryptr();
5187   const Type* m_type = a->Value(&_gvn);
5188   const TypeAryPtr* top_m = m_type->isa_aryptr();
5189   if (top_a  == NULL || top_a->klass()  == NULL ||
5190       top_n == NULL || top_n->klass()  == NULL ||
5191       top_m == NULL || top_m->klass()  == NULL) {
5192     // failed array check
5193     return false;
5194   }
5195 
5196   BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5197   BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5198   BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5199   if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
5200     return false;
5201   }
5202 


5232   Node* obja = argument(0);
5233   Node* aoffset = argument(1);
5234   Node* objb = argument(3);
5235   Node* boffset = argument(4);
5236   Node* length = argument(6);
5237   Node* scale = argument(7);
5238 
5239   const Type* a_type = obja->Value(&_gvn);
5240   const Type* b_type = objb->Value(&_gvn);
5241   const TypeAryPtr* top_a = a_type->isa_aryptr();
5242   const TypeAryPtr* top_b = b_type->isa_aryptr();
5243   if (top_a == NULL || top_a->klass() == NULL ||
5244     top_b == NULL || top_b->klass() == NULL) {
5245     // failed array check
5246     return false;
5247   }
5248 
5249   Node* call;
5250   jvms()->set_should_reexecute(true);
5251 
5252   Node* obja_adr = make_unsafe_address(obja, aoffset);
5253   Node* objb_adr = make_unsafe_address(objb, boffset);
5254 
5255   call = make_runtime_call(RC_LEAF,
5256     OptoRuntime::vectorizedMismatch_Type(),
5257     stubAddr, stubName, TypePtr::BOTTOM,
5258     obja_adr, objb_adr, length, scale);
5259 
5260   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5261   set_result(result);
5262   return true;
5263 }
5264 
5265 /**
5266  * Calculate CRC32 for byte.
5267  * int java.util.zip.CRC32.update(int crc, int b)
5268  */
5269 bool LibraryCallKit::inline_updateCRC32() {
5270   assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
5271   assert(callee()->signature()->size() == 2, "update has 2 parameters");
5272   // no receiver since it is static method
5273   Node* crc  = argument(0); // type: int


5307   // no receiver since it is static method
5308   Node* crc     = argument(0); // type: int
5309   Node* src     = argument(1); // type: oop
5310   Node* offset  = argument(2); // type: int
5311   Node* length  = argument(3); // type: int
5312 
5313   const Type* src_type = src->Value(&_gvn);
5314   const TypeAryPtr* top_src = src_type->isa_aryptr();
5315   if (top_src  == NULL || top_src->klass()  == NULL) {
5316     // failed array check
5317     return false;
5318   }
5319 
5320   // Figure out the size and type of the elements we will be copying.
5321   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5322   if (src_elem != T_BYTE) {
5323     return false;
5324   }
5325 
5326   // 'src_start' points to src array + scaled offset


5327   Node* src_start = array_element_address(src, offset, src_elem);
5328 
5329   // We assume that range check is done by caller.
5330   // TODO: generate range check (offset+length < src.length) in debug VM.
5331 
5332   // Call the stub.
5333   address stubAddr = StubRoutines::updateBytesCRC32();
5334   const char *stubName = "updateBytesCRC32";
5335 
5336   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
5337                                  stubAddr, stubName, TypePtr::BOTTOM,
5338                                  crc, src_start, length);
5339   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5340   set_result(result);
5341   return true;
5342 }
5343 
5344 /**
5345  * Calculate CRC32 for ByteBuffer.
5346  * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)


5395   Node* src     = argument(1); // type: oop
5396   Node* offset  = argument(2); // type: int
5397   Node* end     = argument(3); // type: int
5398 
5399   Node* length = _gvn.transform(new SubINode(end, offset));
5400 
5401   const Type* src_type = src->Value(&_gvn);
5402   const TypeAryPtr* top_src = src_type->isa_aryptr();
5403   if (top_src  == NULL || top_src->klass()  == NULL) {
5404     // failed array check
5405     return false;
5406   }
5407 
5408   // Figure out the size and type of the elements we will be copying.
5409   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5410   if (src_elem != T_BYTE) {
5411     return false;
5412   }
5413 
5414   // 'src_start' points to src array + scaled offset


5415   Node* src_start = array_element_address(src, offset, src_elem);
5416 
5417   // static final int[] byteTable in class CRC32C
5418   Node* table = get_table_from_crc32c_class(callee()->holder());


5419   Node* table_start = array_element_address(table, intcon(0), T_INT);
5420 
5421   // We assume that range check is done by caller.
5422   // TODO: generate range check (offset+length < src.length) in debug VM.
5423 
5424   // Call the stub.
5425   address stubAddr = StubRoutines::updateBytesCRC32C();
5426   const char *stubName = "updateBytesCRC32C";
5427 
5428   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
5429                                  stubAddr, stubName, TypePtr::BOTTOM,
5430                                  crc, src_start, length, table_start);
5431   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5432   set_result(result);
5433   return true;
5434 }
5435 
5436 //------------------------------inline_updateDirectByteBufferCRC32C-----------------------
5437 //
5438 // Calculate CRC32C for DirectByteBuffer.


5442   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
5443   assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long");
5444   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
5445   // no receiver since it is a static method
5446   Node* crc     = argument(0); // type: int
5447   Node* src     = argument(1); // type: long
5448   Node* offset  = argument(3); // type: int
5449   Node* end     = argument(4); // type: int
5450 
5451   Node* length = _gvn.transform(new SubINode(end, offset));
5452 
5453   src = ConvL2X(src);  // adjust Java long to machine word
5454   Node* base = _gvn.transform(new CastX2PNode(src));
5455   offset = ConvI2X(offset);
5456 
5457   // 'src_start' points to src array + scaled offset
5458   Node* src_start = basic_plus_adr(top(), base, offset);
5459 
5460   // static final int[] byteTable in class CRC32C
5461   Node* table = get_table_from_crc32c_class(callee()->holder());


5462   Node* table_start = array_element_address(table, intcon(0), T_INT);
5463 
5464   // Call the stub.
5465   address stubAddr = StubRoutines::updateBytesCRC32C();
5466   const char *stubName = "updateBytesCRC32C";
5467 
5468   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
5469                                  stubAddr, stubName, TypePtr::BOTTOM,
5470                                  crc, src_start, length, table_start);
5471   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5472   set_result(result);
5473   return true;
5474 }
5475 
5476 //------------------------------inline_updateBytesAdler32----------------------
5477 //
5478 // Calculate Adler32 checksum for byte[] array.
5479 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len)
5480 //
5481 bool LibraryCallKit::inline_updateBytesAdler32() {


5485   // no receiver since it is static method
5486   Node* crc     = argument(0); // type: int
5487   Node* src     = argument(1); // type: oop
5488   Node* offset  = argument(2); // type: int
5489   Node* length  = argument(3); // type: int
5490 
5491   const Type* src_type = src->Value(&_gvn);
5492   const TypeAryPtr* top_src = src_type->isa_aryptr();
5493   if (top_src  == NULL || top_src->klass()  == NULL) {
5494     // failed array check
5495     return false;
5496   }
5497 
5498   // Figure out the size and type of the elements we will be copying.
5499   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5500   if (src_elem != T_BYTE) {
5501     return false;
5502   }
5503 
5504   // 'src_start' points to src array + scaled offset

5505   Node* src_start = array_element_address(src, offset, src_elem);
5506 
5507   // We assume that range check is done by caller.
5508   // TODO: generate range check (offset+length < src.length) in debug VM.
5509 
5510   // Call the stub.
5511   address stubAddr = StubRoutines::updateBytesAdler32();
5512   const char *stubName = "updateBytesAdler32";
5513 
5514   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
5515                                  stubAddr, stubName, TypePtr::BOTTOM,
5516                                  crc, src_start, length);
5517   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5518   set_result(result);
5519   return true;
5520 }
5521 
5522 //------------------------------inline_updateByteBufferAdler32---------------
5523 //
5524 // Calculate Adler32 checksum for DirectByteBuffer.


5597     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
5598     assert(tinst != NULL, "obj is null");
5599     assert(tinst->klass()->is_loaded(), "obj is not loaded");
5600     assert(!is_exact || tinst->klass_is_exact(), "klass not exact");
5601     fromKls = tinst->klass()->as_instance_klass();
5602   } else {
5603     assert(is_static, "only for static field access");
5604   }
5605   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
5606                                               ciSymbol::make(fieldTypeString),
5607                                               is_static);
5608 
5609   assert (field != NULL, "undefined field");
5610   if (field == NULL) return (Node *) NULL;
5611 
5612   if (is_static) {
5613     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
5614     fromObj = makecon(tip);
5615   }
5616 










5617   // Next code  copied from Parse::do_get_xxx():
5618 
5619   // Compute address and memory type.
5620   int offset  = field->offset_in_bytes();
5621   bool is_vol = field->is_volatile();
5622   ciType* field_klass = field->type();
5623   assert(field_klass->is_loaded(), "should be loaded");
5624   const TypePtr* adr_type = C->alias_type(field)->adr_type();
5625   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
5626   BasicType bt = field->layout_type();
5627 
5628   // Build the resultant type of the load
5629   const Type *type;
5630   if (bt == T_OBJECT) {
5631     type = TypeOopPtr::make_from_klass(field_klass->as_klass());
5632   } else {
5633     type = Type::get_const_basic_type(bt);
5634   }
5635 
5636   DecoratorSet decorators = IN_HEAP;


5685   switch(id) {
5686   case vmIntrinsics::_aescrypt_encryptBlock:
5687     stubAddr = StubRoutines::aescrypt_encryptBlock();
5688     stubName = "aescrypt_encryptBlock";
5689     break;
5690   case vmIntrinsics::_aescrypt_decryptBlock:
5691     stubAddr = StubRoutines::aescrypt_decryptBlock();
5692     stubName = "aescrypt_decryptBlock";
5693     break;
5694   default:
5695     break;
5696   }
5697   if (stubAddr == NULL) return false;
5698 
5699   Node* aescrypt_object = argument(0);
5700   Node* src             = argument(1);
5701   Node* src_offset      = argument(2);
5702   Node* dest            = argument(3);
5703   Node* dest_offset     = argument(4);
5704 






5705   // (1) src and dest are arrays.
5706   const Type* src_type = src->Value(&_gvn);
5707   const Type* dest_type = dest->Value(&_gvn);
5708   const TypeAryPtr* top_src = src_type->isa_aryptr();
5709   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
5710   assert (top_src  != NULL && top_src->klass()  != NULL &&  top_dest != NULL && top_dest->klass() != NULL, "args are strange");
5711 
5712   // for the quick and dirty code we will skip all the checks.
5713   // we are just trying to get the call to be generated.
5714   Node* src_start  = src;
5715   Node* dest_start = dest;
5716   if (src_offset != NULL || dest_offset != NULL) {
5717     assert(src_offset != NULL && dest_offset != NULL, "");
5718     src_start  = array_element_address(src,  src_offset,  T_BYTE);
5719     dest_start = array_element_address(dest, dest_offset, T_BYTE);
5720   }
5721 
5722   // now need to get the start of its expanded key array
5723   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
5724   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);


5755   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
5756     stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt();
5757     stubName = "cipherBlockChaining_encryptAESCrypt";
5758     break;
5759   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
5760     stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt();
5761     stubName = "cipherBlockChaining_decryptAESCrypt";
5762     break;
5763   default:
5764     break;
5765   }
5766   if (stubAddr == NULL) return false;
5767 
5768   Node* cipherBlockChaining_object = argument(0);
5769   Node* src                        = argument(1);
5770   Node* src_offset                 = argument(2);
5771   Node* len                        = argument(3);
5772   Node* dest                       = argument(4);
5773   Node* dest_offset                = argument(5);
5774 








5775   // (1) src and dest are arrays.
5776   const Type* src_type = src->Value(&_gvn);
5777   const Type* dest_type = dest->Value(&_gvn);
5778   const TypeAryPtr* top_src = src_type->isa_aryptr();
5779   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
5780   assert (top_src  != NULL && top_src->klass()  != NULL
5781           &&  top_dest != NULL && top_dest->klass() != NULL, "args are strange");
5782 
5783   // checks are the responsibility of the caller
5784   Node* src_start  = src;
5785   Node* dest_start = dest;
5786   if (src_offset != NULL || dest_offset != NULL) {
5787     assert(src_offset != NULL && dest_offset != NULL, "");
5788     src_start  = array_element_address(src,  src_offset,  T_BYTE);
5789     dest_start = array_element_address(dest, dest_offset, T_BYTE);
5790   }
5791 
5792   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
5793   // (because of the predicated logic executed earlier).
5794   // so we cast it here safely.


5799 
5800   // cast it to what we know it will be at runtime
5801   const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
5802   assert(tinst != NULL, "CBC obj is null");
5803   assert(tinst->klass()->is_loaded(), "CBC obj is not loaded");
5804   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
5805   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
5806 
5807   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
5808   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
5809   const TypeOopPtr* xtype = aklass->as_instance_type();
5810   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
5811   aescrypt_object = _gvn.transform(aescrypt_object);
5812 
5813   // we need to get the start of the aescrypt_object's expanded key array
5814   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);
5815   if (k_start == NULL) return false;
5816 
5817   // similarly, get the start address of the r vector
5818   Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false);



5819   if (objRvec == NULL) return false;
5820   Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
5821 
5822   Node* cbcCrypt;
5823   if (Matcher::pass_original_key_for_aes()) {
5824     // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to
5825     // compatibility issues between Java key expansion and SPARC crypto instructions
5826     Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object);
5827     if (original_k_start == NULL) return false;
5828 
5829     // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start
5830     cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
5831                                  OptoRuntime::cipherBlockChaining_aescrypt_Type(),
5832                                  stubAddr, stubName, TypePtr::BOTTOM,
5833                                  src_start, dest_start, k_start, r_start, len, original_k_start);
5834   } else {
5835     // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
5836     cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
5837                                  OptoRuntime::cipherBlockChaining_aescrypt_Type(),
5838                                  stubAddr, stubName, TypePtr::BOTTOM,


5856     stubAddr = StubRoutines::counterMode_AESCrypt();
5857     stubName = "counterMode_AESCrypt";
5858   }
5859   if (stubAddr == NULL) return false;
5860 
5861   Node* counterMode_object = argument(0);
5862   Node* src = argument(1);
5863   Node* src_offset = argument(2);
5864   Node* len = argument(3);
5865   Node* dest = argument(4);
5866   Node* dest_offset = argument(5);
5867 
5868   // (1) src and dest are arrays.
5869   const Type* src_type = src->Value(&_gvn);
5870   const Type* dest_type = dest->Value(&_gvn);
5871   const TypeAryPtr* top_src = src_type->isa_aryptr();
5872   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
5873   assert(top_src != NULL && top_src->klass() != NULL &&
5874          top_dest != NULL && top_dest->klass() != NULL, "args are strange");
5875 




5876   // checks are the responsibility of the caller
5877   Node* src_start = src;
5878   Node* dest_start = dest;
5879   if (src_offset != NULL || dest_offset != NULL) {
5880     assert(src_offset != NULL && dest_offset != NULL, "");
5881     src_start = array_element_address(src, src_offset, T_BYTE);
5882     dest_start = array_element_address(dest, dest_offset, T_BYTE);
5883   }
5884 
5885   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
5886   // (because of the predicated logic executed earlier).
5887   // so we cast it here safely.
5888   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
5889   Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
5890   if (embeddedCipherObj == NULL) return false;
5891   // cast it to what we know it will be at runtime
5892   const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
5893   assert(tinst != NULL, "CTR obj is null");
5894   assert(tinst->klass()->is_loaded(), "CTR obj is not loaded");
5895   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
5896   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
5897   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
5898   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
5899   const TypeOopPtr* xtype = aklass->as_instance_type();
5900   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
5901   aescrypt_object = _gvn.transform(aescrypt_object);
5902   // we need to get the start of the aescrypt_object's expanded key array
5903   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);
5904   if (k_start == NULL) return false;
5905   // similarly, get the start address of the r vector
5906   Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B", /*is_exact*/ false);
5907   if (obj_counter == NULL) return false;

5908   Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
5909 
5910   Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B", /*is_exact*/ false);
5911   if (saved_encCounter == NULL) return false;

5912   Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
5913   Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
5914 
5915   Node* ctrCrypt;
5916   if (Matcher::pass_original_key_for_aes()) {
5917     // no SPARC version for AES/CTR intrinsics now.
5918     return false;
5919   }
5920   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
5921   ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
5922                                OptoRuntime::counterMode_aescrypt_Type(),
5923                                stubAddr, stubName, TypePtr::BOTTOM,
5924                                src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
5925 
5926   // return cipher length (int)
5927   Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms));
5928   set_result(retvalue);
5929   return true;
5930 }
5931 
5932 //------------------------------get_key_start_from_aescrypt_object-----------------------
5933 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) {
5934 #if defined(PPC64) || defined(S390)
5935   // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys.
5936   // Intel's extention is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns.
5937   // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption.
5938   // The ppc64 stubs of encryption and decryption use the same round keys (sessionK[0]).
5939   Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I", /*is_exact*/ false);
5940   assert (objSessionK != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
5941   if (objSessionK == NULL) {
5942     return (Node *) NULL;
5943   }
5944   Node* objAESCryptKey = load_array_element(control(), objSessionK, intcon(0), TypeAryPtr::OOPS);
5945 #else
5946   Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false);
5947 #endif // PPC64
5948   assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
5949   if (objAESCryptKey == NULL) return (Node *) NULL;
5950 


5951   // now have the array, need to get the start address of the K array
5952   Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT);
5953   return k_start;
5954 }
5955 
5956 //------------------------------get_original_key_start_from_aescrypt_object-----------------------
5957 Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) {
5958   Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false);
5959   assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
5960   if (objAESCryptKey == NULL) return (Node *) NULL;
5961 


5962   // now have the array, need to get the start address of the lastKey array
5963   Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE);
5964   return original_k_start;
5965 }
5966 
5967 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate----------------------------
5968 // Return node representing slow path of predicate check.
5969 // the pseudo code we want to emulate with this predicate is:
5970 // for encryption:
5971 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
5972 // for decryption:
5973 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
5974 //    note cipher==plain is more conservative than the original java code but that's OK
5975 //
5976 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) {
5977   // The receiver was checked for NULL already.
5978   Node* objCBC = argument(0);
5979 



5980   // Load embeddedCipher field of CipherBlockChaining object.
5981   Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
5982 
5983   // get AESCrypt klass for instanceOf check
5984   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
5985   // will have same classloader as CipherBlockChaining object
5986   const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr();
5987   assert(tinst != NULL, "CBCobj is null");
5988   assert(tinst->klass()->is_loaded(), "CBCobj is not loaded");
5989 
5990   // we want to do an instanceof comparison against the AESCrypt class
5991   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
5992   if (!klass_AESCrypt->is_loaded()) {
5993     // if AESCrypt is not even loaded, we never take the intrinsic fast path
5994     Node* ctrl = control();
5995     set_control(top()); // no regular fast path
5996     return ctrl;
5997   }









5998   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
5999 
6000   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
6001   Node* cmp_instof  = _gvn.transform(new CmpINode(instof, intcon(1)));
6002   Node* bool_instof  = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
6003 
6004   Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6005 
6006   // for encryption, we are done
6007   if (!decrypting)
6008     return instof_false;  // even if it is NULL
6009 
6010   // for decryption, we need to add a further check to avoid
6011   // taking the intrinsic path when cipher and plain are the same
6012   // see the original java code for why.
6013   RegionNode* region = new RegionNode(3);
6014   region->init_req(1, instof_false);
6015   Node* src = argument(1);
6016   Node* dest = argument(4);
6017   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
6018   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
6019   Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN);
6020   region->init_req(2, src_dest_conjoint);
6021 
6022   record_for_igvn(region);
6023   return _gvn.transform(region);
6024 }
6025 
6026 //----------------------------inline_counterMode_AESCrypt_predicate----------------------------
6027 // Return node representing slow path of predicate check.
6028 // the pseudo code we want to emulate with this predicate is:
6029 // for encryption:
6030 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
6031 // for decryption:
6032 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
6033 //    note cipher==plain is more conservative than the original java code but that's OK
6034 //
6035 
6036 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() {


6063   Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6064 
6065   return instof_false; // even if it is NULL
6066 }
6067 
6068 //------------------------------inline_ghash_processBlocks
6069 bool LibraryCallKit::inline_ghash_processBlocks() {
6070   address stubAddr;
6071   const char *stubName;
6072   assert(UseGHASHIntrinsics, "need GHASH intrinsics support");
6073 
6074   stubAddr = StubRoutines::ghash_processBlocks();
6075   stubName = "ghash_processBlocks";
6076 
6077   Node* data           = argument(0);
6078   Node* offset         = argument(1);
6079   Node* len            = argument(2);
6080   Node* state          = argument(3);
6081   Node* subkeyH        = argument(4);
6082 








6083   Node* state_start  = array_element_address(state, intcon(0), T_LONG);
6084   assert(state_start, "state is NULL");
6085   Node* subkeyH_start  = array_element_address(subkeyH, intcon(0), T_LONG);
6086   assert(subkeyH_start, "subkeyH is NULL");
6087   Node* data_start  = array_element_address(data, offset, T_BYTE);
6088   assert(data_start, "data is NULL");
6089 
6090   Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP,
6091                                   OptoRuntime::ghash_processBlocks_Type(),
6092                                   stubAddr, stubName, TypePtr::BOTTOM,
6093                                   state_start, subkeyH_start, data_start, len);
6094   return true;
6095 }
6096 
6097 bool LibraryCallKit::inline_base64_encodeBlock() {
6098   address stubAddr;
6099   const char *stubName;
6100   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
6101   assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters");
6102   stubAddr = StubRoutines::base64_encodeBlock();
6103   stubName = "encodeBlock";
6104 
6105   if (!stubAddr) return false;
6106   Node* base64obj = argument(0);
6107   Node* src = argument(1);
6108   Node* offset = argument(2);
6109   Node* len = argument(3);
6110   Node* dest = argument(4);
6111   Node* dp = argument(5);
6112   Node* isURL = argument(6);
6113 





6114   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
6115   assert(src_start, "source array is NULL");
6116   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
6117   assert(dest_start, "destination array is NULL");
6118 
6119   Node* base64 = make_runtime_call(RC_LEAF,
6120                                    OptoRuntime::base64_encodeBlock_Type(),
6121                                    stubAddr, stubName, TypePtr::BOTTOM,
6122                                    src_start, offset, len, dest_start, dp, isURL);
6123   return true;
6124 }
6125 
6126 //------------------------------inline_sha_implCompress-----------------------
6127 //
6128 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
6129 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
6130 //
6131 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
6132 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
6133 //


6136 //
6137 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) {
6138   assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
6139 
6140   Node* sha_obj = argument(0);
6141   Node* src     = argument(1); // type oop
6142   Node* ofs     = argument(2); // type int
6143 
6144   const Type* src_type = src->Value(&_gvn);
6145   const TypeAryPtr* top_src = src_type->isa_aryptr();
6146   if (top_src  == NULL || top_src->klass()  == NULL) {
6147     // failed array check
6148     return false;
6149   }
6150   // Figure out the size and type of the elements we will be copying.
6151   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6152   if (src_elem != T_BYTE) {
6153     return false;
6154   }
6155   // 'src_start' points to src array + offset


6156   Node* src_start = array_element_address(src, ofs, src_elem);
6157   Node* state = NULL;
6158   address stubAddr;
6159   const char *stubName;
6160 
6161   switch(id) {
6162   case vmIntrinsics::_sha_implCompress:
6163     assert(UseSHA1Intrinsics, "need SHA1 instruction support");
6164     state = get_state_from_sha_object(sha_obj);
6165     stubAddr = StubRoutines::sha1_implCompress();
6166     stubName = "sha1_implCompress";
6167     break;
6168   case vmIntrinsics::_sha2_implCompress:
6169     assert(UseSHA256Intrinsics, "need SHA256 instruction support");
6170     state = get_state_from_sha_object(sha_obj);
6171     stubAddr = StubRoutines::sha256_implCompress();
6172     stubName = "sha256_implCompress";
6173     break;
6174   case vmIntrinsics::_sha5_implCompress:
6175     assert(UseSHA512Intrinsics, "need SHA512 instruction support");


6205   assert((uint)predicate < 3, "sanity");
6206   assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
6207 
6208   Node* digestBase_obj = argument(0); // The receiver was checked for NULL already.
6209   Node* src            = argument(1); // byte[] array
6210   Node* ofs            = argument(2); // type int
6211   Node* limit          = argument(3); // type int
6212 
6213   const Type* src_type = src->Value(&_gvn);
6214   const TypeAryPtr* top_src = src_type->isa_aryptr();
6215   if (top_src  == NULL || top_src->klass()  == NULL) {
6216     // failed array check
6217     return false;
6218   }
6219   // Figure out the size and type of the elements we will be copying.
6220   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6221   if (src_elem != T_BYTE) {
6222     return false;
6223   }
6224   // 'src_start' points to src array + offset


6225   Node* src_start = array_element_address(src, ofs, src_elem);
6226 
6227   const char* klass_SHA_name = NULL;
6228   const char* stub_name = NULL;
6229   address     stub_addr = NULL;
6230   bool        long_state = false;
6231 
6232   switch (predicate) {
6233   case 0:
6234     if (UseSHA1Intrinsics) {
6235       klass_SHA_name = "sun/security/provider/SHA";
6236       stub_name = "sha1_implCompressMB";
6237       stub_addr = StubRoutines::sha1_implCompressMB();
6238     }
6239     break;
6240   case 1:
6241     if (UseSHA256Intrinsics) {
6242       klass_SHA_name = "sun/security/provider/SHA2";
6243       stub_name = "sha256_implCompressMB";
6244       stub_addr = StubRoutines::sha256_implCompressMB();


6289   if (state == NULL) return false;
6290 
6291   // Call the stub.
6292   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
6293                                  OptoRuntime::digestBase_implCompressMB_Type(),
6294                                  stubAddr, stubName, TypePtr::BOTTOM,
6295                                  src_start, state, ofs, limit);
6296   // return ofs (int)
6297   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
6298   set_result(result);
6299 
6300   return true;
6301 }
6302 
6303 //------------------------------get_state_from_sha_object-----------------------
6304 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) {
6305   Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false);
6306   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2");
6307   if (sha_state == NULL) return (Node *) NULL;
6308 


6309   // now have the array, need to get the start address of the state array
6310   Node* state = array_element_address(sha_state, intcon(0), T_INT);
6311   return state;
6312 }
6313 
6314 //------------------------------get_state_from_sha5_object-----------------------
6315 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) {
6316   Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false);
6317   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5");
6318   if (sha_state == NULL) return (Node *) NULL;


6319 
6320   // now have the array, need to get the start address of the state array
6321   Node* state = array_element_address(sha_state, intcon(0), T_LONG);
6322   return state;
6323 }
6324 
6325 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
6326 // Return node representing slow path of predicate check.
6327 // the pseudo code we want to emulate with this predicate is:
6328 //    if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath
6329 //
6330 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
6331   assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6332          "need SHA1/SHA256/SHA512 instruction support");
6333   assert((uint)predicate < 3, "sanity");
6334 
6335   // The receiver was checked for NULL already.
6336   Node* digestBaseObj = argument(0);
6337 
6338   // get DigestBase klass for instanceOf check




  40 #include "opto/castnode.hpp"
  41 #include "opto/cfgnode.hpp"
  42 #include "opto/convertnode.hpp"
  43 #include "opto/countbitsnode.hpp"
  44 #include "opto/intrinsicnode.hpp"
  45 #include "opto/idealKit.hpp"
  46 #include "opto/mathexactnode.hpp"
  47 #include "opto/movenode.hpp"
  48 #include "opto/mulnode.hpp"
  49 #include "opto/narrowptrnode.hpp"
  50 #include "opto/opaquenode.hpp"
  51 #include "opto/parse.hpp"
  52 #include "opto/runtime.hpp"
  53 #include "opto/rootnode.hpp"
  54 #include "opto/subnode.hpp"
  55 #include "prims/nativeLookup.hpp"
  56 #include "prims/unsafe.hpp"
  57 #include "runtime/objectMonitor.hpp"
  58 #include "runtime/sharedRuntime.hpp"
  59 #include "utilities/macros.hpp"
  60 #include "utilities/macros.hpp"
  61 #if INCLUDE_SHENANDOAHGC
  62 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  63 #endif
  64 
  65 
  66 class LibraryIntrinsic : public InlineCallGenerator {
  67   // Extend the set of intrinsics known to the runtime:
  68  public:
  69  private:
  70   bool             _is_virtual;
  71   bool             _does_virtual_dispatch;
  72   int8_t           _predicates_count;  // Intrinsic is predicated by several conditions
  73   int8_t           _last_predicate; // Last generated predicate
  74   vmIntrinsics::ID _intrinsic_id;
  75 
  76  public:
  77   LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
  78     : InlineCallGenerator(m),
  79       _is_virtual(is_virtual),
  80       _does_virtual_dispatch(does_virtual_dispatch),
  81       _predicates_count((int8_t)predicates_count),
  82       _last_predicate((int8_t)-1),
  83       _intrinsic_id(id)


 231   bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName);
 232   bool inline_math_native(vmIntrinsics::ID id);
 233   bool inline_math(vmIntrinsics::ID id);
 234   template <typename OverflowOp>
 235   bool inline_math_overflow(Node* arg1, Node* arg2);
 236   void inline_math_mathExact(Node* math, Node* test);
 237   bool inline_math_addExactI(bool is_increment);
 238   bool inline_math_addExactL(bool is_increment);
 239   bool inline_math_multiplyExactI();
 240   bool inline_math_multiplyExactL();
 241   bool inline_math_multiplyHigh();
 242   bool inline_math_negateExactI();
 243   bool inline_math_negateExactL();
 244   bool inline_math_subtractExactI(bool is_decrement);
 245   bool inline_math_subtractExactL(bool is_decrement);
 246   bool inline_min_max(vmIntrinsics::ID id);
 247   bool inline_notify(vmIntrinsics::ID id);
 248   Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
 249   // This returns Type::AnyPtr, RawPtr, or OopPtr.
 250   int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
 251   Node* make_unsafe_address(Node*& base, Node* offset, bool is_store, BasicType type = T_ILLEGAL, bool can_cast = false);
 252 
 253   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
 254   DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
 255   bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
 256   static bool klass_needs_init_guard(Node* kls);
 257   bool inline_unsafe_allocate();
 258   bool inline_unsafe_newArray(bool uninitialized);
 259   bool inline_unsafe_copyMemory();
 260   bool inline_native_currentThread();
 261 
 262   bool inline_native_time_funcs(address method, const char* funcName);
 263 #ifdef JFR_HAVE_INTRINSICS
 264   bool inline_native_classID();
 265   bool inline_native_getEventWriter();
 266 #endif
 267   bool inline_native_isInterrupted();
 268   bool inline_native_Class_query(vmIntrinsics::ID id);
 269   bool inline_native_subtype_check();
 270   bool inline_native_getLength();
 271   bool inline_array_copyOf(bool is_copyOfRange);


 322   bool inline_updateByteBufferAdler32();
 323   bool inline_multiplyToLen();
 324   bool inline_hasNegatives();
 325   bool inline_squareToLen();
 326   bool inline_mulAdd();
 327   bool inline_montgomeryMultiply();
 328   bool inline_montgomerySquare();
 329   bool inline_vectorizedMismatch();
 330   bool inline_fma(vmIntrinsics::ID id);
 331   bool inline_character_compare(vmIntrinsics::ID id);
 332 
 333   bool inline_profileBoolean();
 334   bool inline_isCompileConstant();
 335   void clear_upper_avx() {
 336 #ifdef X86
 337     if (UseAVX >= 2) {
 338       C->set_clear_upper_avx(true);
 339     }
 340 #endif
 341   }
 342 
 343   Node* shenandoah_must_be_not_null(Node* n, bool f) {
 344     return UseShenandoahGC ? must_be_not_null(n, f) : n;
 345   }
 346 };
 347 
 348 //---------------------------make_vm_intrinsic----------------------------
 349 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
 350   vmIntrinsics::ID id = m->intrinsic_id();
 351   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 352 
 353   if (!m->is_loaded()) {
 354     // Do not attempt to inline unloaded methods.
 355     return NULL;
 356   }
 357 
 358   C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
 359   bool is_available = false;
 360 
 361   {
 362     // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
 363     // the compiler must transition to '_thread_in_vm' state because both
 364     // methods access VM-internal data.
 365     VM_ENTRY_MARK;


1098     result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES),
1099                                str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae);
1100     break;
1101   default:
1102     ShouldNotReachHere();
1103     return NULL;
1104   }
1105 
1106   // All these intrinsics have checks.
1107   C->set_has_split_ifs(true); // Has chance for split-if optimization
1108   clear_upper_avx();
1109 
1110   return _gvn.transform(result);
1111 }
1112 
1113 //------------------------------inline_string_compareTo------------------------
1114 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) {
1115   Node* arg1 = argument(0);
1116   Node* arg2 = argument(1);
1117 
1118   arg1 = shenandoah_must_be_not_null(arg1, true);
1119   arg2 = shenandoah_must_be_not_null(arg2, true);
1120 
1121   arg1 = access_resolve_for_read(arg1);
1122   arg2 = access_resolve_for_read(arg2);
1123 
1124   // Get start addr and length of first argument
1125   Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
1126   Node* arg1_cnt    = load_array_length(arg1);
1127 
1128   // Get start addr and length of second argument
1129   Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
1130   Node* arg2_cnt    = load_array_length(arg2);
1131 
1132   Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
1133   set_result(result);
1134   return true;
1135 }
1136 
1137 //------------------------------inline_string_equals------------------------
1138 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) {
1139   Node* arg1 = argument(0);
1140   Node* arg2 = argument(1);
1141 
1142   // paths (plus control) merge
1143   RegionNode* region = new RegionNode(3);
1144   Node* phi = new PhiNode(region, TypeInt::BOOL);
1145 
1146   if (!stopped()) {
1147 
1148     arg1 = shenandoah_must_be_not_null(arg1, true);
1149     arg2 = shenandoah_must_be_not_null(arg2, true);
1150 
1151     arg1 = access_resolve_for_read(arg1);
1152     arg2 = access_resolve_for_read(arg2);
1153 
1154    // Get start addr and length of first argument
1155     Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
1156     Node* arg1_cnt    = load_array_length(arg1);
1157 
1158     // Get start addr and length of second argument
1159     Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
1160     Node* arg2_cnt    = load_array_length(arg2);
1161 
1162     // Check for arg1_cnt != arg2_cnt
1163     Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt));
1164     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
1165     Node* if_ne = generate_slow_guard(bol, NULL);
1166     if (if_ne != NULL) {
1167       phi->init_req(2, intcon(0));
1168       region->init_req(2, if_ne);
1169     }
1170 
1171     // Check for count == 0 is done by assembler code for StrEquals.
1172 
1173     if (!stopped()) {
1174       Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
1175       phi->init_req(1, equals);
1176       region->init_req(1, control());
1177     }
1178   }
1179 
1180   // post merge
1181   set_control(_gvn.transform(region));
1182   record_for_igvn(region);
1183 
1184   set_result(_gvn.transform(phi));
1185   return true;
1186 }
1187 
1188 //------------------------------inline_array_equals----------------------------
1189 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
1190   assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types");
1191   Node* arg1 = argument(0);
1192   Node* arg2 = argument(1);
1193 
1194   arg1 = access_resolve_for_read(arg1);
1195   arg2 = access_resolve_for_read(arg2);
1196 
1197   const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES;
1198   set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae)));
1199   clear_upper_avx();
1200 
1201   return true;
1202 }
1203 
1204 //------------------------------inline_hasNegatives------------------------------
1205 bool LibraryCallKit::inline_hasNegatives() {
1206   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1207     return false;
1208   }
1209 
1210   assert(callee()->signature()->size() == 3, "hasNegatives has 3 parameters");
1211   // no receiver since it is static method
1212   Node* ba         = argument(0);
1213   Node* offset     = argument(1);
1214   Node* len        = argument(2);
1215 
1216   ba = shenandoah_must_be_not_null(ba, true);
1217 
1218   // Range checks
1219   generate_string_range_check(ba, offset, len, false);
1220   if (stopped()) {
1221     return true;
1222   }
1223 
1224   ba = access_resolve_for_read(ba);
1225 
1226   Node* ba_start = array_element_address(ba, offset, T_BYTE);
1227   Node* result = new HasNegativesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len);
1228   set_result(_gvn.transform(result));
1229   return true;
1230 }
1231 
1232 bool LibraryCallKit::inline_preconditions_checkIndex() {
1233   Node* index = argument(0);
1234   Node* length = argument(1);
1235   if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) {
1236     return false;
1237   }
1238 
1239   Node* len_pos_cmp = _gvn.transform(new CmpINode(length, intcon(0)));
1240   Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge));
1241 
1242   {
1243     BuildCutout unless(this, len_pos_bol, PROB_MAX);
1244     uncommon_trap(Deoptimization::Reason_intrinsic,
1245                   Deoptimization::Action_make_not_entrant);


1273   result->set_req(0, control());
1274   result = _gvn.transform(result);
1275   set_result(result);
1276   replace_in_map(index, result);
1277   clear_upper_avx();
1278   return true;
1279 }
1280 
1281 //------------------------------inline_string_indexOf------------------------
1282 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) {
1283   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
1284     return false;
1285   }
1286   Node* src = argument(0);
1287   Node* tgt = argument(1);
1288 
1289   // Make the merge point
1290   RegionNode* result_rgn = new RegionNode(4);
1291   Node*       result_phi = new PhiNode(result_rgn, TypeInt::INT);
1292 
1293   src = shenandoah_must_be_not_null(src, true);
1294   tgt = shenandoah_must_be_not_null(tgt, true);
1295 
1296   src = access_resolve_for_read(src);
1297   tgt = access_resolve_for_read(tgt);
1298 
1299   // Get start addr and length of source string
1300   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
1301   Node* src_count = load_array_length(src);
1302 
1303   // Get start addr and length of substring
1304   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
1305   Node* tgt_count = load_array_length(tgt);
1306 
1307   if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) {
1308     // Divide src size by 2 if String is UTF16 encoded
1309     src_count = _gvn.transform(new RShiftINode(src_count, intcon(1)));
1310   }
1311   if (ae == StrIntrinsicNode::UU) {
1312     // Divide substring size by 2 if String is UTF16 encoded
1313     tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1)));
1314   }
1315 
1316   Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, result_rgn, result_phi, ae);
1317   if (result != NULL) {
1318     result_phi->init_req(3, result);


1323   set_result(_gvn.transform(result_phi));
1324 
1325   return true;
1326 }
1327 
1328 //-----------------------------inline_string_indexOf-----------------------
1329 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) {
1330   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1331     return false;
1332   }
1333   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
1334     return false;
1335   }
1336   assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments");
1337   Node* src         = argument(0); // byte[]
1338   Node* src_count   = argument(1); // char count
1339   Node* tgt         = argument(2); // byte[]
1340   Node* tgt_count   = argument(3); // char count
1341   Node* from_index  = argument(4); // char index
1342 
1343   src = shenandoah_must_be_not_null(src, true);
1344   tgt = shenandoah_must_be_not_null(tgt, true);
1345 
1346   src = access_resolve_for_read(src);
1347   tgt = access_resolve_for_read(tgt);
1348 
1349   // Multiply byte array index by 2 if String is UTF16 encoded
1350   Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
1351   src_count = _gvn.transform(new SubINode(src_count, from_index));
1352   Node* src_start = array_element_address(src, src_offset, T_BYTE);
1353   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
1354 
1355   // Range checks
1356   generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL);
1357   generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU);
1358   if (stopped()) {
1359     return true;
1360   }
1361 
1362   RegionNode* region = new RegionNode(5);
1363   Node* phi = new PhiNode(region, TypeInt::INT);
1364 
1365   Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, region, phi, ae);
1366   if (result != NULL) {
1367     // The result is index relative to from_index if substring was found, -1 otherwise.
1368     // Generate code which will fold into cmove.


1414   if (!stopped()) {
1415     return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae);
1416   }
1417   return NULL;
1418 }
1419 
1420 //-----------------------------inline_string_indexOfChar-----------------------
1421 bool LibraryCallKit::inline_string_indexOfChar() {
1422   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
1423     return false;
1424   }
1425   if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) {
1426     return false;
1427   }
1428   assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments");
1429   Node* src         = argument(0); // byte[]
1430   Node* tgt         = argument(1); // tgt is int ch
1431   Node* from_index  = argument(2);
1432   Node* max         = argument(3);
1433 
1434   src = shenandoah_must_be_not_null(src, true);
1435   src = access_resolve_for_read(src);
1436 
1437   Node* src_offset = _gvn.transform(new LShiftINode(from_index, intcon(1)));
1438   Node* src_start = array_element_address(src, src_offset, T_BYTE);
1439   Node* src_count = _gvn.transform(new SubINode(max, from_index));
1440 
1441   // Range checks
1442   generate_string_range_check(src, src_offset, src_count, true);
1443   if (stopped()) {
1444     return true;
1445   }
1446 
1447   RegionNode* region = new RegionNode(3);
1448   Node* phi = new PhiNode(region, TypeInt::INT);
1449 
1450   Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, tgt, StrIntrinsicNode::none);
1451   C->set_has_split_ifs(true); // Has chance for split-if optimization
1452   _gvn.transform(result);
1453 
1454   Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
1455   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
1456 


1487 
1488   Node* src         = argument(0);
1489   Node* src_offset  = argument(1);
1490   Node* dst         = argument(2);
1491   Node* dst_offset  = argument(3);
1492   Node* length      = argument(4);
1493 
1494   // Check for allocation before we add nodes that would confuse
1495   // tightly_coupled_allocation()
1496   AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL);
1497 
1498   // Figure out the size and type of the elements we will be copying.
1499   const Type* src_type = src->Value(&_gvn);
1500   const Type* dst_type = dst->Value(&_gvn);
1501   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
1502   BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
1503   assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) ||
1504          (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)),
1505          "Unsupported array types for inline_string_copy");
1506 
1507   src = shenandoah_must_be_not_null(src, true);
1508   dst = shenandoah_must_be_not_null(dst, true);
1509 
1510   // Convert char[] offsets to byte[] offsets
1511   bool convert_src = (compress && src_elem == T_BYTE);
1512   bool convert_dst = (!compress && dst_elem == T_BYTE);
1513   if (convert_src) {
1514     src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1)));
1515   } else if (convert_dst) {
1516     dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1)));
1517   }
1518 
1519   // Range checks
1520   generate_string_range_check(src, src_offset, length, convert_src);
1521   generate_string_range_check(dst, dst_offset, length, convert_dst);
1522   if (stopped()) {
1523     return true;
1524   }
1525 
1526   src = access_resolve_for_read(src);
1527   dst = access_resolve_for_write(dst);
1528 
1529   Node* src_start = array_element_address(src, src_offset, src_elem);
1530   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
1531   // 'src_start' points to src array + scaled offset
1532   // 'dst_start' points to dst array + scaled offset
1533   Node* count = NULL;
1534   if (compress) {
1535     count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length);
1536   } else {
1537     inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length);
1538   }
1539 
1540   if (alloc != NULL) {
1541     if (alloc->maybe_set_complete(&_gvn)) {
1542       // "You break it, you buy it."
1543       InitializeNode* init = alloc->initialization();
1544       assert(init->is_complete(), "we just did this");
1545       init->set_complete_with_arraycopy();
1546       assert(dst->is_CheckCastPP(), "sanity");
1547       assert(dst->in(0)->in(0) == init, "dest pinned");
1548     }


1599     generate_limit_guard(offset, length, load_array_length(value), bailout);
1600     // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE
1601     generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout);
1602 
1603     if (bailout->req() > 1) {
1604       PreserveJVMState pjvms(this);
1605       set_control(_gvn.transform(bailout));
1606       uncommon_trap(Deoptimization::Reason_intrinsic,
1607                     Deoptimization::Action_maybe_recompile);
1608     }
1609     if (stopped()) {
1610       return true;
1611     }
1612 
1613     Node* size = _gvn.transform(new LShiftINode(length, intcon(1)));
1614     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE)));
1615     newcopy = new_array(klass_node, size, 0);  // no arguments to push
1616     AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy, NULL);
1617 
1618     // Calculate starting addresses.
1619     value = access_resolve_for_read(value);
1620 
1621     Node* src_start = array_element_address(value, offset, T_CHAR);
1622     Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1623 
1624     // Check if src array address is aligned to HeapWordSize (dst is always aligned)
1625     const TypeInt* toffset = gvn().type(offset)->is_int();
1626     bool aligned = toffset->is_con() && ((toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
1627 
1628     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
1629     const char* copyfunc_name = "arraycopy";
1630     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
1631     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
1632                       OptoRuntime::fast_arraycopy_Type(),
1633                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
1634                       src_start, dst_start, ConvI2X(length) XTOP);
1635     // Do not let reads from the cloned object float above the arraycopy.
1636     if (alloc != NULL) {
1637       if (alloc->maybe_set_complete(&_gvn)) {
1638         // "You break it, you buy it."
1639         InitializeNode* init = alloc->initialization();
1640         assert(init->is_complete(), "we just did this");


1684 
1685   // Check if a null path was taken unconditionally.
1686   src = null_check(src);
1687   dst = null_check(dst);
1688   if (stopped()) {
1689     return true;
1690   }
1691 
1692   // Get length and convert char[] offset to byte[] offset
1693   Node* length = _gvn.transform(new SubINode(src_end, src_begin));
1694   src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1)));
1695 
1696   // Range checks
1697   generate_string_range_check(src, src_begin, length, true);
1698   generate_string_range_check(dst, dst_begin, length, false);
1699   if (stopped()) {
1700     return true;
1701   }
1702 
1703   if (!stopped()) {
1704 
1705     src = access_resolve_for_read(src);
1706     dst = access_resolve_for_write(dst);
1707 
1708     // Calculate starting addresses.
1709     Node* src_start = array_element_address(src, src_begin, T_BYTE);
1710     Node* dst_start = array_element_address(dst, dst_begin, T_CHAR);
1711 
1712     // Check if array addresses are aligned to HeapWordSize
1713     const TypeInt* tsrc = gvn().type(src_begin)->is_int();
1714     const TypeInt* tdst = gvn().type(dst_begin)->is_int();
1715     bool aligned = tsrc->is_con() && ((tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) &&
1716                    tdst->is_con() && ((tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
1717 
1718     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
1719     const char* copyfunc_name = "arraycopy";
1720     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
1721     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
1722                       OptoRuntime::fast_arraycopy_Type(),
1723                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
1724                       src_start, dst_start, ConvI2X(length) XTOP);
1725     // Do not let reads from the cloned object float above the arraycopy.
1726     if (alloc != NULL) {
1727       if (alloc->maybe_set_complete(&_gvn)) {


1755 // static char StringUTF16.getChar(byte[] val, int index)
1756 bool LibraryCallKit::inline_string_char_access(bool is_store) {
1757   Node* value  = argument(0);
1758   Node* index  = argument(1);
1759   Node* ch = is_store ? argument(2) : NULL;
1760 
1761   // This intrinsic accesses byte[] array as char[] array. Computing the offsets
1762   // correctly requires matched array shapes.
1763   assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE),
1764           "sanity: byte[] and char[] bases agree");
1765   assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2,
1766           "sanity: byte[] and char[] scales agree");
1767 
1768   // Bail when getChar over constants is requested: constant folding would
1769   // reject folding mismatched char access over byte[]. A normal inlining for getChar
1770   // Java method would constant fold nicely instead.
1771   if (!is_store && value->is_Con() && index->is_Con()) {
1772     return false;
1773   }
1774 
1775   value = shenandoah_must_be_not_null(value, true);
1776 
1777   if (is_store) {
1778     value = access_resolve_for_write(value);
1779   } else {
1780     value = access_resolve_for_read(value);
1781   }
1782 
1783   Node* adr = array_element_address(value, index, T_CHAR);
1784   if (adr->is_top()) {
1785     return false;
1786   }
1787   if (is_store) {
1788     (void) store_to_memory(control(), adr, ch, T_CHAR, TypeAryPtr::BYTES, MemNode::unordered,
1789                            false, false, true /* mismatched */);
1790   } else {
1791     ch = make_load(control(), adr, TypeInt::CHAR, T_CHAR, TypeAryPtr::BYTES, MemNode::unordered,
1792                    LoadNode::DependsOnlyOnTest, false, false, true /* mismatched */);
1793     set_result(ch);
1794   }
1795   return true;
1796 }
1797 
1798 //--------------------------round_double_node--------------------------------
1799 // Round a double node if necessary.
1800 Node* LibraryCallKit::round_double_node(Node* n) {
1801   if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1)
1802     n = _gvn.transform(new RoundDoubleNode(0, n));


2200     // Offset is small => always a heap address.
2201     const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
2202     if (offset_type != NULL &&
2203         base_type->offset() == 0 &&     // (should always be?)
2204         offset_type->_lo >= 0 &&
2205         !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
2206       return Type::OopPtr;
2207     } else if (type == T_OBJECT) {
2208       // off heap access to an oop doesn't make any sense. Has to be on
2209       // heap.
2210       return Type::OopPtr;
2211     }
2212     // Otherwise, it might either be oop+off or NULL+addr.
2213     return Type::AnyPtr;
2214   } else {
2215     // No information:
2216     return Type::AnyPtr;
2217   }
2218 }
2219 
2220 inline Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, bool is_store, BasicType type, bool can_cast) {
2221   Node* uncasted_base = base;
2222   int kind = classify_unsafe_addr(uncasted_base, offset, type);
2223   if (kind == Type::RawPtr) {
2224     return basic_plus_adr(top(), uncasted_base, offset);
2225   } else if (kind == Type::AnyPtr) {
2226     assert(base == uncasted_base, "unexpected base change");
2227     if (can_cast) {
2228       if (!_gvn.type(base)->speculative_maybe_null() &&
2229           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
2230         // According to profiling, this access is always on
2231         // heap. Casting the base to not null and thus avoiding membars
2232         // around the access should allow better optimizations
2233         Node* null_ctl = top();
2234         base = null_check_oop(base, &null_ctl, true, true, true);
2235         assert(null_ctl->is_top(), "no null control here");
2236         Node* new_base = base;
2237 #if INCLUDE_SHENANDOAHGC
2238         if (UseShenandoahGC &&
2239             ((ShenandoahWriteBarrier && is_store) || (ShenandoahReadBarrier && !is_store))) {
2240           if (is_store) {
2241             new_base = access_resolve_for_write(base);
2242           } else {
2243             new_base = access_resolve_for_read(base);
2244           }
2245         }
2246 #endif
2247         return basic_plus_adr(new_base, offset);
2248       } else if (_gvn.type(base)->speculative_always_null() &&
2249                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
2250         // According to profiling, this access is always off
2251         // heap.
2252         base = null_assert(base);
2253         Node* raw_base = _gvn.transform(new CastX2PNode(offset));
2254         offset = MakeConX(0);
2255         return basic_plus_adr(top(), raw_base, offset);
2256       }
2257     }
2258     // We don't know if it's an on heap or off heap access. Fall back
2259     // to raw memory access.
2260     Node* new_base = base;
2261 #if INCLUDE_SHENANDOAHGC
2262     if (UseShenandoahGC &&
2263             ((ShenandoahWriteBarrier && is_store) || (ShenandoahReadBarrier && !is_store))) {
2264       if (is_store) {
2265         new_base = access_resolve_for_write(base);
2266       } else {
2267         new_base = access_resolve_for_read(base);
2268       }
2269     }
2270 #endif
2271     Node* raw = _gvn.transform(new CheckCastPPNode(control(), new_base, TypeRawPtr::BOTTOM));
2272     return basic_plus_adr(top(), raw, offset);
2273   } else {
2274     assert(base == uncasted_base, "unexpected base change");
2275     // We know it's an on heap access so base can't be null
2276     if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) {
2277       base = must_be_not_null(base, true);
2278     }
2279     Node* new_base = base;
2280 #if INCLUDE_SHENANDOAHGC
2281     if (UseShenandoahGC &&
2282             ((ShenandoahWriteBarrier && is_store) || (ShenandoahReadBarrier && !is_store))) {
2283       if (is_store) {
2284         new_base = access_resolve_for_write(base);
2285       } else {
2286         new_base = access_resolve_for_read(base);
2287       }
2288     }
2289 #endif
2290     return basic_plus_adr(new_base, offset);
2291   }
2292 }
2293 
2294 //--------------------------inline_number_methods-----------------------------
2295 // inline int     Integer.numberOfLeadingZeros(int)
2296 // inline int        Long.numberOfLeadingZeros(long)
2297 //
2298 // inline int     Integer.numberOfTrailingZeros(int)
2299 // inline int        Long.numberOfTrailingZeros(long)
2300 //
2301 // inline int     Integer.bitCount(int)
2302 // inline int        Long.bitCount(long)
2303 //
2304 // inline char  Character.reverseBytes(char)
2305 // inline short     Short.reverseBytes(short)
2306 // inline int     Integer.reverseBytes(int)
2307 // inline long       Long.reverseBytes(long)
2308 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) {
2309   Node* arg = argument(0);
2310   Node* n = NULL;


2428 
2429   Node* receiver = argument(0);  // type: oop
2430 
2431   // Build address expression.
2432   Node* adr;
2433   Node* heap_base_oop = top();
2434   Node* offset = top();
2435   Node* val;
2436 
2437   // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2438   Node* base = argument(1);  // type: oop
2439   // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2440   offset = argument(2);  // type: long
2441   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2442   // to be plain byte offsets, which are also the same as those accepted
2443   // by oopDesc::field_addr.
2444   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2445          "fieldOffset must be byte-scaled");
2446   // 32-bit machines ignore the high half!
2447   offset = ConvL2X(offset);
2448   adr = make_unsafe_address(base, offset, is_store, type, kind == Relaxed);

2449   if (_gvn.type(base)->isa_ptr() != TypePtr::NULL_PTR) {
2450     heap_base_oop = base;
2451   } else if (type == T_OBJECT) {
2452     return false; // off-heap oop accesses are not supported
2453   }
2454 
2455   // Can base be NULL? Otherwise, always on-heap access.
2456   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base));
2457 
2458   if (!can_access_non_heap) {
2459     decorators |= IN_HEAP;
2460   }
2461 
2462   val = is_store ? argument(4) : NULL;
2463 
2464   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2465 
2466   // Try to categorize the address.
2467   Compile::AliasType* alias_type = C->alias_type(adr_type);
2468   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");


2711     case LS_get_add:
2712     case LS_get_set: {
2713       receiver = argument(0);  // type: oop
2714       base     = argument(1);  // type: oop
2715       offset   = argument(2);  // type: long
2716       oldval   = NULL;
2717       newval   = argument(4);  // type: oop, int, or long
2718       break;
2719     }
2720     default:
2721       ShouldNotReachHere();
2722   }
2723 
2724   // Build field offset expression.
2725   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2726   // to be plain byte offsets, which are also the same as those accepted
2727   // by oopDesc::field_addr.
2728   assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
2729   // 32-bit machines ignore the high half of long offsets
2730   offset = ConvL2X(offset);
2731   Node* adr = make_unsafe_address(base, offset, true, type, false);
2732   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2733 
2734   Compile::AliasType* alias_type = C->alias_type(adr_type);
2735   BasicType bt = alias_type->basic_type();
2736   if (bt != T_ILLEGAL &&
2737       ((bt == T_OBJECT || bt == T_ARRAY) != (type == T_OBJECT))) {
2738     // Don't intrinsify mismatched object accesses.
2739     return false;
2740   }
2741 
2742   // For CAS, unlike inline_unsafe_access, there seems no point in
2743   // trying to refine types. Just use the coarse types here.
2744   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2745   const Type *value_type = Type::get_const_basic_type(type);
2746 
2747   switch (kind) {
2748     case LS_get_set:
2749     case LS_cmp_exchange: {
2750       if (type == T_OBJECT) {
2751         const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);


3006     no_int_result_path   = 1, // t == Thread.current() && !TLS._osthread._interrupted
3007     no_clear_result_path = 2, // t == Thread.current() &&  TLS._osthread._interrupted && !clear_int
3008     slow_result_path     = 3, // slow path: t.isInterrupted(clear_int)
3009     PATH_LIMIT
3010   };
3011 
3012   // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag
3013   // out of the function.
3014   insert_mem_bar(Op_MemBarCPUOrder);
3015 
3016   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
3017   PhiNode*    result_val = new PhiNode(result_rgn, TypeInt::BOOL);
3018 
3019   RegionNode* slow_region = new RegionNode(1);
3020   record_for_igvn(slow_region);
3021 
3022   // (a) Receiving thread must be the current thread.
3023   Node* rec_thr = argument(0);
3024   Node* tls_ptr = NULL;
3025   Node* cur_thr = generate_current_thread(tls_ptr);
3026 
3027   cur_thr = access_resolve_for_write(cur_thr);
3028   rec_thr = access_resolve_for_write(rec_thr);
3029   Node* cmp_thr = _gvn.transform(new CmpPNode(cur_thr, rec_thr));
3030   Node* bol_thr = _gvn.transform(new BoolNode(cmp_thr, BoolTest::ne));
3031 
3032   generate_slow_guard(bol_thr, slow_region);
3033 
3034   // (b) Interrupt bit on TLS must be false.
3035   Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
3036   Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
3037   p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
3038 
3039   // Set the control input on the field _interrupted read to prevent it floating up.
3040   Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered);
3041   Node* cmp_bit = _gvn.transform(new CmpINode(int_bit, intcon(0)));
3042   Node* bol_bit = _gvn.transform(new BoolNode(cmp_bit, BoolTest::ne));
3043 
3044   IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
3045 
3046   // First fast path:  if (!TLS._interrupted) return false;
3047   Node* false_bit = _gvn.transform(new IfFalseNode(iff_bit));
3048   result_rgn->init_req(no_int_result_path, false_bit);


3424   // Pull both arguments off the stack.
3425   Node* args[2];                // two java.lang.Class mirrors: superc, subc
3426   args[0] = argument(0);
3427   args[1] = argument(1);
3428   Node* klasses[2];             // corresponding Klasses: superk, subk
3429   klasses[0] = klasses[1] = top();
3430 
3431   enum {
3432     // A full decision tree on {superc is prim, subc is prim}:
3433     _prim_0_path = 1,           // {P,N} => false
3434                                 // {P,P} & superc!=subc => false
3435     _prim_same_path,            // {P,P} & superc==subc => true
3436     _prim_1_path,               // {N,P} => false
3437     _ref_subtype_path,          // {N,N} & subtype check wins => true
3438     _both_ref_path,             // {N,N} & subtype check loses => false
3439     PATH_LIMIT
3440   };
3441 
3442   RegionNode* region = new RegionNode(PATH_LIMIT);
3443   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
3444   Node*       mem_phi= new PhiNode(region, Type::MEMORY, TypePtr::BOTTOM);
3445   record_for_igvn(region);
3446   Node* init_mem = map()->memory();
3447 
3448   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
3449   const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3450   int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
3451 
3452   // First null-check both mirrors and load each mirror's klass metaobject.
3453   int which_arg;
3454   for (which_arg = 0; which_arg <= 1; which_arg++) {
3455     Node* arg = args[which_arg];
3456     arg = null_check(arg);
3457     if (stopped())  break;
3458     args[which_arg] = arg;
3459 
3460     Node* p = basic_plus_adr(arg, class_klass_offset);
3461     Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type);
3462     klasses[which_arg] = _gvn.transform(kls);
3463   }
3464 
3465   args[0] = access_resolve_for_write(args[0]);
3466   args[1] = access_resolve_for_write(args[1]);
3467 
3468   // Having loaded both klasses, test each for null.
3469   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3470   for (which_arg = 0; which_arg <= 1; which_arg++) {
3471     Node* kls = klasses[which_arg];
3472     Node* null_ctl = top();
3473     kls = null_check_oop(kls, &null_ctl, never_see_null);
3474     int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path);
3475     region->init_req(prim_path, null_ctl);
3476     if (stopped())  break;
3477     klasses[which_arg] = kls;
3478   }
3479 
3480   if (!stopped()) {
3481     // now we have two reference types, in klasses[0..1]
3482     Node* subk   = klasses[1];  // the argument to isAssignableFrom
3483     Node* superk = klasses[0];  // the receiver
3484     region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
3485     // now we have a successful reference subtype check
3486     region->set_req(_ref_subtype_path, control());
3487   }


3492   set_control(region->in(_prim_0_path)); // go back to first null check
3493   if (!stopped()) {
3494     // Since superc is primitive, make a guard for the superc==subc case.
3495     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
3496     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
3497     generate_guard(bol_eq, region, PROB_FAIR);
3498     if (region->req() == PATH_LIMIT+1) {
3499       // A guard was added.  If the added guard is taken, superc==subc.
3500       region->swap_edges(PATH_LIMIT, _prim_same_path);
3501       region->del_req(PATH_LIMIT);
3502     }
3503     region->set_req(_prim_0_path, control()); // Not equal after all.
3504   }
3505 
3506   // these are the only paths that produce 'true':
3507   phi->set_req(_prim_same_path,   intcon(1));
3508   phi->set_req(_ref_subtype_path, intcon(1));
3509 
3510   // pull together the cases:
3511   assert(region->req() == PATH_LIMIT, "sane region");
3512   Node* cur_mem = reset_memory();
3513   for (uint i = 1; i < region->req(); i++) {
3514     Node* ctl = region->in(i);
3515     if (ctl == NULL || ctl == top()) {
3516       region->set_req(i, top());
3517       phi   ->set_req(i, top());
3518       mem_phi->set_req(i, top());
3519     } else {
3520       if (phi->in(i) == NULL) {
3521         phi->set_req(i, intcon(0)); // all other paths produce 'false'
3522       }
3523       mem_phi->set_req(i, (i == _prim_0_path || i == _prim_same_path) ?  cur_mem : init_mem);
3524     }
3525   }
3526 
3527   set_control(_gvn.transform(region));
3528   set_result(_gvn.transform(phi));
3529   set_all_memory(_gvn.transform(mem_phi));
3530   return true;
3531 }
3532 
3533 //---------------------generate_array_guard_common------------------------
3534 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
3535                                                   bool obj_array, bool not_array) {
3536 
3537   if (stopped()) {
3538     return NULL;
3539   }
3540 
3541   // If obj_array/non_array==false/false:
3542   // Branch around if the given klass is in fact an array (either obj or prim).
3543   // If obj_array/non_array==false/true:
3544   // Branch around if the given klass is not an array klass of any kind.
3545   // If obj_array/non_array==true/true:
3546   // Branch around if the kls is not an oop array (kls is int[], String, etc.)
3547   // If obj_array/non_array==true/false:
3548   // Branch around if the kls is an oop array (Object[] or subtype)
3549   //


3739 
3740     // Bail out if length is negative.
3741     // Without this the new_array would throw
3742     // NegativeArraySizeException but IllegalArgumentException is what
3743     // should be thrown
3744     generate_negative_guard(length, bailout, &length);
3745 
3746     if (bailout->req() > 1) {
3747       PreserveJVMState pjvms(this);
3748       set_control(_gvn.transform(bailout));
3749       uncommon_trap(Deoptimization::Reason_intrinsic,
3750                     Deoptimization::Action_maybe_recompile);
3751     }
3752 
3753     if (!stopped()) {
3754       // How many elements will we copy from the original?
3755       // The answer is MinI(orig_length - start, length).
3756       Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
3757       Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length);
3758 
3759       original = access_resolve_for_read(original);
3760 
3761       // Generate a direct call to the right arraycopy function(s).
3762       // We know the copy is disjoint but we might not know if the
3763       // oop stores need checking.
3764       // Extreme case:  Arrays.copyOf((Integer[])x, 10, String[].class).
3765       // This will fail a store-check if x contains any non-nulls.
3766 
3767       // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
3768       // loads/stores but it is legal only if we're sure the
3769       // Arrays.copyOf would succeed. So we need all input arguments
3770       // to the copyOf to be validated, including that the copy to the
3771       // new array won't trigger an ArrayStoreException. That subtype
3772       // check can be optimized if we know something on the type of
3773       // the input array from type speculation.
3774       if (_gvn.type(klass_node)->singleton()) {
3775         ciKlass* subk   = _gvn.type(load_object_klass(original))->is_klassptr()->klass();
3776         ciKlass* superk = _gvn.type(klass_node)->is_klassptr()->klass();
3777 
3778         int test = C->static_subtype_check(superk, subk);
3779         if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) {
3780           const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr();


3796           set_control(not_subtype_ctrl);
3797           uncommon_trap(Deoptimization::Reason_class_check,
3798                         Deoptimization::Action_make_not_entrant);
3799           assert(stopped(), "Should be stopped");
3800         }
3801         validated = true;
3802       }
3803 
3804       if (!stopped()) {
3805         newcopy = new_array(klass_node, length, 0);  // no arguments to push
3806 
3807         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false,
3808                                                 load_object_klass(original), klass_node);
3809         if (!is_copyOfRange) {
3810           ac->set_copyof(validated);
3811         } else {
3812           ac->set_copyofrange(validated);
3813         }
3814         Node* n = _gvn.transform(ac);
3815         if (n == ac) {
3816           if (UseShenandoahGC) {
3817             ac->_adr_type = TypePtr::BOTTOM;
3818           }
3819           ac->connect_outputs(this);
3820         } else {
3821           assert(validated, "shouldn't transform if all arguments not validated");
3822           set_all_memory(n);
3823         }
3824       }
3825     }
3826   } // original reexecute is set back here
3827 
3828   C->set_has_split_ifs(true); // Has chance for split-if optimization
3829   if (!stopped()) {
3830     set_result(newcopy);
3831   }
3832   return true;
3833 }
3834 
3835 
3836 //----------------------generate_virtual_guard---------------------------
3837 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
3838 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,


4234 }
4235 
4236 //----------------------inline_unsafe_copyMemory-------------------------
4237 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
4238 bool LibraryCallKit::inline_unsafe_copyMemory() {
4239   if (callee()->is_static())  return false;  // caller must have the capability!
4240   null_check_receiver();  // null-check receiver
4241   if (stopped())  return true;
4242 
4243   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
4244 
4245   Node* src_ptr =         argument(1);   // type: oop
4246   Node* src_off = ConvL2X(argument(2));  // type: long
4247   Node* dst_ptr =         argument(4);   // type: oop
4248   Node* dst_off = ConvL2X(argument(5));  // type: long
4249   Node* size    = ConvL2X(argument(7));  // type: long
4250 
4251   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
4252          "fieldOffset must be byte-scaled");
4253 
4254   Node* src = make_unsafe_address(src_ptr, src_off, false);
4255   Node* dst = make_unsafe_address(dst_ptr, dst_off, true);
4256 
4257   // Conservatively insert a memory barrier on all memory slices.
4258   // Do not let writes of the copy source or destination float below the copy.
4259   insert_mem_bar(Op_MemBarCPUOrder);
4260 
4261   // Call it.  Note that the length argument is not scaled.
4262   make_runtime_call(RC_LEAF|RC_NO_FP,
4263                     OptoRuntime::fast_arraycopy_Type(),
4264                     StubRoutines::unsafe_arraycopy(),
4265                     "unsafe_arraycopy",
4266                     TypeRawPtr::BOTTOM,
4267                     src, dst, size XTOP);
4268 
4269   // Do not let reads of the copy destination float above the copy.
4270   insert_mem_bar(Op_MemBarCPUOrder);
4271 
4272   return true;
4273 }
4274 
4275 //------------------------clone_coping-----------------------------------
4276 // Helper function for inline_native_clone.
4277 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) {
4278   assert(obj_size != NULL, "");
4279   Node* raw_obj = alloc_obj->in(1);
4280   assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), "");
4281 
4282   obj = access_resolve_for_read(obj);
4283 
4284   AllocateNode* alloc = NULL;
4285   if (ReduceBulkZeroing) {
4286     // We will be completely responsible for initializing this object -
4287     // mark Initialize node as complete.
4288     alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn);
4289     // The object was just allocated - there should be no any stores!
4290     guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), "");
4291     // Mark as complete_with_arraycopy so that on AllocateNode
4292     // expansion, we know this AllocateNode is initialized by an array
4293     // copy and a StoreStore barrier exists after the array copy.
4294     alloc->initialization()->set_complete_with_arraycopy();
4295   }
4296 
4297   // Copy the fastest available way.
4298   // TODO: generate fields copies for small objects instead.
4299   Node* size = _gvn.transform(obj_size);
4300 
4301   access_clone(control(), obj, alloc_obj, size, is_array);
4302 
4303   // Do not let reads from the cloned object float above the arraycopy.


4388     PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
4389     record_for_igvn(result_reg);
4390 
4391     Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL);
4392     if (array_ctl != NULL) {
4393       // It's an array.
4394       PreserveJVMState pjvms(this);
4395       set_control(array_ctl);
4396       Node* obj_length = load_array_length(obj);
4397       Node* obj_size  = NULL;
4398       Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size);  // no arguments to push
4399 
4400       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
4401       if (bs->array_copy_requires_gc_barriers(T_OBJECT)) {
4402         // If it is an oop array, it requires very special treatment,
4403         // because gc barriers are required when accessing the array.
4404         Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);
4405         if (is_obja != NULL) {
4406           PreserveJVMState pjvms2(this);
4407           set_control(is_obja);
4408 
4409           obj = access_resolve_for_read(obj);
4410 
4411           // Generate a direct call to the right arraycopy function(s).
4412           Node* alloc = tightly_coupled_allocation(alloc_obj, NULL);
4413           ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false);
4414           ac->set_cloneoop();
4415           Node* n = _gvn.transform(ac);
4416           assert(n == ac, "cannot disappear");
4417           if (UseShenandoahGC) {
4418             ac->_adr_type = TypePtr::BOTTOM;
4419           }
4420           ac->connect_outputs(this);
4421 
4422           result_reg->init_req(_objArray_path, control());
4423           result_val->init_req(_objArray_path, alloc_obj);
4424           result_i_o ->set_req(_objArray_path, i_o());
4425           result_mem ->set_req(_objArray_path, reset_memory());
4426         }
4427       }
4428       // Otherwise, there are no barriers to worry about.
4429       // (We can dispense with card marks if we know the allocation
4430       //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
4431       //  causes the non-eden paths to take compensating steps to
4432       //  simulate a fresh allocation, so that no further
4433       //  card marks are required in compiled code to initialize
4434       //  the object.)
4435 
4436       if (!stopped()) {
4437         copy_to_clone(obj, alloc_obj, obj_size, true);
4438 
4439         // Present the results of the copy.


4519 // we set the JVM state for uncommon traps between the allocation and
4520 // the arraycopy to the state before the allocation so, in case of
4521 // deoptimization, we'll reexecute the allocation and the
4522 // initialization.
4523 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) {
4524   if (alloc != NULL) {
4525     ciMethod* trap_method = alloc->jvms()->method();
4526     int trap_bci = alloc->jvms()->bci();
4527 
4528     if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &
4529           !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) {
4530       // Make sure there's no store between the allocation and the
4531       // arraycopy otherwise visible side effects could be rexecuted
4532       // in case of deoptimization and cause incorrect execution.
4533       bool no_interfering_store = true;
4534       Node* mem = alloc->in(TypeFunc::Memory);
4535       if (mem->is_MergeMem()) {
4536         for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) {
4537           Node* n = mms.memory();
4538           if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
4539             assert(n->is_Store() || n->Opcode() == Op_ShenandoahWBMemProj, "what else?");
4540             no_interfering_store = false;
4541             break;
4542           }
4543         }
4544       } else {
4545         for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) {
4546           Node* n = mms.memory();
4547           if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
4548             assert(n->is_Store() || n->Opcode() == Op_ShenandoahWBMemProj, "what else?");
4549             no_interfering_store = false;
4550             break;
4551           }
4552         }
4553       }
4554 
4555       if (no_interfering_store) {
4556         JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
4557         uint size = alloc->req();
4558         SafePointNode* sfpt = new SafePointNode(size, old_jvms);
4559         old_jvms->set_map(sfpt);
4560         for (uint i = 0; i < size; i++) {
4561           sfpt->init_req(i, alloc->in(i));
4562         }
4563         // re-push array length for deoptimization
4564         sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), alloc->in(AllocateNode::ALength));
4565         old_jvms->set_sp(old_jvms->sp()+1);
4566         old_jvms->set_monoff(old_jvms->monoff()+1);
4567         old_jvms->set_scloff(old_jvms->scloff()+1);
4568         old_jvms->set_endoff(old_jvms->endoff()+1);


4869     }
4870     {
4871       PreserveJVMState pjvms(this);
4872       set_control(_gvn.transform(slow_region));
4873       uncommon_trap(Deoptimization::Reason_intrinsic,
4874                     Deoptimization::Action_make_not_entrant);
4875       assert(stopped(), "Should be stopped");
4876     }
4877 
4878     const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr();
4879     const Type *toop = TypeOopPtr::make_from_klass(dest_klass_t->klass());
4880     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
4881   }
4882 
4883   arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx);
4884 
4885   if (stopped()) {
4886     return true;
4887   }
4888 
4889   Node* new_src = access_resolve_for_read(src);
4890   Node* new_dest = access_resolve_for_write(dest);
4891 
4892   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, new_src, src_offset, new_dest, dest_offset, length, alloc != NULL, negative_length_guard_generated,
4893                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
4894                                           // so the compiler has a chance to eliminate them: during macro expansion,
4895                                           // we have to set their control (CastPP nodes are eliminated).
4896                                           load_object_klass(src), load_object_klass(dest),
4897                                           load_array_length(src), load_array_length(dest));
4898 
4899   ac->set_arraycopy(validated);
4900 
4901   Node* n = _gvn.transform(ac);
4902   if (n == ac) {
4903     if (UseShenandoahGC) {
4904       ac->_adr_type = TypePtr::BOTTOM;
4905     }
4906     ac->connect_outputs(this);
4907   } else {
4908     assert(validated, "shouldn't transform if all arguments not validated");
4909     set_all_memory(n);
4910   }
4911   clear_upper_avx();
4912 
4913 
4914   return true;
4915 }
4916 
4917 
4918 // Helper function which determines if an arraycopy immediately follows
4919 // an allocation, with no intervening tests or other escapes for the object.
4920 AllocateArrayNode*
4921 LibraryCallKit::tightly_coupled_allocation(Node* ptr,
4922                                            RegionNode* slow_region) {
4923   if (stopped())             return NULL;  // no fast path
4924   if (C->AliasLevel() == 0)  return NULL;  // no MergeMems around
4925 
4926 #if INCLUDE_SHENANDOAHGC
4927   ptr = ShenandoahBarrierNode::skip_through_barrier(ptr);
4928 #endif
4929 
4930   AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn);
4931   if (alloc == NULL)  return NULL;
4932 
4933   Node* rawmem = memory(Compile::AliasIdxRaw);
4934   // Is the allocation's memory state untouched?
4935   if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) {
4936     // Bail out if there have been raw-memory effects since the allocation.
4937     // (Example:  There might have been a call or safepoint.)
4938     return NULL;
4939   }
4940   rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw);
4941   if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) {
4942     return NULL;
4943   }
4944 
4945   // There must be no unexpected observers of this allocation.
4946   for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) {
4947     Node* obs = ptr->fast_out(i);
4948     if (obs != this->map()) {
4949       return NULL;


4989 
4990   // If we get this far, we have an allocation which immediately
4991   // precedes the arraycopy, and we can take over zeroing the new object.
4992   // The arraycopy will finish the initialization, and provide
4993   // a new control state to which we will anchor the destination pointer.
4994 
4995   return alloc;
4996 }
4997 
4998 //-------------inline_encodeISOArray-----------------------------------
4999 // encode char[] to byte[] in ISO_8859_1
5000 bool LibraryCallKit::inline_encodeISOArray() {
5001   assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters");
5002   // no receiver since it is static method
5003   Node *src         = argument(0);
5004   Node *src_offset  = argument(1);
5005   Node *dst         = argument(2);
5006   Node *dst_offset  = argument(3);
5007   Node *length      = argument(4);
5008 
5009   src = shenandoah_must_be_not_null(src, true);
5010   dst = shenandoah_must_be_not_null(dst, true);
5011 
5012   src = access_resolve_for_read(src);
5013   dst = access_resolve_for_write(dst);
5014 
5015   const Type* src_type = src->Value(&_gvn);
5016   const Type* dst_type = dst->Value(&_gvn);
5017   const TypeAryPtr* top_src = src_type->isa_aryptr();
5018   const TypeAryPtr* top_dest = dst_type->isa_aryptr();
5019   if (top_src  == NULL || top_src->klass()  == NULL ||
5020       top_dest == NULL || top_dest->klass() == NULL) {
5021     // failed array check
5022     return false;
5023   }
5024 
5025   // Figure out the size and type of the elements we will be copying.
5026   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5027   BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5028   if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) {
5029     return false;
5030   }
5031 
5032   Node* src_start = array_element_address(src, src_offset, T_CHAR);
5033   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
5034   // 'src_start' points to src array + scaled offset


5047 
5048 //-------------inline_multiplyToLen-----------------------------------
5049 bool LibraryCallKit::inline_multiplyToLen() {
5050   assert(UseMultiplyToLenIntrinsic, "not implemented on this platform");
5051 
5052   address stubAddr = StubRoutines::multiplyToLen();
5053   if (stubAddr == NULL) {
5054     return false; // Intrinsic's stub is not implemented on this platform
5055   }
5056   const char* stubName = "multiplyToLen";
5057 
5058   assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters");
5059 
5060   // no receiver because it is a static method
5061   Node* x    = argument(0);
5062   Node* xlen = argument(1);
5063   Node* y    = argument(2);
5064   Node* ylen = argument(3);
5065   Node* z    = argument(4);
5066 
5067   x = shenandoah_must_be_not_null(x, true);
5068   x = access_resolve_for_read(x);
5069   y = shenandoah_must_be_not_null(y, true);
5070   y = access_resolve_for_read(y);
5071   z = access_resolve_for_write(z);
5072 
5073   const Type* x_type = x->Value(&_gvn);
5074   const Type* y_type = y->Value(&_gvn);
5075   const TypeAryPtr* top_x = x_type->isa_aryptr();
5076   const TypeAryPtr* top_y = y_type->isa_aryptr();
5077   if (top_x  == NULL || top_x->klass()  == NULL ||
5078       top_y == NULL || top_y->klass() == NULL) {
5079     // failed array check
5080     return false;
5081   }
5082 
5083   BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5084   BasicType y_elem = y_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5085   if (x_elem != T_INT || y_elem != T_INT) {
5086     return false;
5087   }
5088 
5089   // Set the original stack and the reexecute bit for the interpreter to reexecute
5090   // the bytecode that invokes BigInteger.multiplyToLen() if deoptimization happens
5091   // on the return from z array allocation in runtime.
5092   { PreserveReexecuteState preexecs(this);


5098     // 'y_start' points to y array + scaled ylen
5099 
5100     // Allocate the result array
5101     Node* zlen = _gvn.transform(new AddINode(xlen, ylen));
5102     ciKlass* klass = ciTypeArrayKlass::make(T_INT);
5103     Node* klass_node = makecon(TypeKlassPtr::make(klass));
5104 
5105     IdealKit ideal(this);
5106 
5107 #define __ ideal.
5108      Node* one = __ ConI(1);
5109      Node* zero = __ ConI(0);
5110      IdealVariable need_alloc(ideal), z_alloc(ideal);  __ declarations_done();
5111      __ set(need_alloc, zero);
5112      __ set(z_alloc, z);
5113      __ if_then(z, BoolTest::eq, null()); {
5114        __ increment (need_alloc, one);
5115      } __ else_(); {
5116        // Update graphKit memory and control from IdealKit.
5117        sync_kit(ideal);
5118        Node* zlen_arg = NULL;
5119        if (UseShenandoahGC) {
5120          Node *cast = new CastPPNode(z, TypePtr::NOTNULL);
5121          cast->init_req(0, control());
5122          _gvn.set_type(cast, cast->bottom_type());
5123          C->record_for_igvn(cast);
5124 
5125          zlen_arg = load_array_length(cast);
5126        } else {
5127          zlen_arg = load_array_length(z);
5128        }
5129        // Update IdealKit memory and control from graphKit.
5130        __ sync_kit(this);
5131        __ if_then(zlen_arg, BoolTest::lt, zlen); {
5132          __ increment (need_alloc, one);
5133        } __ end_if();
5134      } __ end_if();
5135 
5136      __ if_then(__ value(need_alloc), BoolTest::ne, zero); {
5137        // Update graphKit memory and control from IdealKit.
5138        sync_kit(ideal);
5139        Node * narr = new_array(klass_node, zlen, 1);
5140        // Update IdealKit memory and control from graphKit.
5141        __ sync_kit(this);
5142        __ set(z_alloc, narr);
5143      } __ end_if();
5144 
5145      sync_kit(ideal);
5146      z = __ value(z_alloc);
5147      // Can't use TypeAryPtr::INTS which uses Bottom offset.
5148      _gvn.set_type(z, TypeOopPtr::make_from_klass(klass));


5163   return true;
5164 }
5165 
5166 //-------------inline_squareToLen------------------------------------
5167 bool LibraryCallKit::inline_squareToLen() {
5168   assert(UseSquareToLenIntrinsic, "not implemented on this platform");
5169 
5170   address stubAddr = StubRoutines::squareToLen();
5171   if (stubAddr == NULL) {
5172     return false; // Intrinsic's stub is not implemented on this platform
5173   }
5174   const char* stubName = "squareToLen";
5175 
5176   assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters");
5177 
5178   Node* x    = argument(0);
5179   Node* len  = argument(1);
5180   Node* z    = argument(2);
5181   Node* zlen = argument(3);
5182 
5183   x = shenandoah_must_be_not_null(x, true);
5184   x = access_resolve_for_read(x);
5185   z = shenandoah_must_be_not_null(z, true);
5186   z = access_resolve_for_write(z);
5187 
5188   const Type* x_type = x->Value(&_gvn);
5189   const Type* z_type = z->Value(&_gvn);
5190   const TypeAryPtr* top_x = x_type->isa_aryptr();
5191   const TypeAryPtr* top_z = z_type->isa_aryptr();
5192   if (top_x  == NULL || top_x->klass()  == NULL ||
5193       top_z  == NULL || top_z->klass()  == NULL) {
5194     // failed array check
5195     return false;
5196   }
5197 
5198   BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5199   BasicType z_elem = z_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5200   if (x_elem != T_INT || z_elem != T_INT) {
5201     return false;
5202   }
5203 
5204 
5205   Node* x_start = array_element_address(x, intcon(0), x_elem);
5206   Node* z_start = array_element_address(z, intcon(0), z_elem);
5207 


5215 }
5216 
5217 //-------------inline_mulAdd------------------------------------------
5218 bool LibraryCallKit::inline_mulAdd() {
5219   assert(UseMulAddIntrinsic, "not implemented on this platform");
5220 
5221   address stubAddr = StubRoutines::mulAdd();
5222   if (stubAddr == NULL) {
5223     return false; // Intrinsic's stub is not implemented on this platform
5224   }
5225   const char* stubName = "mulAdd";
5226 
5227   assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters");
5228 
5229   Node* out      = argument(0);
5230   Node* in       = argument(1);
5231   Node* offset   = argument(2);
5232   Node* len      = argument(3);
5233   Node* k        = argument(4);
5234 
5235   in = access_resolve_for_read(in);
5236   out = shenandoah_must_be_not_null(out, true);
5237   out = access_resolve_for_write(out);
5238 
5239   const Type* out_type = out->Value(&_gvn);
5240   const Type* in_type = in->Value(&_gvn);
5241   const TypeAryPtr* top_out = out_type->isa_aryptr();
5242   const TypeAryPtr* top_in = in_type->isa_aryptr();
5243   if (top_out  == NULL || top_out->klass()  == NULL ||
5244       top_in == NULL || top_in->klass() == NULL) {
5245     // failed array check
5246     return false;
5247   }
5248 
5249   BasicType out_elem = out_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5250   BasicType in_elem = in_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5251   if (out_elem != T_INT || in_elem != T_INT) {
5252     return false;
5253   }
5254 
5255   Node* outlen = load_array_length(out);
5256   Node* new_offset = _gvn.transform(new SubINode(outlen, offset));
5257   Node* out_start = array_element_address(out, intcon(0), out_elem);
5258   Node* in_start = array_element_address(in, intcon(0), in_elem);


5268 
5269 //-------------inline_montgomeryMultiply-----------------------------------
5270 bool LibraryCallKit::inline_montgomeryMultiply() {
5271   address stubAddr = StubRoutines::montgomeryMultiply();
5272   if (stubAddr == NULL) {
5273     return false; // Intrinsic's stub is not implemented on this platform
5274   }
5275 
5276   assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform");
5277   const char* stubName = "montgomery_multiply";
5278 
5279   assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters");
5280 
5281   Node* a    = argument(0);
5282   Node* b    = argument(1);
5283   Node* n    = argument(2);
5284   Node* len  = argument(3);
5285   Node* inv  = argument(4);
5286   Node* m    = argument(6);
5287 
5288   a = access_resolve_for_read(a);
5289   b = access_resolve_for_read(b);
5290   n = access_resolve_for_read(n);
5291   m = access_resolve_for_write(m);
5292 
5293   const Type* a_type = a->Value(&_gvn);
5294   const TypeAryPtr* top_a = a_type->isa_aryptr();
5295   const Type* b_type = b->Value(&_gvn);
5296   const TypeAryPtr* top_b = b_type->isa_aryptr();
5297   const Type* n_type = a->Value(&_gvn);
5298   const TypeAryPtr* top_n = n_type->isa_aryptr();
5299   const Type* m_type = a->Value(&_gvn);
5300   const TypeAryPtr* top_m = m_type->isa_aryptr();
5301   if (top_a  == NULL || top_a->klass()  == NULL ||
5302       top_b == NULL || top_b->klass()  == NULL ||
5303       top_n == NULL || top_n->klass()  == NULL ||
5304       top_m == NULL || top_m->klass()  == NULL) {
5305     // failed array check
5306     return false;
5307   }
5308 
5309   BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5310   BasicType b_elem = b_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5311   BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5312   BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();


5332   return true;
5333 }
5334 
5335 bool LibraryCallKit::inline_montgomerySquare() {
5336   address stubAddr = StubRoutines::montgomerySquare();
5337   if (stubAddr == NULL) {
5338     return false; // Intrinsic's stub is not implemented on this platform
5339   }
5340 
5341   assert(UseMontgomerySquareIntrinsic, "not implemented on this platform");
5342   const char* stubName = "montgomery_square";
5343 
5344   assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters");
5345 
5346   Node* a    = argument(0);
5347   Node* n    = argument(1);
5348   Node* len  = argument(2);
5349   Node* inv  = argument(3);
5350   Node* m    = argument(5);
5351 
5352   a = access_resolve_for_read(a);
5353   n = access_resolve_for_read(n);
5354   m = access_resolve_for_write(m);
5355 
5356   const Type* a_type = a->Value(&_gvn);
5357   const TypeAryPtr* top_a = a_type->isa_aryptr();
5358   const Type* n_type = a->Value(&_gvn);
5359   const TypeAryPtr* top_n = n_type->isa_aryptr();
5360   const Type* m_type = a->Value(&_gvn);
5361   const TypeAryPtr* top_m = m_type->isa_aryptr();
5362   if (top_a  == NULL || top_a->klass()  == NULL ||
5363       top_n == NULL || top_n->klass()  == NULL ||
5364       top_m == NULL || top_m->klass()  == NULL) {
5365     // failed array check
5366     return false;
5367   }
5368 
5369   BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5370   BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5371   BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5372   if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
5373     return false;
5374   }
5375 


5405   Node* obja = argument(0);
5406   Node* aoffset = argument(1);
5407   Node* objb = argument(3);
5408   Node* boffset = argument(4);
5409   Node* length = argument(6);
5410   Node* scale = argument(7);
5411 
5412   const Type* a_type = obja->Value(&_gvn);
5413   const Type* b_type = objb->Value(&_gvn);
5414   const TypeAryPtr* top_a = a_type->isa_aryptr();
5415   const TypeAryPtr* top_b = b_type->isa_aryptr();
5416   if (top_a == NULL || top_a->klass() == NULL ||
5417     top_b == NULL || top_b->klass() == NULL) {
5418     // failed array check
5419     return false;
5420   }
5421 
5422   Node* call;
5423   jvms()->set_should_reexecute(true);
5424 
5425   Node* obja_adr = make_unsafe_address(obja, aoffset, false);
5426   Node* objb_adr = make_unsafe_address(objb, boffset, false);
5427 
5428   call = make_runtime_call(RC_LEAF,
5429     OptoRuntime::vectorizedMismatch_Type(),
5430     stubAddr, stubName, TypePtr::BOTTOM,
5431     obja_adr, objb_adr, length, scale);
5432 
5433   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5434   set_result(result);
5435   return true;
5436 }
5437 
5438 /**
5439  * Calculate CRC32 for byte.
5440  * int java.util.zip.CRC32.update(int crc, int b)
5441  */
5442 bool LibraryCallKit::inline_updateCRC32() {
5443   assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");
5444   assert(callee()->signature()->size() == 2, "update has 2 parameters");
5445   // no receiver since it is static method
5446   Node* crc  = argument(0); // type: int


5480   // no receiver since it is static method
5481   Node* crc     = argument(0); // type: int
5482   Node* src     = argument(1); // type: oop
5483   Node* offset  = argument(2); // type: int
5484   Node* length  = argument(3); // type: int
5485 
5486   const Type* src_type = src->Value(&_gvn);
5487   const TypeAryPtr* top_src = src_type->isa_aryptr();
5488   if (top_src  == NULL || top_src->klass()  == NULL) {
5489     // failed array check
5490     return false;
5491   }
5492 
5493   // Figure out the size and type of the elements we will be copying.
5494   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5495   if (src_elem != T_BYTE) {
5496     return false;
5497   }
5498 
5499   // 'src_start' points to src array + scaled offset
5500   src = shenandoah_must_be_not_null(src, true);
5501   src = access_resolve_for_read(src);
5502   Node* src_start = array_element_address(src, offset, src_elem);
5503 
5504   // We assume that range check is done by caller.
5505   // TODO: generate range check (offset+length < src.length) in debug VM.
5506 
5507   // Call the stub.
5508   address stubAddr = StubRoutines::updateBytesCRC32();
5509   const char *stubName = "updateBytesCRC32";
5510 
5511   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
5512                                  stubAddr, stubName, TypePtr::BOTTOM,
5513                                  crc, src_start, length);
5514   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5515   set_result(result);
5516   return true;
5517 }
5518 
5519 /**
5520  * Calculate CRC32 for ByteBuffer.
5521  * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)


5570   Node* src     = argument(1); // type: oop
5571   Node* offset  = argument(2); // type: int
5572   Node* end     = argument(3); // type: int
5573 
5574   Node* length = _gvn.transform(new SubINode(end, offset));
5575 
5576   const Type* src_type = src->Value(&_gvn);
5577   const TypeAryPtr* top_src = src_type->isa_aryptr();
5578   if (top_src  == NULL || top_src->klass()  == NULL) {
5579     // failed array check
5580     return false;
5581   }
5582 
5583   // Figure out the size and type of the elements we will be copying.
5584   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5585   if (src_elem != T_BYTE) {
5586     return false;
5587   }
5588 
5589   // 'src_start' points to src array + scaled offset
5590   src = access_resolve_for_read(src);
5591   src = shenandoah_must_be_not_null(src, true);
5592   Node* src_start = array_element_address(src, offset, src_elem);
5593 
5594   // static final int[] byteTable in class CRC32C
5595   Node* table = get_table_from_crc32c_class(callee()->holder());
5596   table = shenandoah_must_be_not_null(table, true);
5597   table = access_resolve_for_read(table);
5598   Node* table_start = array_element_address(table, intcon(0), T_INT);
5599 
5600   // We assume that range check is done by caller.
5601   // TODO: generate range check (offset+length < src.length) in debug VM.
5602 
5603   // Call the stub.
5604   address stubAddr = StubRoutines::updateBytesCRC32C();
5605   const char *stubName = "updateBytesCRC32C";
5606 
5607   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
5608                                  stubAddr, stubName, TypePtr::BOTTOM,
5609                                  crc, src_start, length, table_start);
5610   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5611   set_result(result);
5612   return true;
5613 }
5614 
5615 //------------------------------inline_updateDirectByteBufferCRC32C-----------------------
5616 //
5617 // Calculate CRC32C for DirectByteBuffer.


5621   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
5622   assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long");
5623   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
5624   // no receiver since it is a static method
5625   Node* crc     = argument(0); // type: int
5626   Node* src     = argument(1); // type: long
5627   Node* offset  = argument(3); // type: int
5628   Node* end     = argument(4); // type: int
5629 
5630   Node* length = _gvn.transform(new SubINode(end, offset));
5631 
5632   src = ConvL2X(src);  // adjust Java long to machine word
5633   Node* base = _gvn.transform(new CastX2PNode(src));
5634   offset = ConvI2X(offset);
5635 
5636   // 'src_start' points to src array + scaled offset
5637   Node* src_start = basic_plus_adr(top(), base, offset);
5638 
5639   // static final int[] byteTable in class CRC32C
5640   Node* table = get_table_from_crc32c_class(callee()->holder());
5641   table = shenandoah_must_be_not_null(table, true);
5642   table = access_resolve_for_read(table);
5643   Node* table_start = array_element_address(table, intcon(0), T_INT);
5644 
5645   // Call the stub.
5646   address stubAddr = StubRoutines::updateBytesCRC32C();
5647   const char *stubName = "updateBytesCRC32C";
5648 
5649   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
5650                                  stubAddr, stubName, TypePtr::BOTTOM,
5651                                  crc, src_start, length, table_start);
5652   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5653   set_result(result);
5654   return true;
5655 }
5656 
5657 //------------------------------inline_updateBytesAdler32----------------------
5658 //
5659 // Calculate Adler32 checksum for byte[] array.
5660 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len)
5661 //
5662 bool LibraryCallKit::inline_updateBytesAdler32() {


5666   // no receiver since it is static method
5667   Node* crc     = argument(0); // type: int
5668   Node* src     = argument(1); // type: oop
5669   Node* offset  = argument(2); // type: int
5670   Node* length  = argument(3); // type: int
5671 
5672   const Type* src_type = src->Value(&_gvn);
5673   const TypeAryPtr* top_src = src_type->isa_aryptr();
5674   if (top_src  == NULL || top_src->klass()  == NULL) {
5675     // failed array check
5676     return false;
5677   }
5678 
5679   // Figure out the size and type of the elements we will be copying.
5680   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5681   if (src_elem != T_BYTE) {
5682     return false;
5683   }
5684 
5685   // 'src_start' points to src array + scaled offset
5686   src = access_resolve_for_read(src);
5687   Node* src_start = array_element_address(src, offset, src_elem);
5688 
5689   // We assume that range check is done by caller.
5690   // TODO: generate range check (offset+length < src.length) in debug VM.
5691 
5692   // Call the stub.
5693   address stubAddr = StubRoutines::updateBytesAdler32();
5694   const char *stubName = "updateBytesAdler32";
5695 
5696   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
5697                                  stubAddr, stubName, TypePtr::BOTTOM,
5698                                  crc, src_start, length);
5699   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
5700   set_result(result);
5701   return true;
5702 }
5703 
5704 //------------------------------inline_updateByteBufferAdler32---------------
5705 //
5706 // Calculate Adler32 checksum for DirectByteBuffer.


5779     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
5780     assert(tinst != NULL, "obj is null");
5781     assert(tinst->klass()->is_loaded(), "obj is not loaded");
5782     assert(!is_exact || tinst->klass_is_exact(), "klass not exact");
5783     fromKls = tinst->klass()->as_instance_klass();
5784   } else {
5785     assert(is_static, "only for static field access");
5786   }
5787   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
5788                                               ciSymbol::make(fieldTypeString),
5789                                               is_static);
5790 
5791   assert (field != NULL, "undefined field");
5792   if (field == NULL) return (Node *) NULL;
5793 
5794   if (is_static) {
5795     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
5796     fromObj = makecon(tip);
5797   }
5798 
5799 #if INCLUDE_SHENANDOAHGC
5800   if ((ShenandoahOptimizeStaticFinals   && field->is_static()  && field->is_final()) ||
5801       (ShenandoahOptimizeInstanceFinals && !field->is_static() && field->is_final()) ||
5802       (ShenandoahOptimizeStableFinals   && field->is_stable())) {
5803     // Skip the barrier for special fields
5804   } else {
5805     fromObj = access_resolve_for_read(fromObj);
5806   }
5807 #endif
5808 
5809   // Next code  copied from Parse::do_get_xxx():
5810 
5811   // Compute address and memory type.
5812   int offset  = field->offset_in_bytes();
5813   bool is_vol = field->is_volatile();
5814   ciType* field_klass = field->type();
5815   assert(field_klass->is_loaded(), "should be loaded");
5816   const TypePtr* adr_type = C->alias_type(field)->adr_type();
5817   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
5818   BasicType bt = field->layout_type();
5819 
5820   // Build the resultant type of the load
5821   const Type *type;
5822   if (bt == T_OBJECT) {
5823     type = TypeOopPtr::make_from_klass(field_klass->as_klass());
5824   } else {
5825     type = Type::get_const_basic_type(bt);
5826   }
5827 
5828   DecoratorSet decorators = IN_HEAP;


5877   switch(id) {
5878   case vmIntrinsics::_aescrypt_encryptBlock:
5879     stubAddr = StubRoutines::aescrypt_encryptBlock();
5880     stubName = "aescrypt_encryptBlock";
5881     break;
5882   case vmIntrinsics::_aescrypt_decryptBlock:
5883     stubAddr = StubRoutines::aescrypt_decryptBlock();
5884     stubName = "aescrypt_decryptBlock";
5885     break;
5886   default:
5887     break;
5888   }
5889   if (stubAddr == NULL) return false;
5890 
5891   Node* aescrypt_object = argument(0);
5892   Node* src             = argument(1);
5893   Node* src_offset      = argument(2);
5894   Node* dest            = argument(3);
5895   Node* dest_offset     = argument(4);
5896 
5897   // Resolve src and dest arrays for ShenandoahGC.
5898   src = shenandoah_must_be_not_null(src, true);
5899   src = access_resolve_for_read(src);
5900   dest = shenandoah_must_be_not_null(dest, true);
5901   dest = access_resolve_for_write(dest);
5902 
5903   // (1) src and dest are arrays.
5904   const Type* src_type = src->Value(&_gvn);
5905   const Type* dest_type = dest->Value(&_gvn);
5906   const TypeAryPtr* top_src = src_type->isa_aryptr();
5907   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
5908   assert (top_src  != NULL && top_src->klass()  != NULL &&  top_dest != NULL && top_dest->klass() != NULL, "args are strange");
5909 
5910   // for the quick and dirty code we will skip all the checks.
5911   // we are just trying to get the call to be generated.
5912   Node* src_start  = src;
5913   Node* dest_start = dest;
5914   if (src_offset != NULL || dest_offset != NULL) {
5915     assert(src_offset != NULL && dest_offset != NULL, "");
5916     src_start  = array_element_address(src,  src_offset,  T_BYTE);
5917     dest_start = array_element_address(dest, dest_offset, T_BYTE);
5918   }
5919 
5920   // now need to get the start of its expanded key array
5921   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
5922   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);


5953   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
5954     stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt();
5955     stubName = "cipherBlockChaining_encryptAESCrypt";
5956     break;
5957   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
5958     stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt();
5959     stubName = "cipherBlockChaining_decryptAESCrypt";
5960     break;
5961   default:
5962     break;
5963   }
5964   if (stubAddr == NULL) return false;
5965 
5966   Node* cipherBlockChaining_object = argument(0);
5967   Node* src                        = argument(1);
5968   Node* src_offset                 = argument(2);
5969   Node* len                        = argument(3);
5970   Node* dest                       = argument(4);
5971   Node* dest_offset                = argument(5);
5972 
5973 
5974   // inline_cipherBlockChaining_AESCrypt_predicate() has its own
5975   // barrier. This one should optimize away.
5976   src = shenandoah_must_be_not_null(src, false);
5977   dest = shenandoah_must_be_not_null(dest, false);
5978   src = access_resolve_for_read(src);
5979   dest = access_resolve_for_write(dest);
5980 
5981   // (1) src and dest are arrays.
5982   const Type* src_type = src->Value(&_gvn);
5983   const Type* dest_type = dest->Value(&_gvn);
5984   const TypeAryPtr* top_src = src_type->isa_aryptr();
5985   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
5986   assert (top_src  != NULL && top_src->klass()  != NULL
5987           &&  top_dest != NULL && top_dest->klass() != NULL, "args are strange");
5988 
5989   // checks are the responsibility of the caller
5990   Node* src_start  = src;
5991   Node* dest_start = dest;
5992   if (src_offset != NULL || dest_offset != NULL) {
5993     assert(src_offset != NULL && dest_offset != NULL, "");
5994     src_start  = array_element_address(src,  src_offset,  T_BYTE);
5995     dest_start = array_element_address(dest, dest_offset, T_BYTE);
5996   }
5997 
5998   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
5999   // (because of the predicated logic executed earlier).
6000   // so we cast it here safely.


6005 
6006   // cast it to what we know it will be at runtime
6007   const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
6008   assert(tinst != NULL, "CBC obj is null");
6009   assert(tinst->klass()->is_loaded(), "CBC obj is not loaded");
6010   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
6011   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
6012 
6013   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
6014   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
6015   const TypeOopPtr* xtype = aklass->as_instance_type();
6016   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
6017   aescrypt_object = _gvn.transform(aescrypt_object);
6018 
6019   // we need to get the start of the aescrypt_object's expanded key array
6020   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);
6021   if (k_start == NULL) return false;
6022 
6023   // similarly, get the start address of the r vector
6024   Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false);
6025 
6026   objRvec = access_resolve_for_write(objRvec);
6027 
6028   if (objRvec == NULL) return false;
6029   Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
6030 
6031   Node* cbcCrypt;
6032   if (Matcher::pass_original_key_for_aes()) {
6033     // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to
6034     // compatibility issues between Java key expansion and SPARC crypto instructions
6035     Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object);
6036     if (original_k_start == NULL) return false;
6037 
6038     // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start
6039     cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
6040                                  OptoRuntime::cipherBlockChaining_aescrypt_Type(),
6041                                  stubAddr, stubName, TypePtr::BOTTOM,
6042                                  src_start, dest_start, k_start, r_start, len, original_k_start);
6043   } else {
6044     // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
6045     cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
6046                                  OptoRuntime::cipherBlockChaining_aescrypt_Type(),
6047                                  stubAddr, stubName, TypePtr::BOTTOM,


6065     stubAddr = StubRoutines::counterMode_AESCrypt();
6066     stubName = "counterMode_AESCrypt";
6067   }
6068   if (stubAddr == NULL) return false;
6069 
6070   Node* counterMode_object = argument(0);
6071   Node* src = argument(1);
6072   Node* src_offset = argument(2);
6073   Node* len = argument(3);
6074   Node* dest = argument(4);
6075   Node* dest_offset = argument(5);
6076 
6077   // (1) src and dest are arrays.
6078   const Type* src_type = src->Value(&_gvn);
6079   const Type* dest_type = dest->Value(&_gvn);
6080   const TypeAryPtr* top_src = src_type->isa_aryptr();
6081   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
6082   assert(top_src != NULL && top_src->klass() != NULL &&
6083          top_dest != NULL && top_dest->klass() != NULL, "args are strange");
6084 
6085   src = access_resolve_for_read(src);
6086   dest = access_resolve_for_write(dest);
6087   counterMode_object = access_resolve_for_write(counterMode_object);
6088 
6089   // checks are the responsibility of the caller
6090   Node* src_start = src;
6091   Node* dest_start = dest;
6092   if (src_offset != NULL || dest_offset != NULL) {
6093     assert(src_offset != NULL && dest_offset != NULL, "");
6094     src_start = array_element_address(src, src_offset, T_BYTE);
6095     dest_start = array_element_address(dest, dest_offset, T_BYTE);
6096   }
6097 
6098   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
6099   // (because of the predicated logic executed earlier).
6100   // so we cast it here safely.
6101   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
6102   Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
6103   if (embeddedCipherObj == NULL) return false;
6104   // cast it to what we know it will be at runtime
6105   const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
6106   assert(tinst != NULL, "CTR obj is null");
6107   assert(tinst->klass()->is_loaded(), "CTR obj is not loaded");
6108   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
6109   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
6110   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
6111   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
6112   const TypeOopPtr* xtype = aklass->as_instance_type();
6113   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
6114   aescrypt_object = _gvn.transform(aescrypt_object);
6115   // we need to get the start of the aescrypt_object's expanded key array
6116   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object);
6117   if (k_start == NULL) return false;
6118   // similarly, get the start address of the r vector
6119   Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B", /*is_exact*/ false);
6120   if (obj_counter == NULL) return false;
6121   obj_counter = access_resolve_for_write(obj_counter);
6122   Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
6123 
6124   Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B", /*is_exact*/ false);
6125   if (saved_encCounter == NULL) return false;
6126   saved_encCounter = access_resolve_for_write(saved_encCounter);
6127   Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
6128   Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
6129 
6130   Node* ctrCrypt;
6131   if (Matcher::pass_original_key_for_aes()) {
6132     // no SPARC version for AES/CTR intrinsics now.
6133     return false;
6134   }
6135   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
6136   ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
6137                                OptoRuntime::counterMode_aescrypt_Type(),
6138                                stubAddr, stubName, TypePtr::BOTTOM,
6139                                src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
6140 
6141   // return cipher length (int)
6142   Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms));
6143   set_result(retvalue);
6144   return true;
6145 }
6146 
6147 //------------------------------get_key_start_from_aescrypt_object-----------------------
6148 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) {
6149 #if defined(PPC64) || defined(S390)
6150   // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys.
6151   // Intel's extention is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns.
6152   // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption.
6153   // The ppc64 stubs of encryption and decryption use the same round keys (sessionK[0]).
6154   Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I", /*is_exact*/ false);
6155   assert (objSessionK != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
6156   if (objSessionK == NULL) {
6157     return (Node *) NULL;
6158   }
6159   Node* objAESCryptKey = load_array_element(control(), objSessionK, intcon(0), TypeAryPtr::OOPS);
6160 #else
6161   Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false);
6162 #endif // PPC64
6163   assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
6164   if (objAESCryptKey == NULL) return (Node *) NULL;
6165 
6166   objAESCryptKey = access_resolve_for_read(objAESCryptKey);
6167 
6168   // now have the array, need to get the start address of the K array
6169   Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT);
6170   return k_start;
6171 }
6172 
6173 //------------------------------get_original_key_start_from_aescrypt_object-----------------------
6174 Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) {
6175   Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false);
6176   assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt");
6177   if (objAESCryptKey == NULL) return (Node *) NULL;
6178 
6179   objAESCryptKey = access_resolve_for_read(objAESCryptKey);
6180 
6181   // now have the array, need to get the start address of the lastKey array
6182   Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE);
6183   return original_k_start;
6184 }
6185 
6186 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate----------------------------
6187 // Return node representing slow path of predicate check.
6188 // the pseudo code we want to emulate with this predicate is:
6189 // for encryption:
6190 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
6191 // for decryption:
6192 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
6193 //    note cipher==plain is more conservative than the original java code but that's OK
6194 //
6195 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) {
6196   // The receiver was checked for NULL already.
6197   Node* objCBC = argument(0);
6198 
6199   Node* src = argument(1);
6200   Node* dest = argument(4);
6201 
6202   // Load embeddedCipher field of CipherBlockChaining object.
6203   Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
6204 
6205   // get AESCrypt klass for instanceOf check
6206   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
6207   // will have same classloader as CipherBlockChaining object
6208   const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr();
6209   assert(tinst != NULL, "CBCobj is null");
6210   assert(tinst->klass()->is_loaded(), "CBCobj is not loaded");
6211 
6212   // we want to do an instanceof comparison against the AESCrypt class
6213   ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
6214   if (!klass_AESCrypt->is_loaded()) {
6215     // if AESCrypt is not even loaded, we never take the intrinsic fast path
6216     Node* ctrl = control();
6217     set_control(top()); // no regular fast path
6218     return ctrl;
6219   }
6220 
6221   // Resolve src and dest arrays for ShenandoahGC.  Here because new
6222   // memory state is not handled by predicate logic in
6223   // inline_cipherBlockChaining_AESCrypt itself
6224   src = shenandoah_must_be_not_null(src, true);
6225   dest = shenandoah_must_be_not_null(dest, true);
6226   src = access_resolve_for_write(src);
6227   dest = access_resolve_for_write(dest);
6228 
6229   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
6230 
6231   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
6232   Node* cmp_instof  = _gvn.transform(new CmpINode(instof, intcon(1)));
6233   Node* bool_instof  = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
6234 
6235   Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6236 
6237   // for encryption, we are done
6238   if (!decrypting)
6239     return instof_false;  // even if it is NULL
6240 
6241   // for decryption, we need to add a further check to avoid
6242   // taking the intrinsic path when cipher and plain are the same
6243   // see the original java code for why.
6244   RegionNode* region = new RegionNode(3);
6245   region->init_req(1, instof_false);
6246 

6247   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
6248   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
6249   Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN);
6250   region->init_req(2, src_dest_conjoint);
6251 
6252   record_for_igvn(region);
6253   return _gvn.transform(region);
6254 }
6255 
6256 //----------------------------inline_counterMode_AESCrypt_predicate----------------------------
6257 // Return node representing slow path of predicate check.
6258 // the pseudo code we want to emulate with this predicate is:
6259 // for encryption:
6260 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
6261 // for decryption:
6262 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
6263 //    note cipher==plain is more conservative than the original java code but that's OK
6264 //
6265 
6266 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() {


6293   Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6294 
6295   return instof_false; // even if it is NULL
6296 }
6297 
6298 //------------------------------inline_ghash_processBlocks
6299 bool LibraryCallKit::inline_ghash_processBlocks() {
6300   address stubAddr;
6301   const char *stubName;
6302   assert(UseGHASHIntrinsics, "need GHASH intrinsics support");
6303 
6304   stubAddr = StubRoutines::ghash_processBlocks();
6305   stubName = "ghash_processBlocks";
6306 
6307   Node* data           = argument(0);
6308   Node* offset         = argument(1);
6309   Node* len            = argument(2);
6310   Node* state          = argument(3);
6311   Node* subkeyH        = argument(4);
6312 
6313   state = shenandoah_must_be_not_null(state, true);
6314   subkeyH = shenandoah_must_be_not_null(subkeyH, true);
6315   data = shenandoah_must_be_not_null(data, true);
6316 
6317   state = access_resolve_for_write(state);
6318   subkeyH = access_resolve_for_read(subkeyH);
6319   data = access_resolve_for_read(data);
6320 
6321   Node* state_start  = array_element_address(state, intcon(0), T_LONG);
6322   assert(state_start, "state is NULL");
6323   Node* subkeyH_start  = array_element_address(subkeyH, intcon(0), T_LONG);
6324   assert(subkeyH_start, "subkeyH is NULL");
6325   Node* data_start  = array_element_address(data, offset, T_BYTE);
6326   assert(data_start, "data is NULL");
6327 
6328   Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP,
6329                                   OptoRuntime::ghash_processBlocks_Type(),
6330                                   stubAddr, stubName, TypePtr::BOTTOM,
6331                                   state_start, subkeyH_start, data_start, len);
6332   return true;
6333 }
6334 
6335 bool LibraryCallKit::inline_base64_encodeBlock() {
6336   address stubAddr;
6337   const char *stubName;
6338   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
6339   assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters");
6340   stubAddr = StubRoutines::base64_encodeBlock();
6341   stubName = "encodeBlock";
6342 
6343   if (!stubAddr) return false;
6344   Node* base64obj = argument(0);
6345   Node* src = argument(1);
6346   Node* offset = argument(2);
6347   Node* len = argument(3);
6348   Node* dest = argument(4);
6349   Node* dp = argument(5);
6350   Node* isURL = argument(6);
6351 
6352   src = must_be_not_null(src, true);
6353   src = access_resolve_for_read(src);
6354   dest = must_be_not_null(dest, true);
6355   dest = access_resolve_for_write(dest);
6356 
6357   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
6358   assert(src_start, "source array is NULL");
6359   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
6360   assert(dest_start, "destination array is NULL");
6361 
6362   Node* base64 = make_runtime_call(RC_LEAF,
6363                                    OptoRuntime::base64_encodeBlock_Type(),
6364                                    stubAddr, stubName, TypePtr::BOTTOM,
6365                                    src_start, offset, len, dest_start, dp, isURL);
6366   return true;
6367 }
6368 
6369 //------------------------------inline_sha_implCompress-----------------------
6370 //
6371 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
6372 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
6373 //
6374 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
6375 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
6376 //


6379 //
6380 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) {
6381   assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
6382 
6383   Node* sha_obj = argument(0);
6384   Node* src     = argument(1); // type oop
6385   Node* ofs     = argument(2); // type int
6386 
6387   const Type* src_type = src->Value(&_gvn);
6388   const TypeAryPtr* top_src = src_type->isa_aryptr();
6389   if (top_src  == NULL || top_src->klass()  == NULL) {
6390     // failed array check
6391     return false;
6392   }
6393   // Figure out the size and type of the elements we will be copying.
6394   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6395   if (src_elem != T_BYTE) {
6396     return false;
6397   }
6398   // 'src_start' points to src array + offset
6399   src = shenandoah_must_be_not_null(src, true);
6400   src = access_resolve_for_read(src);
6401   Node* src_start = array_element_address(src, ofs, src_elem);
6402   Node* state = NULL;
6403   address stubAddr;
6404   const char *stubName;
6405 
6406   switch(id) {
6407   case vmIntrinsics::_sha_implCompress:
6408     assert(UseSHA1Intrinsics, "need SHA1 instruction support");
6409     state = get_state_from_sha_object(sha_obj);
6410     stubAddr = StubRoutines::sha1_implCompress();
6411     stubName = "sha1_implCompress";
6412     break;
6413   case vmIntrinsics::_sha2_implCompress:
6414     assert(UseSHA256Intrinsics, "need SHA256 instruction support");
6415     state = get_state_from_sha_object(sha_obj);
6416     stubAddr = StubRoutines::sha256_implCompress();
6417     stubName = "sha256_implCompress";
6418     break;
6419   case vmIntrinsics::_sha5_implCompress:
6420     assert(UseSHA512Intrinsics, "need SHA512 instruction support");


6450   assert((uint)predicate < 3, "sanity");
6451   assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
6452 
6453   Node* digestBase_obj = argument(0); // The receiver was checked for NULL already.
6454   Node* src            = argument(1); // byte[] array
6455   Node* ofs            = argument(2); // type int
6456   Node* limit          = argument(3); // type int
6457 
6458   const Type* src_type = src->Value(&_gvn);
6459   const TypeAryPtr* top_src = src_type->isa_aryptr();
6460   if (top_src  == NULL || top_src->klass()  == NULL) {
6461     // failed array check
6462     return false;
6463   }
6464   // Figure out the size and type of the elements we will be copying.
6465   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6466   if (src_elem != T_BYTE) {
6467     return false;
6468   }
6469   // 'src_start' points to src array + offset
6470   src = shenandoah_must_be_not_null(src, false);
6471   src = access_resolve_for_read(src);
6472   Node* src_start = array_element_address(src, ofs, src_elem);
6473 
6474   const char* klass_SHA_name = NULL;
6475   const char* stub_name = NULL;
6476   address     stub_addr = NULL;
6477   bool        long_state = false;
6478 
6479   switch (predicate) {
6480   case 0:
6481     if (UseSHA1Intrinsics) {
6482       klass_SHA_name = "sun/security/provider/SHA";
6483       stub_name = "sha1_implCompressMB";
6484       stub_addr = StubRoutines::sha1_implCompressMB();
6485     }
6486     break;
6487   case 1:
6488     if (UseSHA256Intrinsics) {
6489       klass_SHA_name = "sun/security/provider/SHA2";
6490       stub_name = "sha256_implCompressMB";
6491       stub_addr = StubRoutines::sha256_implCompressMB();


6536   if (state == NULL) return false;
6537 
6538   // Call the stub.
6539   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
6540                                  OptoRuntime::digestBase_implCompressMB_Type(),
6541                                  stubAddr, stubName, TypePtr::BOTTOM,
6542                                  src_start, state, ofs, limit);
6543   // return ofs (int)
6544   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
6545   set_result(result);
6546 
6547   return true;
6548 }
6549 
6550 //------------------------------get_state_from_sha_object-----------------------
6551 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) {
6552   Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false);
6553   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2");
6554   if (sha_state == NULL) return (Node *) NULL;
6555 
6556   sha_state = access_resolve_for_write(sha_state);
6557 
6558   // now have the array, need to get the start address of the state array
6559   Node* state = array_element_address(sha_state, intcon(0), T_INT);
6560   return state;
6561 }
6562 
6563 //------------------------------get_state_from_sha5_object-----------------------
6564 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) {
6565   Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false);
6566   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5");
6567   if (sha_state == NULL) return (Node *) NULL;
6568 
6569   sha_state = access_resolve_for_write(sha_state);
6570 
6571   // now have the array, need to get the start address of the state array
6572   Node* state = array_element_address(sha_state, intcon(0), T_LONG);
6573   return state;
6574 }
6575 
6576 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
6577 // Return node representing slow path of predicate check.
6578 // the pseudo code we want to emulate with this predicate is:
6579 //    if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath
6580 //
6581 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
6582   assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6583          "need SHA1/SHA256/SHA512 instruction support");
6584   assert((uint)predicate < 3, "sanity");
6585 
6586   // The receiver was checked for NULL already.
6587   Node* digestBaseObj = argument(0);
6588 
6589   // get DigestBase klass for instanceOf check


< prev index next >