1 /*
    2  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
    3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4  *
    5  * This code is free software; you can redistribute it and/or modify it
    6  * under the terms of the GNU General Public License version 2 only, as
    7  * published by the Free Software Foundation.
    8  *
    9  * This code is distributed in the hope that it will be useful, but WITHOUT
   10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12  * version 2 for more details (a copy is included in the LICENSE file that
   13  * accompanied this code).
   14  *
   15  * You should have received a copy of the GNU General Public License version
   16  * 2 along with this work; if not, write to the Free Software Foundation,
   17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18  *
   19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20  * or visit www.oracle.com if you need additional information or have any
   21  * questions.
   22  *
   23  */
   24 
   25 #include "asm/macroAssembler.hpp"
   26 #include "ci/ciArrayKlass.hpp"
   27 #include "ci/ciFlatArrayKlass.hpp"
   28 #include "ci/ciInstanceKlass.hpp"
   29 #include "ci/ciSymbols.hpp"
   30 #include "ci/ciUtilities.inline.hpp"
   31 #include "classfile/vmIntrinsics.hpp"
   32 #include "compiler/compileBroker.hpp"
   33 #include "compiler/compileLog.hpp"
   34 #include "gc/shared/barrierSet.hpp"
   35 #include "gc/shared/c2/barrierSetC2.hpp"
   36 #include "jfr/support/jfrIntrinsics.hpp"
   37 #include "memory/resourceArea.hpp"
   38 #include "oops/accessDecorators.hpp"
   39 #include "oops/klass.inline.hpp"
   40 #include "oops/layoutKind.hpp"
   41 #include "oops/objArrayKlass.hpp"
   42 #include "opto/addnode.hpp"
   43 #include "opto/arraycopynode.hpp"
   44 #include "opto/c2compiler.hpp"
   45 #include "opto/castnode.hpp"
   46 #include "opto/cfgnode.hpp"
   47 #include "opto/convertnode.hpp"
   48 #include "opto/countbitsnode.hpp"
   49 #include "opto/graphKit.hpp"
   50 #include "opto/idealKit.hpp"
   51 #include "opto/inlinetypenode.hpp"
   52 #include "opto/library_call.hpp"
   53 #include "opto/mathexactnode.hpp"
   54 #include "opto/mulnode.hpp"
   55 #include "opto/narrowptrnode.hpp"
   56 #include "opto/opaquenode.hpp"
   57 #include "opto/opcodes.hpp"
   58 #include "opto/parse.hpp"
   59 #include "opto/rootnode.hpp"
   60 #include "opto/runtime.hpp"
   61 #include "opto/subnode.hpp"
   62 #include "opto/type.hpp"
   63 #include "opto/vectornode.hpp"
   64 #include "prims/jvmtiExport.hpp"
   65 #include "prims/jvmtiThreadState.hpp"
   66 #include "prims/unsafe.hpp"
   67 #include "runtime/globals.hpp"
   68 #include "runtime/jniHandles.inline.hpp"
   69 #include "runtime/mountUnmountDisabler.hpp"
   70 #include "runtime/objectMonitor.hpp"
   71 #include "runtime/sharedRuntime.hpp"
   72 #include "runtime/stubRoutines.hpp"
   73 #include "utilities/globalDefinitions.hpp"
   74 #include "utilities/macros.hpp"
   75 #include "utilities/powerOfTwo.hpp"
   76 
   77 //---------------------------make_vm_intrinsic----------------------------
   78 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
   79   vmIntrinsicID id = m->intrinsic_id();
   80   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
   81 
   82   if (!m->is_loaded()) {
   83     // Do not attempt to inline unloaded methods.
   84     return nullptr;
   85   }
   86 
   87   C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
   88   bool is_available = false;
   89 
   90   {
   91     // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
   92     // the compiler must transition to '_thread_in_vm' state because both
   93     // methods access VM-internal data.
   94     VM_ENTRY_MARK;
   95     methodHandle mh(THREAD, m->get_Method());
   96     is_available = compiler != nullptr && compiler->is_intrinsic_available(mh, C->directive());
   97     if (is_available && is_virtual) {
   98       is_available = vmIntrinsics::does_virtual_dispatch(id);
   99     }
  100   }
  101 
  102   if (is_available) {
  103     assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
  104     assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
  105     return new LibraryIntrinsic(m, is_virtual,
  106                                 vmIntrinsics::predicates_needed(id),
  107                                 vmIntrinsics::does_virtual_dispatch(id),
  108                                 id);
  109   } else {
  110     return nullptr;
  111   }
  112 }
  113 
  114 JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
  115   LibraryCallKit kit(jvms, this);
  116   Compile* C = kit.C;
  117   int nodes = C->unique();
  118 #ifndef PRODUCT
  119   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
  120     char buf[1000];
  121     const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
  122     tty->print_cr("Intrinsic %s", str);
  123   }
  124 #endif
  125   ciMethod* callee = kit.callee();
  126   const int bci    = kit.bci();
  127 #ifdef ASSERT
  128   Node* ctrl = kit.control();
  129 #endif
  130   // Try to inline the intrinsic.
  131   if (callee->check_intrinsic_candidate() &&
  132       kit.try_to_inline(_last_predicate)) {
  133     const char *inline_msg = is_virtual() ? "(intrinsic, virtual)"
  134                                           : "(intrinsic)";
  135     CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::SUCCESS, inline_msg);
  136     C->inline_printer()->record(callee, jvms, InliningResult::SUCCESS, inline_msg);
  137     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
  138     if (C->log()) {
  139       C->log()->elem("intrinsic id='%s'%s nodes='%d'",
  140                      vmIntrinsics::name_at(intrinsic_id()),
  141                      (is_virtual() ? " virtual='1'" : ""),
  142                      C->unique() - nodes);
  143     }
  144     // Push the result from the inlined method onto the stack.
  145     kit.push_result();
  146     return kit.transfer_exceptions_into_jvms();
  147   }
  148 
  149   // The intrinsic bailed out
  150   assert(ctrl == kit.control(), "Control flow was added although the intrinsic bailed out");
  151   assert(jvms->map() == kit.map(), "Out of sync JVM state");
  152   if (jvms->has_method()) {
  153     // Not a root compile.
  154     const char* msg;
  155     if (callee->intrinsic_candidate()) {
  156       msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
  157     } else {
  158       msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
  159                          : "failed to inline (intrinsic), method not annotated";
  160     }
  161     CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::FAILURE, msg);
  162     C->inline_printer()->record(callee, jvms, InliningResult::FAILURE, msg);
  163   } else {
  164     // Root compile
  165     ResourceMark rm;
  166     stringStream msg_stream;
  167     msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
  168                      vmIntrinsics::name_at(intrinsic_id()),
  169                      is_virtual() ? " (virtual)" : "", bci);
  170     const char *msg = msg_stream.freeze();
  171     log_debug(jit, inlining)("%s", msg);
  172     if (C->print_intrinsics() || C->print_inlining()) {
  173       tty->print("%s", msg);
  174     }
  175   }
  176   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
  177 
  178   return nullptr;
  179 }
  180 
  181 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) {
  182   LibraryCallKit kit(jvms, this);
  183   Compile* C = kit.C;
  184   int nodes = C->unique();
  185   _last_predicate = predicate;
  186 #ifndef PRODUCT
  187   assert(is_predicated() && predicate < predicates_count(), "sanity");
  188   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
  189     char buf[1000];
  190     const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
  191     tty->print_cr("Predicate for intrinsic %s", str);
  192   }
  193 #endif
  194   ciMethod* callee = kit.callee();
  195   const int bci    = kit.bci();
  196 
  197   Node* slow_ctl = kit.try_to_predicate(predicate);
  198   if (!kit.failing()) {
  199     const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)"
  200                                           : "(intrinsic, predicate)";
  201     CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::SUCCESS, inline_msg);
  202     C->inline_printer()->record(callee, jvms, InliningResult::SUCCESS, inline_msg);
  203 
  204     C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
  205     if (C->log()) {
  206       C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'",
  207                      vmIntrinsics::name_at(intrinsic_id()),
  208                      (is_virtual() ? " virtual='1'" : ""),
  209                      C->unique() - nodes);
  210     }
  211     return slow_ctl; // Could be null if the check folds.
  212   }
  213 
  214   // The intrinsic bailed out
  215   if (jvms->has_method()) {
  216     // Not a root compile.
  217     const char* msg = "failed to generate predicate for intrinsic";
  218     CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, InliningResult::FAILURE, msg);
  219     C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg);
  220   } else {
  221     // Root compile
  222     ResourceMark rm;
  223     stringStream msg_stream;
  224     msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
  225                      vmIntrinsics::name_at(intrinsic_id()),
  226                      is_virtual() ? " (virtual)" : "", bci);
  227     const char *msg = msg_stream.freeze();
  228     log_debug(jit, inlining)("%s", msg);
  229     C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg);
  230   }
  231   C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
  232   return nullptr;
  233 }
  234 
  235 bool LibraryCallKit::try_to_inline(int predicate) {
  236   // Handle symbolic names for otherwise undistinguished boolean switches:
  237   const bool is_store       = true;
  238   const bool is_compress    = true;
  239   const bool is_static      = true;
  240   const bool is_volatile    = true;
  241 
  242   if (!jvms()->has_method()) {
  243     // Root JVMState has a null method.
  244     assert(map()->memory()->Opcode() == Op_Parm, "");
  245     // Insert the memory aliasing node
  246     set_all_memory(reset_memory());
  247   }
  248   assert(merged_memory(), "");
  249 
  250   switch (intrinsic_id()) {
  251   case vmIntrinsics::_hashCode:                 return inline_native_hashcode(intrinsic()->is_virtual(), !is_static);
  252   case vmIntrinsics::_identityHashCode:         return inline_native_hashcode(/*!virtual*/ false,         is_static);
  253   case vmIntrinsics::_getClass:                 return inline_native_getClass();
  254 
  255   case vmIntrinsics::_ceil:
  256   case vmIntrinsics::_floor:
  257   case vmIntrinsics::_rint:
  258   case vmIntrinsics::_dsin:
  259   case vmIntrinsics::_dcos:
  260   case vmIntrinsics::_dtan:
  261   case vmIntrinsics::_dsinh:
  262   case vmIntrinsics::_dtanh:
  263   case vmIntrinsics::_dcbrt:
  264   case vmIntrinsics::_dabs:
  265   case vmIntrinsics::_fabs:
  266   case vmIntrinsics::_iabs:
  267   case vmIntrinsics::_labs:
  268   case vmIntrinsics::_datan2:
  269   case vmIntrinsics::_dsqrt:
  270   case vmIntrinsics::_dsqrt_strict:
  271   case vmIntrinsics::_dexp:
  272   case vmIntrinsics::_dlog:
  273   case vmIntrinsics::_dlog10:
  274   case vmIntrinsics::_dpow:
  275   case vmIntrinsics::_dcopySign:
  276   case vmIntrinsics::_fcopySign:
  277   case vmIntrinsics::_dsignum:
  278   case vmIntrinsics::_roundF:
  279   case vmIntrinsics::_roundD:
  280   case vmIntrinsics::_fsignum:                  return inline_math_native(intrinsic_id());
  281 
  282   case vmIntrinsics::_notify:
  283   case vmIntrinsics::_notifyAll:
  284     return inline_notify(intrinsic_id());
  285 
  286   case vmIntrinsics::_addExactI:                return inline_math_addExactI(false /* add */);
  287   case vmIntrinsics::_addExactL:                return inline_math_addExactL(false /* add */);
  288   case vmIntrinsics::_decrementExactI:          return inline_math_subtractExactI(true /* decrement */);
  289   case vmIntrinsics::_decrementExactL:          return inline_math_subtractExactL(true /* decrement */);
  290   case vmIntrinsics::_incrementExactI:          return inline_math_addExactI(true /* increment */);
  291   case vmIntrinsics::_incrementExactL:          return inline_math_addExactL(true /* increment */);
  292   case vmIntrinsics::_multiplyExactI:           return inline_math_multiplyExactI();
  293   case vmIntrinsics::_multiplyExactL:           return inline_math_multiplyExactL();
  294   case vmIntrinsics::_multiplyHigh:             return inline_math_multiplyHigh();
  295   case vmIntrinsics::_unsignedMultiplyHigh:     return inline_math_unsignedMultiplyHigh();
  296   case vmIntrinsics::_negateExactI:             return inline_math_negateExactI();
  297   case vmIntrinsics::_negateExactL:             return inline_math_negateExactL();
  298   case vmIntrinsics::_subtractExactI:           return inline_math_subtractExactI(false /* subtract */);
  299   case vmIntrinsics::_subtractExactL:           return inline_math_subtractExactL(false /* subtract */);
  300 
  301   case vmIntrinsics::_arraycopy:                return inline_arraycopy();
  302 
  303   case vmIntrinsics::_arraySort:                return inline_array_sort();
  304   case vmIntrinsics::_arrayPartition:           return inline_array_partition();
  305 
  306   case vmIntrinsics::_compareToL:               return inline_string_compareTo(StrIntrinsicNode::LL);
  307   case vmIntrinsics::_compareToU:               return inline_string_compareTo(StrIntrinsicNode::UU);
  308   case vmIntrinsics::_compareToLU:              return inline_string_compareTo(StrIntrinsicNode::LU);
  309   case vmIntrinsics::_compareToUL:              return inline_string_compareTo(StrIntrinsicNode::UL);
  310 
  311   case vmIntrinsics::_indexOfL:                 return inline_string_indexOf(StrIntrinsicNode::LL);
  312   case vmIntrinsics::_indexOfU:                 return inline_string_indexOf(StrIntrinsicNode::UU);
  313   case vmIntrinsics::_indexOfUL:                return inline_string_indexOf(StrIntrinsicNode::UL);
  314   case vmIntrinsics::_indexOfIL:                return inline_string_indexOfI(StrIntrinsicNode::LL);
  315   case vmIntrinsics::_indexOfIU:                return inline_string_indexOfI(StrIntrinsicNode::UU);
  316   case vmIntrinsics::_indexOfIUL:               return inline_string_indexOfI(StrIntrinsicNode::UL);
  317   case vmIntrinsics::_indexOfU_char:            return inline_string_indexOfChar(StrIntrinsicNode::U);
  318   case vmIntrinsics::_indexOfL_char:            return inline_string_indexOfChar(StrIntrinsicNode::L);
  319 
  320   case vmIntrinsics::_equalsL:                  return inline_string_equals(StrIntrinsicNode::LL);
  321 
  322   case vmIntrinsics::_vectorizedHashCode:       return inline_vectorizedHashCode();
  323 
  324   case vmIntrinsics::_toBytesStringU:           return inline_string_toBytesU();
  325   case vmIntrinsics::_getCharsStringU:          return inline_string_getCharsU();
  326   case vmIntrinsics::_getCharStringU:           return inline_string_char_access(!is_store);
  327   case vmIntrinsics::_putCharStringU:           return inline_string_char_access( is_store);
  328 
  329   case vmIntrinsics::_compressStringC:
  330   case vmIntrinsics::_compressStringB:          return inline_string_copy( is_compress);
  331   case vmIntrinsics::_inflateStringC:
  332   case vmIntrinsics::_inflateStringB:           return inline_string_copy(!is_compress);
  333 
  334   case vmIntrinsics::_getReference:             return inline_unsafe_access(!is_store, T_OBJECT,   Relaxed, false);
  335   case vmIntrinsics::_getBoolean:               return inline_unsafe_access(!is_store, T_BOOLEAN,  Relaxed, false);
  336   case vmIntrinsics::_getByte:                  return inline_unsafe_access(!is_store, T_BYTE,     Relaxed, false);
  337   case vmIntrinsics::_getShort:                 return inline_unsafe_access(!is_store, T_SHORT,    Relaxed, false);
  338   case vmIntrinsics::_getChar:                  return inline_unsafe_access(!is_store, T_CHAR,     Relaxed, false);
  339   case vmIntrinsics::_getInt:                   return inline_unsafe_access(!is_store, T_INT,      Relaxed, false);
  340   case vmIntrinsics::_getLong:                  return inline_unsafe_access(!is_store, T_LONG,     Relaxed, false);
  341   case vmIntrinsics::_getFloat:                 return inline_unsafe_access(!is_store, T_FLOAT,    Relaxed, false);
  342   case vmIntrinsics::_getDouble:                return inline_unsafe_access(!is_store, T_DOUBLE,   Relaxed, false);
  343 
  344   case vmIntrinsics::_putReference:             return inline_unsafe_access( is_store, T_OBJECT,   Relaxed, false);
  345   case vmIntrinsics::_putBoolean:               return inline_unsafe_access( is_store, T_BOOLEAN,  Relaxed, false);
  346   case vmIntrinsics::_putByte:                  return inline_unsafe_access( is_store, T_BYTE,     Relaxed, false);
  347   case vmIntrinsics::_putShort:                 return inline_unsafe_access( is_store, T_SHORT,    Relaxed, false);
  348   case vmIntrinsics::_putChar:                  return inline_unsafe_access( is_store, T_CHAR,     Relaxed, false);
  349   case vmIntrinsics::_putInt:                   return inline_unsafe_access( is_store, T_INT,      Relaxed, false);
  350   case vmIntrinsics::_putLong:                  return inline_unsafe_access( is_store, T_LONG,     Relaxed, false);
  351   case vmIntrinsics::_putFloat:                 return inline_unsafe_access( is_store, T_FLOAT,    Relaxed, false);
  352   case vmIntrinsics::_putDouble:                return inline_unsafe_access( is_store, T_DOUBLE,   Relaxed, false);
  353 
  354   case vmIntrinsics::_getReferenceVolatile:     return inline_unsafe_access(!is_store, T_OBJECT,   Volatile, false);
  355   case vmIntrinsics::_getBooleanVolatile:       return inline_unsafe_access(!is_store, T_BOOLEAN,  Volatile, false);
  356   case vmIntrinsics::_getByteVolatile:          return inline_unsafe_access(!is_store, T_BYTE,     Volatile, false);
  357   case vmIntrinsics::_getShortVolatile:         return inline_unsafe_access(!is_store, T_SHORT,    Volatile, false);
  358   case vmIntrinsics::_getCharVolatile:          return inline_unsafe_access(!is_store, T_CHAR,     Volatile, false);
  359   case vmIntrinsics::_getIntVolatile:           return inline_unsafe_access(!is_store, T_INT,      Volatile, false);
  360   case vmIntrinsics::_getLongVolatile:          return inline_unsafe_access(!is_store, T_LONG,     Volatile, false);
  361   case vmIntrinsics::_getFloatVolatile:         return inline_unsafe_access(!is_store, T_FLOAT,    Volatile, false);
  362   case vmIntrinsics::_getDoubleVolatile:        return inline_unsafe_access(!is_store, T_DOUBLE,   Volatile, false);
  363 
  364   case vmIntrinsics::_putReferenceVolatile:     return inline_unsafe_access( is_store, T_OBJECT,   Volatile, false);
  365   case vmIntrinsics::_putBooleanVolatile:       return inline_unsafe_access( is_store, T_BOOLEAN,  Volatile, false);
  366   case vmIntrinsics::_putByteVolatile:          return inline_unsafe_access( is_store, T_BYTE,     Volatile, false);
  367   case vmIntrinsics::_putShortVolatile:         return inline_unsafe_access( is_store, T_SHORT,    Volatile, false);
  368   case vmIntrinsics::_putCharVolatile:          return inline_unsafe_access( is_store, T_CHAR,     Volatile, false);
  369   case vmIntrinsics::_putIntVolatile:           return inline_unsafe_access( is_store, T_INT,      Volatile, false);
  370   case vmIntrinsics::_putLongVolatile:          return inline_unsafe_access( is_store, T_LONG,     Volatile, false);
  371   case vmIntrinsics::_putFloatVolatile:         return inline_unsafe_access( is_store, T_FLOAT,    Volatile, false);
  372   case vmIntrinsics::_putDoubleVolatile:        return inline_unsafe_access( is_store, T_DOUBLE,   Volatile, false);
  373 
  374   case vmIntrinsics::_getShortUnaligned:        return inline_unsafe_access(!is_store, T_SHORT,    Relaxed, true);
  375   case vmIntrinsics::_getCharUnaligned:         return inline_unsafe_access(!is_store, T_CHAR,     Relaxed, true);
  376   case vmIntrinsics::_getIntUnaligned:          return inline_unsafe_access(!is_store, T_INT,      Relaxed, true);
  377   case vmIntrinsics::_getLongUnaligned:         return inline_unsafe_access(!is_store, T_LONG,     Relaxed, true);
  378 
  379   case vmIntrinsics::_putShortUnaligned:        return inline_unsafe_access( is_store, T_SHORT,    Relaxed, true);
  380   case vmIntrinsics::_putCharUnaligned:         return inline_unsafe_access( is_store, T_CHAR,     Relaxed, true);
  381   case vmIntrinsics::_putIntUnaligned:          return inline_unsafe_access( is_store, T_INT,      Relaxed, true);
  382   case vmIntrinsics::_putLongUnaligned:         return inline_unsafe_access( is_store, T_LONG,     Relaxed, true);
  383 
  384   case vmIntrinsics::_getReferenceAcquire:      return inline_unsafe_access(!is_store, T_OBJECT,   Acquire, false);
  385   case vmIntrinsics::_getBooleanAcquire:        return inline_unsafe_access(!is_store, T_BOOLEAN,  Acquire, false);
  386   case vmIntrinsics::_getByteAcquire:           return inline_unsafe_access(!is_store, T_BYTE,     Acquire, false);
  387   case vmIntrinsics::_getShortAcquire:          return inline_unsafe_access(!is_store, T_SHORT,    Acquire, false);
  388   case vmIntrinsics::_getCharAcquire:           return inline_unsafe_access(!is_store, T_CHAR,     Acquire, false);
  389   case vmIntrinsics::_getIntAcquire:            return inline_unsafe_access(!is_store, T_INT,      Acquire, false);
  390   case vmIntrinsics::_getLongAcquire:           return inline_unsafe_access(!is_store, T_LONG,     Acquire, false);
  391   case vmIntrinsics::_getFloatAcquire:          return inline_unsafe_access(!is_store, T_FLOAT,    Acquire, false);
  392   case vmIntrinsics::_getDoubleAcquire:         return inline_unsafe_access(!is_store, T_DOUBLE,   Acquire, false);
  393 
  394   case vmIntrinsics::_putReferenceRelease:      return inline_unsafe_access( is_store, T_OBJECT,   Release, false);
  395   case vmIntrinsics::_putBooleanRelease:        return inline_unsafe_access( is_store, T_BOOLEAN,  Release, false);
  396   case vmIntrinsics::_putByteRelease:           return inline_unsafe_access( is_store, T_BYTE,     Release, false);
  397   case vmIntrinsics::_putShortRelease:          return inline_unsafe_access( is_store, T_SHORT,    Release, false);
  398   case vmIntrinsics::_putCharRelease:           return inline_unsafe_access( is_store, T_CHAR,     Release, false);
  399   case vmIntrinsics::_putIntRelease:            return inline_unsafe_access( is_store, T_INT,      Release, false);
  400   case vmIntrinsics::_putLongRelease:           return inline_unsafe_access( is_store, T_LONG,     Release, false);
  401   case vmIntrinsics::_putFloatRelease:          return inline_unsafe_access( is_store, T_FLOAT,    Release, false);
  402   case vmIntrinsics::_putDoubleRelease:         return inline_unsafe_access( is_store, T_DOUBLE,   Release, false);
  403 
  404   case vmIntrinsics::_getReferenceOpaque:       return inline_unsafe_access(!is_store, T_OBJECT,   Opaque, false);
  405   case vmIntrinsics::_getBooleanOpaque:         return inline_unsafe_access(!is_store, T_BOOLEAN,  Opaque, false);
  406   case vmIntrinsics::_getByteOpaque:            return inline_unsafe_access(!is_store, T_BYTE,     Opaque, false);
  407   case vmIntrinsics::_getShortOpaque:           return inline_unsafe_access(!is_store, T_SHORT,    Opaque, false);
  408   case vmIntrinsics::_getCharOpaque:            return inline_unsafe_access(!is_store, T_CHAR,     Opaque, false);
  409   case vmIntrinsics::_getIntOpaque:             return inline_unsafe_access(!is_store, T_INT,      Opaque, false);
  410   case vmIntrinsics::_getLongOpaque:            return inline_unsafe_access(!is_store, T_LONG,     Opaque, false);
  411   case vmIntrinsics::_getFloatOpaque:           return inline_unsafe_access(!is_store, T_FLOAT,    Opaque, false);
  412   case vmIntrinsics::_getDoubleOpaque:          return inline_unsafe_access(!is_store, T_DOUBLE,   Opaque, false);
  413 
  414   case vmIntrinsics::_putReferenceOpaque:       return inline_unsafe_access( is_store, T_OBJECT,   Opaque, false);
  415   case vmIntrinsics::_putBooleanOpaque:         return inline_unsafe_access( is_store, T_BOOLEAN,  Opaque, false);
  416   case vmIntrinsics::_putByteOpaque:            return inline_unsafe_access( is_store, T_BYTE,     Opaque, false);
  417   case vmIntrinsics::_putShortOpaque:           return inline_unsafe_access( is_store, T_SHORT,    Opaque, false);
  418   case vmIntrinsics::_putCharOpaque:            return inline_unsafe_access( is_store, T_CHAR,     Opaque, false);
  419   case vmIntrinsics::_putIntOpaque:             return inline_unsafe_access( is_store, T_INT,      Opaque, false);
  420   case vmIntrinsics::_putLongOpaque:            return inline_unsafe_access( is_store, T_LONG,     Opaque, false);
  421   case vmIntrinsics::_putFloatOpaque:           return inline_unsafe_access( is_store, T_FLOAT,    Opaque, false);
  422   case vmIntrinsics::_putDoubleOpaque:          return inline_unsafe_access( is_store, T_DOUBLE,   Opaque, false);
  423 
  424   case vmIntrinsics::_getFlatValue:             return inline_unsafe_flat_access(!is_store, Relaxed);
  425   case vmIntrinsics::_putFlatValue:             return inline_unsafe_flat_access( is_store, Relaxed);
  426 
  427   case vmIntrinsics::_compareAndSetReference:   return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap,      Volatile);
  428   case vmIntrinsics::_compareAndSetByte:        return inline_unsafe_load_store(T_BYTE,   LS_cmp_swap,      Volatile);
  429   case vmIntrinsics::_compareAndSetShort:       return inline_unsafe_load_store(T_SHORT,  LS_cmp_swap,      Volatile);
  430   case vmIntrinsics::_compareAndSetInt:         return inline_unsafe_load_store(T_INT,    LS_cmp_swap,      Volatile);
  431   case vmIntrinsics::_compareAndSetLong:        return inline_unsafe_load_store(T_LONG,   LS_cmp_swap,      Volatile);
  432 
  433   case vmIntrinsics::_weakCompareAndSetReferencePlain:     return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed);
  434   case vmIntrinsics::_weakCompareAndSetReferenceAcquire:   return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire);
  435   case vmIntrinsics::_weakCompareAndSetReferenceRelease:   return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release);
  436   case vmIntrinsics::_weakCompareAndSetReference:          return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile);
  437   case vmIntrinsics::_weakCompareAndSetBytePlain:          return inline_unsafe_load_store(T_BYTE,   LS_cmp_swap_weak, Relaxed);
  438   case vmIntrinsics::_weakCompareAndSetByteAcquire:        return inline_unsafe_load_store(T_BYTE,   LS_cmp_swap_weak, Acquire);
  439   case vmIntrinsics::_weakCompareAndSetByteRelease:        return inline_unsafe_load_store(T_BYTE,   LS_cmp_swap_weak, Release);
  440   case vmIntrinsics::_weakCompareAndSetByte:               return inline_unsafe_load_store(T_BYTE,   LS_cmp_swap_weak, Volatile);
  441   case vmIntrinsics::_weakCompareAndSetShortPlain:         return inline_unsafe_load_store(T_SHORT,  LS_cmp_swap_weak, Relaxed);
  442   case vmIntrinsics::_weakCompareAndSetShortAcquire:       return inline_unsafe_load_store(T_SHORT,  LS_cmp_swap_weak, Acquire);
  443   case vmIntrinsics::_weakCompareAndSetShortRelease:       return inline_unsafe_load_store(T_SHORT,  LS_cmp_swap_weak, Release);
  444   case vmIntrinsics::_weakCompareAndSetShort:              return inline_unsafe_load_store(T_SHORT,  LS_cmp_swap_weak, Volatile);
  445   case vmIntrinsics::_weakCompareAndSetIntPlain:           return inline_unsafe_load_store(T_INT,    LS_cmp_swap_weak, Relaxed);
  446   case vmIntrinsics::_weakCompareAndSetIntAcquire:         return inline_unsafe_load_store(T_INT,    LS_cmp_swap_weak, Acquire);
  447   case vmIntrinsics::_weakCompareAndSetIntRelease:         return inline_unsafe_load_store(T_INT,    LS_cmp_swap_weak, Release);
  448   case vmIntrinsics::_weakCompareAndSetInt:                return inline_unsafe_load_store(T_INT,    LS_cmp_swap_weak, Volatile);
  449   case vmIntrinsics::_weakCompareAndSetLongPlain:          return inline_unsafe_load_store(T_LONG,   LS_cmp_swap_weak, Relaxed);
  450   case vmIntrinsics::_weakCompareAndSetLongAcquire:        return inline_unsafe_load_store(T_LONG,   LS_cmp_swap_weak, Acquire);
  451   case vmIntrinsics::_weakCompareAndSetLongRelease:        return inline_unsafe_load_store(T_LONG,   LS_cmp_swap_weak, Release);
  452   case vmIntrinsics::_weakCompareAndSetLong:               return inline_unsafe_load_store(T_LONG,   LS_cmp_swap_weak, Volatile);
  453 
  454   case vmIntrinsics::_compareAndExchangeReference:         return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange,  Volatile);
  455   case vmIntrinsics::_compareAndExchangeReferenceAcquire:  return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange,  Acquire);
  456   case vmIntrinsics::_compareAndExchangeReferenceRelease:  return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange,  Release);
  457   case vmIntrinsics::_compareAndExchangeByte:              return inline_unsafe_load_store(T_BYTE,   LS_cmp_exchange,  Volatile);
  458   case vmIntrinsics::_compareAndExchangeByteAcquire:       return inline_unsafe_load_store(T_BYTE,   LS_cmp_exchange,  Acquire);
  459   case vmIntrinsics::_compareAndExchangeByteRelease:       return inline_unsafe_load_store(T_BYTE,   LS_cmp_exchange,  Release);
  460   case vmIntrinsics::_compareAndExchangeShort:             return inline_unsafe_load_store(T_SHORT,  LS_cmp_exchange,  Volatile);
  461   case vmIntrinsics::_compareAndExchangeShortAcquire:      return inline_unsafe_load_store(T_SHORT,  LS_cmp_exchange,  Acquire);
  462   case vmIntrinsics::_compareAndExchangeShortRelease:      return inline_unsafe_load_store(T_SHORT,  LS_cmp_exchange,  Release);
  463   case vmIntrinsics::_compareAndExchangeInt:               return inline_unsafe_load_store(T_INT,    LS_cmp_exchange,  Volatile);
  464   case vmIntrinsics::_compareAndExchangeIntAcquire:        return inline_unsafe_load_store(T_INT,    LS_cmp_exchange,  Acquire);
  465   case vmIntrinsics::_compareAndExchangeIntRelease:        return inline_unsafe_load_store(T_INT,    LS_cmp_exchange,  Release);
  466   case vmIntrinsics::_compareAndExchangeLong:              return inline_unsafe_load_store(T_LONG,   LS_cmp_exchange,  Volatile);
  467   case vmIntrinsics::_compareAndExchangeLongAcquire:       return inline_unsafe_load_store(T_LONG,   LS_cmp_exchange,  Acquire);
  468   case vmIntrinsics::_compareAndExchangeLongRelease:       return inline_unsafe_load_store(T_LONG,   LS_cmp_exchange,  Release);
  469 
  470   case vmIntrinsics::_getAndAddByte:                    return inline_unsafe_load_store(T_BYTE,   LS_get_add,       Volatile);
  471   case vmIntrinsics::_getAndAddShort:                   return inline_unsafe_load_store(T_SHORT,  LS_get_add,       Volatile);
  472   case vmIntrinsics::_getAndAddInt:                     return inline_unsafe_load_store(T_INT,    LS_get_add,       Volatile);
  473   case vmIntrinsics::_getAndAddLong:                    return inline_unsafe_load_store(T_LONG,   LS_get_add,       Volatile);
  474 
  475   case vmIntrinsics::_getAndSetByte:                    return inline_unsafe_load_store(T_BYTE,   LS_get_set,       Volatile);
  476   case vmIntrinsics::_getAndSetShort:                   return inline_unsafe_load_store(T_SHORT,  LS_get_set,       Volatile);
  477   case vmIntrinsics::_getAndSetInt:                     return inline_unsafe_load_store(T_INT,    LS_get_set,       Volatile);
  478   case vmIntrinsics::_getAndSetLong:                    return inline_unsafe_load_store(T_LONG,   LS_get_set,       Volatile);
  479   case vmIntrinsics::_getAndSetReference:               return inline_unsafe_load_store(T_OBJECT, LS_get_set,       Volatile);
  480 
  481   case vmIntrinsics::_loadFence:
  482   case vmIntrinsics::_storeFence:
  483   case vmIntrinsics::_storeStoreFence:
  484   case vmIntrinsics::_fullFence:                return inline_unsafe_fence(intrinsic_id());
  485 
  486   case vmIntrinsics::_arrayInstanceBaseOffset:  return inline_arrayInstanceBaseOffset();
  487   case vmIntrinsics::_arrayInstanceIndexScale:  return inline_arrayInstanceIndexScale();
  488   case vmIntrinsics::_arrayLayout:              return inline_arrayLayout();
  489   case vmIntrinsics::_getFieldMap:              return inline_getFieldMap();
  490 
  491   case vmIntrinsics::_onSpinWait:               return inline_onspinwait();
  492 
  493   case vmIntrinsics::_currentCarrierThread:     return inline_native_currentCarrierThread();
  494   case vmIntrinsics::_currentThread:            return inline_native_currentThread();
  495   case vmIntrinsics::_setCurrentThread:         return inline_native_setCurrentThread();
  496 
  497   case vmIntrinsics::_scopedValueCache:          return inline_native_scopedValueCache();
  498   case vmIntrinsics::_setScopedValueCache:       return inline_native_setScopedValueCache();
  499 
  500   case vmIntrinsics::_Continuation_pin:          return inline_native_Continuation_pinning(false);
  501   case vmIntrinsics::_Continuation_unpin:        return inline_native_Continuation_pinning(true);
  502 
  503   case vmIntrinsics::_vthreadEndFirstTransition:    return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_first_transition_Java()),
  504                                                                                                 "endFirstTransition", true);
  505   case vmIntrinsics::_vthreadStartFinalTransition:  return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_final_transition_Java()),
  506                                                                                                   "startFinalTransition", true);
  507   case vmIntrinsics::_vthreadStartTransition:       return inline_native_vthread_start_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_start_transition_Java()),
  508                                                                                                   "startTransition", false);
  509   case vmIntrinsics::_vthreadEndTransition:         return inline_native_vthread_end_transition(CAST_FROM_FN_PTR(address, OptoRuntime::vthread_end_transition_Java()),
  510                                                                                                 "endTransition", false);
  511 #if INCLUDE_JVMTI
  512   case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend: return inline_native_notify_jvmti_sync();
  513 #endif
  514 
  515 #ifdef JFR_HAVE_INTRINSICS
  516   case vmIntrinsics::_counterTime:              return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JfrTime::time_function()), "counterTime");
  517   case vmIntrinsics::_getEventWriter:           return inline_native_getEventWriter();
  518   case vmIntrinsics::_jvm_commit:               return inline_native_jvm_commit();
  519   case vmIntrinsics::_tryUpdateEpochField:      return inline_native_try_update_epoch();
  520 #endif
  521   case vmIntrinsics::_currentTimeMillis:        return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
  522   case vmIntrinsics::_nanoTime:                 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
  523   case vmIntrinsics::_writeback0:               return inline_unsafe_writeback0();
  524   case vmIntrinsics::_writebackPreSync0:        return inline_unsafe_writebackSync0(true);
  525   case vmIntrinsics::_writebackPostSync0:       return inline_unsafe_writebackSync0(false);
  526   case vmIntrinsics::_allocateInstance:         return inline_unsafe_allocate();
  527   case vmIntrinsics::_copyMemory:               return inline_unsafe_copyMemory();
  528   case vmIntrinsics::_setMemory:                return inline_unsafe_setMemory();
  529   case vmIntrinsics::_getLength:                return inline_native_getLength();
  530   case vmIntrinsics::_copyOf:                   return inline_array_copyOf(false);
  531   case vmIntrinsics::_copyOfRange:              return inline_array_copyOf(true);
  532   case vmIntrinsics::_equalsB:                  return inline_array_equals(StrIntrinsicNode::LL);
  533   case vmIntrinsics::_equalsC:                  return inline_array_equals(StrIntrinsicNode::UU);
  534   case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(T_INT);
  535   case vmIntrinsics::_Preconditions_checkLongIndex: return inline_preconditions_checkIndex(T_LONG);
  536   case vmIntrinsics::_clone:                    return inline_native_clone(intrinsic()->is_virtual());
  537 
  538   case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
  539   case vmIntrinsics::_newArray:                   return inline_unsafe_newArray(false);
  540   case vmIntrinsics::_newNullRestrictedNonAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ false);
  541   case vmIntrinsics::_newNullRestrictedAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ true);
  542   case vmIntrinsics::_newNullableAtomicArray:     return inline_newArray(/* null_free */ false, /* atomic */ true);
  543   case vmIntrinsics::_isFlatArray:              return inline_getArrayProperties(IsFlat);
  544   case vmIntrinsics::_isNullRestrictedArray:    return inline_getArrayProperties(IsNullRestricted);
  545   case vmIntrinsics::_isAtomicArray:            return inline_getArrayProperties(IsAtomic);
  546 
  547   case vmIntrinsics::_isAssignableFrom:         return inline_native_subtype_check();
  548 
  549   case vmIntrinsics::_isInstance:
  550   case vmIntrinsics::_isHidden:
  551   case vmIntrinsics::_getSuperclass:            return inline_native_Class_query(intrinsic_id());
  552 
  553   case vmIntrinsics::_floatToRawIntBits:
  554   case vmIntrinsics::_floatToIntBits:
  555   case vmIntrinsics::_intBitsToFloat:
  556   case vmIntrinsics::_doubleToRawLongBits:
  557   case vmIntrinsics::_doubleToLongBits:
  558   case vmIntrinsics::_longBitsToDouble:
  559   case vmIntrinsics::_floatToFloat16:
  560   case vmIntrinsics::_float16ToFloat:           return inline_fp_conversions(intrinsic_id());
  561   case vmIntrinsics::_sqrt_float16:             return inline_fp16_operations(intrinsic_id(), 1);
  562   case vmIntrinsics::_fma_float16:              return inline_fp16_operations(intrinsic_id(), 3);
  563   case vmIntrinsics::_floatIsFinite:
  564   case vmIntrinsics::_floatIsInfinite:
  565   case vmIntrinsics::_doubleIsFinite:
  566   case vmIntrinsics::_doubleIsInfinite:         return inline_fp_range_check(intrinsic_id());
  567 
  568   case vmIntrinsics::_numberOfLeadingZeros_i:
  569   case vmIntrinsics::_numberOfLeadingZeros_l:
  570   case vmIntrinsics::_numberOfTrailingZeros_i:
  571   case vmIntrinsics::_numberOfTrailingZeros_l:
  572   case vmIntrinsics::_bitCount_i:
  573   case vmIntrinsics::_bitCount_l:
  574   case vmIntrinsics::_reverse_i:
  575   case vmIntrinsics::_reverse_l:
  576   case vmIntrinsics::_reverseBytes_i:
  577   case vmIntrinsics::_reverseBytes_l:
  578   case vmIntrinsics::_reverseBytes_s:
  579   case vmIntrinsics::_reverseBytes_c:           return inline_number_methods(intrinsic_id());
  580 
  581   case vmIntrinsics::_compress_i:
  582   case vmIntrinsics::_compress_l:
  583   case vmIntrinsics::_expand_i:
  584   case vmIntrinsics::_expand_l:                 return inline_bitshuffle_methods(intrinsic_id());
  585 
  586   case vmIntrinsics::_compareUnsigned_i:
  587   case vmIntrinsics::_compareUnsigned_l:        return inline_compare_unsigned(intrinsic_id());
  588 
  589   case vmIntrinsics::_divideUnsigned_i:
  590   case vmIntrinsics::_divideUnsigned_l:
  591   case vmIntrinsics::_remainderUnsigned_i:
  592   case vmIntrinsics::_remainderUnsigned_l:      return inline_divmod_methods(intrinsic_id());
  593 
  594   case vmIntrinsics::_getCallerClass:           return inline_native_Reflection_getCallerClass();
  595 
  596   case vmIntrinsics::_Reference_get0:           return inline_reference_get0();
  597   case vmIntrinsics::_Reference_refersTo0:      return inline_reference_refersTo0(false);
  598   case vmIntrinsics::_Reference_reachabilityFence: return inline_reference_reachabilityFence();
  599   case vmIntrinsics::_PhantomReference_refersTo0: return inline_reference_refersTo0(true);
  600   case vmIntrinsics::_Reference_clear0:         return inline_reference_clear0(false);
  601   case vmIntrinsics::_PhantomReference_clear0:  return inline_reference_clear0(true);
  602 
  603   case vmIntrinsics::_Class_cast:               return inline_Class_cast();
  604 
  605   case vmIntrinsics::_aescrypt_encryptBlock:
  606   case vmIntrinsics::_aescrypt_decryptBlock:    return inline_aescrypt_Block(intrinsic_id());
  607 
  608   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
  609   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
  610     return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
  611 
  612   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
  613   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
  614     return inline_electronicCodeBook_AESCrypt(intrinsic_id());
  615 
  616   case vmIntrinsics::_counterMode_AESCrypt:
  617     return inline_counterMode_AESCrypt(intrinsic_id());
  618 
  619   case vmIntrinsics::_galoisCounterMode_AESCrypt:
  620     return inline_galoisCounterMode_AESCrypt();
  621 
  622   case vmIntrinsics::_md5_implCompress:
  623   case vmIntrinsics::_sha_implCompress:
  624   case vmIntrinsics::_sha2_implCompress:
  625   case vmIntrinsics::_sha5_implCompress:
  626   case vmIntrinsics::_sha3_implCompress:
  627     return inline_digestBase_implCompress(intrinsic_id());
  628   case vmIntrinsics::_double_keccak:
  629   case vmIntrinsics::_quad_keccak:
  630     return inline_keccak(intrinsic_id());
  631 
  632   case vmIntrinsics::_digestBase_implCompressMB:
  633     return inline_digestBase_implCompressMB(predicate);
  634 
  635   case vmIntrinsics::_multiplyToLen:
  636     return inline_multiplyToLen();
  637 
  638   case vmIntrinsics::_squareToLen:
  639     return inline_squareToLen();
  640 
  641   case vmIntrinsics::_mulAdd:
  642     return inline_mulAdd();
  643 
  644   case vmIntrinsics::_montgomeryMultiply:
  645     return inline_montgomeryMultiply();
  646   case vmIntrinsics::_montgomerySquare:
  647     return inline_montgomerySquare();
  648 
  649   case vmIntrinsics::_bigIntegerRightShiftWorker:
  650     return inline_bigIntegerShift(true);
  651   case vmIntrinsics::_bigIntegerLeftShiftWorker:
  652     return inline_bigIntegerShift(false);
  653 
  654   case vmIntrinsics::_vectorizedMismatch:
  655     return inline_vectorizedMismatch();
  656 
  657   case vmIntrinsics::_ghash_processBlocks:
  658     return inline_ghash_processBlocks();
  659   case vmIntrinsics::_chacha20Block:
  660     return inline_chacha20Block();
  661   case vmIntrinsics::_kyberNtt:
  662     return inline_kyberNtt();
  663   case vmIntrinsics::_kyberInverseNtt:
  664     return inline_kyberInverseNtt();
  665   case vmIntrinsics::_kyberNttMult:
  666     return inline_kyberNttMult();
  667   case vmIntrinsics::_kyberAddPoly_2:
  668     return inline_kyberAddPoly_2();
  669   case vmIntrinsics::_kyberAddPoly_3:
  670     return inline_kyberAddPoly_3();
  671   case vmIntrinsics::_kyber12To16:
  672     return inline_kyber12To16();
  673   case vmIntrinsics::_kyberBarrettReduce:
  674     return inline_kyberBarrettReduce();
  675   case vmIntrinsics::_dilithiumAlmostNtt:
  676     return inline_dilithiumAlmostNtt();
  677   case vmIntrinsics::_dilithiumAlmostInverseNtt:
  678     return inline_dilithiumAlmostInverseNtt();
  679   case vmIntrinsics::_dilithiumNttMult:
  680     return inline_dilithiumNttMult();
  681   case vmIntrinsics::_dilithiumMontMulByConstant:
  682     return inline_dilithiumMontMulByConstant();
  683   case vmIntrinsics::_dilithiumDecomposePoly:
  684     return inline_dilithiumDecomposePoly();
  685   case vmIntrinsics::_base64_encodeBlock:
  686     return inline_base64_encodeBlock();
  687   case vmIntrinsics::_base64_decodeBlock:
  688     return inline_base64_decodeBlock();
  689   case vmIntrinsics::_poly1305_processBlocks:
  690     return inline_poly1305_processBlocks();
  691   case vmIntrinsics::_intpoly_montgomeryMult_P256:
  692     return inline_intpoly_montgomeryMult_P256();
  693   case vmIntrinsics::_intpoly_assign:
  694     return inline_intpoly_assign();
  695   case vmIntrinsics::_encodeISOArray:
  696   case vmIntrinsics::_encodeByteISOArray:
  697     return inline_encodeISOArray(false);
  698   case vmIntrinsics::_encodeAsciiArray:
  699     return inline_encodeISOArray(true);
  700 
  701   case vmIntrinsics::_updateCRC32:
  702     return inline_updateCRC32();
  703   case vmIntrinsics::_updateBytesCRC32:
  704     return inline_updateBytesCRC32();
  705   case vmIntrinsics::_updateByteBufferCRC32:
  706     return inline_updateByteBufferCRC32();
  707 
  708   case vmIntrinsics::_updateBytesCRC32C:
  709     return inline_updateBytesCRC32C();
  710   case vmIntrinsics::_updateDirectByteBufferCRC32C:
  711     return inline_updateDirectByteBufferCRC32C();
  712 
  713   case vmIntrinsics::_updateBytesAdler32:
  714     return inline_updateBytesAdler32();
  715   case vmIntrinsics::_updateByteBufferAdler32:
  716     return inline_updateByteBufferAdler32();
  717 
  718   case vmIntrinsics::_profileBoolean:
  719     return inline_profileBoolean();
  720   case vmIntrinsics::_isCompileConstant:
  721     return inline_isCompileConstant();
  722 
  723   case vmIntrinsics::_countPositives:
  724     return inline_countPositives();
  725 
  726   case vmIntrinsics::_fmaD:
  727   case vmIntrinsics::_fmaF:
  728     return inline_fma(intrinsic_id());
  729 
  730   case vmIntrinsics::_isDigit:
  731   case vmIntrinsics::_isLowerCase:
  732   case vmIntrinsics::_isUpperCase:
  733   case vmIntrinsics::_isWhitespace:
  734     return inline_character_compare(intrinsic_id());
  735 
  736   case vmIntrinsics::_min:
  737   case vmIntrinsics::_max:
  738   case vmIntrinsics::_min_strict:
  739   case vmIntrinsics::_max_strict:
  740   case vmIntrinsics::_minL:
  741   case vmIntrinsics::_maxL:
  742   case vmIntrinsics::_minF:
  743   case vmIntrinsics::_maxF:
  744   case vmIntrinsics::_minD:
  745   case vmIntrinsics::_maxD:
  746   case vmIntrinsics::_minF_strict:
  747   case vmIntrinsics::_maxF_strict:
  748   case vmIntrinsics::_minD_strict:
  749   case vmIntrinsics::_maxD_strict:
  750     return inline_min_max(intrinsic_id());
  751 
  752   case vmIntrinsics::_VectorUnaryOp:
  753     return inline_vector_nary_operation(1);
  754   case vmIntrinsics::_VectorBinaryOp:
  755     return inline_vector_nary_operation(2);
  756   case vmIntrinsics::_VectorUnaryLibOp:
  757     return inline_vector_call(1);
  758   case vmIntrinsics::_VectorBinaryLibOp:
  759     return inline_vector_call(2);
  760   case vmIntrinsics::_VectorTernaryOp:
  761     return inline_vector_nary_operation(3);
  762   case vmIntrinsics::_VectorFromBitsCoerced:
  763     return inline_vector_frombits_coerced();
  764   case vmIntrinsics::_VectorMaskOp:
  765     return inline_vector_mask_operation();
  766   case vmIntrinsics::_VectorLoadOp:
  767     return inline_vector_mem_operation(/*is_store=*/false);
  768   case vmIntrinsics::_VectorLoadMaskedOp:
  769     return inline_vector_mem_masked_operation(/*is_store*/false);
  770   case vmIntrinsics::_VectorStoreOp:
  771     return inline_vector_mem_operation(/*is_store=*/true);
  772   case vmIntrinsics::_VectorStoreMaskedOp:
  773     return inline_vector_mem_masked_operation(/*is_store=*/true);
  774   case vmIntrinsics::_VectorGatherOp:
  775     return inline_vector_gather_scatter(/*is_scatter*/ false);
  776   case vmIntrinsics::_VectorScatterOp:
  777     return inline_vector_gather_scatter(/*is_scatter*/ true);
  778   case vmIntrinsics::_VectorReductionCoerced:
  779     return inline_vector_reduction();
  780   case vmIntrinsics::_VectorTest:
  781     return inline_vector_test();
  782   case vmIntrinsics::_VectorBlend:
  783     return inline_vector_blend();
  784   case vmIntrinsics::_VectorRearrange:
  785     return inline_vector_rearrange();
  786   case vmIntrinsics::_VectorSelectFrom:
  787     return inline_vector_select_from();
  788   case vmIntrinsics::_VectorCompare:
  789     return inline_vector_compare();
  790   case vmIntrinsics::_VectorBroadcastInt:
  791     return inline_vector_broadcast_int();
  792   case vmIntrinsics::_VectorConvert:
  793     return inline_vector_convert();
  794   case vmIntrinsics::_VectorInsert:
  795     return inline_vector_insert();
  796   case vmIntrinsics::_VectorExtract:
  797     return inline_vector_extract();
  798   case vmIntrinsics::_VectorCompressExpand:
  799     return inline_vector_compress_expand();
  800   case vmIntrinsics::_VectorSelectFromTwoVectorOp:
  801     return inline_vector_select_from_two_vectors();
  802   case vmIntrinsics::_IndexVector:
  803     return inline_index_vector();
  804   case vmIntrinsics::_IndexPartiallyInUpperRange:
  805     return inline_index_partially_in_upper_range();
  806 
  807   case vmIntrinsics::_getObjectSize:
  808     return inline_getObjectSize();
  809 
  810   case vmIntrinsics::_blackhole:
  811     return inline_blackhole();
  812 
  813   default:
  814     // If you get here, it may be that someone has added a new intrinsic
  815     // to the list in vmIntrinsics.hpp without implementing it here.
  816 #ifndef PRODUCT
  817     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
  818       tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
  819                     vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id()));
  820     }
  821 #endif
  822     return false;
  823   }
  824 }
  825 
  826 Node* LibraryCallKit::try_to_predicate(int predicate) {
  827   if (!jvms()->has_method()) {
  828     // Root JVMState has a null method.
  829     assert(map()->memory()->Opcode() == Op_Parm, "");
  830     // Insert the memory aliasing node
  831     set_all_memory(reset_memory());
  832   }
  833   assert(merged_memory(), "");
  834 
  835   switch (intrinsic_id()) {
  836   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
  837     return inline_cipherBlockChaining_AESCrypt_predicate(false);
  838   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
  839     return inline_cipherBlockChaining_AESCrypt_predicate(true);
  840   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
  841     return inline_electronicCodeBook_AESCrypt_predicate(false);
  842   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
  843     return inline_electronicCodeBook_AESCrypt_predicate(true);
  844   case vmIntrinsics::_counterMode_AESCrypt:
  845     return inline_counterMode_AESCrypt_predicate();
  846   case vmIntrinsics::_digestBase_implCompressMB:
  847     return inline_digestBase_implCompressMB_predicate(predicate);
  848   case vmIntrinsics::_galoisCounterMode_AESCrypt:
  849     return inline_galoisCounterMode_AESCrypt_predicate();
  850 
  851   default:
  852     // If you get here, it may be that someone has added a new intrinsic
  853     // to the list in vmIntrinsics.hpp without implementing it here.
  854 #ifndef PRODUCT
  855     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
  856       tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)",
  857                     vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id()));
  858     }
  859 #endif
  860     Node* slow_ctl = control();
  861     set_control(top()); // No fast path intrinsic
  862     return slow_ctl;
  863   }
  864 }
  865 
  866 //------------------------------set_result-------------------------------
  867 // Helper function for finishing intrinsics.
  868 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) {
  869   record_for_igvn(region);
  870   set_control(_gvn.transform(region));
  871   set_result( _gvn.transform(value));
  872   assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity");
  873 }
  874 
  875 RegionNode* LibraryCallKit::create_bailout() {
  876   RegionNode* bailout = new RegionNode(1);
  877   record_for_igvn(bailout);
  878   return bailout;
  879 }
  880 
  881 bool LibraryCallKit::check_bailout(RegionNode* bailout) {
  882   if (bailout->req() > 1) {
  883     bailout = _gvn.transform(bailout)->as_Region();
  884     Node* frame = _gvn.transform(new ParmNode(C->start(), TypeFunc::FramePtr));
  885     Node* halt = _gvn.transform(new HaltNode(bailout, frame, "unexpected guard failure in intrinsic"));
  886     C->root()->add_req(halt);
  887   }
  888   return stopped();
  889 }
  890 
  891 //------------------------------generate_guard---------------------------
  892 // Helper function for generating guarded fast-slow graph structures.
  893 // The given 'test', if true, guards a slow path.  If the test fails
  894 // then a fast path can be taken.  (We generally hope it fails.)
  895 // In all cases, GraphKit::control() is updated to the fast path.
  896 // The returned value represents the control for the slow path.
  897 // The return value is never 'top'; it is either a valid control
  898 // or null if it is obvious that the slow path can never be taken.
  899 // Also, if region and the slow control are not null, the slow edge
  900 // is appended to the region.
  901 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) {
  902   if (stopped()) {
  903     // Already short circuited.
  904     return nullptr;
  905   }
  906 
  907   // Build an if node and its projections.
  908   // If test is true we take the slow path, which we assume is uncommon.
  909   if (_gvn.type(test) == TypeInt::ZERO) {
  910     // The slow branch is never taken.  No need to build this guard.
  911     return nullptr;
  912   }
  913 
  914   IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
  915 
  916   Node* if_slow = _gvn.transform(new IfTrueNode(iff));
  917   if (if_slow == top()) {
  918     // The slow branch is never taken.  No need to build this guard.
  919     return nullptr;
  920   }
  921 
  922   if (region != nullptr)
  923     region->add_req(if_slow);
  924 
  925   Node* if_fast = _gvn.transform(new IfFalseNode(iff));
  926   set_control(if_fast);
  927 
  928   return if_slow;
  929 }
  930 
  931 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) {
  932   return generate_guard(test, region, PROB_UNLIKELY_MAG(3));
  933 }
  934 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) {
  935   return generate_guard(test, region, PROB_FAIR);
  936 }
  937 
  938 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region,
  939                                                      Node** pos_index, bool with_opaque) {
  940   if (stopped())
  941     return nullptr;                // already stopped
  942   if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
  943     return nullptr;                // index is already adequately typed
  944   Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0)));
  945   Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
  946   if (with_opaque) {
  947     bol_lt = _gvn.transform(new OpaqueConstantBoolNode(C, bol_lt, false));
  948   }
  949   Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
  950   if (is_neg != nullptr && pos_index != nullptr) {
  951     // Emulate effect of Parse::adjust_map_after_if.
  952     Node* ccast = new CastIINode(control(), index, TypeInt::POS);
  953     (*pos_index) = _gvn.transform(ccast);
  954   }
  955   return is_neg;
  956 }
  957 
  958 // Make sure that 'position' is a valid limit index, in [0..length].
  959 // There are two equivalent plans for checking this:
  960 //   A. (offset + copyLength)  unsigned<=  arrayLength
  961 //   B. offset  <=  (arrayLength - copyLength)
  962 // We require that all of the values above, except for the sum and
  963 // difference, are already known to be non-negative.
  964 // Plan A is robust in the face of overflow, if offset and copyLength
  965 // are both hugely positive.
  966 //
  967 // Plan B is less direct and intuitive, but it does not overflow at
  968 // all, since the difference of two non-negatives is always
  969 // representable.  Whenever Java methods must perform the equivalent
  970 // check they generally use Plan B instead of Plan A.
  971 // For the moment we use Plan A.
  972 inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
  973                                                   Node* subseq_length,
  974                                                   Node* array_length,
  975                                                   RegionNode* region,
  976                                                   bool with_opaque) {
  977   if (stopped())
  978     return nullptr;                // already stopped
  979   bool zero_offset = _gvn.type(offset) == TypeInt::ZERO;
  980   if (zero_offset && subseq_length->eqv_uncast(array_length))
  981     return nullptr;                // common case of whole-array copy
  982   Node* last = subseq_length;
  983   if (!zero_offset)             // last += offset
  984     last = _gvn.transform(new AddINode(last, offset));
  985   Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last));
  986   Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
  987   if (with_opaque) {
  988     bol_lt = _gvn.transform(new OpaqueConstantBoolNode(C, bol_lt, false));
  989   }
  990   Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
  991   return is_over;
  992 }
  993 
  994 // Emit range checks for the given String.value byte array
  995 void LibraryCallKit::generate_string_range_check(Node* array,
  996                                                  Node* offset,
  997                                                  Node* count,
  998                                                  bool char_count,
  999                                                  RegionNode* region) {
 1000   if (stopped()) {
 1001     return; // already stopped
 1002   }
 1003   if (char_count) {
 1004     // Convert char count to byte count
 1005     count = _gvn.transform(new LShiftINode(count, intcon(1)));
 1006   }
 1007   // Offset and count must not be negative
 1008   generate_negative_guard(offset, region, nullptr, true);
 1009   generate_negative_guard(count, region, nullptr, true);
 1010   // Offset + count must not exceed length of array
 1011   generate_limit_guard(offset, count, load_array_length(array), region, true);
 1012 }
 1013 
 1014 Node* LibraryCallKit::current_thread_helper(Node*& tls_output, ByteSize handle_offset,
 1015                                             bool is_immutable) {
 1016   ciKlass* thread_klass = env()->Thread_klass();
 1017   const Type* thread_type
 1018     = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
 1019 
 1020   Node* thread = _gvn.transform(new ThreadLocalNode());
 1021   Node* p = off_heap_plus_addr(thread, in_bytes(handle_offset));
 1022   tls_output = thread;
 1023 
 1024   Node* thread_obj_handle
 1025     = (is_immutable
 1026       ? LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
 1027         TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered)
 1028       : make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered));
 1029   thread_obj_handle = _gvn.transform(thread_obj_handle);
 1030 
 1031   DecoratorSet decorators = IN_NATIVE;
 1032   if (is_immutable) {
 1033     decorators |= C2_IMMUTABLE_MEMORY;
 1034   }
 1035   return access_load(thread_obj_handle, thread_type, T_OBJECT, decorators);
 1036 }
 1037 
 1038 //--------------------------generate_current_thread--------------------
 1039 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) {
 1040   return current_thread_helper(tls_output, JavaThread::threadObj_offset(),
 1041                                /*is_immutable*/false);
 1042 }
 1043 
 1044 //--------------------------generate_virtual_thread--------------------
 1045 Node* LibraryCallKit::generate_virtual_thread(Node* tls_output) {
 1046   return current_thread_helper(tls_output, JavaThread::vthread_offset(),
 1047                                !C->method()->changes_current_thread());
 1048 }
 1049 
 1050 //------------------------------make_string_method_node------------------------
 1051 // Helper method for String intrinsic functions. This version is called with
 1052 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded
 1053 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes
 1054 // containing the lengths of str1 and str2.
 1055 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) {
 1056   Node* result = nullptr;
 1057   switch (opcode) {
 1058   case Op_StrIndexOf:
 1059     result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES),
 1060                                 str1_start, cnt1, str2_start, cnt2, ae);
 1061     break;
 1062   case Op_StrComp:
 1063     result = new StrCompNode(control(), memory(TypeAryPtr::BYTES),
 1064                              str1_start, cnt1, str2_start, cnt2, ae);
 1065     break;
 1066   case Op_StrEquals:
 1067     // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals').
 1068     // Use the constant length if there is one because optimized match rule may exist.
 1069     result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES),
 1070                                str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae);
 1071     break;
 1072   default:
 1073     ShouldNotReachHere();
 1074     return nullptr;
 1075   }
 1076 
 1077   // All these intrinsics have checks.
 1078   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1079   clear_upper_avx();
 1080 
 1081   return _gvn.transform(result);
 1082 }
 1083 
 1084 //------------------------------inline_string_compareTo------------------------
 1085 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) {
 1086   Node* arg1 = argument(0);
 1087   Node* arg2 = argument(1);
 1088 
 1089   arg1 = must_be_not_null(arg1, true);
 1090   arg2 = must_be_not_null(arg2, true);
 1091 
 1092   // Get start addr and length of first argument
 1093   Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
 1094   Node* arg1_cnt    = load_array_length(arg1);
 1095 
 1096   // Get start addr and length of second argument
 1097   Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
 1098   Node* arg2_cnt    = load_array_length(arg2);
 1099 
 1100   Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
 1101   set_result(result);
 1102   return true;
 1103 }
 1104 
 1105 //------------------------------inline_string_equals------------------------
 1106 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) {
 1107   Node* arg1 = argument(0);
 1108   Node* arg2 = argument(1);
 1109 
 1110   // paths (plus control) merge
 1111   RegionNode* region = new RegionNode(3);
 1112   Node* phi = new PhiNode(region, TypeInt::BOOL);
 1113 
 1114   if (!stopped()) {
 1115 
 1116     arg1 = must_be_not_null(arg1, true);
 1117     arg2 = must_be_not_null(arg2, true);
 1118 
 1119     // Get start addr and length of first argument
 1120     Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
 1121     Node* arg1_cnt    = load_array_length(arg1);
 1122 
 1123     // Get start addr and length of second argument
 1124     Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
 1125     Node* arg2_cnt    = load_array_length(arg2);
 1126 
 1127     // Check for arg1_cnt != arg2_cnt
 1128     Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt));
 1129     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
 1130     Node* if_ne = generate_slow_guard(bol, nullptr);
 1131     if (if_ne != nullptr) {
 1132       phi->init_req(2, intcon(0));
 1133       region->init_req(2, if_ne);
 1134     }
 1135 
 1136     // Check for count == 0 is done by assembler code for StrEquals.
 1137 
 1138     if (!stopped()) {
 1139       Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
 1140       phi->init_req(1, equals);
 1141       region->init_req(1, control());
 1142     }
 1143   }
 1144 
 1145   // post merge
 1146   set_control(_gvn.transform(region));
 1147   record_for_igvn(region);
 1148 
 1149   set_result(_gvn.transform(phi));
 1150   return true;
 1151 }
 1152 
 1153 //------------------------------inline_array_equals----------------------------
 1154 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
 1155   assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types");
 1156   Node* arg1 = argument(0);
 1157   Node* arg2 = argument(1);
 1158 
 1159   const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES;
 1160   set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), mtype, arg1, arg2, ae)));
 1161   clear_upper_avx();
 1162 
 1163   return true;
 1164 }
 1165 
 1166 
 1167 //------------------------------inline_countPositives------------------------------
 1168 // int java.lang.StringCoding#countPositives0(byte[] ba, int off, int len)
 1169 bool LibraryCallKit::inline_countPositives() {
 1170   assert(callee()->signature()->size() == 3, "countPositives has 3 parameters");
 1171   // no receiver since it is static method
 1172   Node* ba         = argument(0);
 1173   Node* offset     = argument(1);
 1174   Node* len        = argument(2);
 1175 
 1176   ba = must_be_not_null(ba, true);
 1177   RegionNode* bailout = create_bailout();
 1178   generate_string_range_check(ba, offset, len, false, bailout);
 1179   if (check_bailout(bailout)) {
 1180     return true;
 1181   }
 1182 
 1183   Node* ba_start = array_element_address(ba, offset, T_BYTE);
 1184   Node* result = new CountPositivesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len);
 1185   set_result(_gvn.transform(result));
 1186   clear_upper_avx();
 1187   return true;
 1188 }
 1189 
 1190 bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) {
 1191   Node* index = argument(0);
 1192   Node* length = bt == T_INT ? argument(1) : argument(2);
 1193   if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) {
 1194     return false;
 1195   }
 1196 
 1197   // check that length is positive
 1198   Node* len_pos_cmp = _gvn.transform(CmpNode::make(length, integercon(0, bt), bt));
 1199   Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge));
 1200 
 1201   {
 1202     BuildCutout unless(this, len_pos_bol, PROB_MAX);
 1203     uncommon_trap(Deoptimization::Reason_intrinsic,
 1204                   Deoptimization::Action_make_not_entrant);
 1205   }
 1206 
 1207   if (stopped()) {
 1208     // Length is known to be always negative during compilation and the IR graph so far constructed is good so return success
 1209     return true;
 1210   }
 1211 
 1212   // length is now known positive, add a cast node to make this explicit
 1213   jlong upper_bound = _gvn.type(length)->is_integer(bt)->hi_as_long();
 1214   Node* casted_length = ConstraintCastNode::make_cast_for_basic_type(
 1215       control(), length, TypeInteger::make(0, upper_bound, Type::WidenMax, bt),
 1216       ConstraintCastNode::DependencyType::FloatingNarrowing, bt);
 1217   casted_length = _gvn.transform(casted_length);
 1218   replace_in_map(length, casted_length);
 1219   length = casted_length;
 1220 
 1221   // Use an unsigned comparison for the range check itself
 1222   Node* rc_cmp = _gvn.transform(CmpNode::make(index, length, bt, true));
 1223   BoolTest::mask btest = BoolTest::lt;
 1224   Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest));
 1225   RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN);
 1226   _gvn.set_type(rc, rc->Value(&_gvn));
 1227   if (!rc_bool->is_Con()) {
 1228     record_for_igvn(rc);
 1229   }
 1230   set_control(_gvn.transform(new IfTrueNode(rc)));
 1231   {
 1232     PreserveJVMState pjvms(this);
 1233     set_control(_gvn.transform(new IfFalseNode(rc)));
 1234     uncommon_trap(Deoptimization::Reason_range_check,
 1235                   Deoptimization::Action_make_not_entrant);
 1236   }
 1237 
 1238   if (stopped()) {
 1239     // Range check is known to always fail during compilation and the IR graph so far constructed is good so return success
 1240     return true;
 1241   }
 1242 
 1243   // index is now known to be >= 0 and < length, cast it
 1244   Node* result = ConstraintCastNode::make_cast_for_basic_type(
 1245       control(), index, TypeInteger::make(0, upper_bound, Type::WidenMax, bt),
 1246       ConstraintCastNode::DependencyType::FloatingNarrowing, bt);
 1247   result = _gvn.transform(result);
 1248   set_result(result);
 1249   replace_in_map(index, result);
 1250   return true;
 1251 }
 1252 
 1253 //------------------------------inline_string_indexOf------------------------
 1254 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) {
 1255   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
 1256     return false;
 1257   }
 1258   Node* src = argument(0);
 1259   Node* tgt = argument(1);
 1260 
 1261   // Make the merge point
 1262   RegionNode* result_rgn = new RegionNode(4);
 1263   Node*       result_phi = new PhiNode(result_rgn, TypeInt::INT);
 1264 
 1265   src = must_be_not_null(src, true);
 1266   tgt = must_be_not_null(tgt, true);
 1267 
 1268   // Get start addr and length of source string
 1269   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 1270   Node* src_count = load_array_length(src);
 1271 
 1272   // Get start addr and length of substring
 1273   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
 1274   Node* tgt_count = load_array_length(tgt);
 1275 
 1276   Node* result = nullptr;
 1277   bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr);
 1278 
 1279   if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) {
 1280     // Divide src size by 2 if String is UTF16 encoded
 1281     src_count = _gvn.transform(new RShiftINode(src_count, intcon(1)));
 1282   }
 1283   if (ae == StrIntrinsicNode::UU) {
 1284     // Divide substring size by 2 if String is UTF16 encoded
 1285     tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1)));
 1286   }
 1287 
 1288   if (call_opt_stub) {
 1289     Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(),
 1290                                    StubRoutines::_string_indexof_array[ae],
 1291                                    "stringIndexOf", TypePtr::BOTTOM, src_start,
 1292                                    src_count, tgt_start, tgt_count);
 1293     result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 1294   } else {
 1295     result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count,
 1296                                result_rgn, result_phi, ae);
 1297   }
 1298   if (result != nullptr) {
 1299     result_phi->init_req(3, result);
 1300     result_rgn->init_req(3, control());
 1301   }
 1302   set_control(_gvn.transform(result_rgn));
 1303   record_for_igvn(result_rgn);
 1304   set_result(_gvn.transform(result_phi));
 1305 
 1306   return true;
 1307 }
 1308 
 1309 //-----------------------------inline_string_indexOfI-----------------------
 1310 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) {
 1311   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
 1312     return false;
 1313   }
 1314 
 1315   assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments");
 1316   Node* src         = argument(0); // byte[]
 1317   Node* src_count   = argument(1); // char count
 1318   Node* tgt         = argument(2); // byte[]
 1319   Node* tgt_count   = argument(3); // char count
 1320   Node* from_index  = argument(4); // char index
 1321 
 1322   src = must_be_not_null(src, true);
 1323   tgt = must_be_not_null(tgt, true);
 1324 
 1325   // Multiply byte array index by 2 if String is UTF16 encoded
 1326   Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
 1327   src_count = _gvn.transform(new SubINode(src_count, from_index));
 1328   Node* src_start = array_element_address(src, src_offset, T_BYTE);
 1329   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
 1330 
 1331   // Range checks
 1332   RegionNode* bailout = create_bailout();
 1333   generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL, bailout);
 1334   generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU, bailout);
 1335   if (check_bailout(bailout)) {
 1336     return true;
 1337   }
 1338 
 1339   RegionNode* region = new RegionNode(5);
 1340   Node* phi = new PhiNode(region, TypeInt::INT);
 1341   Node* result = nullptr;
 1342 
 1343   bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr);
 1344 
 1345   if (call_opt_stub) {
 1346     Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(),
 1347                                    StubRoutines::_string_indexof_array[ae],
 1348                                    "stringIndexOf", TypePtr::BOTTOM, src_start,
 1349                                    src_count, tgt_start, tgt_count);
 1350     result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 1351   } else {
 1352     result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count,
 1353                                region, phi, ae);
 1354   }
 1355   if (result != nullptr) {
 1356     // The result is index relative to from_index if substring was found, -1 otherwise.
 1357     // Generate code which will fold into cmove.
 1358     Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
 1359     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
 1360 
 1361     Node* if_lt = generate_slow_guard(bol, nullptr);
 1362     if (if_lt != nullptr) {
 1363       // result == -1
 1364       phi->init_req(3, result);
 1365       region->init_req(3, if_lt);
 1366     }
 1367     if (!stopped()) {
 1368       result = _gvn.transform(new AddINode(result, from_index));
 1369       phi->init_req(4, result);
 1370       region->init_req(4, control());
 1371     }
 1372   }
 1373 
 1374   set_control(_gvn.transform(region));
 1375   record_for_igvn(region);
 1376   set_result(_gvn.transform(phi));
 1377   clear_upper_avx();
 1378 
 1379   return true;
 1380 }
 1381 
 1382 // Create StrIndexOfNode with fast path checks
 1383 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
 1384                                         RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) {
 1385   // Check for substr count > string count
 1386   Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count));
 1387   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt));
 1388   Node* if_gt = generate_slow_guard(bol, nullptr);
 1389   if (if_gt != nullptr) {
 1390     phi->init_req(1, intcon(-1));
 1391     region->init_req(1, if_gt);
 1392   }
 1393   if (!stopped()) {
 1394     // Check for substr count == 0
 1395     cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0)));
 1396     bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 1397     Node* if_zero = generate_slow_guard(bol, nullptr);
 1398     if (if_zero != nullptr) {
 1399       phi->init_req(2, intcon(0));
 1400       region->init_req(2, if_zero);
 1401     }
 1402   }
 1403   if (!stopped()) {
 1404     return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae);
 1405   }
 1406   return nullptr;
 1407 }
 1408 
 1409 //-----------------------------inline_string_indexOfChar-----------------------
 1410 bool LibraryCallKit::inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae) {
 1411   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 1412     return false;
 1413   }
 1414   if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) {
 1415     return false;
 1416   }
 1417   assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments");
 1418   Node* src         = argument(0); // byte[]
 1419   Node* int_ch      = argument(1);
 1420   Node* from_index  = argument(2);
 1421   Node* max         = argument(3);
 1422 
 1423   src = must_be_not_null(src, true);
 1424 
 1425   Node* src_offset = ae == StrIntrinsicNode::L ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
 1426   Node* src_start = array_element_address(src, src_offset, T_BYTE);
 1427   Node* src_count = _gvn.transform(new SubINode(max, from_index));
 1428 
 1429   // Range checks
 1430   RegionNode* bailout = create_bailout();
 1431   generate_string_range_check(src, src_offset, src_count, ae == StrIntrinsicNode::U, bailout);
 1432   if (check_bailout(bailout)) {
 1433     return true;
 1434   }
 1435 
 1436   // Check for int_ch >= 0
 1437   Node* int_ch_cmp = _gvn.transform(new CmpINode(int_ch, intcon(0)));
 1438   Node* int_ch_bol = _gvn.transform(new BoolNode(int_ch_cmp, BoolTest::ge));
 1439   {
 1440     BuildCutout unless(this, int_ch_bol, PROB_MAX);
 1441     uncommon_trap(Deoptimization::Reason_intrinsic,
 1442                   Deoptimization::Action_maybe_recompile);
 1443   }
 1444   if (stopped()) {
 1445     return true;
 1446   }
 1447 
 1448   RegionNode* region = new RegionNode(3);
 1449   Node* phi = new PhiNode(region, TypeInt::INT);
 1450 
 1451   Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, int_ch, ae);
 1452   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1453   _gvn.transform(result);
 1454 
 1455   Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
 1456   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
 1457 
 1458   Node* if_lt = generate_slow_guard(bol, nullptr);
 1459   if (if_lt != nullptr) {
 1460     // result == -1
 1461     phi->init_req(2, result);
 1462     region->init_req(2, if_lt);
 1463   }
 1464   if (!stopped()) {
 1465     result = _gvn.transform(new AddINode(result, from_index));
 1466     phi->init_req(1, result);
 1467     region->init_req(1, control());
 1468   }
 1469   set_control(_gvn.transform(region));
 1470   record_for_igvn(region);
 1471   set_result(_gvn.transform(phi));
 1472   clear_upper_avx();
 1473 
 1474   return true;
 1475 }
 1476 //---------------------------inline_string_copy---------------------
 1477 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[])
 1478 //   int StringUTF16.compress0(char[] src, int srcOff, byte[] dst, int dstOff, int len)
 1479 //   int StringUTF16.compress0(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
 1480 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[])
 1481 //   void StringLatin1.inflate0(byte[] src, int srcOff, char[] dst, int dstOff, int len)
 1482 //   void StringLatin1.inflate0(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
 1483 bool LibraryCallKit::inline_string_copy(bool compress) {
 1484   int nargs = 5;  // 2 oops, 3 ints
 1485   assert(callee()->signature()->size() == nargs, "string copy has 5 arguments");
 1486 
 1487   Node* src         = argument(0);
 1488   Node* src_offset  = argument(1);
 1489   Node* dst         = argument(2);
 1490   Node* dst_offset  = argument(3);
 1491   Node* length      = argument(4);
 1492 
 1493   // Check for allocation before we add nodes that would confuse
 1494   // tightly_coupled_allocation()
 1495   AllocateArrayNode* alloc = tightly_coupled_allocation(dst);
 1496 
 1497   // Figure out the size and type of the elements we will be copying.
 1498   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 1499   const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr();
 1500   if (src_type == nullptr || dst_type == nullptr) {
 1501     return false;
 1502   }
 1503   BasicType src_elem = src_type->elem()->array_element_basic_type();
 1504   BasicType dst_elem = dst_type->elem()->array_element_basic_type();
 1505   assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) ||
 1506          (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)),
 1507          "Unsupported array types for inline_string_copy");
 1508 
 1509   src = must_be_not_null(src, true);
 1510   dst = must_be_not_null(dst, true);
 1511 
 1512   // Convert char[] offsets to byte[] offsets
 1513   bool convert_src = (compress && src_elem == T_BYTE);
 1514   bool convert_dst = (!compress && dst_elem == T_BYTE);
 1515   if (convert_src) {
 1516     src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1)));
 1517   } else if (convert_dst) {
 1518     dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1)));
 1519   }
 1520 
 1521   // Range checks
 1522   RegionNode* bailout = create_bailout();
 1523   generate_string_range_check(src, src_offset, length, convert_src, bailout);
 1524   generate_string_range_check(dst, dst_offset, length, convert_dst, bailout);
 1525   if (check_bailout(bailout)) {
 1526     return true;
 1527   }
 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 = nullptr;
 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 != nullptr) {
 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     }
 1549     // Do not let stores that initialize this object be reordered with
 1550     // a subsequent store that would make this object accessible by
 1551     // other threads.
 1552     // Record what AllocateNode this StoreStore protects so that
 1553     // escape analysis can go from the MemBarStoreStoreNode to the
 1554     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1555     // based on the escape status of the AllocateNode.
 1556     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1557   }
 1558   if (compress) {
 1559     set_result(_gvn.transform(count));
 1560   }
 1561   clear_upper_avx();
 1562 
 1563   return true;
 1564 }
 1565 
 1566 #ifdef _LP64
 1567 #define XTOP ,top() /*additional argument*/
 1568 #else  //_LP64
 1569 #define XTOP        /*no additional argument*/
 1570 #endif //_LP64
 1571 
 1572 //------------------------inline_string_toBytesU--------------------------
 1573 // public static byte[] StringUTF16.toBytes0(char[] value, int off, int len)
 1574 bool LibraryCallKit::inline_string_toBytesU() {
 1575   // Get the arguments.
 1576   assert(callee()->signature()->size() == 3, "character array encoder requires 3 arguments");
 1577   Node* value     = argument(0);
 1578   Node* offset    = argument(1);
 1579   Node* length    = argument(2);
 1580 
 1581   Node* newcopy = nullptr;
 1582 
 1583   // Set the original stack and the reexecute bit for the interpreter to reexecute
 1584   // the bytecode that invokes StringUTF16.toBytes0() if deoptimization happens.
 1585   { PreserveReexecuteState preexecs(this);
 1586     jvms()->set_should_reexecute(true);
 1587 
 1588     value = must_be_not_null(value, true);
 1589     RegionNode* bailout = create_bailout();
 1590     generate_negative_guard(offset, bailout, nullptr, true);
 1591     generate_negative_guard(length, bailout, nullptr, true);
 1592     generate_limit_guard(offset, length, load_array_length(value), bailout, true);
 1593     // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE
 1594     generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout, true);
 1595     if (check_bailout(bailout)) {
 1596       return true;
 1597     }
 1598 
 1599     Node* size = _gvn.transform(new LShiftINode(length, intcon(1)));
 1600     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE)));
 1601     newcopy = new_array(klass_node, size, 0);  // no arguments to push
 1602     AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy);
 1603     guarantee(alloc != nullptr, "created above");
 1604 
 1605     // Calculate starting addresses.
 1606     Node* src_start = array_element_address(value, offset, T_CHAR);
 1607     Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE));
 1608 
 1609     // Check if dst array address is aligned to HeapWordSize
 1610     bool aligned = (arrayOopDesc::base_offset_in_bytes(T_BYTE) % HeapWordSize == 0);
 1611     // If true, then check if src array address is aligned to HeapWordSize
 1612     if (aligned) {
 1613       const TypeInt* toffset = gvn().type(offset)->is_int();
 1614       aligned = toffset->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) +
 1615                                        toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
 1616     }
 1617 
 1618     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
 1619     const char* copyfunc_name = "arraycopy";
 1620     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
 1621     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 1622                       OptoRuntime::fast_arraycopy_Type(),
 1623                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
 1624                       src_start, dst_start, ConvI2X(length) XTOP);
 1625     // Do not let reads from the cloned object float above the arraycopy.
 1626     if (alloc->maybe_set_complete(&_gvn)) {
 1627       // "You break it, you buy it."
 1628       InitializeNode* init = alloc->initialization();
 1629       assert(init->is_complete(), "we just did this");
 1630       init->set_complete_with_arraycopy();
 1631       assert(newcopy->is_CheckCastPP(), "sanity");
 1632       assert(newcopy->in(0)->in(0) == init, "dest pinned");
 1633     }
 1634     // Do not let stores that initialize this object be reordered with
 1635     // a subsequent store that would make this object accessible by
 1636     // other threads.
 1637     // Record what AllocateNode this StoreStore protects so that
 1638     // escape analysis can go from the MemBarStoreStoreNode to the
 1639     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1640     // based on the escape status of the AllocateNode.
 1641     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1642   } // original reexecute is set back here
 1643 
 1644   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1645   if (!stopped()) {
 1646     set_result(newcopy);
 1647   }
 1648   clear_upper_avx();
 1649 
 1650   return true;
 1651 }
 1652 
 1653 //------------------------inline_string_getCharsU--------------------------
 1654 // public void StringUTF16.getChars0(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin)
 1655 bool LibraryCallKit::inline_string_getCharsU() {
 1656   assert(callee()->signature()->size() == 5, "StringUTF16.getChars0() has 5 arguments");
 1657   // Get the arguments.
 1658   Node* src       = argument(0);
 1659   Node* src_begin = argument(1);
 1660   Node* src_end   = argument(2); // exclusive offset (i < src_end)
 1661   Node* dst       = argument(3);
 1662   Node* dst_begin = argument(4);
 1663 
 1664   // Check for allocation before we add nodes that would confuse
 1665   // tightly_coupled_allocation()
 1666   AllocateArrayNode* alloc = tightly_coupled_allocation(dst);
 1667 
 1668   // Check if a null path was taken unconditionally.
 1669   src = must_be_not_null(src, true);
 1670   dst = must_be_not_null(dst, true);
 1671   if (stopped()) {
 1672     return true;
 1673   }
 1674 
 1675   // Get length and convert char[] offset to byte[] offset
 1676   Node* length = _gvn.transform(new SubINode(src_end, src_begin));
 1677   src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1)));
 1678 
 1679   // Range checks
 1680   RegionNode* bailout = create_bailout();
 1681   generate_string_range_check(src, src_begin, length, true, bailout);
 1682   generate_string_range_check(dst, dst_begin, length, false, bailout);
 1683   if (check_bailout(bailout)) {
 1684     return true;
 1685   }
 1686 
 1687   // Calculate starting addresses.
 1688   Node* src_start = array_element_address(src, src_begin, T_BYTE);
 1689   Node* dst_start = array_element_address(dst, dst_begin, T_CHAR);
 1690 
 1691   // Check if array addresses are aligned to HeapWordSize
 1692   const TypeInt* tsrc = gvn().type(src_begin)->is_int();
 1693   const TypeInt* tdst = gvn().type(dst_begin)->is_int();
 1694   bool aligned = tsrc->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_BYTE) + tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) &&
 1695                  tdst->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) + tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
 1696 
 1697   // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
 1698   const char* copyfunc_name = "arraycopy";
 1699   address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
 1700   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 1701                     OptoRuntime::fast_arraycopy_Type(),
 1702                     copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
 1703                     src_start, dst_start, ConvI2X(length) XTOP);
 1704   // Do not let reads from the cloned object float above the arraycopy.
 1705   if (alloc != nullptr) {
 1706     if (alloc->maybe_set_complete(&_gvn)) {
 1707       // "You break it, you buy it."
 1708       InitializeNode* init = alloc->initialization();
 1709       assert(init->is_complete(), "we just did this");
 1710       init->set_complete_with_arraycopy();
 1711       assert(dst->is_CheckCastPP(), "sanity");
 1712       assert(dst->in(0)->in(0) == init, "dest pinned");
 1713     }
 1714     // Do not let stores that initialize this object be reordered with
 1715     // a subsequent store that would make this object accessible by
 1716     // other threads.
 1717     // Record what AllocateNode this StoreStore protects so that
 1718     // escape analysis can go from the MemBarStoreStoreNode to the
 1719     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1720     // based on the escape status of the AllocateNode.
 1721     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1722   } else {
 1723     insert_mem_bar(Op_MemBarCPUOrder);
 1724   }
 1725 
 1726   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1727   return true;
 1728 }
 1729 
 1730 //----------------------inline_string_char_access----------------------------
 1731 // Store/Load char to/from byte[] array.
 1732 // static void StringUTF16.putChar(byte[] val, int index, int c)
 1733 // static char StringUTF16.getChar(byte[] val, int index)
 1734 bool LibraryCallKit::inline_string_char_access(bool is_store) {
 1735   Node* ch;
 1736   if (is_store) {
 1737     assert(callee()->signature()->size() == 3, "StringUTF16.putChar() has 3 arguments");
 1738     ch = argument(2);
 1739   } else {
 1740     assert(callee()->signature()->size() == 2, "StringUTF16.getChar() has 2 arguments");
 1741     ch = nullptr;
 1742   }
 1743   Node* value  = argument(0);
 1744   Node* index  = argument(1);
 1745 
 1746   // This intrinsic accesses byte[] array as char[] array. Computing the offsets
 1747   // correctly requires matched array shapes.
 1748   assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE),
 1749           "sanity: byte[] and char[] bases agree");
 1750   assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2,
 1751           "sanity: byte[] and char[] scales agree");
 1752 
 1753   // Bail when getChar over constants is requested: constant folding would
 1754   // reject folding mismatched char access over byte[]. A normal inlining for getChar
 1755   // Java method would constant fold nicely instead.
 1756   if (!is_store && value->is_Con() && index->is_Con()) {
 1757     return false;
 1758   }
 1759 
 1760   // Save state and restore on bailout
 1761   SavedState old_state(this);
 1762 
 1763   value = must_be_not_null(value, true);
 1764 
 1765   Node* adr = array_element_address(value, index, T_CHAR);
 1766   if (adr->is_top()) {
 1767     return false;
 1768   }
 1769   old_state.discard();
 1770   if (is_store) {
 1771     access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED);
 1772   } else {
 1773     ch = access_load_at(value, adr, TypeAryPtr::BYTES, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD);
 1774     set_result(ch);
 1775   }
 1776   return true;
 1777 }
 1778 
 1779 
 1780 //------------------------------inline_math-----------------------------------
 1781 // public static double Math.abs(double)
 1782 // public static double Math.sqrt(double)
 1783 // public static double Math.log(double)
 1784 // public static double Math.log10(double)
 1785 // public static double Math.round(double)
 1786 bool LibraryCallKit::inline_double_math(vmIntrinsics::ID id) {
 1787   Node* arg = argument(0);
 1788   Node* n = nullptr;
 1789   switch (id) {
 1790   case vmIntrinsics::_dabs:   n = new AbsDNode(                arg);  break;
 1791   case vmIntrinsics::_dsqrt:
 1792   case vmIntrinsics::_dsqrt_strict:
 1793                               n = new SqrtDNode(C, control(),  arg);  break;
 1794   case vmIntrinsics::_ceil:   n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_ceil); break;
 1795   case vmIntrinsics::_floor:  n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_floor); break;
 1796   case vmIntrinsics::_rint:   n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_rint); break;
 1797   case vmIntrinsics::_roundD: n = new RoundDNode(arg); break;
 1798   case vmIntrinsics::_dcopySign: n = CopySignDNode::make(_gvn, arg, argument(2)); break;
 1799   case vmIntrinsics::_dsignum: n = SignumDNode::make(_gvn, arg); break;
 1800   default:  fatal_unexpected_iid(id);  break;
 1801   }
 1802   set_result(_gvn.transform(n));
 1803   return true;
 1804 }
 1805 
 1806 //------------------------------inline_math-----------------------------------
 1807 // public static float Math.abs(float)
 1808 // public static int Math.abs(int)
 1809 // public static long Math.abs(long)
 1810 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) {
 1811   Node* arg = argument(0);
 1812   Node* n = nullptr;
 1813   switch (id) {
 1814   case vmIntrinsics::_fabs:   n = new AbsFNode(                arg);  break;
 1815   case vmIntrinsics::_iabs:   n = new AbsINode(                arg);  break;
 1816   case vmIntrinsics::_labs:   n = new AbsLNode(                arg);  break;
 1817   case vmIntrinsics::_fcopySign: n = new CopySignFNode(arg, argument(1)); break;
 1818   case vmIntrinsics::_fsignum: n = SignumFNode::make(_gvn, arg); break;
 1819   case vmIntrinsics::_roundF: n = new RoundFNode(arg); break;
 1820   default:  fatal_unexpected_iid(id);  break;
 1821   }
 1822   set_result(_gvn.transform(n));
 1823   return true;
 1824 }
 1825 
 1826 //------------------------------runtime_math-----------------------------
 1827 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
 1828   assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(),
 1829          "must be (DD)D or (D)D type");
 1830 
 1831   // Inputs
 1832   Node* a = argument(0);
 1833   Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? argument(2) : nullptr;
 1834 
 1835   const TypePtr* no_memory_effects = nullptr;
 1836   Node* trig = make_runtime_call(RC_LEAF | RC_PURE, call_type, funcAddr, funcName,
 1837                                  no_memory_effects,
 1838                                  a, top(), b, b ? top() : nullptr);
 1839   Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0));
 1840 #ifdef ASSERT
 1841   Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1));
 1842   assert(value_top == top(), "second value must be top");
 1843 #endif
 1844 
 1845   set_result(value);
 1846   return true;
 1847 }
 1848 
 1849 //------------------------------inline_math_pow-----------------------------
 1850 bool LibraryCallKit::inline_math_pow() {
 1851   Node* base = argument(0);
 1852   Node* exp = argument(2);
 1853 
 1854   CallNode* pow = new PowDNode(C, base, exp);
 1855   set_predefined_input_for_runtime_call(pow);
 1856   pow = _gvn.transform(pow)->as_CallLeafPure();
 1857   set_predefined_output_for_runtime_call(pow);
 1858   Node* result = _gvn.transform(new ProjNode(pow, TypeFunc::Parms + 0));
 1859   record_for_igvn(pow);
 1860   set_result(result);
 1861   return true;
 1862 }
 1863 
 1864 //------------------------------inline_math_native-----------------------------
 1865 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
 1866   switch (id) {
 1867   case vmIntrinsics::_dsin:
 1868     return StubRoutines::dsin() != nullptr ?
 1869       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") :
 1870       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin),   "SIN");
 1871   case vmIntrinsics::_dcos:
 1872     return StubRoutines::dcos() != nullptr ?
 1873       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") :
 1874       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos),   "COS");
 1875   case vmIntrinsics::_dtan:
 1876     return StubRoutines::dtan() != nullptr ?
 1877       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") :
 1878       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN");
 1879   case vmIntrinsics::_dsinh:
 1880     return StubRoutines::dsinh() != nullptr ?
 1881       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsinh(), "dsinh") : false;
 1882   case vmIntrinsics::_dtanh:
 1883     return StubRoutines::dtanh() != nullptr ?
 1884       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtanh(), "dtanh") : false;
 1885   case vmIntrinsics::_dcbrt:
 1886     return StubRoutines::dcbrt() != nullptr ?
 1887       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcbrt(), "dcbrt") : false;
 1888   case vmIntrinsics::_dexp:
 1889     return StubRoutines::dexp() != nullptr ?
 1890       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(),  "dexp") :
 1891       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp),  "EXP");
 1892   case vmIntrinsics::_dlog:
 1893     return StubRoutines::dlog() != nullptr ?
 1894       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") :
 1895       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog),   "LOG");
 1896   case vmIntrinsics::_dlog10:
 1897     return StubRoutines::dlog10() != nullptr ?
 1898       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") :
 1899       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10");
 1900 
 1901   case vmIntrinsics::_roundD: return Matcher::match_rule_supported(Op_RoundD) ? inline_double_math(id) : false;
 1902   case vmIntrinsics::_ceil:
 1903   case vmIntrinsics::_floor:
 1904   case vmIntrinsics::_rint:   return Matcher::match_rule_supported(Op_RoundDoubleMode) ? inline_double_math(id) : false;
 1905 
 1906   case vmIntrinsics::_dsqrt:
 1907   case vmIntrinsics::_dsqrt_strict:
 1908                               return Matcher::match_rule_supported(Op_SqrtD) ? inline_double_math(id) : false;
 1909   case vmIntrinsics::_dabs:   return Matcher::has_match_rule(Op_AbsD)   ? inline_double_math(id) : false;
 1910   case vmIntrinsics::_fabs:   return Matcher::match_rule_supported(Op_AbsF)   ? inline_math(id) : false;
 1911   case vmIntrinsics::_iabs:   return Matcher::match_rule_supported(Op_AbsI)   ? inline_math(id) : false;
 1912   case vmIntrinsics::_labs:   return Matcher::match_rule_supported(Op_AbsL)   ? inline_math(id) : false;
 1913 
 1914   case vmIntrinsics::_dpow:      return inline_math_pow();
 1915   case vmIntrinsics::_dcopySign: return inline_double_math(id);
 1916   case vmIntrinsics::_fcopySign: return inline_math(id);
 1917   case vmIntrinsics::_dsignum: return Matcher::match_rule_supported(Op_SignumD) ? inline_double_math(id) : false;
 1918   case vmIntrinsics::_fsignum: return Matcher::match_rule_supported(Op_SignumF) ? inline_math(id) : false;
 1919   case vmIntrinsics::_roundF: return Matcher::match_rule_supported(Op_RoundF) ? inline_math(id) : false;
 1920 
 1921    // These intrinsics are not yet correctly implemented
 1922   case vmIntrinsics::_datan2:
 1923     return false;
 1924 
 1925   default:
 1926     fatal_unexpected_iid(id);
 1927     return false;
 1928   }
 1929 }
 1930 
 1931 //----------------------------inline_notify-----------------------------------*
 1932 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) {
 1933   const TypeFunc* ftype = OptoRuntime::monitor_notify_Type();
 1934   address func;
 1935   if (id == vmIntrinsics::_notify) {
 1936     func = OptoRuntime::monitor_notify_Java();
 1937   } else {
 1938     func = OptoRuntime::monitor_notifyAll_Java();
 1939   }
 1940   Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, nullptr, TypeRawPtr::BOTTOM, argument(0));
 1941   make_slow_call_ex(call, env()->Throwable_klass(), false);
 1942   return true;
 1943 }
 1944 
 1945 
 1946 //----------------------------inline_min_max-----------------------------------
 1947 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
 1948   Node* a = nullptr;
 1949   Node* b = nullptr;
 1950   Node* n = nullptr;
 1951   switch (id) {
 1952     case vmIntrinsics::_min:
 1953     case vmIntrinsics::_max:
 1954     case vmIntrinsics::_minF:
 1955     case vmIntrinsics::_maxF:
 1956     case vmIntrinsics::_minF_strict:
 1957     case vmIntrinsics::_maxF_strict:
 1958     case vmIntrinsics::_min_strict:
 1959     case vmIntrinsics::_max_strict:
 1960       assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each.");
 1961       a = argument(0);
 1962       b = argument(1);
 1963       break;
 1964     case vmIntrinsics::_minD:
 1965     case vmIntrinsics::_maxD:
 1966     case vmIntrinsics::_minD_strict:
 1967     case vmIntrinsics::_maxD_strict:
 1968       assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each.");
 1969       a = argument(0);
 1970       b = argument(2);
 1971       break;
 1972     case vmIntrinsics::_minL:
 1973     case vmIntrinsics::_maxL:
 1974       assert(callee()->signature()->size() == 4, "minL/maxL has 2 parameters of size 2 each.");
 1975       a = argument(0);
 1976       b = argument(2);
 1977       break;
 1978     default:
 1979       fatal_unexpected_iid(id);
 1980       break;
 1981   }
 1982 
 1983   switch (id) {
 1984     case vmIntrinsics::_min:
 1985     case vmIntrinsics::_min_strict:
 1986       n = new MinINode(a, b);
 1987       break;
 1988     case vmIntrinsics::_max:
 1989     case vmIntrinsics::_max_strict:
 1990       n = new MaxINode(a, b);
 1991       break;
 1992     case vmIntrinsics::_minF:
 1993     case vmIntrinsics::_minF_strict:
 1994       n = new MinFNode(a, b);
 1995       break;
 1996     case vmIntrinsics::_maxF:
 1997     case vmIntrinsics::_maxF_strict:
 1998       n = new MaxFNode(a, b);
 1999       break;
 2000     case vmIntrinsics::_minD:
 2001     case vmIntrinsics::_minD_strict:
 2002       n = new MinDNode(a, b);
 2003       break;
 2004     case vmIntrinsics::_maxD:
 2005     case vmIntrinsics::_maxD_strict:
 2006       n = new MaxDNode(a, b);
 2007       break;
 2008     case vmIntrinsics::_minL:
 2009       n = new MinLNode(_gvn.C, a, b);
 2010       break;
 2011     case vmIntrinsics::_maxL:
 2012       n = new MaxLNode(_gvn.C, a, b);
 2013       break;
 2014     default:
 2015       fatal_unexpected_iid(id);
 2016       break;
 2017   }
 2018 
 2019   set_result(_gvn.transform(n));
 2020   return true;
 2021 }
 2022 
 2023 bool LibraryCallKit::inline_math_mathExact(Node* math, Node* test) {
 2024   if (builtin_throw_too_many_traps(Deoptimization::Reason_intrinsic,
 2025                                    env()->ArithmeticException_instance())) {
 2026     // It has been already too many times, but we cannot use builtin_throw (e.g. we care about backtraces),
 2027     // so let's bail out intrinsic rather than risking deopting again.
 2028     return false;
 2029   }
 2030 
 2031   Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) );
 2032   IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
 2033   Node* fast_path = _gvn.transform( new IfFalseNode(check));
 2034   Node* slow_path = _gvn.transform( new IfTrueNode(check) );
 2035 
 2036   {
 2037     PreserveJVMState pjvms(this);
 2038     PreserveReexecuteState preexecs(this);
 2039     jvms()->set_should_reexecute(true);
 2040 
 2041     set_control(slow_path);
 2042     set_i_o(i_o());
 2043 
 2044     builtin_throw(Deoptimization::Reason_intrinsic,
 2045                   env()->ArithmeticException_instance(),
 2046                   /*allow_too_many_traps*/ false);
 2047   }
 2048 
 2049   set_control(fast_path);
 2050   set_result(math);
 2051   return true;
 2052 }
 2053 
 2054 template <typename OverflowOp>
 2055 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) {
 2056   typedef typename OverflowOp::MathOp MathOp;
 2057 
 2058   MathOp* mathOp = new MathOp(arg1, arg2);
 2059   Node* operation = _gvn.transform( mathOp );
 2060   Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) );
 2061   return inline_math_mathExact(operation, ofcheck);
 2062 }
 2063 
 2064 bool LibraryCallKit::inline_math_addExactI(bool is_increment) {
 2065   return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1));
 2066 }
 2067 
 2068 bool LibraryCallKit::inline_math_addExactL(bool is_increment) {
 2069   return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2));
 2070 }
 2071 
 2072 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) {
 2073   return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1));
 2074 }
 2075 
 2076 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) {
 2077   return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2));
 2078 }
 2079 
 2080 bool LibraryCallKit::inline_math_negateExactI() {
 2081   return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0));
 2082 }
 2083 
 2084 bool LibraryCallKit::inline_math_negateExactL() {
 2085   return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0));
 2086 }
 2087 
 2088 bool LibraryCallKit::inline_math_multiplyExactI() {
 2089   return inline_math_overflow<OverflowMulINode>(argument(0), argument(1));
 2090 }
 2091 
 2092 bool LibraryCallKit::inline_math_multiplyExactL() {
 2093   return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2));
 2094 }
 2095 
 2096 bool LibraryCallKit::inline_math_multiplyHigh() {
 2097   set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2))));
 2098   return true;
 2099 }
 2100 
 2101 bool LibraryCallKit::inline_math_unsignedMultiplyHigh() {
 2102   set_result(_gvn.transform(new UMulHiLNode(argument(0), argument(2))));
 2103   return true;
 2104 }
 2105 
 2106 inline int
 2107 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) {
 2108   const TypePtr* base_type = TypePtr::NULL_PTR;
 2109   if (base != nullptr)  base_type = _gvn.type(base)->isa_ptr();
 2110   if (base_type == nullptr) {
 2111     // Unknown type.
 2112     return Type::AnyPtr;
 2113   } else if (_gvn.type(base->uncast()) == TypePtr::NULL_PTR) {
 2114     // Since this is a null+long form, we have to switch to a rawptr.
 2115     base   = _gvn.transform(new CastX2PNode(offset));
 2116     offset = MakeConX(0);
 2117     return Type::RawPtr;
 2118   } else if (base_type->base() == Type::RawPtr) {
 2119     return Type::RawPtr;
 2120   } else if (base_type->isa_oopptr()) {
 2121     // Base is never null => always a heap address.
 2122     if (!TypePtr::NULL_PTR->higher_equal(base_type)) {
 2123       return Type::OopPtr;
 2124     }
 2125     // Offset is small => always a heap address.
 2126     const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
 2127     if (offset_type != nullptr &&
 2128         base_type->offset() == 0 &&     // (should always be?)
 2129         offset_type->_lo >= 0 &&
 2130         !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
 2131       return Type::OopPtr;
 2132     } else if (type == T_OBJECT) {
 2133       // off heap access to an oop doesn't make any sense. Has to be on
 2134       // heap.
 2135       return Type::OopPtr;
 2136     }
 2137     // Otherwise, it might either be oop+off or null+addr.
 2138     return Type::AnyPtr;
 2139   } else {
 2140     // No information:
 2141     return Type::AnyPtr;
 2142   }
 2143 }
 2144 
 2145 Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, BasicType type, bool can_cast) {
 2146   Node* uncasted_base = base;
 2147   int kind = classify_unsafe_addr(uncasted_base, offset, type);
 2148   if (kind == Type::RawPtr) {
 2149     return off_heap_plus_addr(uncasted_base, offset);
 2150   } else if (kind == Type::AnyPtr) {
 2151     assert(base == uncasted_base, "unexpected base change");
 2152     if (can_cast) {
 2153       if (!_gvn.type(base)->speculative_maybe_null() &&
 2154           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
 2155         // According to profiling, this access is always on
 2156         // heap. Casting the base to not null and thus avoiding membars
 2157         // around the access should allow better optimizations
 2158         Node* null_ctl = top();
 2159         base = null_check_oop(base, &null_ctl, true, true, true);
 2160         assert(null_ctl->is_top(), "no null control here");
 2161         return basic_plus_adr(base, offset);
 2162       } else if (_gvn.type(base)->speculative_always_null() &&
 2163                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
 2164         // According to profiling, this access is always off
 2165         // heap.
 2166         base = null_assert(base);
 2167         Node* raw_base = _gvn.transform(new CastX2PNode(offset));
 2168         offset = MakeConX(0);
 2169         return off_heap_plus_addr(raw_base, offset);
 2170       }
 2171     }
 2172     // We don't know if it's an on heap or off heap access. Fall back
 2173     // to raw memory access.
 2174     Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM));
 2175     return off_heap_plus_addr(raw, offset);
 2176   } else {
 2177     assert(base == uncasted_base, "unexpected base change");
 2178     // We know it's an on heap access so base can't be null
 2179     if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) {
 2180       base = must_be_not_null(base, true);
 2181     }
 2182     return basic_plus_adr(base, offset);
 2183   }
 2184 }
 2185 
 2186 //--------------------------inline_number_methods-----------------------------
 2187 // inline int     Integer.numberOfLeadingZeros(int)
 2188 // inline int        Long.numberOfLeadingZeros(long)
 2189 //
 2190 // inline int     Integer.numberOfTrailingZeros(int)
 2191 // inline int        Long.numberOfTrailingZeros(long)
 2192 //
 2193 // inline int     Integer.bitCount(int)
 2194 // inline int        Long.bitCount(long)
 2195 //
 2196 // inline char  Character.reverseBytes(char)
 2197 // inline short     Short.reverseBytes(short)
 2198 // inline int     Integer.reverseBytes(int)
 2199 // inline long       Long.reverseBytes(long)
 2200 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) {
 2201   Node* arg = argument(0);
 2202   Node* n = nullptr;
 2203   switch (id) {
 2204   case vmIntrinsics::_numberOfLeadingZeros_i:   n = new CountLeadingZerosINode( arg); break;
 2205   case vmIntrinsics::_numberOfLeadingZeros_l:   n = new CountLeadingZerosLNode( arg); break;
 2206   case vmIntrinsics::_numberOfTrailingZeros_i:  n = new CountTrailingZerosINode(arg); break;
 2207   case vmIntrinsics::_numberOfTrailingZeros_l:  n = new CountTrailingZerosLNode(arg); break;
 2208   case vmIntrinsics::_bitCount_i:               n = new PopCountINode(          arg); break;
 2209   case vmIntrinsics::_bitCount_l:               n = new PopCountLNode(          arg); break;
 2210   case vmIntrinsics::_reverseBytes_c:           n = new ReverseBytesUSNode(     arg); break;
 2211   case vmIntrinsics::_reverseBytes_s:           n = new ReverseBytesSNode(      arg); break;
 2212   case vmIntrinsics::_reverseBytes_i:           n = new ReverseBytesINode(      arg); break;
 2213   case vmIntrinsics::_reverseBytes_l:           n = new ReverseBytesLNode(      arg); break;
 2214   case vmIntrinsics::_reverse_i:                n = new ReverseINode(           arg); break;
 2215   case vmIntrinsics::_reverse_l:                n = new ReverseLNode(           arg); break;
 2216   default:  fatal_unexpected_iid(id);  break;
 2217   }
 2218   set_result(_gvn.transform(n));
 2219   return true;
 2220 }
 2221 
 2222 //--------------------------inline_bitshuffle_methods-----------------------------
 2223 // inline int Integer.compress(int, int)
 2224 // inline int Integer.expand(int, int)
 2225 // inline long Long.compress(long, long)
 2226 // inline long Long.expand(long, long)
 2227 bool LibraryCallKit::inline_bitshuffle_methods(vmIntrinsics::ID id) {
 2228   Node* n = nullptr;
 2229   switch (id) {
 2230     case vmIntrinsics::_compress_i:  n = new CompressBitsNode(argument(0), argument(1), TypeInt::INT); break;
 2231     case vmIntrinsics::_expand_i:    n = new ExpandBitsNode(argument(0),  argument(1), TypeInt::INT); break;
 2232     case vmIntrinsics::_compress_l:  n = new CompressBitsNode(argument(0), argument(2), TypeLong::LONG); break;
 2233     case vmIntrinsics::_expand_l:    n = new ExpandBitsNode(argument(0), argument(2), TypeLong::LONG); break;
 2234     default:  fatal_unexpected_iid(id);  break;
 2235   }
 2236   set_result(_gvn.transform(n));
 2237   return true;
 2238 }
 2239 
 2240 //--------------------------inline_number_methods-----------------------------
 2241 // inline int Integer.compareUnsigned(int, int)
 2242 // inline int    Long.compareUnsigned(long, long)
 2243 bool LibraryCallKit::inline_compare_unsigned(vmIntrinsics::ID id) {
 2244   Node* arg1 = argument(0);
 2245   Node* arg2 = (id == vmIntrinsics::_compareUnsigned_l) ? argument(2) : argument(1);
 2246   Node* n = nullptr;
 2247   switch (id) {
 2248     case vmIntrinsics::_compareUnsigned_i:   n = new CmpU3Node(arg1, arg2);  break;
 2249     case vmIntrinsics::_compareUnsigned_l:   n = new CmpUL3Node(arg1, arg2); break;
 2250     default:  fatal_unexpected_iid(id);  break;
 2251   }
 2252   set_result(_gvn.transform(n));
 2253   return true;
 2254 }
 2255 
 2256 //--------------------------inline_unsigned_divmod_methods-----------------------------
 2257 // inline int Integer.divideUnsigned(int, int)
 2258 // inline int Integer.remainderUnsigned(int, int)
 2259 // inline long Long.divideUnsigned(long, long)
 2260 // inline long Long.remainderUnsigned(long, long)
 2261 bool LibraryCallKit::inline_divmod_methods(vmIntrinsics::ID id) {
 2262   Node* n = nullptr;
 2263   switch (id) {
 2264     case vmIntrinsics::_divideUnsigned_i: {
 2265       zero_check_int(argument(1));
 2266       // Compile-time detect of null-exception
 2267       if (stopped()) {
 2268         return true; // keep the graph constructed so far
 2269       }
 2270       n = new UDivINode(control(), argument(0), argument(1));
 2271       break;
 2272     }
 2273     case vmIntrinsics::_divideUnsigned_l: {
 2274       zero_check_long(argument(2));
 2275       // Compile-time detect of null-exception
 2276       if (stopped()) {
 2277         return true; // keep the graph constructed so far
 2278       }
 2279       n = new UDivLNode(control(), argument(0), argument(2));
 2280       break;
 2281     }
 2282     case vmIntrinsics::_remainderUnsigned_i: {
 2283       zero_check_int(argument(1));
 2284       // Compile-time detect of null-exception
 2285       if (stopped()) {
 2286         return true; // keep the graph constructed so far
 2287       }
 2288       n = new UModINode(control(), argument(0), argument(1));
 2289       break;
 2290     }
 2291     case vmIntrinsics::_remainderUnsigned_l: {
 2292       zero_check_long(argument(2));
 2293       // Compile-time detect of null-exception
 2294       if (stopped()) {
 2295         return true; // keep the graph constructed so far
 2296       }
 2297       n = new UModLNode(control(), argument(0), argument(2));
 2298       break;
 2299     }
 2300     default:  fatal_unexpected_iid(id);  break;
 2301   }
 2302   set_result(_gvn.transform(n));
 2303   return true;
 2304 }
 2305 
 2306 //----------------------------inline_unsafe_access----------------------------
 2307 
 2308 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
 2309   // Attempt to infer a sharper value type from the offset and base type.
 2310   ciKlass* sharpened_klass = nullptr;
 2311   bool null_free = false;
 2312 
 2313   // See if it is an instance field, with an object type.
 2314   if (alias_type->field() != nullptr) {
 2315     if (alias_type->field()->type()->is_klass()) {
 2316       sharpened_klass = alias_type->field()->type()->as_klass();
 2317       null_free = alias_type->field()->is_null_free();
 2318     }
 2319   }
 2320 
 2321   const TypeOopPtr* result = nullptr;
 2322   // See if it is a narrow oop array.
 2323   if (adr_type->isa_aryptr()) {
 2324     if (adr_type->offset() >= refArrayOopDesc::base_offset_in_bytes()) {
 2325       const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr();
 2326       null_free = adr_type->is_aryptr()->is_null_free();
 2327       if (elem_type != nullptr && elem_type->is_loaded()) {
 2328         // Sharpen the value type.
 2329         result = elem_type;
 2330       }
 2331     }
 2332   }
 2333 
 2334   // The sharpened class might be unloaded if there is no class loader
 2335   // contraint in place.
 2336   if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) {
 2337     // Sharpen the value type.
 2338     result = TypeOopPtr::make_from_klass(sharpened_klass);
 2339     if (null_free) {
 2340       result = result->join_speculative(TypePtr::NOTNULL)->is_oopptr();
 2341     }
 2342   }
 2343   if (result != nullptr) {
 2344 #ifndef PRODUCT
 2345     if (C->print_intrinsics() || C->print_inlining()) {
 2346       tty->print("  from base type:  ");  adr_type->dump(); tty->cr();
 2347       tty->print("  sharpened value: ");  result->dump();    tty->cr();
 2348     }
 2349 #endif
 2350   }
 2351   return result;
 2352 }
 2353 
 2354 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) {
 2355   switch (kind) {
 2356       case Relaxed:
 2357         return MO_UNORDERED;
 2358       case Opaque:
 2359         return MO_RELAXED;
 2360       case Acquire:
 2361         return MO_ACQUIRE;
 2362       case Release:
 2363         return MO_RELEASE;
 2364       case Volatile:
 2365         return MO_SEQ_CST;
 2366       default:
 2367         ShouldNotReachHere();
 2368         return 0;
 2369   }
 2370 }
 2371 
 2372 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) {
 2373   if (callee()->is_static())  return false;  // caller must have the capability!
 2374   DecoratorSet decorators = C2_UNSAFE_ACCESS;
 2375   guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads");
 2376   guarantee( is_store || kind != Release, "Release accesses can be produced only for stores");
 2377   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
 2378 
 2379   if (is_reference_type(type)) {
 2380     decorators |= ON_UNKNOWN_OOP_REF;
 2381   }
 2382 
 2383   if (unaligned) {
 2384     decorators |= C2_UNALIGNED;
 2385   }
 2386 
 2387 #ifndef PRODUCT
 2388   {
 2389     ResourceMark rm;
 2390     // Check the signatures.
 2391     ciSignature* sig = callee()->signature();
 2392 #ifdef ASSERT
 2393     if (!is_store) {
 2394       // Object getReference(Object base, int/long offset), etc.
 2395       BasicType rtype = sig->return_type()->basic_type();
 2396       assert(rtype == type, "getter must return the expected value");
 2397       assert(sig->count() == 2, "oop getter has 2 arguments");
 2398       assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
 2399       assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
 2400     } else {
 2401       // void putReference(Object base, int/long offset, Object x), etc.
 2402       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
 2403       assert(sig->count() == 3, "oop putter has 3 arguments");
 2404       assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
 2405       assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
 2406       BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
 2407       assert(vtype == type, "putter must accept the expected value");
 2408     }
 2409 #endif // ASSERT
 2410  }
 2411 #endif //PRODUCT
 2412 
 2413   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 2414 
 2415   Node* receiver = argument(0);  // type: oop
 2416 
 2417   // Build address expression.
 2418   Node* heap_base_oop = top();
 2419 
 2420   // The base is either a Java object or a value produced by Unsafe.staticFieldBase
 2421   Node* base = argument(1);  // type: oop
 2422   // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
 2423   Node* offset = argument(2);  // type: long
 2424   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
 2425   // to be plain byte offsets, which are also the same as those accepted
 2426   // by oopDesc::field_addr.
 2427   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 2428          "fieldOffset must be byte-scaled");
 2429 
 2430   if (base->is_InlineType()) {
 2431     assert(!is_store, "InlineTypeNodes are non-larval value objects");
 2432     InlineTypeNode* vt = base->as_InlineType();
 2433     if (offset->is_Con()) {
 2434       long off = find_long_con(offset, 0);
 2435       ciInlineKlass* vk = vt->type()->inline_klass();
 2436       if ((long)(int)off != off || !vk->contains_field_offset(off)) {
 2437         return false;
 2438       }
 2439 
 2440       ciField* field = vk->get_non_flat_field_by_offset(off);
 2441       if (field != nullptr) {
 2442         BasicType bt = type2field[field->type()->basic_type()];
 2443         if (bt == T_ARRAY || bt == T_NARROWOOP) {
 2444           bt = T_OBJECT;
 2445         }
 2446         if (bt == type && !field->is_flat()) {
 2447           Node* value = vt->field_value_by_offset(off, false);
 2448           const Type* value_type = _gvn.type(value);
 2449           if (value_type->is_inlinetypeptr()) {
 2450             value = InlineTypeNode::make_from_oop(this, value, value_type->inline_klass());
 2451           }
 2452           set_result(value);
 2453           return true;
 2454         }
 2455       }
 2456     }
 2457     {
 2458       // Re-execute the unsafe access if allocation triggers deoptimization.
 2459       PreserveReexecuteState preexecs(this);
 2460       jvms()->set_should_reexecute(true);
 2461       vt = vt->buffer(this);
 2462     }
 2463     base = vt->get_oop();
 2464   }
 2465 
 2466   // 32-bit machines ignore the high half!
 2467   offset = ConvL2X(offset);
 2468 
 2469   // Save state and restore on bailout
 2470   SavedState old_state(this);
 2471 
 2472   Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed);
 2473   assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly");
 2474 
 2475   if (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR) {
 2476     if (type != T_OBJECT) {
 2477       decorators |= IN_NATIVE; // off-heap primitive access
 2478     } else {
 2479       return false; // off-heap oop accesses are not supported
 2480     }
 2481   } else {
 2482     heap_base_oop = base; // on-heap or mixed access
 2483   }
 2484 
 2485   // Can base be null? Otherwise, always on-heap access.
 2486   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base));
 2487 
 2488   if (!can_access_non_heap) {
 2489     decorators |= IN_HEAP;
 2490   }
 2491 
 2492   Node* val = is_store ? argument(4) : nullptr;
 2493 
 2494   const TypePtr* adr_type = _gvn.type(adr)->isa_ptr();
 2495   if (adr_type == TypePtr::NULL_PTR) {
 2496     return false; // off-heap access with zero address
 2497   }
 2498 
 2499   // Try to categorize the address.
 2500   Compile::AliasType* alias_type = C->alias_type(adr_type);
 2501   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
 2502 
 2503   if (alias_type->adr_type() == TypeInstPtr::KLASS ||
 2504       alias_type->adr_type() == TypeAryPtr::RANGE) {
 2505     return false; // not supported
 2506   }
 2507 
 2508   bool mismatched = false;
 2509   BasicType bt = T_ILLEGAL;
 2510   ciField* field = nullptr;
 2511   if (adr_type->isa_instptr()) {
 2512     const TypeInstPtr* instptr = adr_type->is_instptr();
 2513     ciInstanceKlass* k = instptr->instance_klass();
 2514     int off = instptr->offset();
 2515     if (instptr->const_oop() != nullptr &&
 2516         k == ciEnv::current()->Class_klass() &&
 2517         instptr->offset() >= (k->size_helper() * wordSize)) {
 2518       k = instptr->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
 2519       field = k->get_field_by_offset(off, true);
 2520     } else {
 2521       field = k->get_non_flat_field_by_offset(off);
 2522     }
 2523     if (field != nullptr) {
 2524       bt = type2field[field->type()->basic_type()];
 2525     }
 2526     if (bt != alias_type->basic_type()) {
 2527       // Type mismatch. Is it an access to a nested flat field?
 2528       field = k->get_field_by_offset(off, false);
 2529       if (field != nullptr) {
 2530         bt = type2field[field->type()->basic_type()];
 2531       }
 2532     }
 2533     assert(bt == alias_type->basic_type(), "should match");
 2534   } else {
 2535     bt = alias_type->basic_type();
 2536   }
 2537 
 2538   if (bt != T_ILLEGAL) {
 2539     assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
 2540     if (bt == T_BYTE && adr_type->isa_aryptr()) {
 2541       // Alias type doesn't differentiate between byte[] and boolean[]).
 2542       // Use address type to get the element type.
 2543       bt = adr_type->is_aryptr()->elem()->array_element_basic_type();
 2544     }
 2545     if (is_reference_type(bt, true)) {
 2546       // accessing an array field with getReference is not a mismatch
 2547       bt = T_OBJECT;
 2548     }
 2549     if ((bt == T_OBJECT) != (type == T_OBJECT)) {
 2550       // Don't intrinsify mismatched object accesses
 2551       return false;
 2552     }
 2553     mismatched = (bt != type);
 2554   } else if (alias_type->adr_type()->isa_oopptr()) {
 2555     mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
 2556   }
 2557 
 2558   old_state.discard();
 2559   assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched");
 2560 
 2561   if (mismatched) {
 2562     decorators |= C2_MISMATCHED;
 2563   }
 2564 
 2565   // First guess at the value type.
 2566   const Type *value_type = Type::get_const_basic_type(type);
 2567 
 2568   // Figure out the memory ordering.
 2569   decorators |= mo_decorator_for_access_kind(kind);
 2570 
 2571   if (!is_store) {
 2572     if (type == T_OBJECT) {
 2573       const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
 2574       if (tjp != nullptr) {
 2575         value_type = tjp;
 2576       }
 2577     }
 2578   }
 2579 
 2580   receiver = null_check(receiver);
 2581   if (stopped()) {
 2582     return true;
 2583   }
 2584   // Heap pointers get a null-check from the interpreter,
 2585   // as a courtesy.  However, this is not guaranteed by Unsafe,
 2586   // and it is not possible to fully distinguish unintended nulls
 2587   // from intended ones in this API.
 2588 
 2589   if (!is_store) {
 2590     Node* p = nullptr;
 2591     // Try to constant fold a load from a constant field
 2592 
 2593     if (heap_base_oop != top() && field != nullptr && field->is_constant() && !field->is_flat() && !mismatched) {
 2594       // final or stable field
 2595       p = make_constant_from_field(field, heap_base_oop);
 2596     }
 2597 
 2598     if (p == nullptr) { // Could not constant fold the load
 2599       p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators);
 2600       const TypeOopPtr* ptr = value_type->make_oopptr();
 2601       if (ptr != nullptr && ptr->is_inlinetypeptr()) {
 2602         // Load a non-flattened inline type from memory
 2603         p = InlineTypeNode::make_from_oop(this, p, ptr->inline_klass());
 2604       }
 2605       // Normalize the value returned by getBoolean in the following cases
 2606       if (type == T_BOOLEAN &&
 2607           (mismatched ||
 2608            heap_base_oop == top() ||                  // - heap_base_oop is null or
 2609            (can_access_non_heap && field == nullptr)) // - heap_base_oop is potentially null
 2610                                                       //   and the unsafe access is made to large offset
 2611                                                       //   (i.e., larger than the maximum offset necessary for any
 2612                                                       //   field access)
 2613             ) {
 2614           IdealKit ideal = IdealKit(this);
 2615 #define __ ideal.
 2616           IdealVariable normalized_result(ideal);
 2617           __ declarations_done();
 2618           __ set(normalized_result, p);
 2619           __ if_then(p, BoolTest::ne, ideal.ConI(0));
 2620           __ set(normalized_result, ideal.ConI(1));
 2621           ideal.end_if();
 2622           final_sync(ideal);
 2623           p = __ value(normalized_result);
 2624 #undef __
 2625       }
 2626     }
 2627     if (type == T_ADDRESS) {
 2628       p = gvn().transform(new CastP2XNode(nullptr, p));
 2629       p = ConvX2UL(p);
 2630     }
 2631     // The load node has the control of the preceding MemBarCPUOrder.  All
 2632     // following nodes will have the control of the MemBarCPUOrder inserted at
 2633     // the end of this method.  So, pushing the load onto the stack at a later
 2634     // point is fine.
 2635     set_result(p);
 2636   } else {
 2637     if (bt == T_ADDRESS) {
 2638       // Repackage the long as a pointer.
 2639       val = ConvL2X(val);
 2640       val = gvn().transform(new CastX2PNode(val));
 2641     }
 2642     access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators);
 2643   }
 2644 
 2645   return true;
 2646 }
 2647 
 2648 bool LibraryCallKit::inline_unsafe_flat_access(bool is_store, AccessKind kind) {
 2649 #ifdef ASSERT
 2650   {
 2651     ResourceMark rm;
 2652     // Check the signatures.
 2653     ciSignature* sig = callee()->signature();
 2654     assert(sig->type_at(0)->basic_type() == T_OBJECT, "base should be object, but is %s", type2name(sig->type_at(0)->basic_type()));
 2655     assert(sig->type_at(1)->basic_type() == T_LONG, "offset should be long, but is %s", type2name(sig->type_at(1)->basic_type()));
 2656     assert(sig->type_at(2)->basic_type() == T_INT, "layout kind should be int, but is %s", type2name(sig->type_at(3)->basic_type()));
 2657     assert(sig->type_at(3)->basic_type() == T_OBJECT, "value klass should be object, but is %s", type2name(sig->type_at(4)->basic_type()));
 2658     if (is_store) {
 2659       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value, but returns %s", type2name(sig->return_type()->basic_type()));
 2660       assert(sig->count() == 5, "flat putter should have 5 arguments, but has %d", sig->count());
 2661       assert(sig->type_at(4)->basic_type() == T_OBJECT, "put value should be object, but is %s", type2name(sig->type_at(5)->basic_type()));
 2662     } else {
 2663       assert(sig->return_type()->basic_type() == T_OBJECT, "getter must return an object, but returns %s", type2name(sig->return_type()->basic_type()));
 2664       assert(sig->count() == 4, "flat getter should have 4 arguments, but has %d", sig->count());
 2665     }
 2666  }
 2667 #endif // ASSERT
 2668 
 2669   assert(kind == Relaxed, "Only plain accesses for now");
 2670   if (callee()->is_static()) {
 2671     // caller must have the capability!
 2672     return false;
 2673   }
 2674   C->set_has_unsafe_access(true);
 2675 
 2676   const TypeInstPtr* value_klass_node = _gvn.type(argument(5))->isa_instptr();
 2677   if (value_klass_node == nullptr || value_klass_node->const_oop() == nullptr) {
 2678     // parameter valueType is not a constant
 2679     return false;
 2680   }
 2681   ciType* mirror_type = value_klass_node->const_oop()->as_instance()->java_mirror_type();
 2682   if (!mirror_type->is_inlinetype()) {
 2683     // Dead code
 2684     return false;
 2685   }
 2686   ciInlineKlass* value_klass = mirror_type->as_inline_klass();
 2687 
 2688   const TypeInt* layout_type = _gvn.type(argument(4))->isa_int();
 2689   if (layout_type == nullptr || !layout_type->is_con()) {
 2690     // parameter layoutKind is not a constant
 2691     return false;
 2692   }
 2693   assert(layout_type->get_con() >= static_cast<int>(LayoutKind::REFERENCE) &&
 2694          layout_type->get_con() < static_cast<int>(LayoutKind::UNKNOWN),
 2695          "invalid layoutKind %d", layout_type->get_con());
 2696   LayoutKind layout = static_cast<LayoutKind>(layout_type->get_con());
 2697   assert(layout == LayoutKind::REFERENCE || layout == LayoutKind::NULL_FREE_NON_ATOMIC_FLAT ||
 2698          layout == LayoutKind::NULL_FREE_ATOMIC_FLAT || layout == LayoutKind::NULLABLE_ATOMIC_FLAT,
 2699          "unexpected layoutKind %d", layout_type->get_con());
 2700 
 2701   null_check(argument(0));
 2702   if (stopped()) {
 2703     return true;
 2704   }
 2705 
 2706   Node* base = must_be_not_null(argument(1), true);
 2707   Node* offset = argument(2);
 2708   const Type* base_type = _gvn.type(base);
 2709 
 2710   Node* ptr;
 2711   bool immutable_memory = false;
 2712   DecoratorSet decorators = C2_UNSAFE_ACCESS | IN_HEAP | MO_UNORDERED;
 2713   if (base_type->isa_instptr()) {
 2714     const TypeLong* offset_type = _gvn.type(offset)->isa_long();
 2715     if (offset_type == nullptr || !offset_type->is_con()) {
 2716       // Offset into a non-array should be a constant
 2717       decorators |= C2_MISMATCHED;
 2718     } else {
 2719       int offset_con = checked_cast<int>(offset_type->get_con());
 2720       ciInstanceKlass* base_klass = base_type->is_instptr()->instance_klass();
 2721       ciField* field = base_klass->get_non_flat_field_by_offset(offset_con);
 2722       if (field == nullptr) {
 2723         assert(!base_klass->is_final(), "non-existence field at offset %d of class %s", offset_con, base_klass->name()->as_utf8());
 2724         decorators |= C2_MISMATCHED;
 2725       } else {
 2726         assert(field->type() == value_klass, "field at offset %d of %s is of type %s, but valueType is %s",
 2727                offset_con, base_klass->name()->as_utf8(), field->type()->name(), value_klass->name()->as_utf8());
 2728         immutable_memory = field->is_strict() && field->is_final();
 2729 
 2730         if (base->is_InlineType()) {
 2731           assert(!is_store, "Cannot store into a non-larval value object");
 2732           set_result(base->as_InlineType()->field_value_by_offset(offset_con, false));
 2733           return true;
 2734         }
 2735       }
 2736     }
 2737 
 2738     if (base->is_InlineType()) {
 2739       assert(!is_store, "Cannot store into a non-larval value object");
 2740       base = base->as_InlineType()->buffer(this, true);
 2741     }
 2742     ptr = basic_plus_adr(base, ConvL2X(offset));
 2743   } else if (base_type->isa_aryptr()) {
 2744     decorators |= IS_ARRAY;
 2745     if (layout == LayoutKind::REFERENCE) {
 2746       if (!base_type->is_aryptr()->is_not_flat()) {
 2747         const TypeAryPtr* array_type = base_type->is_aryptr()->cast_to_not_flat();
 2748         // TODO 8350865 This should be a CheckCastPP, can we add a test?
 2749         Node* new_base = _gvn.transform(new CastPPNode(control(), base, array_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2750         replace_in_map(base, new_base);
 2751         base = new_base;
 2752       }
 2753       ptr = basic_plus_adr(base, ConvL2X(offset));
 2754     } else {
 2755       if (UseArrayFlattening) {
 2756         // Flat array must have an exact type
 2757         bool is_null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2758         bool is_atomic = LayoutKindHelper::is_atomic_flat(layout);
 2759         Node* new_base = cast_to_flat_array_exact(base, value_klass, is_null_free, is_atomic);
 2760         replace_in_map(base, new_base);
 2761         base = new_base;
 2762         ptr = basic_plus_adr(base, ConvL2X(offset));
 2763         const TypeAryPtr* ptr_type = _gvn.type(ptr)->is_aryptr();
 2764         if (ptr_type->field_offset().get() != 0) {
 2765           // TODO 8350865 This should be a CheckCastPP, can we add a test?
 2766           ptr = _gvn.transform(new CastPPNode(control(), ptr, ptr_type->with_field_offset(0), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2767         }
 2768       } else {
 2769         uncommon_trap(Deoptimization::Reason_intrinsic,
 2770                       Deoptimization::Action_none);
 2771         return true;
 2772       }
 2773     }
 2774   } else {
 2775     decorators |= C2_MISMATCHED;
 2776     ptr = basic_plus_adr(base, ConvL2X(offset));
 2777   }
 2778 
 2779   if (is_store) {
 2780     Node* value = argument(6);
 2781     const Type* value_type = _gvn.type(value);
 2782     if (!value_type->is_inlinetypeptr()) {
 2783       value_type = Type::get_const_type(value_klass)->filter_speculative(value_type);
 2784       Node* new_value = _gvn.transform(new CheckCastPPNode(control(), value, value_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2785       new_value = InlineTypeNode::make_from_oop(this, new_value, value_klass);
 2786       replace_in_map(value, new_value);
 2787       value = new_value;
 2788     }
 2789 
 2790     assert(value_type->inline_klass() == value_klass, "value is of type %s while valueType is %s", value_type->inline_klass()->name()->as_utf8(), value_klass->name()->as_utf8());
 2791     if (layout == LayoutKind::REFERENCE) {
 2792       const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
 2793       access_store_at(base, ptr, ptr_type, value, value_type, T_OBJECT, decorators);
 2794     } else {
 2795       bool atomic = LayoutKindHelper::is_atomic_flat(layout);
 2796       bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2797       value->as_InlineType()->store_flat(this, base, ptr, atomic, immutable_memory, null_free, decorators);
 2798     }
 2799 
 2800     return true;
 2801   } else {
 2802     decorators |= (C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD);
 2803     InlineTypeNode* result;
 2804     if (layout == LayoutKind::REFERENCE) {
 2805       const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
 2806       Node* oop = access_load_at(base, ptr, ptr_type, Type::get_const_type(value_klass), T_OBJECT, decorators);
 2807       result = InlineTypeNode::make_from_oop(this, oop, value_klass);
 2808     } else {
 2809       bool atomic = LayoutKindHelper::is_atomic_flat(layout);
 2810       bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2811       result = InlineTypeNode::make_from_flat(this, value_klass, base, ptr, atomic, immutable_memory, null_free, decorators);
 2812     }
 2813 
 2814     set_result(result);
 2815     return true;
 2816   }
 2817 }
 2818 
 2819 //----------------------------inline_unsafe_load_store----------------------------
 2820 // This method serves a couple of different customers (depending on LoadStoreKind):
 2821 //
 2822 // LS_cmp_swap:
 2823 //
 2824 //   boolean compareAndSetReference(Object o, long offset, Object expected, Object x);
 2825 //   boolean compareAndSetInt(   Object o, long offset, int    expected, int    x);
 2826 //   boolean compareAndSetLong(  Object o, long offset, long   expected, long   x);
 2827 //
 2828 // LS_cmp_swap_weak:
 2829 //
 2830 //   boolean weakCompareAndSetReference(       Object o, long offset, Object expected, Object x);
 2831 //   boolean weakCompareAndSetReferencePlain(  Object o, long offset, Object expected, Object x);
 2832 //   boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x);
 2833 //   boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x);
 2834 //
 2835 //   boolean weakCompareAndSetInt(          Object o, long offset, int    expected, int    x);
 2836 //   boolean weakCompareAndSetIntPlain(     Object o, long offset, int    expected, int    x);
 2837 //   boolean weakCompareAndSetIntAcquire(   Object o, long offset, int    expected, int    x);
 2838 //   boolean weakCompareAndSetIntRelease(   Object o, long offset, int    expected, int    x);
 2839 //
 2840 //   boolean weakCompareAndSetLong(         Object o, long offset, long   expected, long   x);
 2841 //   boolean weakCompareAndSetLongPlain(    Object o, long offset, long   expected, long   x);
 2842 //   boolean weakCompareAndSetLongAcquire(  Object o, long offset, long   expected, long   x);
 2843 //   boolean weakCompareAndSetLongRelease(  Object o, long offset, long   expected, long   x);
 2844 //
 2845 // LS_cmp_exchange:
 2846 //
 2847 //   Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x);
 2848 //   Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x);
 2849 //   Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x);
 2850 //
 2851 //   Object compareAndExchangeIntVolatile(   Object o, long offset, Object expected, Object x);
 2852 //   Object compareAndExchangeIntAcquire(    Object o, long offset, Object expected, Object x);
 2853 //   Object compareAndExchangeIntRelease(    Object o, long offset, Object expected, Object x);
 2854 //
 2855 //   Object compareAndExchangeLongVolatile(  Object o, long offset, Object expected, Object x);
 2856 //   Object compareAndExchangeLongAcquire(   Object o, long offset, Object expected, Object x);
 2857 //   Object compareAndExchangeLongRelease(   Object o, long offset, Object expected, Object x);
 2858 //
 2859 // LS_get_add:
 2860 //
 2861 //   int  getAndAddInt( Object o, long offset, int  delta)
 2862 //   long getAndAddLong(Object o, long offset, long delta)
 2863 //
 2864 // LS_get_set:
 2865 //
 2866 //   int    getAndSet(Object o, long offset, int    newValue)
 2867 //   long   getAndSet(Object o, long offset, long   newValue)
 2868 //   Object getAndSet(Object o, long offset, Object newValue)
 2869 //
 2870 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) {
 2871   // This basic scheme here is the same as inline_unsafe_access, but
 2872   // differs in enough details that combining them would make the code
 2873   // overly confusing.  (This is a true fact! I originally combined
 2874   // them, but even I was confused by it!) As much code/comments as
 2875   // possible are retained from inline_unsafe_access though to make
 2876   // the correspondences clearer. - dl
 2877 
 2878   if (callee()->is_static())  return false;  // caller must have the capability!
 2879 
 2880   DecoratorSet decorators = C2_UNSAFE_ACCESS;
 2881   decorators |= mo_decorator_for_access_kind(access_kind);
 2882 
 2883 #ifndef PRODUCT
 2884   BasicType rtype;
 2885   {
 2886     ResourceMark rm;
 2887     // Check the signatures.
 2888     ciSignature* sig = callee()->signature();
 2889     rtype = sig->return_type()->basic_type();
 2890     switch(kind) {
 2891       case LS_get_add:
 2892       case LS_get_set: {
 2893       // Check the signatures.
 2894 #ifdef ASSERT
 2895       assert(rtype == type, "get and set must return the expected type");
 2896       assert(sig->count() == 3, "get and set has 3 arguments");
 2897       assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object");
 2898       assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long");
 2899       assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta");
 2900       assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation");
 2901 #endif // ASSERT
 2902         break;
 2903       }
 2904       case LS_cmp_swap:
 2905       case LS_cmp_swap_weak: {
 2906       // Check the signatures.
 2907 #ifdef ASSERT
 2908       assert(rtype == T_BOOLEAN, "CAS must return boolean");
 2909       assert(sig->count() == 4, "CAS has 4 arguments");
 2910       assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
 2911       assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
 2912 #endif // ASSERT
 2913         break;
 2914       }
 2915       case LS_cmp_exchange: {
 2916       // Check the signatures.
 2917 #ifdef ASSERT
 2918       assert(rtype == type, "CAS must return the expected type");
 2919       assert(sig->count() == 4, "CAS has 4 arguments");
 2920       assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
 2921       assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
 2922 #endif // ASSERT
 2923         break;
 2924       }
 2925       default:
 2926         ShouldNotReachHere();
 2927     }
 2928   }
 2929 #endif //PRODUCT
 2930 
 2931   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 2932 
 2933   // Get arguments:
 2934   Node* receiver = nullptr;
 2935   Node* base     = nullptr;
 2936   Node* offset   = nullptr;
 2937   Node* oldval   = nullptr;
 2938   Node* newval   = nullptr;
 2939   switch(kind) {
 2940     case LS_cmp_swap:
 2941     case LS_cmp_swap_weak:
 2942     case LS_cmp_exchange: {
 2943       const bool two_slot_type = type2size[type] == 2;
 2944       receiver = argument(0);  // type: oop
 2945       base     = argument(1);  // type: oop
 2946       offset   = argument(2);  // type: long
 2947       oldval   = argument(4);  // type: oop, int, or long
 2948       newval   = argument(two_slot_type ? 6 : 5);  // type: oop, int, or long
 2949       break;
 2950     }
 2951     case LS_get_add:
 2952     case LS_get_set: {
 2953       receiver = argument(0);  // type: oop
 2954       base     = argument(1);  // type: oop
 2955       offset   = argument(2);  // type: long
 2956       oldval   = nullptr;
 2957       newval   = argument(4);  // type: oop, int, or long
 2958       break;
 2959     }
 2960     default:
 2961       ShouldNotReachHere();
 2962   }
 2963 
 2964   // Build field offset expression.
 2965   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
 2966   // to be plain byte offsets, which are also the same as those accepted
 2967   // by oopDesc::field_addr.
 2968   assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
 2969   // 32-bit machines ignore the high half of long offsets
 2970   offset = ConvL2X(offset);
 2971   // Save state and restore on bailout
 2972   SavedState old_state(this);
 2973   Node* adr = make_unsafe_address(base, offset,type, false);
 2974   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
 2975 
 2976   Compile::AliasType* alias_type = C->alias_type(adr_type);
 2977   BasicType bt = alias_type->basic_type();
 2978   if (bt != T_ILLEGAL &&
 2979       (is_reference_type(bt) != (type == T_OBJECT))) {
 2980     // Don't intrinsify mismatched object accesses.
 2981     return false;
 2982   }
 2983 
 2984   old_state.discard();
 2985 
 2986   // For CAS, unlike inline_unsafe_access, there seems no point in
 2987   // trying to refine types. Just use the coarse types here.
 2988   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
 2989   const Type *value_type = Type::get_const_basic_type(type);
 2990 
 2991   switch (kind) {
 2992     case LS_get_set:
 2993     case LS_cmp_exchange: {
 2994       if (type == T_OBJECT) {
 2995         const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
 2996         if (tjp != nullptr) {
 2997           value_type = tjp;
 2998         }
 2999       }
 3000       break;
 3001     }
 3002     case LS_cmp_swap:
 3003     case LS_cmp_swap_weak:
 3004     case LS_get_add:
 3005       break;
 3006     default:
 3007       ShouldNotReachHere();
 3008   }
 3009 
 3010   // Null check receiver.
 3011   receiver = null_check(receiver);
 3012   if (stopped()) {
 3013     return true;
 3014   }
 3015 
 3016   int alias_idx = C->get_alias_index(adr_type);
 3017 
 3018   if (is_reference_type(type)) {
 3019     decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF;
 3020 
 3021     if (oldval != nullptr && oldval->is_InlineType()) {
 3022       // Re-execute the unsafe access if allocation triggers deoptimization.
 3023       PreserveReexecuteState preexecs(this);
 3024       jvms()->set_should_reexecute(true);
 3025       oldval = oldval->as_InlineType()->buffer(this)->get_oop();
 3026     }
 3027     if (newval != nullptr && newval->is_InlineType()) {
 3028       // Re-execute the unsafe access if allocation triggers deoptimization.
 3029       PreserveReexecuteState preexecs(this);
 3030       jvms()->set_should_reexecute(true);
 3031       newval = newval->as_InlineType()->buffer(this)->get_oop();
 3032     }
 3033 
 3034     // Transformation of a value which could be null pointer (CastPP #null)
 3035     // could be delayed during Parse (for example, in adjust_map_after_if()).
 3036     // Execute transformation here to avoid barrier generation in such case.
 3037     if (_gvn.type(newval) == TypePtr::NULL_PTR)
 3038       newval = _gvn.makecon(TypePtr::NULL_PTR);
 3039 
 3040     if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) {
 3041       // Refine the value to a null constant, when it is known to be null
 3042       oldval = _gvn.makecon(TypePtr::NULL_PTR);
 3043     }
 3044   }
 3045 
 3046   Node* result = nullptr;
 3047   switch (kind) {
 3048     case LS_cmp_exchange: {
 3049       result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx,
 3050                                             oldval, newval, value_type, type, decorators);
 3051       break;
 3052     }
 3053     case LS_cmp_swap_weak:
 3054       decorators |= C2_WEAK_CMPXCHG;
 3055     case LS_cmp_swap: {
 3056       result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx,
 3057                                              oldval, newval, value_type, type, decorators);
 3058       break;
 3059     }
 3060     case LS_get_set: {
 3061       result = access_atomic_xchg_at(base, adr, adr_type, alias_idx,
 3062                                      newval, value_type, type, decorators);
 3063       break;
 3064     }
 3065     case LS_get_add: {
 3066       result = access_atomic_add_at(base, adr, adr_type, alias_idx,
 3067                                     newval, value_type, type, decorators);
 3068       break;
 3069     }
 3070     default:
 3071       ShouldNotReachHere();
 3072   }
 3073 
 3074   assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match");
 3075   set_result(result);
 3076   return true;
 3077 }
 3078 
 3079 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) {
 3080   // Regardless of form, don't allow previous ld/st to move down,
 3081   // then issue acquire, release, or volatile mem_bar.
 3082   insert_mem_bar(Op_MemBarCPUOrder);
 3083   switch(id) {
 3084     case vmIntrinsics::_loadFence:
 3085       insert_mem_bar(Op_LoadFence);
 3086       return true;
 3087     case vmIntrinsics::_storeFence:
 3088       insert_mem_bar(Op_StoreFence);
 3089       return true;
 3090     case vmIntrinsics::_storeStoreFence:
 3091       insert_mem_bar(Op_StoreStoreFence);
 3092       return true;
 3093     case vmIntrinsics::_fullFence:
 3094       insert_mem_bar(Op_MemBarFull);
 3095       return true;
 3096     default:
 3097       fatal_unexpected_iid(id);
 3098       return false;
 3099   }
 3100 }
 3101 
 3102 // private native int arrayInstanceBaseOffset0(Object[] array);
 3103 bool LibraryCallKit::inline_arrayInstanceBaseOffset() {
 3104   Node* array = argument(1);
 3105   Node* klass_node = load_object_klass(array);
 3106 
 3107   jint  layout_con = Klass::_lh_neutral_value;
 3108   Node* layout_val = get_layout_helper(klass_node, layout_con);
 3109   int   layout_is_con = (layout_val == nullptr);
 3110 
 3111   Node* header_size = nullptr;
 3112   if (layout_is_con) {
 3113     int hsize = Klass::layout_helper_header_size(layout_con);
 3114     header_size = intcon(hsize);
 3115   } else {
 3116     Node* hss = intcon(Klass::_lh_header_size_shift);
 3117     Node* hsm = intcon(Klass::_lh_header_size_mask);
 3118     header_size = _gvn.transform(new URShiftINode(layout_val, hss));
 3119     header_size = _gvn.transform(new AndINode(header_size, hsm));
 3120   }
 3121   set_result(header_size);
 3122   return true;
 3123 }
 3124 
 3125 // private native int arrayInstanceIndexScale0(Object[] array);
 3126 bool LibraryCallKit::inline_arrayInstanceIndexScale() {
 3127   Node* array = argument(1);
 3128   Node* klass_node = load_object_klass(array);
 3129 
 3130   jint  layout_con = Klass::_lh_neutral_value;
 3131   Node* layout_val = get_layout_helper(klass_node, layout_con);
 3132   int   layout_is_con = (layout_val == nullptr);
 3133 
 3134   Node* element_size = nullptr;
 3135   if (layout_is_con) {
 3136     int log_element_size  = Klass::layout_helper_log2_element_size(layout_con);
 3137     int elem_size = 1 << log_element_size;
 3138     element_size = intcon(elem_size);
 3139   } else {
 3140     Node* ess = intcon(Klass::_lh_log2_element_size_shift);
 3141     Node* esm = intcon(Klass::_lh_log2_element_size_mask);
 3142     Node* log_element_size = _gvn.transform(new URShiftINode(layout_val, ess));
 3143     log_element_size = _gvn.transform(new AndINode(log_element_size, esm));
 3144     element_size = _gvn.transform(new LShiftINode(intcon(1), log_element_size));
 3145   }
 3146   set_result(element_size);
 3147   return true;
 3148 }
 3149 
 3150 // private native int arrayLayout0(Object[] array);
 3151 bool LibraryCallKit::inline_arrayLayout() {
 3152   RegionNode* region = new RegionNode(2);
 3153   Node* phi = new PhiNode(region, TypeInt::POS);
 3154 
 3155   Node* array = argument(1);
 3156   Node* klass_node = load_object_klass(array);
 3157   generate_refArray_guard(klass_node, region);
 3158   if (region->req() == 3) {
 3159     phi->add_req(intcon((jint)LayoutKind::REFERENCE));
 3160   }
 3161 
 3162   int layout_kind_offset = in_bytes(FlatArrayKlass::layout_kind_offset());
 3163   Node* layout_kind_addr = basic_plus_adr(top(), klass_node, layout_kind_offset);
 3164   Node* layout_kind = make_load(nullptr, layout_kind_addr, TypeInt::POS, T_INT, MemNode::unordered);
 3165 
 3166   region->init_req(1, control());
 3167   phi->init_req(1, layout_kind);
 3168 
 3169   set_control(_gvn.transform(region));
 3170   set_result(_gvn.transform(phi));
 3171   return true;
 3172 }
 3173 
 3174 // private native int[] getFieldMap0(Class <?> c);
 3175 //   int offset = c._klass._acmp_maps_offset;
 3176 //   return (int[])c.obj_field(offset);
 3177 bool LibraryCallKit::inline_getFieldMap() {
 3178   Node* mirror = argument(1);
 3179   Node* klass = load_klass_from_mirror(mirror, false, nullptr, 0);
 3180 
 3181   int field_map_offset_offset = in_bytes(InstanceKlass::acmp_maps_offset_offset());
 3182   Node* field_map_offset_addr = basic_plus_adr(top(), klass, field_map_offset_offset);
 3183   Node* field_map_offset = make_load(nullptr, field_map_offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
 3184   field_map_offset = _gvn.transform(ConvI2L(field_map_offset));
 3185 
 3186   Node* map_addr = basic_plus_adr(mirror, field_map_offset);
 3187   const TypeAryPtr* val_type = TypeAryPtr::INTS->cast_to_ptr_type(TypePtr::NotNull)->with_offset(0);
 3188   Node* map = access_load_at(mirror, map_addr, TypeAryPtr::INTS, val_type, T_ARRAY, IN_HEAP | MO_UNORDERED);
 3189 
 3190   set_result(map);
 3191   return true;
 3192 }
 3193 
 3194 bool LibraryCallKit::inline_onspinwait() {
 3195   insert_mem_bar(Op_OnSpinWait);
 3196   return true;
 3197 }
 3198 
 3199 bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
 3200   if (!kls->is_Con()) {
 3201     return true;
 3202   }
 3203   const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr();
 3204   if (klsptr == nullptr) {
 3205     return true;
 3206   }
 3207   ciInstanceKlass* ik = klsptr->instance_klass();
 3208   // don't need a guard for a klass that is already initialized
 3209   return !ik->is_initialized();
 3210 }
 3211 
 3212 //----------------------------inline_unsafe_writeback0-------------------------
 3213 // public native void Unsafe.writeback0(long address)
 3214 bool LibraryCallKit::inline_unsafe_writeback0() {
 3215   if (!Matcher::has_match_rule(Op_CacheWB)) {
 3216     return false;
 3217   }
 3218 #ifndef PRODUCT
 3219   assert(Matcher::has_match_rule(Op_CacheWBPreSync), "found match rule for CacheWB but not CacheWBPreSync");
 3220   assert(Matcher::has_match_rule(Op_CacheWBPostSync), "found match rule for CacheWB but not CacheWBPostSync");
 3221   ciSignature* sig = callee()->signature();
 3222   assert(sig->type_at(0)->basic_type() == T_LONG, "Unsafe_writeback0 address is long!");
 3223 #endif
 3224   null_check_receiver();  // null-check, then ignore
 3225   Node *addr = argument(1);
 3226   addr = new CastX2PNode(addr);
 3227   addr = _gvn.transform(addr);
 3228   Node *flush = new CacheWBNode(control(), memory(TypeRawPtr::BOTTOM), addr);
 3229   flush = _gvn.transform(flush);
 3230   set_memory(flush, TypeRawPtr::BOTTOM);
 3231   return true;
 3232 }
 3233 
 3234 //----------------------------inline_unsafe_writeback0-------------------------
 3235 // public native void Unsafe.writeback0(long address)
 3236 bool LibraryCallKit::inline_unsafe_writebackSync0(bool is_pre) {
 3237   if (is_pre && !Matcher::has_match_rule(Op_CacheWBPreSync)) {
 3238     return false;
 3239   }
 3240   if (!is_pre && !Matcher::has_match_rule(Op_CacheWBPostSync)) {
 3241     return false;
 3242   }
 3243 #ifndef PRODUCT
 3244   assert(Matcher::has_match_rule(Op_CacheWB),
 3245          (is_pre ? "found match rule for CacheWBPreSync but not CacheWB"
 3246                 : "found match rule for CacheWBPostSync but not CacheWB"));
 3247 
 3248 #endif
 3249   null_check_receiver();  // null-check, then ignore
 3250   Node *sync;
 3251   if (is_pre) {
 3252     sync = new CacheWBPreSyncNode(control(), memory(TypeRawPtr::BOTTOM));
 3253   } else {
 3254     sync = new CacheWBPostSyncNode(control(), memory(TypeRawPtr::BOTTOM));
 3255   }
 3256   sync = _gvn.transform(sync);
 3257   set_memory(sync, TypeRawPtr::BOTTOM);
 3258   return true;
 3259 }
 3260 
 3261 //----------------------------inline_unsafe_allocate---------------------------
 3262 // public native Object Unsafe.allocateInstance(Class<?> cls);
 3263 bool LibraryCallKit::inline_unsafe_allocate() {
 3264 
 3265 #if INCLUDE_JVMTI
 3266   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 3267     return false;
 3268   }
 3269 #endif //INCLUDE_JVMTI
 3270 
 3271   if (callee()->is_static())  return false;  // caller must have the capability!
 3272 
 3273   null_check_receiver();  // null-check, then ignore
 3274   Node* cls = null_check(argument(1));
 3275   if (stopped())  return true;
 3276 
 3277   Node* kls = load_klass_from_mirror(cls, false, nullptr, 0);
 3278   kls = null_check(kls);
 3279   if (stopped())  return true;  // argument was like int.class
 3280 
 3281 #if INCLUDE_JVMTI
 3282     // Don't try to access new allocated obj in the intrinsic.
 3283     // It causes perfomance issues even when jvmti event VmObjectAlloc is disabled.
 3284     // Deoptimize and allocate in interpreter instead.
 3285     Node* addr = makecon(TypeRawPtr::make((address) &JvmtiExport::_should_notify_object_alloc));
 3286     Node* should_post_vm_object_alloc = make_load(this->control(), addr, TypeInt::INT, T_INT, MemNode::unordered);
 3287     Node* chk = _gvn.transform(new CmpINode(should_post_vm_object_alloc, intcon(0)));
 3288     Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
 3289     {
 3290       BuildCutout unless(this, tst, PROB_MAX);
 3291       uncommon_trap(Deoptimization::Reason_intrinsic,
 3292                     Deoptimization::Action_make_not_entrant);
 3293     }
 3294     if (stopped()) {
 3295       return true;
 3296     }
 3297 #endif //INCLUDE_JVMTI
 3298 
 3299   Node* test = nullptr;
 3300   if (LibraryCallKit::klass_needs_init_guard(kls)) {
 3301     // Note:  The argument might still be an illegal value like
 3302     // Serializable.class or Object[].class.   The runtime will handle it.
 3303     // But we must make an explicit check for initialization.
 3304     Node* insp = off_heap_plus_addr(kls, in_bytes(InstanceKlass::init_state_offset()));
 3305     // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
 3306     // can generate code to load it as unsigned byte.
 3307     Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire);
 3308     Node* bits = intcon(InstanceKlass::fully_initialized);
 3309     test = _gvn.transform(new SubINode(inst, bits));
 3310     // The 'test' is non-zero if we need to take a slow path.
 3311   }
 3312   Node* obj = new_instance(kls, test);
 3313   set_result(obj);
 3314   return true;
 3315 }
 3316 
 3317 //------------------------inline_native_time_funcs--------------
 3318 // inline code for System.currentTimeMillis() and System.nanoTime()
 3319 // these have the same type and signature
 3320 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
 3321   const TypeFunc* tf = OptoRuntime::void_long_Type();
 3322   const TypePtr* no_memory_effects = nullptr;
 3323   Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
 3324   Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0));
 3325 #ifdef ASSERT
 3326   Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1));
 3327   assert(value_top == top(), "second value must be top");
 3328 #endif
 3329   set_result(value);
 3330   return true;
 3331 }
 3332 
 3333 //--------------------inline_native_vthread_start_transition--------------------
 3334 // inline void startTransition(boolean is_mount);
 3335 // inline void startFinalTransition();
 3336 // Pseudocode of implementation:
 3337 //
 3338 // java_lang_Thread::set_is_in_vthread_transition(vthread, true);
 3339 // carrier->set_is_in_vthread_transition(true);
 3340 // OrderAccess::storeload();
 3341 // int disable_requests = java_lang_Thread::vthread_transition_disable_count(vthread)
 3342 //                        + global_vthread_transition_disable_count();
 3343 // if (disable_requests > 0) {
 3344 //   slow path: runtime call
 3345 // }
 3346 bool LibraryCallKit::inline_native_vthread_start_transition(address funcAddr, const char* funcName, bool is_final_transition) {
 3347   Node* vt_oop = must_be_not_null(argument(0), true); // VirtualThread this argument
 3348   IdealKit ideal(this);
 3349 
 3350   Node* thread = ideal.thread();
 3351   Node* jt_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_in_vthread_transition_offset()));
 3352   Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_vthread_transition_offset());
 3353   access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), ideal.ConI(1), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3354   access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), ideal.ConI(1), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3355   insert_mem_bar(Op_MemBarStoreLoad);
 3356   ideal.sync_kit(this);
 3357 
 3358   Node* global_disable_addr = makecon(TypeRawPtr::make((address)MountUnmountDisabler::global_vthread_transition_disable_count_address()));
 3359   Node* global_disable = ideal.load(ideal.ctrl(), global_disable_addr, TypeInt::INT, T_INT, Compile::AliasIdxRaw, true /*require_atomic_access*/);
 3360   Node* vt_disable_addr = basic_plus_adr(vt_oop, java_lang_Thread::vthread_transition_disable_count_offset());
 3361   const TypePtr* vt_disable_addr_t = _gvn.type(vt_disable_addr)->is_ptr();
 3362   Node* vt_disable = ideal.load(ideal.ctrl(), vt_disable_addr, TypeInt::INT, T_INT, C->get_alias_index(vt_disable_addr_t), true /*require_atomic_access*/);
 3363   Node* disabled = _gvn.transform(new AddINode(global_disable, vt_disable));
 3364 
 3365   ideal.if_then(disabled, BoolTest::ne, ideal.ConI(0)); {
 3366     sync_kit(ideal);
 3367     Node* is_mount = is_final_transition ? ideal.ConI(0) : argument(1);
 3368     const TypeFunc* tf = OptoRuntime::vthread_transition_Type();
 3369     make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, is_mount);
 3370     ideal.sync_kit(this);
 3371   }
 3372   ideal.end_if();
 3373 
 3374   final_sync(ideal);
 3375   return true;
 3376 }
 3377 
 3378 bool LibraryCallKit::inline_native_vthread_end_transition(address funcAddr, const char* funcName, bool is_first_transition) {
 3379   Node* vt_oop = must_be_not_null(argument(0), true); // VirtualThread this argument
 3380   IdealKit ideal(this);
 3381 
 3382   Node* _notify_jvmti_addr = makecon(TypeRawPtr::make((address)MountUnmountDisabler::notify_jvmti_events_address()));
 3383   Node* _notify_jvmti = ideal.load(ideal.ctrl(), _notify_jvmti_addr, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw);
 3384 
 3385   ideal.if_then(_notify_jvmti, BoolTest::eq, ideal.ConI(1)); {
 3386     sync_kit(ideal);
 3387     Node* is_mount = is_first_transition ? ideal.ConI(1) : argument(1);
 3388     const TypeFunc* tf = OptoRuntime::vthread_transition_Type();
 3389     make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, is_mount);
 3390     ideal.sync_kit(this);
 3391   } ideal.else_(); {
 3392     Node* thread = ideal.thread();
 3393     Node* jt_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_in_vthread_transition_offset()));
 3394     Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_vthread_transition_offset());
 3395 
 3396     sync_kit(ideal);
 3397     access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), ideal.ConI(0), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3398     access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), ideal.ConI(0), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3399     ideal.sync_kit(this);
 3400   } ideal.end_if();
 3401 
 3402   final_sync(ideal);
 3403   return true;
 3404 }
 3405 
 3406 #if INCLUDE_JVMTI
 3407 
 3408 // Always update the is_disable_suspend bit.
 3409 bool LibraryCallKit::inline_native_notify_jvmti_sync() {
 3410   if (!DoJVMTIVirtualThreadTransitions) {
 3411     return true;
 3412   }
 3413   IdealKit ideal(this);
 3414 
 3415   {
 3416     // unconditionally update the is_disable_suspend bit in current JavaThread
 3417     Node* thread = ideal.thread();
 3418     Node* arg = argument(0); // argument for notification
 3419     Node* addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_disable_suspend_offset()));
 3420     const TypePtr *addr_type = _gvn.type(addr)->isa_ptr();
 3421 
 3422     sync_kit(ideal);
 3423     access_store_at(nullptr, addr, addr_type, arg, _gvn.type(arg), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3424     ideal.sync_kit(this);
 3425   }
 3426   final_sync(ideal);
 3427 
 3428   return true;
 3429 }
 3430 
 3431 #endif // INCLUDE_JVMTI
 3432 
 3433 #ifdef JFR_HAVE_INTRINSICS
 3434 
 3435 /**
 3436  * if oop->klass != null
 3437  *   // normal class
 3438  *   epoch = _epoch_state ? 2 : 1
 3439  *   if oop->klass->trace_id & ((epoch << META_SHIFT) | epoch)) != epoch {
 3440  *     ... // enter slow path when the klass is first recorded or the epoch of JFR shifts
 3441  *   }
 3442  *   id = oop->klass->trace_id >> TRACE_ID_SHIFT // normal class path
 3443  * else
 3444  *   // primitive class
 3445  *   if oop->array_klass != null
 3446  *     id = (oop->array_klass->trace_id >> TRACE_ID_SHIFT) + 1 // primitive class path
 3447  *   else
 3448  *     id = LAST_TYPE_ID + 1 // void class path
 3449  *   if (!signaled)
 3450  *     signaled = true
 3451  */
 3452 bool LibraryCallKit::inline_native_classID() {
 3453   Node* cls = argument(0);
 3454 
 3455   IdealKit ideal(this);
 3456 #define __ ideal.
 3457   IdealVariable result(ideal); __ declarations_done();
 3458   Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(),
 3459                                                  basic_plus_adr(cls, java_lang_Class::klass_offset()),
 3460                                                  TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 3461 
 3462 
 3463   __ if_then(kls, BoolTest::ne, null()); {
 3464     Node* kls_trace_id_addr = basic_plus_adr(kls, in_bytes(KLASS_TRACE_ID_OFFSET));
 3465     Node* kls_trace_id_raw = ideal.load(ideal.ctrl(), kls_trace_id_addr,TypeLong::LONG, T_LONG, Compile::AliasIdxRaw);
 3466 
 3467     Node* epoch_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_address()));
 3468     Node* epoch = ideal.load(ideal.ctrl(), epoch_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw);
 3469     epoch = _gvn.transform(new LShiftLNode(longcon(1), epoch));
 3470     Node* mask = _gvn.transform(new LShiftLNode(epoch, intcon(META_SHIFT)));
 3471     mask = _gvn.transform(new OrLNode(mask, epoch));
 3472     Node* kls_trace_id_raw_and_mask = _gvn.transform(new AndLNode(kls_trace_id_raw, mask));
 3473 
 3474     float unlikely  = PROB_UNLIKELY(0.999);
 3475     __ if_then(kls_trace_id_raw_and_mask, BoolTest::ne, epoch, unlikely); {
 3476       sync_kit(ideal);
 3477       make_runtime_call(RC_LEAF,
 3478                         OptoRuntime::class_id_load_barrier_Type(),
 3479                         CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::load_barrier),
 3480                         "class id load barrier",
 3481                         TypePtr::BOTTOM,
 3482                         kls);
 3483       ideal.sync_kit(this);
 3484     } __ end_if();
 3485 
 3486     ideal.set(result,  _gvn.transform(new URShiftLNode(kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT))));
 3487   } __ else_(); {
 3488     Node* array_kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(),
 3489                                                    basic_plus_adr(cls, java_lang_Class::array_klass_offset()),
 3490                                                    TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 3491     __ if_then(array_kls, BoolTest::ne, null()); {
 3492       Node* array_kls_trace_id_addr = basic_plus_adr(array_kls, in_bytes(KLASS_TRACE_ID_OFFSET));
 3493       Node* array_kls_trace_id_raw = ideal.load(ideal.ctrl(), array_kls_trace_id_addr, TypeLong::LONG, T_LONG, Compile::AliasIdxRaw);
 3494       Node* array_kls_trace_id = _gvn.transform(new URShiftLNode(array_kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT)));
 3495       ideal.set(result, _gvn.transform(new AddLNode(array_kls_trace_id, longcon(1))));
 3496     } __ else_(); {
 3497       // void class case
 3498       ideal.set(result, longcon(LAST_TYPE_ID + 1));
 3499     } __ end_if();
 3500 
 3501     Node* signaled_flag_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::signal_address()));
 3502     Node* signaled = ideal.load(ideal.ctrl(), signaled_flag_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw, true, MemNode::acquire);
 3503     __ if_then(signaled, BoolTest::ne, ideal.ConI(1)); {
 3504       ideal.store(ideal.ctrl(), signaled_flag_address, ideal.ConI(1), T_BOOLEAN, Compile::AliasIdxRaw, MemNode::release, true);
 3505     } __ end_if();
 3506   } __ end_if();
 3507 
 3508   final_sync(ideal);
 3509   set_result(ideal.value(result));
 3510 #undef __
 3511   return true;
 3512 }
 3513 
 3514 //------------------------inline_native_jvm_commit------------------
 3515 bool LibraryCallKit::inline_native_jvm_commit() {
 3516   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3517 
 3518   // Save input memory and i_o state.
 3519   Node* input_memory_state = reset_memory();
 3520   set_all_memory(input_memory_state);
 3521   Node* input_io_state = i_o();
 3522 
 3523   // TLS.
 3524   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 3525   // Jfr java buffer.
 3526   Node* java_buffer_offset = _gvn.transform(AddPNode::make_off_heap(tls_ptr, MakeConX(in_bytes(JAVA_BUFFER_OFFSET_JFR))));
 3527   Node* java_buffer = _gvn.transform(new LoadPNode(control(), input_memory_state, java_buffer_offset, TypePtr::BOTTOM, TypeRawPtr::NOTNULL, MemNode::unordered));
 3528   Node* java_buffer_pos_offset = _gvn.transform(AddPNode::make_off_heap(java_buffer, MakeConX(in_bytes(JFR_BUFFER_POS_OFFSET))));
 3529 
 3530   // Load the current value of the notified field in the JfrThreadLocal.
 3531   Node* notified_offset = off_heap_plus_addr(tls_ptr, in_bytes(NOTIFY_OFFSET_JFR));
 3532   Node* notified = make_load(control(), notified_offset, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered);
 3533 
 3534   // Test for notification.
 3535   Node* notified_cmp = _gvn.transform(new CmpINode(notified, _gvn.intcon(1)));
 3536   Node* test_notified = _gvn.transform(new BoolNode(notified_cmp, BoolTest::eq));
 3537   IfNode* iff_notified = create_and_map_if(control(), test_notified, PROB_MIN, COUNT_UNKNOWN);
 3538 
 3539   // True branch, is notified.
 3540   Node* is_notified = _gvn.transform(new IfTrueNode(iff_notified));
 3541   set_control(is_notified);
 3542 
 3543   // Reset notified state.
 3544   store_to_memory(control(), notified_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::unordered);
 3545   Node* notified_reset_memory = reset_memory();
 3546 
 3547   // Iff notified, the return address of the commit method is the current position of the backing java buffer. This is used to reset the event writer.
 3548   Node* current_pos_X = _gvn.transform(new LoadXNode(control(), input_memory_state, java_buffer_pos_offset, TypeRawPtr::NOTNULL, TypeX_X, MemNode::unordered));
 3549   // Convert the machine-word to a long.
 3550   Node* current_pos = ConvX2L(current_pos_X);
 3551 
 3552   // False branch, not notified.
 3553   Node* not_notified = _gvn.transform(new IfFalseNode(iff_notified));
 3554   set_control(not_notified);
 3555   set_all_memory(input_memory_state);
 3556 
 3557   // Arg is the next position as a long.
 3558   Node* arg = argument(0);
 3559   // Convert long to machine-word.
 3560   Node* next_pos_X = ConvL2X(arg);
 3561 
 3562   // Store the next_position to the underlying jfr java buffer.
 3563   store_to_memory(control(), java_buffer_pos_offset, next_pos_X, LP64_ONLY(T_LONG) NOT_LP64(T_INT), MemNode::release);
 3564 
 3565   Node* commit_memory = reset_memory();
 3566   set_all_memory(commit_memory);
 3567 
 3568   // Now load the flags from off the java buffer and decide if the buffer is a lease. If so, it needs to be returned post-commit.
 3569   Node* java_buffer_flags_offset = _gvn.transform(AddPNode::make_off_heap(java_buffer, MakeConX(in_bytes(JFR_BUFFER_FLAGS_OFFSET))));
 3570   Node* flags = make_load(control(), java_buffer_flags_offset, TypeInt::UBYTE, T_BYTE, MemNode::unordered);
 3571   Node* lease_constant = _gvn.intcon(4);
 3572 
 3573   // And flags with lease constant.
 3574   Node* lease = _gvn.transform(new AndINode(flags, lease_constant));
 3575 
 3576   // Branch on lease to conditionalize returning the leased java buffer.
 3577   Node* lease_cmp = _gvn.transform(new CmpINode(lease, lease_constant));
 3578   Node* test_lease = _gvn.transform(new BoolNode(lease_cmp, BoolTest::eq));
 3579   IfNode* iff_lease = create_and_map_if(control(), test_lease, PROB_MIN, COUNT_UNKNOWN);
 3580 
 3581   // False branch, not a lease.
 3582   Node* not_lease = _gvn.transform(new IfFalseNode(iff_lease));
 3583 
 3584   // True branch, is lease.
 3585   Node* is_lease = _gvn.transform(new IfTrueNode(iff_lease));
 3586   set_control(is_lease);
 3587 
 3588   // Make a runtime call, which can safepoint, to return the leased buffer. This updates both the JfrThreadLocal and the Java event writer oop.
 3589   Node* call_return_lease = make_runtime_call(RC_NO_LEAF,
 3590                                               OptoRuntime::void_void_Type(),
 3591                                               SharedRuntime::jfr_return_lease(),
 3592                                               "return_lease", TypePtr::BOTTOM);
 3593   Node* call_return_lease_control = _gvn.transform(new ProjNode(call_return_lease, TypeFunc::Control));
 3594 
 3595   RegionNode* lease_compare_rgn = new RegionNode(PATH_LIMIT);
 3596   record_for_igvn(lease_compare_rgn);
 3597   PhiNode* lease_compare_mem = new PhiNode(lease_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3598   record_for_igvn(lease_compare_mem);
 3599   PhiNode* lease_compare_io = new PhiNode(lease_compare_rgn, Type::ABIO);
 3600   record_for_igvn(lease_compare_io);
 3601   PhiNode* lease_result_value = new PhiNode(lease_compare_rgn, TypeLong::LONG);
 3602   record_for_igvn(lease_result_value);
 3603 
 3604   // Update control and phi nodes.
 3605   lease_compare_rgn->init_req(_true_path, call_return_lease_control);
 3606   lease_compare_rgn->init_req(_false_path, not_lease);
 3607 
 3608   lease_compare_mem->init_req(_true_path, reset_memory());
 3609   lease_compare_mem->init_req(_false_path, commit_memory);
 3610 
 3611   lease_compare_io->init_req(_true_path, i_o());
 3612   lease_compare_io->init_req(_false_path, input_io_state);
 3613 
 3614   lease_result_value->init_req(_true_path, _gvn.longcon(0)); // if the lease was returned, return 0L.
 3615   lease_result_value->init_req(_false_path, arg); // if not lease, return new updated position.
 3616 
 3617   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 3618   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3619   PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO);
 3620   PhiNode* result_value = new PhiNode(result_rgn, TypeLong::LONG);
 3621 
 3622   // Update control and phi nodes.
 3623   result_rgn->init_req(_true_path, is_notified);
 3624   result_rgn->init_req(_false_path, _gvn.transform(lease_compare_rgn));
 3625 
 3626   result_mem->init_req(_true_path, notified_reset_memory);
 3627   result_mem->init_req(_false_path, _gvn.transform(lease_compare_mem));
 3628 
 3629   result_io->init_req(_true_path, input_io_state);
 3630   result_io->init_req(_false_path, _gvn.transform(lease_compare_io));
 3631 
 3632   result_value->init_req(_true_path, current_pos);
 3633   result_value->init_req(_false_path, _gvn.transform(lease_result_value));
 3634 
 3635   // Set output state.
 3636   set_control(_gvn.transform(result_rgn));
 3637   set_all_memory(_gvn.transform(result_mem));
 3638   set_i_o(_gvn.transform(result_io));
 3639   set_result(result_rgn, result_value);
 3640   return true;
 3641 }
 3642 
 3643 /*
 3644  * The intrinsic is a model of this pseudo-code:
 3645  *
 3646  * JfrThreadLocal* const tl = Thread::jfr_thread_local()
 3647  * jobject h_event_writer = tl->java_event_writer();
 3648  * if (h_event_writer == nullptr) {
 3649  *   return nullptr;
 3650  * }
 3651  * oop threadObj = Thread::threadObj();
 3652  * oop vthread = java_lang_Thread::vthread(threadObj);
 3653  * traceid tid;
 3654  * bool pinVirtualThread;
 3655  * bool excluded;
 3656  * if (vthread != threadObj) {  // i.e. current thread is virtual
 3657  *   tid = java_lang_Thread::tid(vthread);
 3658  *   u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(vthread);
 3659  *   pinVirtualThread = VMContinuations;
 3660  *   excluded = vthread_epoch_raw & excluded_mask;
 3661  *   if (!excluded) {
 3662  *     traceid current_epoch = JfrTraceIdEpoch::current_generation();
 3663  *     u2 vthread_epoch = vthread_epoch_raw & epoch_mask;
 3664  *     if (vthread_epoch != current_epoch) {
 3665  *       write_checkpoint();
 3666  *     }
 3667  *   }
 3668  * } else {
 3669  *   tid = java_lang_Thread::tid(threadObj);
 3670  *   u2 thread_epoch_raw = java_lang_Thread::jfr_epoch(threadObj);
 3671  *   pinVirtualThread = false;
 3672  *   excluded = thread_epoch_raw & excluded_mask;
 3673  * }
 3674  * oop event_writer = JNIHandles::resolve_non_null(h_event_writer);
 3675  * traceid tid_in_event_writer = getField(event_writer, "threadID");
 3676  * if (tid_in_event_writer != tid) {
 3677  *   setField(event_writer, "pinVirtualThread", pinVirtualThread);
 3678  *   setField(event_writer, "excluded", excluded);
 3679  *   setField(event_writer, "threadID", tid);
 3680  * }
 3681  * return event_writer
 3682  */
 3683 bool LibraryCallKit::inline_native_getEventWriter() {
 3684   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3685 
 3686   // Save input memory and i_o state.
 3687   Node* input_memory_state = reset_memory();
 3688   set_all_memory(input_memory_state);
 3689   Node* input_io_state = i_o();
 3690 
 3691   // The most significant bit of the u2 is used to denote thread exclusion
 3692   Node* excluded_shift = _gvn.intcon(15);
 3693   Node* excluded_mask = _gvn.intcon(1 << 15);
 3694   // The epoch generation is the range [1-32767]
 3695   Node* epoch_mask = _gvn.intcon(32767);
 3696 
 3697   // TLS
 3698   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 3699 
 3700   // Load the address of java event writer jobject handle from the jfr_thread_local structure.
 3701   Node* jobj_ptr = off_heap_plus_addr(tls_ptr, in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR));
 3702 
 3703   // Load the eventwriter jobject handle.
 3704   Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
 3705 
 3706   // Null check the jobject handle.
 3707   Node* jobj_cmp_null = _gvn.transform(new CmpPNode(jobj, null()));
 3708   Node* test_jobj_not_equal_null = _gvn.transform(new BoolNode(jobj_cmp_null, BoolTest::ne));
 3709   IfNode* iff_jobj_not_equal_null = create_and_map_if(control(), test_jobj_not_equal_null, PROB_MAX, COUNT_UNKNOWN);
 3710 
 3711   // False path, jobj is null.
 3712   Node* jobj_is_null = _gvn.transform(new IfFalseNode(iff_jobj_not_equal_null));
 3713 
 3714   // True path, jobj is not null.
 3715   Node* jobj_is_not_null = _gvn.transform(new IfTrueNode(iff_jobj_not_equal_null));
 3716 
 3717   set_control(jobj_is_not_null);
 3718 
 3719   // Load the threadObj for the CarrierThread.
 3720   Node* threadObj = generate_current_thread(tls_ptr);
 3721 
 3722   // Load the vthread.
 3723   Node* vthread = generate_virtual_thread(tls_ptr);
 3724 
 3725   // If vthread != threadObj, this is a virtual thread.
 3726   Node* vthread_cmp_threadObj = _gvn.transform(new CmpPNode(vthread, threadObj));
 3727   Node* test_vthread_not_equal_threadObj = _gvn.transform(new BoolNode(vthread_cmp_threadObj, BoolTest::ne));
 3728   IfNode* iff_vthread_not_equal_threadObj =
 3729     create_and_map_if(jobj_is_not_null, test_vthread_not_equal_threadObj, PROB_FAIR, COUNT_UNKNOWN);
 3730 
 3731   // False branch, fallback to threadObj.
 3732   Node* vthread_equal_threadObj = _gvn.transform(new IfFalseNode(iff_vthread_not_equal_threadObj));
 3733   set_control(vthread_equal_threadObj);
 3734 
 3735   // Load the tid field from the vthread object.
 3736   Node* thread_obj_tid = load_field_from_object(threadObj, "tid", "J");
 3737 
 3738   // Load the raw epoch value from the threadObj.
 3739   Node* threadObj_epoch_offset = basic_plus_adr(threadObj, java_lang_Thread::jfr_epoch_offset());
 3740   Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset,
 3741                                              _gvn.type(threadObj_epoch_offset)->isa_ptr(),
 3742                                              TypeInt::CHAR, T_CHAR,
 3743                                              IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 3744 
 3745   // Mask off the excluded information from the epoch.
 3746   Node * threadObj_is_excluded = _gvn.transform(new AndINode(threadObj_epoch_raw, excluded_mask));
 3747 
 3748   // True branch, this is a virtual thread.
 3749   Node* vthread_not_equal_threadObj = _gvn.transform(new IfTrueNode(iff_vthread_not_equal_threadObj));
 3750   set_control(vthread_not_equal_threadObj);
 3751 
 3752   // Load the tid field from the vthread object.
 3753   Node* vthread_tid = load_field_from_object(vthread, "tid", "J");
 3754 
 3755   // Continuation support determines if a virtual thread should be pinned.
 3756   Node* global_addr = makecon(TypeRawPtr::make((address)&VMContinuations));
 3757   Node* continuation_support = make_load(control(), global_addr, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered);
 3758 
 3759   // Load the raw epoch value from the vthread.
 3760   Node* vthread_epoch_offset = basic_plus_adr(vthread, java_lang_Thread::jfr_epoch_offset());
 3761   Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, _gvn.type(vthread_epoch_offset)->is_ptr(),
 3762                                            TypeInt::CHAR, T_CHAR,
 3763                                            IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 3764 
 3765   // Mask off the excluded information from the epoch.
 3766   Node * vthread_is_excluded = _gvn.transform(new AndINode(vthread_epoch_raw, excluded_mask));
 3767 
 3768   // Branch on excluded to conditionalize updating the epoch for the virtual thread.
 3769   Node* is_excluded_cmp = _gvn.transform(new CmpINode(vthread_is_excluded, excluded_mask));
 3770   Node* test_not_excluded = _gvn.transform(new BoolNode(is_excluded_cmp, BoolTest::ne));
 3771   IfNode* iff_not_excluded = create_and_map_if(control(), test_not_excluded, PROB_MAX, COUNT_UNKNOWN);
 3772 
 3773   // False branch, vthread is excluded, no need to write epoch info.
 3774   Node* excluded = _gvn.transform(new IfFalseNode(iff_not_excluded));
 3775 
 3776   // True branch, vthread is included, update epoch info.
 3777   Node* included = _gvn.transform(new IfTrueNode(iff_not_excluded));
 3778   set_control(included);
 3779 
 3780   // Get epoch value.
 3781   Node* epoch = _gvn.transform(new AndINode(vthread_epoch_raw, epoch_mask));
 3782 
 3783   // Load the current epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR.
 3784   Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address()));
 3785   Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered);
 3786 
 3787   // Compare the epoch in the vthread to the current epoch generation.
 3788   Node* const epoch_cmp = _gvn.transform(new CmpUNode(current_epoch_generation, epoch));
 3789   Node* test_epoch_not_equal = _gvn.transform(new BoolNode(epoch_cmp, BoolTest::ne));
 3790   IfNode* iff_epoch_not_equal = create_and_map_if(control(), test_epoch_not_equal, PROB_FAIR, COUNT_UNKNOWN);
 3791 
 3792   // False path, epoch is equal, checkpoint information is valid.
 3793   Node* epoch_is_equal = _gvn.transform(new IfFalseNode(iff_epoch_not_equal));
 3794 
 3795   // True path, epoch is not equal, write a checkpoint for the vthread.
 3796   Node* epoch_is_not_equal = _gvn.transform(new IfTrueNode(iff_epoch_not_equal));
 3797 
 3798   set_control(epoch_is_not_equal);
 3799 
 3800   // Make a runtime call, which can safepoint, to write a checkpoint for the vthread for this epoch.
 3801   // The call also updates the native thread local thread id and the vthread with the current epoch.
 3802   Node* call_write_checkpoint = make_runtime_call(RC_NO_LEAF,
 3803                                                   OptoRuntime::jfr_write_checkpoint_Type(),
 3804                                                   SharedRuntime::jfr_write_checkpoint(),
 3805                                                   "write_checkpoint", TypePtr::BOTTOM);
 3806   Node* call_write_checkpoint_control = _gvn.transform(new ProjNode(call_write_checkpoint, TypeFunc::Control));
 3807 
 3808   // vthread epoch != current epoch
 3809   RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT);
 3810   record_for_igvn(epoch_compare_rgn);
 3811   PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3812   record_for_igvn(epoch_compare_mem);
 3813   PhiNode* epoch_compare_io = new PhiNode(epoch_compare_rgn, Type::ABIO);
 3814   record_for_igvn(epoch_compare_io);
 3815 
 3816   // Update control and phi nodes.
 3817   epoch_compare_rgn->init_req(_true_path, call_write_checkpoint_control);
 3818   epoch_compare_rgn->init_req(_false_path, epoch_is_equal);
 3819   epoch_compare_mem->init_req(_true_path, reset_memory());
 3820   epoch_compare_mem->init_req(_false_path, input_memory_state);
 3821   epoch_compare_io->init_req(_true_path, i_o());
 3822   epoch_compare_io->init_req(_false_path, input_io_state);
 3823 
 3824   // excluded != true
 3825   RegionNode* exclude_compare_rgn = new RegionNode(PATH_LIMIT);
 3826   record_for_igvn(exclude_compare_rgn);
 3827   PhiNode* exclude_compare_mem = new PhiNode(exclude_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3828   record_for_igvn(exclude_compare_mem);
 3829   PhiNode* exclude_compare_io = new PhiNode(exclude_compare_rgn, Type::ABIO);
 3830   record_for_igvn(exclude_compare_io);
 3831 
 3832   // Update control and phi nodes.
 3833   exclude_compare_rgn->init_req(_true_path, _gvn.transform(epoch_compare_rgn));
 3834   exclude_compare_rgn->init_req(_false_path, excluded);
 3835   exclude_compare_mem->init_req(_true_path, _gvn.transform(epoch_compare_mem));
 3836   exclude_compare_mem->init_req(_false_path, input_memory_state);
 3837   exclude_compare_io->init_req(_true_path, _gvn.transform(epoch_compare_io));
 3838   exclude_compare_io->init_req(_false_path, input_io_state);
 3839 
 3840   // vthread != threadObj
 3841   RegionNode* vthread_compare_rgn = new RegionNode(PATH_LIMIT);
 3842   record_for_igvn(vthread_compare_rgn);
 3843   PhiNode* vthread_compare_mem = new PhiNode(vthread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3844   PhiNode* vthread_compare_io = new PhiNode(vthread_compare_rgn, Type::ABIO);
 3845   record_for_igvn(vthread_compare_io);
 3846   PhiNode* tid = new PhiNode(vthread_compare_rgn, TypeLong::LONG);
 3847   record_for_igvn(tid);
 3848   PhiNode* exclusion = new PhiNode(vthread_compare_rgn, TypeInt::CHAR);
 3849   record_for_igvn(exclusion);
 3850   PhiNode* pinVirtualThread = new PhiNode(vthread_compare_rgn, TypeInt::BOOL);
 3851   record_for_igvn(pinVirtualThread);
 3852 
 3853   // Update control and phi nodes.
 3854   vthread_compare_rgn->init_req(_true_path, _gvn.transform(exclude_compare_rgn));
 3855   vthread_compare_rgn->init_req(_false_path, vthread_equal_threadObj);
 3856   vthread_compare_mem->init_req(_true_path, _gvn.transform(exclude_compare_mem));
 3857   vthread_compare_mem->init_req(_false_path, input_memory_state);
 3858   vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io));
 3859   vthread_compare_io->init_req(_false_path, input_io_state);
 3860   tid->init_req(_true_path, vthread_tid);
 3861   tid->init_req(_false_path, thread_obj_tid);
 3862   exclusion->init_req(_true_path, vthread_is_excluded);
 3863   exclusion->init_req(_false_path, threadObj_is_excluded);
 3864   pinVirtualThread->init_req(_true_path, continuation_support);
 3865   pinVirtualThread->init_req(_false_path, _gvn.intcon(0));
 3866 
 3867   // Update branch state.
 3868   set_control(_gvn.transform(vthread_compare_rgn));
 3869   set_all_memory(_gvn.transform(vthread_compare_mem));
 3870   set_i_o(_gvn.transform(vthread_compare_io));
 3871 
 3872   // Load the event writer oop by dereferencing the jobject handle.
 3873   ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter"));
 3874   assert(klass_EventWriter->is_loaded(), "invariant");
 3875   ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass();
 3876   const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter);
 3877   const TypeOopPtr* const xtype = aklass->as_instance_type();
 3878   Node* jobj_untagged = _gvn.transform(AddPNode::make_off_heap(jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global)));
 3879   Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD);
 3880 
 3881   // Load the current thread id from the event writer object.
 3882   Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J");
 3883   // Get the field offset to, conditionally, store an updated tid value later.
 3884   Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false);
 3885   // Get the field offset to, conditionally, store an updated exclusion value later.
 3886   Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false);
 3887   // Get the field offset to, conditionally, store an updated pinVirtualThread value later.
 3888   Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false);
 3889 
 3890   RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT);
 3891   record_for_igvn(event_writer_tid_compare_rgn);
 3892   PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3893   record_for_igvn(event_writer_tid_compare_mem);
 3894   PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO);
 3895   record_for_igvn(event_writer_tid_compare_io);
 3896 
 3897   // Compare the current tid from the thread object to what is currently stored in the event writer object.
 3898   Node* const tid_cmp = _gvn.transform(new CmpLNode(event_writer_tid, _gvn.transform(tid)));
 3899   Node* test_tid_not_equal = _gvn.transform(new BoolNode(tid_cmp, BoolTest::ne));
 3900   IfNode* iff_tid_not_equal = create_and_map_if(_gvn.transform(vthread_compare_rgn), test_tid_not_equal, PROB_FAIR, COUNT_UNKNOWN);
 3901 
 3902   // False path, tids are the same.
 3903   Node* tid_is_equal = _gvn.transform(new IfFalseNode(iff_tid_not_equal));
 3904 
 3905   // True path, tid is not equal, need to update the tid in the event writer.
 3906   Node* tid_is_not_equal = _gvn.transform(new IfTrueNode(iff_tid_not_equal));
 3907   record_for_igvn(tid_is_not_equal);
 3908 
 3909   // Store the pin state to the event writer.
 3910   store_to_memory(tid_is_not_equal, event_writer_pin_field, _gvn.transform(pinVirtualThread), T_BOOLEAN, MemNode::unordered);
 3911 
 3912   // Store the exclusion state to the event writer.
 3913   Node* excluded_bool = _gvn.transform(new URShiftINode(_gvn.transform(exclusion), excluded_shift));
 3914   store_to_memory(tid_is_not_equal, event_writer_excluded_field, excluded_bool, T_BOOLEAN, MemNode::unordered);
 3915 
 3916   // Store the tid to the event writer.
 3917   store_to_memory(tid_is_not_equal, event_writer_tid_field, tid, T_LONG, MemNode::unordered);
 3918 
 3919   // Update control and phi nodes.
 3920   event_writer_tid_compare_rgn->init_req(_true_path, tid_is_not_equal);
 3921   event_writer_tid_compare_rgn->init_req(_false_path, tid_is_equal);
 3922   event_writer_tid_compare_mem->init_req(_true_path, reset_memory());
 3923   event_writer_tid_compare_mem->init_req(_false_path, _gvn.transform(vthread_compare_mem));
 3924   event_writer_tid_compare_io->init_req(_true_path, i_o());
 3925   event_writer_tid_compare_io->init_req(_false_path, _gvn.transform(vthread_compare_io));
 3926 
 3927   // Result of top level CFG, Memory, IO and Value.
 3928   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 3929   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3930   PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO);
 3931   PhiNode* result_value = new PhiNode(result_rgn, TypeInstPtr::BOTTOM);
 3932 
 3933   // Result control.
 3934   result_rgn->init_req(_true_path, _gvn.transform(event_writer_tid_compare_rgn));
 3935   result_rgn->init_req(_false_path, jobj_is_null);
 3936 
 3937   // Result memory.
 3938   result_mem->init_req(_true_path, _gvn.transform(event_writer_tid_compare_mem));
 3939   result_mem->init_req(_false_path, input_memory_state);
 3940 
 3941   // Result IO.
 3942   result_io->init_req(_true_path, _gvn.transform(event_writer_tid_compare_io));
 3943   result_io->init_req(_false_path, input_io_state);
 3944 
 3945   // Result value.
 3946   result_value->init_req(_true_path, event_writer); // return event writer oop
 3947   result_value->init_req(_false_path, null()); // return null
 3948 
 3949   // Set output state.
 3950   set_control(_gvn.transform(result_rgn));
 3951   set_all_memory(_gvn.transform(result_mem));
 3952   set_i_o(_gvn.transform(result_io));
 3953   set_result(result_rgn, result_value);
 3954   return true;
 3955 }
 3956 
 3957 /*
 3958  * The intrinsic is a model of this pseudo-code:
 3959  *
 3960  * JfrThreadLocal* const tl = thread->jfr_thread_local();
 3961  * if (carrierThread != thread) { // is virtual thread
 3962  *   const u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(thread);
 3963  *   bool excluded = vthread_epoch_raw & excluded_mask;
 3964  *   AtomicAccess::store(&tl->_contextual_tid, java_lang_Thread::tid(thread));
 3965  *   AtomicAccess::store(&tl->_contextual_thread_excluded, is_excluded);
 3966  *   if (!excluded) {
 3967  *     const u2 vthread_epoch = vthread_epoch_raw & epoch_mask;
 3968  *     AtomicAccess::store(&tl->_vthread_epoch, vthread_epoch);
 3969  *   }
 3970  *   AtomicAccess::release_store(&tl->_vthread, true);
 3971  *   return;
 3972  * }
 3973  * AtomicAccess::release_store(&tl->_vthread, false);
 3974  */
 3975 void LibraryCallKit::extend_setCurrentThread(Node* jt, Node* thread) {
 3976   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3977 
 3978   Node* input_memory_state = reset_memory();
 3979   set_all_memory(input_memory_state);
 3980 
 3981   // The most significant bit of the u2 is used to denote thread exclusion
 3982   Node* excluded_mask = _gvn.intcon(1 << 15);
 3983   // The epoch generation is the range [1-32767]
 3984   Node* epoch_mask = _gvn.intcon(32767);
 3985 
 3986   Node* const carrierThread = generate_current_thread(jt);
 3987   // If thread != carrierThread, this is a virtual thread.
 3988   Node* thread_cmp_carrierThread = _gvn.transform(new CmpPNode(thread, carrierThread));
 3989   Node* test_thread_not_equal_carrierThread = _gvn.transform(new BoolNode(thread_cmp_carrierThread, BoolTest::ne));
 3990   IfNode* iff_thread_not_equal_carrierThread =
 3991     create_and_map_if(control(), test_thread_not_equal_carrierThread, PROB_FAIR, COUNT_UNKNOWN);
 3992 
 3993   Node* vthread_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_OFFSET_JFR));
 3994 
 3995   // False branch, is carrierThread.
 3996   Node* thread_equal_carrierThread = _gvn.transform(new IfFalseNode(iff_thread_not_equal_carrierThread));
 3997   // Store release
 3998   Node* vthread_false_memory = store_to_memory(thread_equal_carrierThread, vthread_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::release, true);
 3999 
 4000   set_all_memory(input_memory_state);
 4001 
 4002   // True branch, is virtual thread.
 4003   Node* thread_not_equal_carrierThread = _gvn.transform(new IfTrueNode(iff_thread_not_equal_carrierThread));
 4004   set_control(thread_not_equal_carrierThread);
 4005 
 4006   // Load the raw epoch value from the vthread.
 4007   Node* epoch_offset = basic_plus_adr(thread, java_lang_Thread::jfr_epoch_offset());
 4008   Node* epoch_raw = access_load_at(thread, epoch_offset, _gvn.type(epoch_offset)->is_ptr(), TypeInt::CHAR, T_CHAR,
 4009                                    IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 4010 
 4011   // Mask off the excluded information from the epoch.
 4012   Node * const is_excluded = _gvn.transform(new AndINode(epoch_raw, excluded_mask));
 4013 
 4014   // Load the tid field from the thread.
 4015   Node* tid = load_field_from_object(thread, "tid", "J");
 4016 
 4017   // Store the vthread tid to the jfr thread local.
 4018   Node* thread_id_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_ID_OFFSET_JFR));
 4019   Node* tid_memory = store_to_memory(control(), thread_id_offset, tid, T_LONG, MemNode::unordered, true);
 4020 
 4021   // Branch is_excluded to conditionalize updating the epoch .
 4022   Node* excluded_cmp = _gvn.transform(new CmpINode(is_excluded, excluded_mask));
 4023   Node* test_excluded = _gvn.transform(new BoolNode(excluded_cmp, BoolTest::eq));
 4024   IfNode* iff_excluded = create_and_map_if(control(), test_excluded, PROB_MIN, COUNT_UNKNOWN);
 4025 
 4026   // True branch, vthread is excluded, no need to write epoch info.
 4027   Node* excluded = _gvn.transform(new IfTrueNode(iff_excluded));
 4028   set_control(excluded);
 4029   Node* vthread_is_excluded = _gvn.intcon(1);
 4030 
 4031   // False branch, vthread is included, update epoch info.
 4032   Node* included = _gvn.transform(new IfFalseNode(iff_excluded));
 4033   set_control(included);
 4034   Node* vthread_is_included = _gvn.intcon(0);
 4035 
 4036   // Get epoch value.
 4037   Node* epoch = _gvn.transform(new AndINode(epoch_raw, epoch_mask));
 4038 
 4039   // Store the vthread epoch to the jfr thread local.
 4040   Node* vthread_epoch_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EPOCH_OFFSET_JFR));
 4041   Node* included_memory = store_to_memory(control(), vthread_epoch_offset, epoch, T_CHAR, MemNode::unordered, true);
 4042 
 4043   RegionNode* excluded_rgn = new RegionNode(PATH_LIMIT);
 4044   record_for_igvn(excluded_rgn);
 4045   PhiNode* excluded_mem = new PhiNode(excluded_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4046   record_for_igvn(excluded_mem);
 4047   PhiNode* exclusion = new PhiNode(excluded_rgn, TypeInt::BOOL);
 4048   record_for_igvn(exclusion);
 4049 
 4050   // Merge the excluded control and memory.
 4051   excluded_rgn->init_req(_true_path, excluded);
 4052   excluded_rgn->init_req(_false_path, included);
 4053   excluded_mem->init_req(_true_path, tid_memory);
 4054   excluded_mem->init_req(_false_path, included_memory);
 4055   exclusion->init_req(_true_path, vthread_is_excluded);
 4056   exclusion->init_req(_false_path, vthread_is_included);
 4057 
 4058   // Set intermediate state.
 4059   set_control(_gvn.transform(excluded_rgn));
 4060   set_all_memory(excluded_mem);
 4061 
 4062   // Store the vthread exclusion state to the jfr thread local.
 4063   Node* thread_local_excluded_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EXCLUDED_OFFSET_JFR));
 4064   store_to_memory(control(), thread_local_excluded_offset, _gvn.transform(exclusion), T_BOOLEAN, MemNode::unordered, true);
 4065 
 4066   // Store release
 4067   Node * vthread_true_memory = store_to_memory(control(), vthread_offset, _gvn.intcon(1), T_BOOLEAN, MemNode::release, true);
 4068 
 4069   RegionNode* thread_compare_rgn = new RegionNode(PATH_LIMIT);
 4070   record_for_igvn(thread_compare_rgn);
 4071   PhiNode* thread_compare_mem = new PhiNode(thread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4072   record_for_igvn(thread_compare_mem);
 4073   PhiNode* vthread = new PhiNode(thread_compare_rgn, TypeInt::BOOL);
 4074   record_for_igvn(vthread);
 4075 
 4076   // Merge the thread_compare control and memory.
 4077   thread_compare_rgn->init_req(_true_path, control());
 4078   thread_compare_rgn->init_req(_false_path, thread_equal_carrierThread);
 4079   thread_compare_mem->init_req(_true_path, vthread_true_memory);
 4080   thread_compare_mem->init_req(_false_path, vthread_false_memory);
 4081 
 4082   // Set output state.
 4083   set_control(_gvn.transform(thread_compare_rgn));
 4084   set_all_memory(_gvn.transform(thread_compare_mem));
 4085 }
 4086 
 4087 //------------------------inline_native_try_update_epoch------------------
 4088 //
 4089 // The generated code is a function of the argument type.
 4090 //
 4091 bool LibraryCallKit::inline_native_try_update_epoch() {
 4092   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 4093 
 4094   // Save input memory.
 4095   Node* input_memory_state = reset_memory();
 4096   set_all_memory(input_memory_state);
 4097 
 4098   // Argument is an oop whose class has an injected instance field,
 4099   // called 'jfr_epoch' of type T_INT, used for holding a jfr epoch value.
 4100   Node* oop = argument(0);
 4101   const TypeInstPtr* tinst = _gvn.type(oop)->isa_instptr();
 4102   assert(tinst != nullptr, "oop is null");
 4103   assert(tinst->is_loaded(), "klass is not loaded");
 4104   ciInstanceKlass* const ik = tinst->instance_klass();
 4105 
 4106   ciField* const field = ik->get_injected_instance_field_by_name(ciSymbol::make("jfr_epoch"),
 4107                                                                  ciSymbol::make("I"));
 4108 
 4109   assert(field != nullptr, "field 'jfr_epoch' of type I not injected in klass %s", ik->name()->as_utf8());
 4110 
 4111   const int jfr_epoch_field_offset = field->offset_in_bytes();
 4112   Node* oop_epoch_field_offset = basic_plus_adr(oop, jfr_epoch_field_offset);
 4113   const TypePtr* adr_type = _gvn.type(oop_epoch_field_offset)->isa_ptr();
 4114   const int alias_idx = C->get_alias_index(adr_type);
 4115   BasicType bt = field->layout_type();
 4116   const Type * oop_epoch_field_type = Type::get_const_basic_type(bt);
 4117 
 4118   // Load the epoch value from the oop.
 4119   Node* oop_epoch = access_load_at(oop,
 4120                                    oop_epoch_field_offset,
 4121                                    adr_type, oop_epoch_field_type,
 4122                                    bt, IN_HEAP | MO_UNORDERED);
 4123 
 4124   // Load the current JFR epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR.
 4125   Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address()));
 4126   Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered);
 4127 
 4128   // Compare the epoch in the oop against the current JFR epoch generation.
 4129   Node* const epochs_cmp = _gvn.transform(new CmpINode(current_epoch_generation, oop_epoch));
 4130   Node* epochs_equal_test = _gvn.transform(new BoolNode(epochs_cmp, BoolTest::eq));
 4131   IfNode* iff_epochs_equal = create_and_map_if(control(), epochs_equal_test, PROB_LIKELY(0.999), COUNT_UNKNOWN);
 4132 
 4133   // True path.
 4134   Node* epochs_are_equal = _gvn.transform(new IfTrueNode(iff_epochs_equal));
 4135 
 4136   // False path.
 4137   Node* epochs_are_not_equal = _gvn.transform(new IfFalseNode(iff_epochs_equal));
 4138 
 4139   set_control(_gvn.transform(epochs_are_not_equal));
 4140 
 4141   // Attempt to cas the current JFR epoch generation into the oop epoch field.
 4142   DecoratorSet decorators = IN_HEAP;
 4143   decorators |= mo_decorator_for_access_kind(Volatile);
 4144 
 4145   Node* result = access_atomic_cmpxchg_val_at(oop,
 4146                                               oop_epoch_field_offset,
 4147                                               adr_type, alias_idx,
 4148                                               oop_epoch, // expected value
 4149                                               current_epoch_generation, // new value
 4150                                               oop_epoch_field_type,
 4151                                               bt,
 4152                                               decorators);
 4153 
 4154   // Compare the result of the cas operation to the expected value.
 4155   Node* const cas_cmp_to_expected_value = _gvn.transform(new CmpINode(result, oop_epoch));
 4156   Node* cas_operation_test = _gvn.transform(new BoolNode(cas_cmp_to_expected_value, BoolTest::eq));
 4157   IfNode* iff_cas_success = create_and_map_if(control(), cas_operation_test, PROB_LIKELY(0.999), COUNT_UNKNOWN);
 4158 
 4159   // True path.
 4160   Node* cas_success = _gvn.transform(new IfTrueNode(iff_cas_success));
 4161 
 4162   // False path.
 4163   Node* cas_failure = _gvn.transform(new IfFalseNode(iff_cas_success));
 4164 
 4165   // Cas result region and phi nodes.
 4166   RegionNode* cas_operation_rgn = new RegionNode(PATH_LIMIT);
 4167   record_for_igvn(cas_operation_rgn);
 4168   PhiNode* cas_operation_mem = new PhiNode(cas_operation_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4169   record_for_igvn(cas_operation_mem);
 4170   PhiNode* cas_result = new PhiNode(cas_operation_rgn, TypeInt::BOOL);
 4171   record_for_igvn(cas_result);
 4172 
 4173   cas_operation_rgn->init_req(_true_path, _gvn.transform(cas_success));
 4174   cas_operation_rgn->init_req(_false_path, _gvn.transform(cas_failure));
 4175   cas_operation_mem->init_req(_true_path, reset_memory());
 4176   cas_operation_mem->init_req(_false_path, input_memory_state);
 4177   cas_result->init_req(_true_path, _gvn.intcon(1));
 4178   cas_result->init_req(_false_path, _gvn.intcon(0));
 4179 
 4180   // Epoch compare region and phi nodes.
 4181   RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT);
 4182   record_for_igvn(epoch_compare_rgn);
 4183   PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4184   record_for_igvn(epoch_compare_mem);
 4185   PhiNode* result_value = new PhiNode(epoch_compare_rgn, TypeInt::BOOL);
 4186   record_for_igvn(result_value);
 4187 
 4188   epoch_compare_rgn->init_req(_true_path, _gvn.transform(epochs_are_equal));
 4189   epoch_compare_rgn->init_req(_false_path, _gvn.transform(cas_operation_rgn));
 4190   epoch_compare_mem->init_req(_true_path, _gvn.transform(input_memory_state));
 4191   epoch_compare_mem->init_req(_false_path, _gvn.transform(cas_operation_mem));
 4192   result_value->init_req(_true_path, _gvn.intcon(0));
 4193   result_value->init_req(_false_path, _gvn.transform(cas_result));
 4194 
 4195   // Set output state.
 4196   set_result(epoch_compare_rgn, result_value);
 4197   set_all_memory(_gvn.transform(epoch_compare_mem));
 4198 
 4199   return true;
 4200 }
 4201 
 4202 #endif // JFR_HAVE_INTRINSICS
 4203 
 4204 //------------------------inline_native_currentCarrierThread------------------
 4205 bool LibraryCallKit::inline_native_currentCarrierThread() {
 4206   Node* junk = nullptr;
 4207   set_result(generate_current_thread(junk));
 4208   return true;
 4209 }
 4210 
 4211 //------------------------inline_native_currentThread------------------
 4212 bool LibraryCallKit::inline_native_currentThread() {
 4213   Node* junk = nullptr;
 4214   set_result(generate_virtual_thread(junk));
 4215   return true;
 4216 }
 4217 
 4218 //------------------------inline_native_setVthread------------------
 4219 bool LibraryCallKit::inline_native_setCurrentThread() {
 4220   assert(C->method()->changes_current_thread(),
 4221          "method changes current Thread but is not annotated ChangesCurrentThread");
 4222   Node* arr = argument(1);
 4223   Node* thread = _gvn.transform(new ThreadLocalNode());
 4224   Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::vthread_offset()));
 4225   Node* thread_obj_handle
 4226     = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered);
 4227   const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr();
 4228   access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED);
 4229 
 4230   // Change the _monitor_owner_id of the JavaThread
 4231   Node* tid = load_field_from_object(arr, "tid", "J");
 4232   Node* monitor_owner_id_offset = off_heap_plus_addr(thread, in_bytes(JavaThread::monitor_owner_id_offset()));
 4233   store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true);
 4234 
 4235   JFR_ONLY(extend_setCurrentThread(thread, arr);)
 4236   return true;
 4237 }
 4238 
 4239 const Type* LibraryCallKit::scopedValueCache_type() {
 4240   ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass());
 4241   const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass());
 4242   const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
 4243 
 4244   // Because we create the scopedValue cache lazily we have to make the
 4245   // type of the result BotPTR.
 4246   bool xk = etype->klass_is_exact();
 4247   const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, TypeAryPtr::Offset(0));
 4248   return objects_type;
 4249 }
 4250 
 4251 Node* LibraryCallKit::scopedValueCache_helper() {
 4252   Node* thread = _gvn.transform(new ThreadLocalNode());
 4253   Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::scopedValueCache_offset()));
 4254   // We cannot use immutable_memory() because we might flip onto a
 4255   // different carrier thread, at which point we'll need to use that
 4256   // carrier thread's cache.
 4257   // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
 4258   //       TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered));
 4259   return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered);
 4260 }
 4261 
 4262 //------------------------inline_native_scopedValueCache------------------
 4263 bool LibraryCallKit::inline_native_scopedValueCache() {
 4264   Node* cache_obj_handle = scopedValueCache_helper();
 4265   const Type* objects_type = scopedValueCache_type();
 4266   set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE));
 4267 
 4268   return true;
 4269 }
 4270 
 4271 //------------------------inline_native_setScopedValueCache------------------
 4272 bool LibraryCallKit::inline_native_setScopedValueCache() {
 4273   Node* arr = argument(0);
 4274   Node* cache_obj_handle = scopedValueCache_helper();
 4275   const Type* objects_type = scopedValueCache_type();
 4276 
 4277   const TypePtr *adr_type = _gvn.type(cache_obj_handle)->isa_ptr();
 4278   access_store_at(nullptr, cache_obj_handle, adr_type, arr, objects_type, T_OBJECT, IN_NATIVE | MO_UNORDERED);
 4279 
 4280   return true;
 4281 }
 4282 
 4283 //------------------------inline_native_Continuation_pin and unpin-----------
 4284 
 4285 // Shared implementation routine for both pin and unpin.
 4286 bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
 4287   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 4288 
 4289   // Save input memory.
 4290   Node* input_memory_state = reset_memory();
 4291   set_all_memory(input_memory_state);
 4292 
 4293   // TLS
 4294   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 4295   Node* last_continuation_offset = off_heap_plus_addr(tls_ptr, in_bytes(JavaThread::cont_entry_offset()));
 4296   Node* last_continuation = make_load(control(), last_continuation_offset, last_continuation_offset->get_ptr_type(), T_ADDRESS, MemNode::unordered);
 4297 
 4298   // Null check the last continuation object.
 4299   Node* continuation_cmp_null = _gvn.transform(new CmpPNode(last_continuation, null()));
 4300   Node* test_continuation_not_equal_null = _gvn.transform(new BoolNode(continuation_cmp_null, BoolTest::ne));
 4301   IfNode* iff_continuation_not_equal_null = create_and_map_if(control(), test_continuation_not_equal_null, PROB_MAX, COUNT_UNKNOWN);
 4302 
 4303   // False path, last continuation is null.
 4304   Node* continuation_is_null = _gvn.transform(new IfFalseNode(iff_continuation_not_equal_null));
 4305 
 4306   // True path, last continuation is not null.
 4307   Node* continuation_is_not_null = _gvn.transform(new IfTrueNode(iff_continuation_not_equal_null));
 4308 
 4309   set_control(continuation_is_not_null);
 4310 
 4311   // Load the pin count from the last continuation.
 4312   Node* pin_count_offset = off_heap_plus_addr(last_continuation, in_bytes(ContinuationEntry::pin_count_offset()));
 4313   Node* pin_count = make_load(control(), pin_count_offset, TypeInt::INT, T_INT, MemNode::unordered);
 4314 
 4315   // The loaded pin count is compared against a context specific rhs for over/underflow detection.
 4316   Node* pin_count_rhs;
 4317   if (unpin) {
 4318     pin_count_rhs = _gvn.intcon(0);
 4319   } else {
 4320     pin_count_rhs = _gvn.intcon(UINT32_MAX);
 4321   }
 4322   Node* pin_count_cmp = _gvn.transform(new CmpUNode(pin_count, pin_count_rhs));
 4323   Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq));
 4324   IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN);
 4325 
 4326   // True branch, pin count over/underflow.
 4327   Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
 4328   {
 4329     // Trap (but not deoptimize (Action_none)) and continue in the interpreter
 4330     // which will throw IllegalStateException for pin count over/underflow.
 4331     // No memory changed so far - we can use memory create by reset_memory()
 4332     // at the beginning of this intrinsic. No need to call reset_memory() again.
 4333     PreserveJVMState pjvms(this);
 4334     set_control(pin_count_over_underflow);
 4335     uncommon_trap(Deoptimization::Reason_intrinsic,
 4336                   Deoptimization::Action_none);
 4337     assert(stopped(), "invariant");
 4338   }
 4339 
 4340   // False branch, no pin count over/underflow. Increment or decrement pin count and store back.
 4341   Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow));
 4342   set_control(valid_pin_count);
 4343 
 4344   Node* next_pin_count;
 4345   if (unpin) {
 4346     next_pin_count = _gvn.transform(new SubINode(pin_count, _gvn.intcon(1)));
 4347   } else {
 4348     next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1)));
 4349   }
 4350 
 4351   store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
 4352 
 4353   // Result of top level CFG and Memory.
 4354   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 4355   record_for_igvn(result_rgn);
 4356   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4357   record_for_igvn(result_mem);
 4358 
 4359   result_rgn->init_req(_true_path, valid_pin_count);
 4360   result_rgn->init_req(_false_path, continuation_is_null);
 4361   result_mem->init_req(_true_path, reset_memory());
 4362   result_mem->init_req(_false_path, input_memory_state);
 4363 
 4364   // Set output state.
 4365   set_control(_gvn.transform(result_rgn));
 4366   set_all_memory(_gvn.transform(result_mem));
 4367 
 4368   return true;
 4369 }
 4370 
 4371 //---------------------------load_mirror_from_klass----------------------------
 4372 // Given a klass oop, load its java mirror (a java.lang.Class oop).
 4373 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
 4374   Node* p = off_heap_plus_addr(klass, in_bytes(Klass::java_mirror_offset()));
 4375   Node* load = make_load(nullptr, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
 4376   // mirror = ((OopHandle)mirror)->resolve();
 4377   return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE);
 4378 }
 4379 
 4380 //-----------------------load_klass_from_mirror_common-------------------------
 4381 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
 4382 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
 4383 // and branch to the given path on the region.
 4384 // If never_see_null, take an uncommon trap on null, so we can optimistically
 4385 // compile for the non-null case.
 4386 // If the region is null, force never_see_null = true.
 4387 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
 4388                                                     bool never_see_null,
 4389                                                     RegionNode* region,
 4390                                                     int null_path,
 4391                                                     int offset) {
 4392   if (region == nullptr)  never_see_null = true;
 4393   Node* p = basic_plus_adr(mirror, offset);
 4394   const TypeKlassPtr*  kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
 4395   Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type));
 4396   Node* null_ctl = top();
 4397   kls = null_check_oop(kls, &null_ctl, never_see_null);
 4398   if (region != nullptr) {
 4399     // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
 4400     region->init_req(null_path, null_ctl);
 4401   } else {
 4402     assert(null_ctl == top(), "no loose ends");
 4403   }
 4404   return kls;
 4405 }
 4406 
 4407 //--------------------(inline_native_Class_query helpers)---------------------
 4408 // Use this for JVM_ACC_INTERFACE.
 4409 // Fall through if (mods & mask) == bits, take the guard otherwise.
 4410 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region,
 4411                                                  ByteSize offset, const Type* type, BasicType bt) {
 4412   // Branch around if the given klass has the given modifier bit set.
 4413   // Like generate_guard, adds a new path onto the region.
 4414   Node* modp = off_heap_plus_addr(kls, in_bytes(offset));
 4415   Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered);
 4416   Node* mask = intcon(modifier_mask);
 4417   Node* bits = intcon(modifier_bits);
 4418   Node* mbit = _gvn.transform(new AndINode(mods, mask));
 4419   Node* cmp  = _gvn.transform(new CmpINode(mbit, bits));
 4420   Node* bol  = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
 4421   return generate_fair_guard(bol, region);
 4422 }
 4423 
 4424 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
 4425   return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region,
 4426                                     InstanceKlass::access_flags_offset(), TypeInt::CHAR, T_CHAR);
 4427 }
 4428 
 4429 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast.
 4430 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
 4431   return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region,
 4432                                     Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN);
 4433 }
 4434 
 4435 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) {
 4436   return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region);
 4437 }
 4438 
 4439 //-------------------------inline_native_Class_query-------------------
 4440 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
 4441   const Type* return_type = TypeInt::BOOL;
 4442   Node* prim_return_value = top();  // what happens if it's a primitive class?
 4443   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 4444   bool expect_prim = false;     // most of these guys expect to work on refs
 4445 
 4446   enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
 4447 
 4448   Node* mirror = argument(0);
 4449   Node* obj    = top();
 4450 
 4451   switch (id) {
 4452   case vmIntrinsics::_isInstance:
 4453     // nothing is an instance of a primitive type
 4454     prim_return_value = intcon(0);
 4455     obj = argument(1);
 4456     break;
 4457   case vmIntrinsics::_isHidden:
 4458     prim_return_value = intcon(0);
 4459     break;
 4460   case vmIntrinsics::_getSuperclass:
 4461     prim_return_value = null();
 4462     return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
 4463     break;
 4464   default:
 4465     fatal_unexpected_iid(id);
 4466     break;
 4467   }
 4468 
 4469   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
 4470   if (mirror_con == nullptr)  return false;  // cannot happen?
 4471 
 4472 #ifndef PRODUCT
 4473   if (C->print_intrinsics() || C->print_inlining()) {
 4474     ciType* k = mirror_con->java_mirror_type();
 4475     if (k) {
 4476       tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id()));
 4477       k->print_name();
 4478       tty->cr();
 4479     }
 4480   }
 4481 #endif
 4482 
 4483   // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
 4484   RegionNode* region = new RegionNode(PATH_LIMIT);
 4485   record_for_igvn(region);
 4486   PhiNode* phi = new PhiNode(region, return_type);
 4487 
 4488   // The mirror will never be null of Reflection.getClassAccessFlags, however
 4489   // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
 4490   // if it is. See bug 4774291.
 4491 
 4492   // For Reflection.getClassAccessFlags(), the null check occurs in
 4493   // the wrong place; see inline_unsafe_access(), above, for a similar
 4494   // situation.
 4495   mirror = null_check(mirror);
 4496   // If mirror or obj is dead, only null-path is taken.
 4497   if (stopped())  return true;
 4498 
 4499   if (expect_prim)  never_see_null = false;  // expect nulls (meaning prims)
 4500 
 4501   // Now load the mirror's klass metaobject, and null-check it.
 4502   // Side-effects region with the control path if the klass is null.
 4503   Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path);
 4504   // If kls is null, we have a primitive mirror.
 4505   phi->init_req(_prim_path, prim_return_value);
 4506   if (stopped()) { set_result(region, phi); return true; }
 4507   bool safe_for_replace = (region->in(_prim_path) == top());
 4508 
 4509   Node* p;  // handy temp
 4510   Node* null_ctl;
 4511 
 4512   // Now that we have the non-null klass, we can perform the real query.
 4513   // For constant classes, the query will constant-fold in LoadNode::Value.
 4514   Node* query_value = top();
 4515   switch (id) {
 4516   case vmIntrinsics::_isInstance:
 4517     // nothing is an instance of a primitive type
 4518     query_value = gen_instanceof(obj, kls, safe_for_replace);
 4519     break;
 4520 
 4521   case vmIntrinsics::_isHidden:
 4522     // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.)
 4523     if (generate_hidden_class_guard(kls, region) != nullptr)
 4524       // A guard was added.  If the guard is taken, it was an hidden class.
 4525       phi->add_req(intcon(1));
 4526     // If we fall through, it's a plain class.
 4527     query_value = intcon(0);
 4528     break;
 4529 
 4530 
 4531   case vmIntrinsics::_getSuperclass:
 4532     // The rules here are somewhat unfortunate, but we can still do better
 4533     // with random logic than with a JNI call.
 4534     // Interfaces store null or Object as _super, but must report null.
 4535     // Arrays store an intermediate super as _super, but must report Object.
 4536     // Other types can report the actual _super.
 4537     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
 4538     if (generate_array_guard(kls, region) != nullptr) {
 4539       // A guard was added.  If the guard is taken, it was an array.
 4540       phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
 4541     }
 4542     // Check for interface after array since this checks AccessFlags offset into InstanceKlass.
 4543     // In other words, we are accessing subtype-specific information, so we need to determine the subtype first.
 4544     if (generate_interface_guard(kls, region) != nullptr) {
 4545       // A guard was added.  If the guard is taken, it was an interface.
 4546       phi->add_req(null());
 4547     }
 4548     // If we fall through, it's a plain class.  Get its _super.
 4549     if (!stopped()) {
 4550       p = basic_plus_adr(top(), kls, in_bytes(Klass::super_offset()));
 4551       kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 4552       null_ctl = top();
 4553       kls = null_check_oop(kls, &null_ctl);
 4554       if (null_ctl != top()) {
 4555         // If the guard is taken, Object.superClass is null (both klass and mirror).
 4556         region->add_req(null_ctl);
 4557         phi   ->add_req(null());
 4558       }
 4559       if (!stopped()) {
 4560         query_value = load_mirror_from_klass(kls);
 4561       }
 4562     }
 4563     break;
 4564 
 4565   default:
 4566     fatal_unexpected_iid(id);
 4567     break;
 4568   }
 4569 
 4570   // Fall-through is the normal case of a query to a real class.
 4571   phi->init_req(1, query_value);
 4572   region->init_req(1, control());
 4573 
 4574   C->set_has_split_ifs(true); // Has chance for split-if optimization
 4575   set_result(region, phi);
 4576   return true;
 4577 }
 4578 
 4579 
 4580 //-------------------------inline_Class_cast-------------------
 4581 bool LibraryCallKit::inline_Class_cast() {
 4582   Node* mirror = argument(0); // Class
 4583   Node* obj    = argument(1);
 4584   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
 4585   if (mirror_con == nullptr) {
 4586     return false;  // dead path (mirror->is_top()).
 4587   }
 4588   if (obj == nullptr || obj->is_top()) {
 4589     return false;  // dead path
 4590   }
 4591   const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr();
 4592 
 4593   // First, see if Class.cast() can be folded statically.
 4594   // java_mirror_type() returns non-null for compile-time Class constants.
 4595   ciType* tm = mirror_con->java_mirror_type();
 4596   if (tm != nullptr && tm->is_klass() &&
 4597       tp != nullptr) {
 4598     if (!tp->is_loaded()) {
 4599       // Don't use intrinsic when class is not loaded.
 4600       return false;
 4601     } else {
 4602       const TypeKlassPtr* tklass = TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces);
 4603       int static_res = C->static_subtype_check(tklass, tp->as_klass_type());
 4604       if (static_res == Compile::SSC_always_true) {
 4605         // isInstance() is true - fold the code.
 4606         set_result(obj);
 4607         return true;
 4608       } else if (static_res == Compile::SSC_always_false) {
 4609         // Don't use intrinsic, have to throw ClassCastException.
 4610         // If the reference is null, the non-intrinsic bytecode will
 4611         // be optimized appropriately.
 4612         return false;
 4613       }
 4614     }
 4615   }
 4616 
 4617   // Bailout intrinsic and do normal inlining if exception path is frequent.
 4618   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 4619     return false;
 4620   }
 4621 
 4622   // Generate dynamic checks.
 4623   // Class.cast() is java implementation of _checkcast bytecode.
 4624   // Do checkcast (Parse::do_checkcast()) optimizations here.
 4625 
 4626   mirror = null_check(mirror);
 4627   // If mirror is dead, only null-path is taken.
 4628   if (stopped()) {
 4629     return true;
 4630   }
 4631 
 4632   // Not-subtype or the mirror's klass ptr is nullptr (in case it is a primitive).
 4633   enum { _bad_type_path = 1, _prim_path = 2, _npe_path = 3, PATH_LIMIT };
 4634   RegionNode* region = new RegionNode(PATH_LIMIT);
 4635   record_for_igvn(region);
 4636 
 4637   // Now load the mirror's klass metaobject, and null-check it.
 4638   // If kls is null, we have a primitive mirror and
 4639   // nothing is an instance of a primitive type.
 4640   Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path);
 4641 
 4642   Node* res = top();
 4643   Node* io = i_o();
 4644   Node* mem = merged_memory();
 4645   SafePointNode* new_cast_failure_map = nullptr;
 4646 
 4647   if (!stopped()) {
 4648 
 4649     Node* bad_type_ctrl = top();
 4650     // Do checkcast optimizations.
 4651     res = gen_checkcast(obj, kls, &bad_type_ctrl, &new_cast_failure_map);
 4652     region->init_req(_bad_type_path, bad_type_ctrl);
 4653   }
 4654   if (region->in(_prim_path) != top() ||
 4655       region->in(_bad_type_path) != top() ||
 4656       region->in(_npe_path) != top()) {
 4657     // Let Interpreter throw ClassCastException.
 4658     PreserveJVMState pjvms(this);
 4659     if (new_cast_failure_map != nullptr) {
 4660       // The current map on the success path could have been modified. Use the dedicated failure path map.
 4661       set_map(new_cast_failure_map);
 4662     }
 4663     set_control(_gvn.transform(region));
 4664     // Set IO and memory because gen_checkcast may override them when buffering inline types
 4665     set_i_o(io);
 4666     set_all_memory(mem);
 4667     uncommon_trap(Deoptimization::Reason_intrinsic,
 4668                   Deoptimization::Action_maybe_recompile);
 4669   }
 4670   if (!stopped()) {
 4671     set_result(res);
 4672   }
 4673   return true;
 4674 }
 4675 
 4676 
 4677 //--------------------------inline_native_subtype_check------------------------
 4678 // This intrinsic takes the JNI calls out of the heart of
 4679 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
 4680 bool LibraryCallKit::inline_native_subtype_check() {
 4681   // Pull both arguments off the stack.
 4682   Node* args[2];                // two java.lang.Class mirrors: superc, subc
 4683   args[0] = argument(0);
 4684   args[1] = argument(1);
 4685   Node* klasses[2];             // corresponding Klasses: superk, subk
 4686   klasses[0] = klasses[1] = top();
 4687 
 4688   enum {
 4689     // A full decision tree on {superc is prim, subc is prim}:
 4690     _prim_0_path = 1,           // {P,N} => false
 4691                                 // {P,P} & superc!=subc => false
 4692     _prim_same_path,            // {P,P} & superc==subc => true
 4693     _prim_1_path,               // {N,P} => false
 4694     _ref_subtype_path,          // {N,N} & subtype check wins => true
 4695     _both_ref_path,             // {N,N} & subtype check loses => false
 4696     PATH_LIMIT
 4697   };
 4698 
 4699   RegionNode* region = new RegionNode(PATH_LIMIT);
 4700   RegionNode* prim_region = new RegionNode(2);
 4701   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
 4702   record_for_igvn(region);
 4703   record_for_igvn(prim_region);
 4704 
 4705   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
 4706   const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
 4707   int class_klass_offset = java_lang_Class::klass_offset();
 4708 
 4709   // First null-check both mirrors and load each mirror's klass metaobject.
 4710   int which_arg;
 4711   for (which_arg = 0; which_arg <= 1; which_arg++) {
 4712     Node* arg = args[which_arg];
 4713     arg = null_check(arg);
 4714     if (stopped())  break;
 4715     args[which_arg] = arg;
 4716 
 4717     Node* p = basic_plus_adr(arg, class_klass_offset);
 4718     Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
 4719     klasses[which_arg] = _gvn.transform(kls);
 4720   }
 4721 
 4722   // Having loaded both klasses, test each for null.
 4723   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 4724   for (which_arg = 0; which_arg <= 1; which_arg++) {
 4725     Node* kls = klasses[which_arg];
 4726     Node* null_ctl = top();
 4727     kls = null_check_oop(kls, &null_ctl, never_see_null);
 4728     if (which_arg == 0) {
 4729       prim_region->init_req(1, null_ctl);
 4730     } else {
 4731       region->init_req(_prim_1_path, null_ctl);
 4732     }
 4733     if (stopped())  break;
 4734     klasses[which_arg] = kls;
 4735   }
 4736 
 4737   if (!stopped()) {
 4738     // now we have two reference types, in klasses[0..1]
 4739     Node* subk   = klasses[1];  // the argument to isAssignableFrom
 4740     Node* superk = klasses[0];  // the receiver
 4741     region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
 4742     region->set_req(_ref_subtype_path, control());
 4743   }
 4744 
 4745   // If both operands are primitive (both klasses null), then
 4746   // we must return true when they are identical primitives.
 4747   // It is convenient to test this after the first null klass check.
 4748   // This path is also used if superc is a value mirror.
 4749   set_control(_gvn.transform(prim_region));
 4750   if (!stopped()) {
 4751     // Since superc is primitive, make a guard for the superc==subc case.
 4752     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
 4753     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
 4754     generate_fair_guard(bol_eq, region);
 4755     if (region->req() == PATH_LIMIT+1) {
 4756       // A guard was added.  If the added guard is taken, superc==subc.
 4757       region->swap_edges(PATH_LIMIT, _prim_same_path);
 4758       region->del_req(PATH_LIMIT);
 4759     }
 4760     region->set_req(_prim_0_path, control()); // Not equal after all.
 4761   }
 4762 
 4763   // these are the only paths that produce 'true':
 4764   phi->set_req(_prim_same_path,   intcon(1));
 4765   phi->set_req(_ref_subtype_path, intcon(1));
 4766 
 4767   // pull together the cases:
 4768   assert(region->req() == PATH_LIMIT, "sane region");
 4769   for (uint i = 1; i < region->req(); i++) {
 4770     Node* ctl = region->in(i);
 4771     if (ctl == nullptr || ctl == top()) {
 4772       region->set_req(i, top());
 4773       phi   ->set_req(i, top());
 4774     } else if (phi->in(i) == nullptr) {
 4775       phi->set_req(i, intcon(0)); // all other paths produce 'false'
 4776     }
 4777   }
 4778 
 4779   set_control(_gvn.transform(region));
 4780   set_result(_gvn.transform(phi));
 4781   return true;
 4782 }
 4783 
 4784 //---------------------generate_array_guard_common------------------------
 4785 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind, Node** obj) {
 4786 
 4787   if (stopped()) {
 4788     return nullptr;
 4789   }
 4790 
 4791   // Like generate_guard, adds a new path onto the region.
 4792   jint  layout_con = 0;
 4793   Node* layout_val = get_layout_helper(kls, layout_con);
 4794   if (layout_val == nullptr) {
 4795     bool query = 0;
 4796     switch(kind) {
 4797       case RefArray:       query = Klass::layout_helper_is_refArray(layout_con); break;
 4798       case NonRefArray:    query = !Klass::layout_helper_is_refArray(layout_con); break;
 4799       case TypeArray:      query = Klass::layout_helper_is_typeArray(layout_con); break;
 4800       case AnyArray:       query = Klass::layout_helper_is_array(layout_con); break;
 4801       case NonArray:       query = !Klass::layout_helper_is_array(layout_con); break;
 4802       default:
 4803         ShouldNotReachHere();
 4804     }
 4805     if (!query) {
 4806       return nullptr;                       // never a branch
 4807     } else {                             // always a branch
 4808       Node* always_branch = control();
 4809       if (region != nullptr)
 4810         region->add_req(always_branch);
 4811       set_control(top());
 4812       return always_branch;
 4813     }
 4814   }
 4815   unsigned int value = 0;
 4816   BoolTest::mask btest = BoolTest::illegal;
 4817   switch(kind) {
 4818     case RefArray:
 4819     case NonRefArray: {
 4820       value = Klass::_lh_array_tag_ref_value;
 4821       layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
 4822       btest = (kind == RefArray) ? BoolTest::eq : BoolTest::ne;
 4823       break;
 4824     }
 4825     case TypeArray: {
 4826       value = Klass::_lh_array_tag_type_value;
 4827       layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
 4828       btest = BoolTest::eq;
 4829       break;
 4830     }
 4831     case AnyArray:    value = Klass::_lh_neutral_value; btest = BoolTest::lt; break;
 4832     case NonArray:    value = Klass::_lh_neutral_value; btest = BoolTest::gt; break;
 4833     default:
 4834       ShouldNotReachHere();
 4835   }
 4836   // Now test the correct condition.
 4837   jint nval = (jint)value;
 4838   Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval)));
 4839   Node* bol = _gvn.transform(new BoolNode(cmp, btest));
 4840   Node* ctrl = generate_fair_guard(bol, region);
 4841   Node* is_array_ctrl = kind == NonArray ? control() : ctrl;
 4842   if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) {
 4843     // Keep track of the fact that 'obj' is an array to prevent
 4844     // array specific accesses from floating above the guard.
 4845     *obj = _gvn.transform(new CheckCastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
 4846   }
 4847   return ctrl;
 4848 }
 4849 
 4850 // public static native Object[] ValueClass::newNullRestrictedAtomicArray(Class<?> componentType, int length, Object initVal);
 4851 // public static native Object[] ValueClass::newNullRestrictedNonAtomicArray(Class<?> componentType, int length, Object initVal);
 4852 // public static native Object[] ValueClass::newNullableAtomicArray(Class<?> componentType, int length);
 4853 bool LibraryCallKit::inline_newArray(bool null_free, bool atomic) {
 4854   assert(null_free || atomic, "nullable implies atomic");
 4855   Node* componentType = argument(0);
 4856   Node* length = argument(1);
 4857   Node* init_val = null_free ? argument(2) : nullptr;
 4858 
 4859   const TypeInstPtr* tp = _gvn.type(componentType)->isa_instptr();
 4860   if (tp != nullptr) {
 4861     ciInstanceKlass* ik = tp->instance_klass();
 4862     if (ik == C->env()->Class_klass()) {
 4863       ciType* t = tp->java_mirror_type();
 4864       if (t != nullptr && t->is_inlinetype()) {
 4865 
 4866         ciArrayKlass* array_klass = ciArrayKlass::make(t, null_free, atomic, true);
 4867         assert(array_klass->is_elem_null_free() == null_free, "inconsistency");
 4868 
 4869         // TOOD 8350865 ZGC needs card marks on initializing oop stores
 4870         if (UseZGC && null_free && !array_klass->is_flat_array_klass()) {
 4871           return false;
 4872         }
 4873 
 4874         if (array_klass->is_loaded() && array_klass->element_klass()->as_inline_klass()->is_initialized()) {
 4875           const TypeAryKlassPtr* array_klass_type = TypeAryKlassPtr::make(array_klass, Type::trust_interfaces);
 4876           if (null_free) {
 4877             if (init_val->is_InlineType()) {
 4878               if (array_klass_type->is_flat() && init_val->as_InlineType()->is_all_zero(&gvn(), /* flat */ true)) {
 4879                 // Zeroing is enough because the init value is the all-zero value
 4880                 init_val = nullptr;
 4881               } else {
 4882                 init_val = init_val->as_InlineType()->buffer(this);
 4883               }
 4884             }
 4885             if (init_val != nullptr) {
 4886 #ifdef ASSERT
 4887               init_val = null_check(init_val);
 4888               Node* wrong_type_ctl = gen_subtype_check(init_val, makecon(TypeKlassPtr::make(array_klass->element_klass())));
 4889               {
 4890                 PreserveJVMState pjvms(this);
 4891                 set_control(wrong_type_ctl);
 4892                 halt(control(), frameptr(), "incompatible type for initVal in newArray");
 4893                 stop_and_kill_map();
 4894               }
 4895 #endif
 4896               init_val = _gvn.transform(new CheckCastPPNode(control(), init_val, TypeOopPtr::make_from_klass(array_klass->element_klass()), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 4897             }
 4898           }
 4899           Node* obj = new_array(makecon(array_klass_type), length, 0, nullptr, false, init_val);
 4900           const TypeAryPtr* arytype = gvn().type(obj)->is_aryptr();
 4901           assert(arytype->is_null_free() == null_free, "inconsistency");
 4902           assert(arytype->is_not_null_free() == !null_free, "inconsistency");
 4903           set_result(obj);
 4904           return true;
 4905         }
 4906       }
 4907     }
 4908   }
 4909   return false;
 4910 }
 4911 
 4912 // public static native boolean ValueClass::isFlatArray(Object array);
 4913 // public static native boolean ValueClass::isNullRestrictedArray(Object array);
 4914 // public static native boolean ValueClass::isAtomicArray(Object array);
 4915 bool LibraryCallKit::inline_getArrayProperties(ArrayPropertiesCheck check) {
 4916   Node* array = argument(0);
 4917 
 4918   Node* bol;
 4919   switch(check) {
 4920     case IsFlat:
 4921       bol = flat_array_test(load_object_klass(array));
 4922       break;
 4923     case IsNullRestricted:
 4924       bol = null_free_array_test(array);
 4925       break;
 4926     case IsAtomic: {
 4927       // See conditions in JVM_IsAtomicArray
 4928       // 1. If not flat, then atomic, or else...
 4929       RegionNode* atomic_region = new RegionNode(1);
 4930       RegionNode* non_atomic_region = new RegionNode(1);
 4931       Node* array_klass = load_object_klass(array);
 4932       Node* is_flat_bol = flat_array_test(array_klass);
 4933       IfNode* iff_is_flat = create_and_xform_if(control(), is_flat_bol, PROB_FAIR, COUNT_UNKNOWN);
 4934       atomic_region->add_req(_gvn.transform(new IfFalseNode(iff_is_flat)));
 4935       set_control(_gvn.transform(new IfTrueNode(iff_is_flat)));
 4936 
 4937       // 2. ...if the layout is atomic, then atomic, or else...
 4938       Node* layout_kind = atomic_layout_array_test_and_get_layout_kind(array, atomic_region);
 4939 
 4940       // 3. ...if the element type is naturally atomic and null-free OR empty and nullable, then atomic, or else...
 4941       int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset());
 4942       Node* array_element_klass_addr = off_heap_plus_addr(array_klass, element_klass_offset);
 4943       Node* array_element_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), array_element_klass_addr, _gvn.type(array_klass)->is_klassptr()));
 4944       int klass_flags_offset = in_bytes(InstanceKlass::misc_flags_offset() + InstanceKlassFlags::flags_offset());
 4945       Node* array_element_klass_flags_addr = off_heap_plus_addr(array_element_klass, klass_flags_offset);
 4946       Node* array_element_klass_flags = make_load(control(), array_element_klass_flags_addr, TypeInt::INT, T_INT, MemNode::unordered);
 4947 
 4948       // Here, layout can only be non-atomic, otherwise atomic_layout_array_test_and_get_layout_kind already decides the array to be atomic.
 4949       Node* is_null_free_cmp = _gvn.transform(new CmpINode(layout_kind, intcon(static_cast<jint>(LayoutKind::NULL_FREE_NON_ATOMIC_FLAT))));
 4950       Node* is_null_free_bol = _gvn.transform(new BoolNode(is_null_free_cmp, BoolTest::eq));
 4951       IfNode* iff_is_null_free_bol = create_and_xform_if(control(), is_null_free_bol, PROB_FAIR, COUNT_UNKNOWN);
 4952       Node* is_null_free_ctl = _gvn.transform(new IfTrueNode(iff_is_null_free_bol));
 4953       Node* is_nullable_ctl = _gvn.transform(new IfFalseNode(iff_is_null_free_bol));
 4954 
 4955       Node* is_naturally_atomic_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_naturally_atomic)));
 4956       Node* is_naturally_atomic_cmp = _gvn.transform(new CmpINode(is_naturally_atomic_flag, intcon(0)));
 4957       Node* is_naturally_atomic_bol = _gvn.transform(new BoolNode(is_naturally_atomic_cmp, BoolTest::ne));
 4958       IfNode* iff_is_naturally_atomic = create_and_xform_if(is_null_free_ctl, is_naturally_atomic_bol, PROB_FAIR, COUNT_UNKNOWN);
 4959       Node* is_naturally_atomic_ctl = _gvn.transform(new IfTrueNode(iff_is_naturally_atomic));
 4960       Node* is_not_naturally_atomic_ctl = _gvn.transform(new IfFalseNode(iff_is_naturally_atomic));
 4961       atomic_region->add_req(is_naturally_atomic_ctl);
 4962       non_atomic_region->add_req(is_not_naturally_atomic_ctl);
 4963 
 4964       Node* is_empty_inline_type_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_empty_inline_type)));
 4965       Node* is_empty_inline_type_cmp = _gvn.transform(new CmpINode(is_empty_inline_type_flag, intcon(0)));
 4966       Node* is_empty_inline_type_bol = _gvn.transform(new BoolNode(is_empty_inline_type_cmp, BoolTest::ne));
 4967       IfNode* iff_is_empty_inline_type = create_and_xform_if(is_nullable_ctl, is_empty_inline_type_bol, PROB_FAIR, COUNT_UNKNOWN);
 4968       Node* is_empty_inline_type_ctl = _gvn.transform(new IfTrueNode(iff_is_empty_inline_type));
 4969       Node* is_nonempty_inline_type_ctl = _gvn.transform(new IfFalseNode(iff_is_empty_inline_type));
 4970       atomic_region->add_req(is_empty_inline_type_ctl);
 4971       non_atomic_region->add_req(is_nonempty_inline_type_ctl);
 4972 
 4973       // ...non-atomic, but we tried everything.
 4974       RegionNode* decision = new RegionNode(3);
 4975       decision->set_req(1, _gvn.transform(atomic_region));
 4976       decision->set_req(2, _gvn.transform(non_atomic_region));
 4977       PhiNode* result = PhiNode::make(decision, intcon(1), TypeInt::BOOL);
 4978       result->set_req(2, intcon(0));
 4979       set_control(_gvn.transform(decision));
 4980       set_result(_gvn.transform(result));
 4981       return true;
 4982     }
 4983     default:
 4984       ShouldNotReachHere();
 4985   }
 4986 
 4987   Node* res = gvn().transform(new CMoveINode(bol, intcon(0), intcon(1), TypeInt::BOOL));
 4988   set_result(res);
 4989   return true;
 4990 }
 4991 
 4992 // Load the default refined array klass from an ObjArrayKlass. This relies on the first entry in the
 4993 // '_next_refined_array_klass' linked list being the default (see ObjArrayKlass::klass_with_properties).
 4994 Node* LibraryCallKit::load_default_refined_array_klass(Node* klass_node, bool type_array_guard) {
 4995   RegionNode* region = new RegionNode(2);
 4996   Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT_OR_NULL);
 4997 
 4998   if (type_array_guard) {
 4999     generate_typeArray_guard(klass_node, region);
 5000     if (region->req() == 3) {
 5001       phi->add_req(klass_node);
 5002     }
 5003   }
 5004   Node* adr_refined_klass = basic_plus_adr(top(), klass_node, in_bytes(ObjArrayKlass::next_refined_array_klass_offset()));
 5005   Node* refined_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), adr_refined_klass, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 5006 
 5007   // Can be null if not initialized yet, just deopt
 5008   Node* null_ctl = top();
 5009   refined_klass = null_check_oop(refined_klass, &null_ctl, /* never_see_null= */ true);
 5010 
 5011   region->init_req(1, control());
 5012   phi->init_req(1, refined_klass);
 5013 
 5014   set_control(_gvn.transform(region));
 5015   return _gvn.transform(phi);
 5016 }
 5017 
 5018 // Load the non-refined array klass from an ObjArrayKlass.
 5019 Node* LibraryCallKit::load_non_refined_array_klass(Node* klass_node) {
 5020   const TypeAryKlassPtr* ary_klass_ptr = _gvn.type(klass_node)->isa_aryklassptr();
 5021   if (ary_klass_ptr != nullptr && ary_klass_ptr->klass_is_exact()) {
 5022     return _gvn.makecon(ary_klass_ptr->cast_to_refined_array_klass_ptr(false));
 5023   }
 5024 
 5025   RegionNode* region = new RegionNode(2);
 5026   Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT);
 5027 
 5028   generate_typeArray_guard(klass_node, region);
 5029   if (region->req() == 3) {
 5030     phi->add_req(klass_node);
 5031   }
 5032   Node* super_adr = basic_plus_adr(top(), klass_node, in_bytes(Klass::super_offset()));
 5033   Node* super_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), super_adr, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
 5034 
 5035   region->init_req(1, control());
 5036   phi->init_req(1, super_klass);
 5037 
 5038   set_control(_gvn.transform(region));
 5039   return _gvn.transform(phi);
 5040 }
 5041 
 5042 //-----------------------inline_native_newArray--------------------------
 5043 // private static native Object java.lang.reflect.Array.newArray(Class<?> componentType, int length);
 5044 // private        native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size);
 5045 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) {
 5046   Node* mirror;
 5047   Node* count_val;
 5048   if (uninitialized) {
 5049     null_check_receiver();
 5050     mirror    = argument(1);
 5051     count_val = argument(2);
 5052   } else {
 5053     mirror    = argument(0);
 5054     count_val = argument(1);
 5055   }
 5056 
 5057   mirror = null_check(mirror);
 5058   // If mirror or obj is dead, only null-path is taken.
 5059   if (stopped())  return true;
 5060 
 5061   enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
 5062   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 5063   PhiNode*    result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
 5064   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
 5065   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 5066 
 5067   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 5068   Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null,
 5069                                                   result_reg, _slow_path);
 5070   Node* normal_ctl   = control();
 5071   Node* no_array_ctl = result_reg->in(_slow_path);
 5072 
 5073   // Generate code for the slow case.  We make a call to newArray().
 5074   set_control(no_array_ctl);
 5075   if (!stopped()) {
 5076     // Either the input type is void.class, or else the
 5077     // array klass has not yet been cached.  Either the
 5078     // ensuing call will throw an exception, or else it
 5079     // will cache the array klass for next time.
 5080     PreserveJVMState pjvms(this);
 5081     CallJavaNode* slow_call = nullptr;
 5082     if (uninitialized) {
 5083       // Generate optimized virtual call (holder class 'Unsafe' is final)
 5084       slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true);
 5085     } else {
 5086       slow_call = generate_method_call_static(vmIntrinsics::_newArray, true);
 5087     }
 5088     Node* slow_result = set_results_for_java_call(slow_call);
 5089     // this->control() comes from set_results_for_java_call
 5090     result_reg->set_req(_slow_path, control());
 5091     result_val->set_req(_slow_path, slow_result);
 5092     result_io ->set_req(_slow_path, i_o());
 5093     result_mem->set_req(_slow_path, reset_memory());
 5094   }
 5095 
 5096   set_control(normal_ctl);
 5097   if (!stopped()) {
 5098     // Normal case:  The array type has been cached in the java.lang.Class.
 5099     // The following call works fine even if the array type is polymorphic.
 5100     // It could be a dynamic mix of int[], boolean[], Object[], etc.
 5101 
 5102     klass_node = load_default_refined_array_klass(klass_node);
 5103 
 5104     Node* obj = new_array(klass_node, count_val, 0);  // no arguments to push
 5105     result_reg->init_req(_normal_path, control());
 5106     result_val->init_req(_normal_path, obj);
 5107     result_io ->init_req(_normal_path, i_o());
 5108     result_mem->init_req(_normal_path, reset_memory());
 5109 
 5110     if (uninitialized) {
 5111       // Mark the allocation so that zeroing is skipped
 5112       AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj);
 5113       alloc->maybe_set_complete(&_gvn);
 5114     }
 5115   }
 5116 
 5117   // Return the combined state.
 5118   set_i_o(        _gvn.transform(result_io)  );
 5119   set_all_memory( _gvn.transform(result_mem));
 5120 
 5121   C->set_has_split_ifs(true); // Has chance for split-if optimization
 5122   set_result(result_reg, result_val);
 5123   return true;
 5124 }
 5125 
 5126 //----------------------inline_native_getLength--------------------------
 5127 // public static native int java.lang.reflect.Array.getLength(Object array);
 5128 bool LibraryCallKit::inline_native_getLength() {
 5129   if (too_many_traps(Deoptimization::Reason_intrinsic))  return false;
 5130 
 5131   Node* array = null_check(argument(0));
 5132   // If array is dead, only null-path is taken.
 5133   if (stopped())  return true;
 5134 
 5135   // Deoptimize if it is a non-array.
 5136   Node* non_array = generate_non_array_guard(load_object_klass(array), nullptr, &array);
 5137 
 5138   if (non_array != nullptr) {
 5139     PreserveJVMState pjvms(this);
 5140     set_control(non_array);
 5141     uncommon_trap(Deoptimization::Reason_intrinsic,
 5142                   Deoptimization::Action_maybe_recompile);
 5143   }
 5144 
 5145   // If control is dead, only non-array-path is taken.
 5146   if (stopped())  return true;
 5147 
 5148   // The works fine even if the array type is polymorphic.
 5149   // It could be a dynamic mix of int[], boolean[], Object[], etc.
 5150   Node* result = load_array_length(array);
 5151 
 5152   C->set_has_split_ifs(true);  // Has chance for split-if optimization
 5153   set_result(result);
 5154   return true;
 5155 }
 5156 
 5157 //------------------------inline_array_copyOf----------------------------
 5158 // public static <T,U> T[] java.util.Arrays.copyOf(     U[] original, int newLength,         Class<? extends T[]> newType);
 5159 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from,      int to, Class<? extends T[]> newType);
 5160 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) {
 5161   if (too_many_traps(Deoptimization::Reason_intrinsic))  return false;
 5162 
 5163   // Get the arguments.
 5164   Node* original          = argument(0);
 5165   Node* start             = is_copyOfRange? argument(1): intcon(0);
 5166   Node* end               = is_copyOfRange? argument(2): argument(1);
 5167   Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
 5168 
 5169   Node* newcopy = nullptr;
 5170 
 5171   // Set the original stack and the reexecute bit for the interpreter to reexecute
 5172   // the bytecode that invokes Arrays.copyOf if deoptimization happens.
 5173   { PreserveReexecuteState preexecs(this);
 5174     jvms()->set_should_reexecute(true);
 5175 
 5176     array_type_mirror = null_check(array_type_mirror);
 5177     original          = null_check(original);
 5178 
 5179     // Check if a null path was taken unconditionally.
 5180     if (stopped())  return true;
 5181 
 5182     Node* orig_length = load_array_length(original);
 5183 
 5184     Node* klass_node = load_klass_from_mirror(array_type_mirror, false, nullptr, 0);
 5185     klass_node = null_check(klass_node);
 5186 
 5187     RegionNode* bailout = new RegionNode(1);
 5188     record_for_igvn(bailout);
 5189 
 5190     // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc.
 5191     // Bail out if that is so.
 5192     // Inline type array may have object field that would require a
 5193     // write barrier. Conservatively, go to slow path.
 5194     // TODO 8251971: Optimize for the case when flat src/dst are later found
 5195     // to not contain oops (i.e., move this check to the macro expansion phase).
 5196     // TODO 8382226: Revisit for flat abstract value class arrays
 5197     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 5198     const TypeAryPtr* orig_t = _gvn.type(original)->isa_aryptr();
 5199     const TypeKlassPtr* tklass = _gvn.type(klass_node)->is_klassptr();
 5200     bool exclude_flat = UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, false, false, BarrierSetC2::Parsing) &&
 5201                         // Can src array be flat and contain oops?
 5202                         (orig_t == nullptr || (!orig_t->is_not_flat() && (!orig_t->is_flat() || orig_t->elem()->inline_klass()->contains_oops()))) &&
 5203                         // Can dest array be flat and contain oops?
 5204                         tklass->can_be_inline_array() && (!tklass->is_flat() || tklass->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->as_inline_klass()->contains_oops());
 5205     Node* not_objArray = exclude_flat ? generate_non_refArray_guard(klass_node, bailout) : generate_typeArray_guard(klass_node, bailout);
 5206 
 5207     Node* refined_klass_node = load_default_refined_array_klass(klass_node, /* type_array_guard= */ false);
 5208 
 5209     if (not_objArray != nullptr) {
 5210       // Improve the klass node's type from the new optimistic assumption:
 5211       ciKlass* ak = ciArrayKlass::make(env()->Object_klass());
 5212       bool not_flat = !UseArrayFlattening;
 5213       bool not_null_free = !Arguments::is_valhalla_enabled();
 5214       const Type* akls = TypeAryKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0), Type::trust_interfaces, not_flat, not_null_free, false, false, not_flat, true);
 5215       Node* cast = new CastPPNode(control(), refined_klass_node, akls);
 5216       refined_klass_node = _gvn.transform(cast);
 5217     }
 5218 
 5219     // Bail out if either start or end is negative.
 5220     generate_negative_guard(start, bailout, &start);
 5221     generate_negative_guard(end,   bailout, &end);
 5222 
 5223     Node* length = end;
 5224     if (_gvn.type(start) != TypeInt::ZERO) {
 5225       length = _gvn.transform(new SubINode(end, start));
 5226     }
 5227 
 5228     // Bail out if length is negative (i.e., if start > end).
 5229     // Without this the new_array would throw
 5230     // NegativeArraySizeException but IllegalArgumentException is what
 5231     // should be thrown
 5232     generate_negative_guard(length, bailout, &length);
 5233 
 5234     // Handle inline type arrays
 5235     // TODO 8251971 This is too strong
 5236     generate_fair_guard(flat_array_test(load_object_klass(original)), bailout);
 5237     generate_fair_guard(flat_array_test(refined_klass_node), bailout);
 5238     generate_fair_guard(null_free_array_test(original), bailout);
 5239 
 5240     // Bail out if start is larger than the original length
 5241     Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
 5242     generate_negative_guard(orig_tail, bailout, &orig_tail);
 5243 
 5244     if (bailout->req() > 1) {
 5245       PreserveJVMState pjvms(this);
 5246       set_control(_gvn.transform(bailout));
 5247       uncommon_trap(Deoptimization::Reason_intrinsic,
 5248                     Deoptimization::Action_maybe_recompile);
 5249     }
 5250 
 5251     if (!stopped()) {
 5252       // How many elements will we copy from the original?
 5253       // The answer is MinI(orig_tail, length).
 5254       Node* moved = _gvn.transform(new MinINode(orig_tail, length));
 5255 
 5256       // Generate a direct call to the right arraycopy function(s).
 5257       // We know the copy is disjoint but we might not know if the
 5258       // oop stores need checking.
 5259       // Extreme case:  Arrays.copyOf((Integer[])x, 10, String[].class).
 5260       // This will fail a store-check if x contains any non-nulls.
 5261 
 5262       // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
 5263       // loads/stores but it is legal only if we're sure the
 5264       // Arrays.copyOf would succeed. So we need all input arguments
 5265       // to the copyOf to be validated, including that the copy to the
 5266       // new array won't trigger an ArrayStoreException. That subtype
 5267       // check can be optimized if we know something on the type of
 5268       // the input array from type speculation.
 5269       if (_gvn.type(klass_node)->singleton()) {
 5270         const TypeKlassPtr* subk = _gvn.type(load_object_klass(original))->is_klassptr();
 5271         const TypeKlassPtr* superk = _gvn.type(klass_node)->is_klassptr();
 5272 
 5273         int test = C->static_subtype_check(superk, subk);
 5274         if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) {
 5275           const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr();
 5276           if (t_original->speculative_type() != nullptr) {
 5277             original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true);
 5278           }
 5279         }
 5280       }
 5281 
 5282       bool validated = false;
 5283       // Reason_class_check rather than Reason_intrinsic because we
 5284       // want to intrinsify even if this traps.
 5285       if (!too_many_traps(Deoptimization::Reason_class_check)) {
 5286         Node* not_subtype_ctrl = gen_subtype_check(original, klass_node);
 5287 
 5288         if (not_subtype_ctrl != top()) {
 5289           PreserveJVMState pjvms(this);
 5290           set_control(not_subtype_ctrl);
 5291           uncommon_trap(Deoptimization::Reason_class_check,
 5292                         Deoptimization::Action_make_not_entrant);
 5293           assert(stopped(), "Should be stopped");
 5294         }
 5295         validated = true;
 5296       }
 5297 
 5298       if (!stopped()) {
 5299         newcopy = new_array(refined_klass_node, length, 0);  // no arguments to push
 5300 
 5301         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true,
 5302                                                 load_object_klass(original), klass_node);
 5303         if (!is_copyOfRange) {
 5304           ac->set_copyof(validated);
 5305         } else {
 5306           ac->set_copyofrange(validated);
 5307         }
 5308         Node* n = _gvn.transform(ac);
 5309         if (n == ac) {
 5310           ac->connect_outputs(this);
 5311         } else {
 5312           assert(validated, "shouldn't transform if all arguments not validated");
 5313           set_all_memory(n);
 5314         }
 5315       }
 5316     }
 5317   } // original reexecute is set back here
 5318 
 5319   C->set_has_split_ifs(true); // Has chance for split-if optimization
 5320   if (!stopped()) {
 5321     set_result(newcopy);
 5322   }
 5323   return true;
 5324 }
 5325 
 5326 
 5327 //----------------------generate_virtual_guard---------------------------
 5328 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
 5329 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
 5330                                              RegionNode* slow_region) {
 5331   ciMethod* method = callee();
 5332   int vtable_index = method->vtable_index();
 5333   assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
 5334          "bad index %d", vtable_index);
 5335   // Get the Method* out of the appropriate vtable entry.
 5336   int entry_offset = in_bytes(Klass::vtable_start_offset()) +
 5337                      vtable_index*vtableEntry::size_in_bytes() +
 5338                      in_bytes(vtableEntry::method_offset());
 5339   Node* entry_addr = off_heap_plus_addr(obj_klass, entry_offset);
 5340   Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered);
 5341 
 5342   // Compare the target method with the expected method (e.g., Object.hashCode).
 5343   const TypePtr* native_call_addr = TypeMetadataPtr::make(method);
 5344 
 5345   Node* native_call = makecon(native_call_addr);
 5346   Node* chk_native  = _gvn.transform(new CmpPNode(target_call, native_call));
 5347   Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne));
 5348 
 5349   return generate_slow_guard(test_native, slow_region);
 5350 }
 5351 
 5352 //-----------------------generate_method_call----------------------------
 5353 // Use generate_method_call to make a slow-call to the real
 5354 // method if the fast path fails.  An alternative would be to
 5355 // use a stub like OptoRuntime::slow_arraycopy_Java.
 5356 // This only works for expanding the current library call,
 5357 // not another intrinsic.  (E.g., don't use this for making an
 5358 // arraycopy call inside of the copyOf intrinsic.)
 5359 CallJavaNode*
 5360 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) {
 5361   // When compiling the intrinsic method itself, do not use this technique.
 5362   guarantee(callee() != C->method(), "cannot make slow-call to self");
 5363 
 5364   ciMethod* method = callee();
 5365   // ensure the JVMS we have will be correct for this call
 5366   guarantee(method_id == method->intrinsic_id(), "must match");
 5367 
 5368   const TypeFunc* tf = TypeFunc::make(method);
 5369   if (res_not_null) {
 5370     assert(tf->return_type() == T_OBJECT, "");
 5371     const TypeTuple* range = tf->range_cc();
 5372     const Type** fields = TypeTuple::fields(range->cnt());
 5373     fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL);
 5374     const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields);
 5375     tf = TypeFunc::make(tf->domain_cc(), new_range);
 5376   }
 5377   CallJavaNode* slow_call;
 5378   if (is_static) {
 5379     assert(!is_virtual, "");
 5380     slow_call = new CallStaticJavaNode(C, tf,
 5381                            SharedRuntime::get_resolve_static_call_stub(), method);
 5382   } else if (is_virtual) {
 5383     assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
 5384     int vtable_index = Method::invalid_vtable_index;
 5385     if (UseInlineCaches) {
 5386       // Suppress the vtable call
 5387     } else {
 5388       // hashCode and clone are not a miranda methods,
 5389       // so the vtable index is fixed.
 5390       // No need to use the linkResolver to get it.
 5391        vtable_index = method->vtable_index();
 5392        assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
 5393               "bad index %d", vtable_index);
 5394     }
 5395     slow_call = new CallDynamicJavaNode(tf,
 5396                           SharedRuntime::get_resolve_virtual_call_stub(),
 5397                           method, vtable_index);
 5398   } else {  // neither virtual nor static:  opt_virtual
 5399     assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
 5400     slow_call = new CallStaticJavaNode(C, tf,
 5401                                 SharedRuntime::get_resolve_opt_virtual_call_stub(), method);
 5402     slow_call->set_optimized_virtual(true);
 5403   }
 5404   if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) {
 5405     // To be able to issue a direct call (optimized virtual or virtual)
 5406     // and skip a call to MH.linkTo*/invokeBasic adapter, additional information
 5407     // about the method being invoked should be attached to the call site to
 5408     // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C).
 5409     slow_call->set_override_symbolic_info(true);
 5410   }
 5411   set_arguments_for_java_call(slow_call);
 5412   set_edges_for_java_call(slow_call);
 5413   return slow_call;
 5414 }
 5415 
 5416 
 5417 /**
 5418  * Build special case code for calls to hashCode on an object. This call may
 5419  * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
 5420  * slightly different code.
 5421  */
 5422 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
 5423   assert(is_static == callee()->is_static(), "correct intrinsic selection");
 5424   assert(!(is_virtual && is_static), "either virtual, special, or static");
 5425 
 5426   enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
 5427 
 5428   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 5429   PhiNode*    result_val = new PhiNode(result_reg, TypeInt::INT);
 5430   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
 5431   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 5432   Node* obj = argument(0);
 5433 
 5434   // Don't intrinsify hashcode on inline types for now.
 5435   // The "is locked" runtime check also subsumes the inline type check (as inline types cannot be locked) and goes to the slow path.
 5436   if (gvn().type(obj)->is_inlinetypeptr()) {
 5437     return false;
 5438   }
 5439 
 5440   if (!is_static) {
 5441     // Check for hashing null object
 5442     obj = null_check_receiver();
 5443     if (stopped())  return true;        // unconditionally null
 5444     result_reg->init_req(_null_path, top());
 5445     result_val->init_req(_null_path, top());
 5446   } else {
 5447     // Do a null check, and return zero if null.
 5448     // System.identityHashCode(null) == 0
 5449     Node* null_ctl = top();
 5450     obj = null_check_oop(obj, &null_ctl);
 5451     result_reg->init_req(_null_path, null_ctl);
 5452     result_val->init_req(_null_path, _gvn.intcon(0));
 5453   }
 5454 
 5455   // Unconditionally null?  Then return right away.
 5456   if (stopped()) {
 5457     set_control( result_reg->in(_null_path));
 5458     if (!stopped())
 5459       set_result(result_val->in(_null_path));
 5460     return true;
 5461   }
 5462 
 5463   // We only go to the fast case code if we pass a number of guards.  The
 5464   // paths which do not pass are accumulated in the slow_region.
 5465   RegionNode* slow_region = new RegionNode(1);
 5466   record_for_igvn(slow_region);
 5467 
 5468   // If this is a virtual call, we generate a funny guard.  We pull out
 5469   // the vtable entry corresponding to hashCode() from the target object.
 5470   // If the target method which we are calling happens to be the native
 5471   // Object hashCode() method, we pass the guard.  We do not need this
 5472   // guard for non-virtual calls -- the caller is known to be the native
 5473   // Object hashCode().
 5474   if (is_virtual) {
 5475     // After null check, get the object's klass.
 5476     Node* obj_klass = load_object_klass(obj);
 5477     generate_virtual_guard(obj_klass, slow_region);
 5478   }
 5479 
 5480   // Get the header out of the object, use LoadMarkNode when available
 5481   Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
 5482   // The control of the load must be null. Otherwise, the load can move before
 5483   // the null check after castPP removal.
 5484   Node* no_ctrl = nullptr;
 5485   Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
 5486 
 5487   if (!UseObjectMonitorTable) {
 5488     // Test the header to see if it is safe to read w.r.t. locking.
 5489     // We cannot use the inline type mask as this may check bits that are overridden
 5490     // by an object monitor's pointer when inflating locking.
 5491     Node *lock_mask      = _gvn.MakeConX(markWord::lock_mask_in_place);
 5492     Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
 5493     Node *monitor_val   = _gvn.MakeConX(markWord::monitor_value);
 5494     Node *chk_monitor   = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
 5495     Node *test_monitor  = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));
 5496 
 5497     generate_slow_guard(test_monitor, slow_region);
 5498   }
 5499 
 5500   // Get the hash value and check to see that it has been properly assigned.
 5501   // We depend on hash_mask being at most 32 bits and avoid the use of
 5502   // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
 5503   // vm: see markWord.hpp.
 5504   Node *hash_mask      = _gvn.intcon(markWord::hash_mask);
 5505   Node *hash_shift     = _gvn.intcon(markWord::hash_shift);
 5506   Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
 5507   // This hack lets the hash bits live anywhere in the mark object now, as long
 5508   // as the shift drops the relevant bits into the low 32 bits.  Note that
 5509   // Java spec says that HashCode is an int so there's no point in capturing
 5510   // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
 5511   hshifted_header      = ConvX2I(hshifted_header);
 5512   Node *hash_val       = _gvn.transform(new AndINode(hshifted_header, hash_mask));
 5513 
 5514   Node *no_hash_val    = _gvn.intcon(markWord::no_hash);
 5515   Node *chk_assigned   = _gvn.transform(new CmpINode( hash_val, no_hash_val));
 5516   Node *test_assigned  = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq));
 5517 
 5518   generate_slow_guard(test_assigned, slow_region);
 5519 
 5520   Node* init_mem = reset_memory();
 5521   // fill in the rest of the null path:
 5522   result_io ->init_req(_null_path, i_o());
 5523   result_mem->init_req(_null_path, init_mem);
 5524 
 5525   result_val->init_req(_fast_path, hash_val);
 5526   result_reg->init_req(_fast_path, control());
 5527   result_io ->init_req(_fast_path, i_o());
 5528   result_mem->init_req(_fast_path, init_mem);
 5529 
 5530   // Generate code for the slow case.  We make a call to hashCode().
 5531   set_control(_gvn.transform(slow_region));
 5532   if (!stopped()) {
 5533     // No need for PreserveJVMState, because we're using up the present state.
 5534     set_all_memory(init_mem);
 5535     vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode;
 5536     CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false);
 5537     Node* slow_result = set_results_for_java_call(slow_call);
 5538     // this->control() comes from set_results_for_java_call
 5539     result_reg->init_req(_slow_path, control());
 5540     result_val->init_req(_slow_path, slow_result);
 5541     result_io  ->set_req(_slow_path, i_o());
 5542     result_mem ->set_req(_slow_path, reset_memory());
 5543   }
 5544 
 5545   // Return the combined state.
 5546   set_i_o(        _gvn.transform(result_io)  );
 5547   set_all_memory( _gvn.transform(result_mem));
 5548 
 5549   set_result(result_reg, result_val);
 5550   return true;
 5551 }
 5552 
 5553 //---------------------------inline_native_getClass----------------------------
 5554 // public final native Class<?> java.lang.Object.getClass();
 5555 //
 5556 // Build special case code for calls to getClass on an object.
 5557 bool LibraryCallKit::inline_native_getClass() {
 5558   Node* obj = argument(0);
 5559   if (obj->is_InlineType()) {
 5560     const Type* t = _gvn.type(obj);
 5561     if (t->maybe_null()) {
 5562       null_check(obj);
 5563     }
 5564     set_result(makecon(TypeInstPtr::make(t->inline_klass()->java_mirror())));
 5565     return true;
 5566   }
 5567   obj = null_check_receiver();
 5568   if (stopped())  return true;
 5569   set_result(load_mirror_from_klass(load_object_klass(obj)));
 5570   return true;
 5571 }
 5572 
 5573 //-----------------inline_native_Reflection_getCallerClass---------------------
 5574 // public static native Class<?> sun.reflect.Reflection.getCallerClass();
 5575 //
 5576 // In the presence of deep enough inlining, getCallerClass() becomes a no-op.
 5577 //
 5578 // NOTE: This code must perform the same logic as JVM_GetCallerClass
 5579 // in that it must skip particular security frames and checks for
 5580 // caller sensitive methods.
 5581 bool LibraryCallKit::inline_native_Reflection_getCallerClass() {
 5582 #ifndef PRODUCT
 5583   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5584     tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass");
 5585   }
 5586 #endif
 5587 
 5588   if (!jvms()->has_method()) {
 5589 #ifndef PRODUCT
 5590     if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5591       tty->print_cr("  Bailing out because intrinsic was inlined at top level");
 5592     }
 5593 #endif
 5594     return false;
 5595   }
 5596 
 5597   // Walk back up the JVM state to find the caller at the required
 5598   // depth.
 5599   JVMState* caller_jvms = jvms();
 5600 
 5601   // Cf. JVM_GetCallerClass
 5602   // NOTE: Start the loop at depth 1 because the current JVM state does
 5603   // not include the Reflection.getCallerClass() frame.
 5604   for (int n = 1; caller_jvms != nullptr; caller_jvms = caller_jvms->caller(), n++) {
 5605     ciMethod* m = caller_jvms->method();
 5606     switch (n) {
 5607     case 0:
 5608       fatal("current JVM state does not include the Reflection.getCallerClass frame");
 5609       break;
 5610     case 1:
 5611       // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass).
 5612       if (!m->caller_sensitive()) {
 5613 #ifndef PRODUCT
 5614         if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5615           tty->print_cr("  Bailing out: CallerSensitive annotation expected at frame %d", n);
 5616         }
 5617 #endif
 5618         return false;  // bail-out; let JVM_GetCallerClass do the work
 5619       }
 5620       break;
 5621     default:
 5622       if (!m->is_ignored_by_security_stack_walk()) {
 5623         // We have reached the desired frame; return the holder class.
 5624         // Acquire method holder as java.lang.Class and push as constant.
 5625         ciInstanceKlass* caller_klass = caller_jvms->method()->holder();
 5626         ciInstance* caller_mirror = caller_klass->java_mirror();
 5627         set_result(makecon(TypeInstPtr::make(caller_mirror)));
 5628 
 5629 #ifndef PRODUCT
 5630         if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5631           tty->print_cr("  Succeeded: caller = %d) %s.%s, JVMS depth = %d", n, caller_klass->name()->as_utf8(), caller_jvms->method()->name()->as_utf8(), jvms()->depth());
 5632           tty->print_cr("  JVM state at this point:");
 5633           for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) {
 5634             ciMethod* m = jvms()->of_depth(i)->method();
 5635             tty->print_cr("   %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8());
 5636           }
 5637         }
 5638 #endif
 5639         return true;
 5640       }
 5641       break;
 5642     }
 5643   }
 5644 
 5645 #ifndef PRODUCT
 5646   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5647     tty->print_cr("  Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth());
 5648     tty->print_cr("  JVM state at this point:");
 5649     for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) {
 5650       ciMethod* m = jvms()->of_depth(i)->method();
 5651       tty->print_cr("   %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8());
 5652     }
 5653   }
 5654 #endif
 5655 
 5656   return false;  // bail-out; let JVM_GetCallerClass do the work
 5657 }
 5658 
 5659 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
 5660   Node* arg = argument(0);
 5661   Node* result = nullptr;
 5662 
 5663   switch (id) {
 5664   case vmIntrinsics::_floatToRawIntBits:    result = new MoveF2INode(arg);  break;
 5665   case vmIntrinsics::_intBitsToFloat:       result = new MoveI2FNode(arg);  break;
 5666   case vmIntrinsics::_doubleToRawLongBits:  result = new MoveD2LNode(arg);  break;
 5667   case vmIntrinsics::_longBitsToDouble:     result = new MoveL2DNode(arg);  break;
 5668   case vmIntrinsics::_floatToFloat16:       result = new ConvF2HFNode(arg); break;
 5669   case vmIntrinsics::_float16ToFloat:       result = new ConvHF2FNode(arg); break;
 5670 
 5671   case vmIntrinsics::_doubleToLongBits: {
 5672     // two paths (plus control) merge in a wood
 5673     RegionNode *r = new RegionNode(3);
 5674     Node *phi = new PhiNode(r, TypeLong::LONG);
 5675 
 5676     Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg));
 5677     // Build the boolean node
 5678     Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne));
 5679 
 5680     // Branch either way.
 5681     // NaN case is less traveled, which makes all the difference.
 5682     IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
 5683     Node *opt_isnan = _gvn.transform(ifisnan);
 5684     assert( opt_isnan->is_If(), "Expect an IfNode");
 5685     IfNode *opt_ifisnan = (IfNode*)opt_isnan;
 5686     Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan));
 5687 
 5688     set_control(iftrue);
 5689 
 5690     static const jlong nan_bits = CONST64(0x7ff8000000000000);
 5691     Node *slow_result = longcon(nan_bits); // return NaN
 5692     phi->init_req(1, _gvn.transform( slow_result ));
 5693     r->init_req(1, iftrue);
 5694 
 5695     // Else fall through
 5696     Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan));
 5697     set_control(iffalse);
 5698 
 5699     phi->init_req(2, _gvn.transform(new MoveD2LNode(arg)));
 5700     r->init_req(2, iffalse);
 5701 
 5702     // Post merge
 5703     set_control(_gvn.transform(r));
 5704     record_for_igvn(r);
 5705 
 5706     C->set_has_split_ifs(true); // Has chance for split-if optimization
 5707     result = phi;
 5708     assert(result->bottom_type()->isa_long(), "must be");
 5709     break;
 5710   }
 5711 
 5712   case vmIntrinsics::_floatToIntBits: {
 5713     // two paths (plus control) merge in a wood
 5714     RegionNode *r = new RegionNode(3);
 5715     Node *phi = new PhiNode(r, TypeInt::INT);
 5716 
 5717     Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg));
 5718     // Build the boolean node
 5719     Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne));
 5720 
 5721     // Branch either way.
 5722     // NaN case is less traveled, which makes all the difference.
 5723     IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
 5724     Node *opt_isnan = _gvn.transform(ifisnan);
 5725     assert( opt_isnan->is_If(), "Expect an IfNode");
 5726     IfNode *opt_ifisnan = (IfNode*)opt_isnan;
 5727     Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan));
 5728 
 5729     set_control(iftrue);
 5730 
 5731     static const jint nan_bits = 0x7fc00000;
 5732     Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN
 5733     phi->init_req(1, _gvn.transform( slow_result ));
 5734     r->init_req(1, iftrue);
 5735 
 5736     // Else fall through
 5737     Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan));
 5738     set_control(iffalse);
 5739 
 5740     phi->init_req(2, _gvn.transform(new MoveF2INode(arg)));
 5741     r->init_req(2, iffalse);
 5742 
 5743     // Post merge
 5744     set_control(_gvn.transform(r));
 5745     record_for_igvn(r);
 5746 
 5747     C->set_has_split_ifs(true); // Has chance for split-if optimization
 5748     result = phi;
 5749     assert(result->bottom_type()->isa_int(), "must be");
 5750     break;
 5751   }
 5752 
 5753   default:
 5754     fatal_unexpected_iid(id);
 5755     break;
 5756   }
 5757   set_result(_gvn.transform(result));
 5758   return true;
 5759 }
 5760 
 5761 bool LibraryCallKit::inline_fp_range_check(vmIntrinsics::ID id) {
 5762   Node* arg = argument(0);
 5763   Node* result = nullptr;
 5764 
 5765   switch (id) {
 5766   case vmIntrinsics::_floatIsInfinite:
 5767     result = new IsInfiniteFNode(arg);
 5768     break;
 5769   case vmIntrinsics::_floatIsFinite:
 5770     result = new IsFiniteFNode(arg);
 5771     break;
 5772   case vmIntrinsics::_doubleIsInfinite:
 5773     result = new IsInfiniteDNode(arg);
 5774     break;
 5775   case vmIntrinsics::_doubleIsFinite:
 5776     result = new IsFiniteDNode(arg);
 5777     break;
 5778   default:
 5779     fatal_unexpected_iid(id);
 5780     break;
 5781   }
 5782   set_result(_gvn.transform(result));
 5783   return true;
 5784 }
 5785 
 5786 //----------------------inline_unsafe_copyMemory-------------------------
 5787 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
 5788 
 5789 static bool has_wide_mem(PhaseGVN& gvn, Node* addr, Node* base) {
 5790   const TypeAryPtr* addr_t = gvn.type(addr)->isa_aryptr();
 5791   const Type*       base_t = gvn.type(base);
 5792 
 5793   bool in_native = (base_t == TypePtr::NULL_PTR);
 5794   bool in_heap   = !TypePtr::NULL_PTR->higher_equal(base_t);
 5795   bool is_mixed  = !in_heap && !in_native;
 5796 
 5797   if (is_mixed) {
 5798     return true; // mixed accesses can touch both on-heap and off-heap memory
 5799   }
 5800   if (in_heap) {
 5801     bool is_prim_array = (addr_t != nullptr) && (addr_t->elem() != Type::BOTTOM);
 5802     if (!is_prim_array) {
 5803       // Though Unsafe.copyMemory() ensures at runtime for on-heap accesses that base is a primitive array,
 5804       // there's not enough type information available to determine proper memory slice for it.
 5805       return true;
 5806     }
 5807   }
 5808   return false;
 5809 }
 5810 
 5811 bool LibraryCallKit::inline_unsafe_copyMemory() {
 5812   if (callee()->is_static())  return false;  // caller must have the capability!
 5813   null_check_receiver();  // null-check receiver
 5814   if (stopped())  return true;
 5815 
 5816   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 5817 
 5818   Node* src_base =         argument(1);  // type: oop
 5819   Node* src_off  = ConvL2X(argument(2)); // type: long
 5820   Node* dst_base =         argument(4);  // type: oop
 5821   Node* dst_off  = ConvL2X(argument(5)); // type: long
 5822   Node* size     = ConvL2X(argument(7)); // type: long
 5823 
 5824   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 5825          "fieldOffset must be byte-scaled");
 5826 
 5827   Node* src_addr = make_unsafe_address(src_base, src_off);
 5828   Node* dst_addr = make_unsafe_address(dst_base, dst_off);
 5829 
 5830   Node* thread = _gvn.transform(new ThreadLocalNode());
 5831   Node* doing_unsafe_access_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::doing_unsafe_access_offset()));
 5832   BasicType doing_unsafe_access_bt = T_BYTE;
 5833   assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented");
 5834 
 5835   // update volatile field
 5836   store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered);
 5837 
 5838   int flags = RC_LEAF | RC_NO_FP;
 5839 
 5840   const TypePtr* dst_type = TypePtr::BOTTOM;
 5841 
 5842   // Adjust memory effects of the runtime call based on input values.
 5843   if (!has_wide_mem(_gvn, src_addr, src_base) &&
 5844       !has_wide_mem(_gvn, dst_addr, dst_base)) {
 5845     dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory
 5846 
 5847     const TypePtr* src_type = _gvn.type(src_addr)->is_ptr();
 5848     if (C->get_alias_index(src_type) == C->get_alias_index(dst_type)) {
 5849       flags |= RC_NARROW_MEM; // narrow in memory
 5850     }
 5851   }
 5852 
 5853   // Call it.  Note that the length argument is not scaled.
 5854   make_runtime_call(flags,
 5855                     OptoRuntime::fast_arraycopy_Type(),
 5856                     StubRoutines::unsafe_arraycopy(),
 5857                     "unsafe_arraycopy",
 5858                     dst_type,
 5859                     src_addr, dst_addr, size XTOP);
 5860 
 5861   store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered);
 5862 
 5863   return true;
 5864 }
 5865 
 5866 // unsafe_setmemory(void *base, ulong offset, size_t length, char fill_value);
 5867 // Fill 'length' bytes starting from 'base[offset]' with 'fill_value'
 5868 bool LibraryCallKit::inline_unsafe_setMemory() {
 5869   if (callee()->is_static())  return false;  // caller must have the capability!
 5870   null_check_receiver();  // null-check receiver
 5871   if (stopped())  return true;
 5872 
 5873   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 5874 
 5875   Node* dst_base =         argument(1);  // type: oop
 5876   Node* dst_off  = ConvL2X(argument(2)); // type: long
 5877   Node* size     = ConvL2X(argument(4)); // type: long
 5878   Node* byte     =         argument(6);  // type: byte
 5879 
 5880   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 5881          "fieldOffset must be byte-scaled");
 5882 
 5883   Node* dst_addr = make_unsafe_address(dst_base, dst_off);
 5884 
 5885   Node* thread = _gvn.transform(new ThreadLocalNode());
 5886   Node* doing_unsafe_access_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::doing_unsafe_access_offset()));
 5887   BasicType doing_unsafe_access_bt = T_BYTE;
 5888   assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented");
 5889 
 5890   // update volatile field
 5891   store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered);
 5892 
 5893   int flags = RC_LEAF | RC_NO_FP;
 5894 
 5895   const TypePtr* dst_type = TypePtr::BOTTOM;
 5896 
 5897   // Adjust memory effects of the runtime call based on input values.
 5898   if (!has_wide_mem(_gvn, dst_addr, dst_base)) {
 5899     dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory
 5900 
 5901     flags |= RC_NARROW_MEM; // narrow in memory
 5902   }
 5903 
 5904   // Call it.  Note that the length argument is not scaled.
 5905   make_runtime_call(flags,
 5906                     OptoRuntime::unsafe_setmemory_Type(),
 5907                     StubRoutines::unsafe_setmemory(),
 5908                     "unsafe_setmemory",
 5909                     dst_type,
 5910                     dst_addr, size XTOP, byte);
 5911 
 5912   store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered);
 5913 
 5914   return true;
 5915 }
 5916 
 5917 #undef XTOP
 5918 
 5919 //------------------------clone_coping-----------------------------------
 5920 // Helper function for inline_native_clone.
 5921 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) {
 5922   assert(obj_size != nullptr, "");
 5923   Node* raw_obj = alloc_obj->in(1);
 5924   assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), "");
 5925 
 5926   AllocateNode* alloc = nullptr;
 5927   if (ReduceBulkZeroing &&
 5928       // If we are implementing an array clone without knowing its source type
 5929       // (can happen when compiling the array-guarded branch of a reflective
 5930       // Object.clone() invocation), initialize the array within the allocation.
 5931       // This is needed because some GCs (e.g. ZGC) might fall back in this case
 5932       // to a runtime clone call that assumes fully initialized source arrays.
 5933       (!is_array || obj->get_ptr_type()->isa_aryptr() != nullptr)) {
 5934     // We will be completely responsible for initializing this object -
 5935     // mark Initialize node as complete.
 5936     alloc = AllocateNode::Ideal_allocation(alloc_obj);
 5937     // The object was just allocated - there should be no any stores!
 5938     guarantee(alloc != nullptr && alloc->maybe_set_complete(&_gvn), "");
 5939     // Mark as complete_with_arraycopy so that on AllocateNode
 5940     // expansion, we know this AllocateNode is initialized by an array
 5941     // copy and a StoreStore barrier exists after the array copy.
 5942     alloc->initialization()->set_complete_with_arraycopy();
 5943   }
 5944 
 5945   Node* size = _gvn.transform(obj_size);
 5946   access_clone(obj, alloc_obj, size, is_array);
 5947 
 5948   // Do not let reads from the cloned object float above the arraycopy.
 5949   if (alloc != nullptr) {
 5950     // Do not let stores that initialize this object be reordered with
 5951     // a subsequent store that would make this object accessible by
 5952     // other threads.
 5953     // Record what AllocateNode this StoreStore protects so that
 5954     // escape analysis can go from the MemBarStoreStoreNode to the
 5955     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 5956     // based on the escape status of the AllocateNode.
 5957     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 5958   } else {
 5959     insert_mem_bar(Op_MemBarCPUOrder);
 5960   }
 5961 }
 5962 
 5963 //------------------------inline_native_clone----------------------------
 5964 // protected native Object java.lang.Object.clone();
 5965 //
 5966 // Here are the simple edge cases:
 5967 //  null receiver => normal trap
 5968 //  virtual and clone was overridden => slow path to out-of-line clone
 5969 //  not cloneable or finalizer => slow path to out-of-line Object.clone
 5970 //
 5971 // The general case has two steps, allocation and copying.
 5972 // Allocation has two cases, and uses GraphKit::new_instance or new_array.
 5973 //
 5974 // Copying also has two cases, oop arrays and everything else.
 5975 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
 5976 // Everything else uses the tight inline loop supplied by CopyArrayNode.
 5977 //
 5978 // These steps fold up nicely if and when the cloned object's klass
 5979 // can be sharply typed as an object array, a type array, or an instance.
 5980 //
 5981 bool LibraryCallKit::inline_native_clone(bool is_virtual) {
 5982   PhiNode* result_val;
 5983 
 5984   // Set the reexecute bit for the interpreter to reexecute
 5985   // the bytecode that invokes Object.clone if deoptimization happens.
 5986   { PreserveReexecuteState preexecs(this);
 5987     jvms()->set_should_reexecute(true);
 5988 
 5989     Node* obj = argument(0);
 5990     obj = null_check_receiver();
 5991     if (stopped())  return true;
 5992 
 5993     const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
 5994     if (obj_type->is_inlinetypeptr()) {
 5995       // If the object to clone is an inline type, we can simply return it (i.e. a nop) since inline types have
 5996       // no identity.
 5997       set_result(obj);
 5998       return true;
 5999     }
 6000 
 6001     // If we are going to clone an instance, we need its exact type to
 6002     // know the number and types of fields to convert the clone to
 6003     // loads/stores. Maybe a speculative type can help us.
 6004     if (!obj_type->klass_is_exact() &&
 6005         obj_type->speculative_type() != nullptr &&
 6006         obj_type->speculative_type()->is_instance_klass() &&
 6007         !obj_type->speculative_type()->is_inlinetype()) {
 6008       ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass();
 6009       if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem &&
 6010           !spec_ik->has_injected_fields()) {
 6011         if (!obj_type->isa_instptr() ||
 6012             obj_type->is_instptr()->instance_klass()->has_subklass()) {
 6013           obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false);
 6014         }
 6015       }
 6016     }
 6017 
 6018     // Conservatively insert a memory barrier on all memory slices.
 6019     // Do not let writes into the original float below the clone.
 6020     insert_mem_bar(Op_MemBarCPUOrder);
 6021 
 6022     // paths into result_reg:
 6023     enum {
 6024       _slow_path = 1,     // out-of-line call to clone method (virtual or not)
 6025       _objArray_path,     // plain array allocation, plus arrayof_oop_arraycopy
 6026       _array_path,        // plain array allocation, plus arrayof_long_arraycopy
 6027       _instance_path,     // plain instance allocation, plus arrayof_long_arraycopy
 6028       PATH_LIMIT
 6029     };
 6030     RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 6031     result_val             = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
 6032     PhiNode*    result_i_o = new PhiNode(result_reg, Type::ABIO);
 6033     PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 6034     record_for_igvn(result_reg);
 6035 
 6036     Node* obj_klass = load_object_klass(obj);
 6037     // We only go to the fast case code if we pass a number of guards.
 6038     // The paths which do not pass are accumulated in the slow_region.
 6039     RegionNode* slow_region = new RegionNode(1);
 6040     record_for_igvn(slow_region);
 6041 
 6042     Node* array_obj = obj;
 6043     Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj);
 6044     if (array_ctl != nullptr) {
 6045       // It's an array.
 6046       PreserveJVMState pjvms(this);
 6047       set_control(array_ctl);
 6048 
 6049       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 6050       const TypeAryPtr* ary_ptr = obj_type->isa_aryptr();
 6051       if (UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Expansion) &&
 6052           obj_type->can_be_inline_array() &&
 6053           (ary_ptr == nullptr || (!ary_ptr->is_not_flat() && (!ary_ptr->is_flat() || ary_ptr->elem()->inline_klass()->contains_oops())))) {
 6054         // Flat inline type array may have object field that would require a
 6055         // write barrier. Conservatively, go to slow path.
 6056         generate_fair_guard(flat_array_test(obj_klass), slow_region);
 6057       }
 6058 
 6059       if (!stopped()) {
 6060         Node* obj_length = load_array_length(array_obj);
 6061         Node* array_size = nullptr; // Size of the array without object alignment padding.
 6062         Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true);
 6063 
 6064         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 6065         if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) {
 6066           // If it is an oop array, it requires very special treatment,
 6067           // because gc barriers are required when accessing the array.
 6068           Node* is_obja = generate_refArray_guard(obj_klass, (RegionNode*)nullptr);
 6069           if (is_obja != nullptr) {
 6070             PreserveJVMState pjvms2(this);
 6071             set_control(is_obja);
 6072             // Generate a direct call to the right arraycopy function(s).
 6073             // Clones are always tightly coupled.
 6074             ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false);
 6075             ac->set_clone_oop_array();
 6076             Node* n = _gvn.transform(ac);
 6077             assert(n == ac, "cannot disappear");
 6078             ac->connect_outputs(this, /*deoptimize_on_exception=*/true);
 6079 
 6080             result_reg->init_req(_objArray_path, control());
 6081             result_val->init_req(_objArray_path, alloc_obj);
 6082             result_i_o ->set_req(_objArray_path, i_o());
 6083             result_mem ->set_req(_objArray_path, reset_memory());
 6084           }
 6085         }
 6086         // Otherwise, there are no barriers to worry about.
 6087         // (We can dispense with card marks if we know the allocation
 6088         //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
 6089         //  causes the non-eden paths to take compensating steps to
 6090         //  simulate a fresh allocation, so that no further
 6091         //  card marks are required in compiled code to initialize
 6092         //  the object.)
 6093 
 6094         if (!stopped()) {
 6095           copy_to_clone(obj, alloc_obj, array_size, true);
 6096 
 6097           // Present the results of the copy.
 6098           result_reg->init_req(_array_path, control());
 6099           result_val->init_req(_array_path, alloc_obj);
 6100           result_i_o ->set_req(_array_path, i_o());
 6101           result_mem ->set_req(_array_path, reset_memory());
 6102         }
 6103       }
 6104     }
 6105 
 6106     if (!stopped()) {
 6107       // It's an instance (we did array above).  Make the slow-path tests.
 6108       // If this is a virtual call, we generate a funny guard.  We grab
 6109       // the vtable entry corresponding to clone() from the target object.
 6110       // If the target method which we are calling happens to be the
 6111       // Object clone() method, we pass the guard.  We do not need this
 6112       // guard for non-virtual calls; the caller is known to be the native
 6113       // Object clone().
 6114       if (is_virtual) {
 6115         generate_virtual_guard(obj_klass, slow_region);
 6116       }
 6117 
 6118       // The object must be easily cloneable and must not have a finalizer.
 6119       // Both of these conditions may be checked in a single test.
 6120       // We could optimize the test further, but we don't care.
 6121       generate_misc_flags_guard(obj_klass,
 6122                                 // Test both conditions:
 6123                                 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer,
 6124                                 // Must be cloneable but not finalizer:
 6125                                 KlassFlags::_misc_is_cloneable_fast,
 6126                                 slow_region);
 6127     }
 6128 
 6129     if (!stopped()) {
 6130       // It's an instance, and it passed the slow-path tests.
 6131       PreserveJVMState pjvms(this);
 6132       Node* obj_size = nullptr; // Total object size, including object alignment padding.
 6133       // Need to deoptimize on exception from allocation since Object.clone intrinsic
 6134       // is reexecuted if deoptimization occurs and there could be problems when merging
 6135       // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false).
 6136       Node* alloc_obj = new_instance(obj_klass, nullptr, &obj_size, /*deoptimize_on_exception=*/true);
 6137 
 6138       copy_to_clone(obj, alloc_obj, obj_size, false);
 6139 
 6140       // Present the results of the slow call.
 6141       result_reg->init_req(_instance_path, control());
 6142       result_val->init_req(_instance_path, alloc_obj);
 6143       result_i_o ->set_req(_instance_path, i_o());
 6144       result_mem ->set_req(_instance_path, reset_memory());
 6145     }
 6146 
 6147     // Generate code for the slow case.  We make a call to clone().
 6148     set_control(_gvn.transform(slow_region));
 6149     if (!stopped()) {
 6150       PreserveJVMState pjvms(this);
 6151       CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual, false, true);
 6152       // We need to deoptimize on exception (see comment above)
 6153       Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true);
 6154       // this->control() comes from set_results_for_java_call
 6155       result_reg->init_req(_slow_path, control());
 6156       result_val->init_req(_slow_path, slow_result);
 6157       result_i_o ->set_req(_slow_path, i_o());
 6158       result_mem ->set_req(_slow_path, reset_memory());
 6159     }
 6160 
 6161     // Return the combined state.
 6162     set_control(    _gvn.transform(result_reg));
 6163     set_i_o(        _gvn.transform(result_i_o));
 6164     set_all_memory( _gvn.transform(result_mem));
 6165   } // original reexecute is set back here
 6166 
 6167   set_result(_gvn.transform(result_val));
 6168   return true;
 6169 }
 6170 
 6171 // If we have a tightly coupled allocation, the arraycopy may take care
 6172 // of the array initialization. If one of the guards we insert between
 6173 // the allocation and the arraycopy causes a deoptimization, an
 6174 // uninitialized array will escape the compiled method. To prevent that
 6175 // we set the JVM state for uncommon traps between the allocation and
 6176 // the arraycopy to the state before the allocation so, in case of
 6177 // deoptimization, we'll reexecute the allocation and the
 6178 // initialization.
 6179 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) {
 6180   if (alloc != nullptr) {
 6181     ciMethod* trap_method = alloc->jvms()->method();
 6182     int trap_bci = alloc->jvms()->bci();
 6183 
 6184     if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
 6185         !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) {
 6186       // Make sure there's no store between the allocation and the
 6187       // arraycopy otherwise visible side effects could be rexecuted
 6188       // in case of deoptimization and cause incorrect execution.
 6189       bool no_interfering_store = true;
 6190       Node* mem = alloc->in(TypeFunc::Memory);
 6191       if (mem->is_MergeMem()) {
 6192         for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) {
 6193           Node* n = mms.memory();
 6194           if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
 6195             assert(n->is_Store(), "what else?");
 6196             no_interfering_store = false;
 6197             break;
 6198           }
 6199         }
 6200       } else {
 6201         for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) {
 6202           Node* n = mms.memory();
 6203           if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
 6204             assert(n->is_Store(), "what else?");
 6205             no_interfering_store = false;
 6206             break;
 6207           }
 6208         }
 6209       }
 6210 
 6211       if (no_interfering_store) {
 6212         SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc);
 6213 
 6214         JVMState* saved_jvms = jvms();
 6215         saved_reexecute_sp = _reexecute_sp;
 6216 
 6217         set_jvms(sfpt->jvms());
 6218         _reexecute_sp = jvms()->sp();
 6219 
 6220         return saved_jvms;
 6221       }
 6222     }
 6223   }
 6224   return nullptr;
 6225 }
 6226 
 6227 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack
 6228 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter.
 6229 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const {
 6230   JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
 6231   uint size = alloc->req();
 6232   SafePointNode* sfpt = new SafePointNode(size, old_jvms);
 6233   old_jvms->set_map(sfpt);
 6234   for (uint i = 0; i < size; i++) {
 6235     sfpt->init_req(i, alloc->in(i));
 6236   }
 6237   int adjustment = 1;
 6238   const TypeAryKlassPtr* ary_klass_ptr = alloc->in(AllocateNode::KlassNode)->bottom_type()->is_aryklassptr();
 6239   if (ary_klass_ptr->is_null_free()) {
 6240     // A null-free, tightly coupled array allocation can only come from LibraryCallKit::inline_newArray which
 6241     // also requires the componentType and initVal on stack for re-execution.
 6242     // Re-create and push the componentType.
 6243     ciArrayKlass* klass = ary_klass_ptr->exact_klass()->as_array_klass();
 6244     ciInstance* instance = klass->component_mirror_instance();
 6245     const TypeInstPtr* t_instance = TypeInstPtr::make(instance);
 6246     sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), makecon(t_instance));
 6247     adjustment++;
 6248   }
 6249   // re-push array length for deoptimization
 6250   sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment - 1, alloc->in(AllocateNode::ALength));
 6251   if (ary_klass_ptr->is_null_free()) {
 6252     // Re-create and push the initVal.
 6253     Node* init_val = alloc->in(AllocateNode::InitValue);
 6254     if (init_val == nullptr) {
 6255       init_val = InlineTypeNode::make_all_zero(_gvn, ary_klass_ptr->elem()->is_instklassptr()->instance_klass()->as_inline_klass());
 6256     } else if (UseCompressedOops) {
 6257       init_val = _gvn.transform(new DecodeNNode(init_val, init_val->bottom_type()->make_ptr()));
 6258     }
 6259     sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment, init_val);
 6260     adjustment++;
 6261   }
 6262   old_jvms->set_sp(old_jvms->sp() + adjustment);
 6263   old_jvms->set_monoff(old_jvms->monoff() + adjustment);
 6264   old_jvms->set_scloff(old_jvms->scloff() + adjustment);
 6265   old_jvms->set_endoff(old_jvms->endoff() + adjustment);
 6266   old_jvms->set_should_reexecute(true);
 6267 
 6268   sfpt->set_i_o(map()->i_o());
 6269   sfpt->set_memory(map()->memory());
 6270   sfpt->set_control(map()->control());
 6271   return sfpt;
 6272 }
 6273 
 6274 // In case of a deoptimization, we restart execution at the
 6275 // allocation, allocating a new array. We would leave an uninitialized
 6276 // array in the heap that GCs wouldn't expect. Move the allocation
 6277 // after the traps so we don't allocate the array if we
 6278 // deoptimize. This is possible because tightly_coupled_allocation()
 6279 // guarantees there's no observer of the allocated array at this point
 6280 // and the control flow is simple enough.
 6281 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards,
 6282                                                     int saved_reexecute_sp, uint new_idx) {
 6283   if (saved_jvms_before_guards != nullptr && !stopped()) {
 6284     replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards);
 6285 
 6286     assert(alloc != nullptr, "only with a tightly coupled allocation");
 6287     // restore JVM state to the state at the arraycopy
 6288     saved_jvms_before_guards->map()->set_control(map()->control());
 6289     assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?");
 6290     assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?");
 6291     // If we've improved the types of some nodes (null check) while
 6292     // emitting the guards, propagate them to the current state
 6293     map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx);
 6294     set_jvms(saved_jvms_before_guards);
 6295     _reexecute_sp = saved_reexecute_sp;
 6296 
 6297     // Remove the allocation from above the guards
 6298     CallProjections* callprojs = alloc->extract_projections(true);
 6299     InitializeNode* init = alloc->initialization();
 6300     Node* alloc_mem = alloc->in(TypeFunc::Memory);
 6301     C->gvn_replace_by(callprojs->fallthrough_ioproj, alloc->in(TypeFunc::I_O));
 6302     init->replace_mem_projs_by(alloc_mem, C);
 6303 
 6304     // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below
 6305     // the allocation (i.e. is only valid if the allocation succeeds):
 6306     // 1) replace CastIINode with AllocateArrayNode's length here
 6307     // 2) Create CastIINode again once allocation has moved (see below) at the end of this method
 6308     //
 6309     // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate
 6310     // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy)
 6311     Node* init_control = init->proj_out(TypeFunc::Control);
 6312     Node* alloc_length = alloc->Ideal_length();
 6313 #ifdef ASSERT
 6314     Node* prev_cast = nullptr;
 6315 #endif
 6316     for (uint i = 0; i < init_control->outcnt(); i++) {
 6317       Node* init_out = init_control->raw_out(i);
 6318       if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) {
 6319 #ifdef ASSERT
 6320         if (prev_cast == nullptr) {
 6321           prev_cast = init_out;
 6322         } else {
 6323           if (prev_cast->cmp(*init_out) == false) {
 6324             prev_cast->dump();
 6325             init_out->dump();
 6326             assert(false, "not equal CastIINode");
 6327           }
 6328         }
 6329 #endif
 6330         C->gvn_replace_by(init_out, alloc_length);
 6331       }
 6332     }
 6333     C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0));
 6334 
 6335     // move the allocation here (after the guards)
 6336     _gvn.hash_delete(alloc);
 6337     alloc->set_req(TypeFunc::Control, control());
 6338     alloc->set_req(TypeFunc::I_O, i_o());
 6339     Node *mem = reset_memory();
 6340     set_all_memory(mem);
 6341     alloc->set_req(TypeFunc::Memory, mem);
 6342     set_control(init->proj_out_or_null(TypeFunc::Control));
 6343     set_i_o(callprojs->fallthrough_ioproj);
 6344 
 6345     // Update memory as done in GraphKit::set_output_for_allocation()
 6346     const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength));
 6347     const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type();
 6348     if (ary_type->isa_aryptr() && length_type != nullptr) {
 6349       ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
 6350     }
 6351     const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot);
 6352     int            elemidx  = C->get_alias_index(telemref);
 6353     // Need to properly move every memory projection for the Initialize
 6354 #ifdef ASSERT
 6355     int mark_idx = C->get_alias_index(ary_type->add_offset(oopDesc::mark_offset_in_bytes()));
 6356     int klass_idx = C->get_alias_index(ary_type->add_offset(oopDesc::klass_offset_in_bytes()));
 6357 #endif
 6358     auto move_proj = [&](ProjNode* proj) {
 6359       int alias_idx = C->get_alias_index(proj->adr_type());
 6360       assert(alias_idx == Compile::AliasIdxRaw ||
 6361              alias_idx == elemidx ||
 6362              alias_idx == mark_idx ||
 6363              alias_idx == klass_idx, "should be raw memory or array element type");
 6364       set_memory(proj, alias_idx);
 6365     };
 6366     init->for_each_proj(move_proj, TypeFunc::Memory);
 6367 
 6368     Node* allocx = _gvn.transform(alloc);
 6369     assert(allocx == alloc, "where has the allocation gone?");
 6370     assert(dest->is_CheckCastPP(), "not an allocation result?");
 6371 
 6372     _gvn.hash_delete(dest);
 6373     dest->set_req(0, control());
 6374     Node* destx = _gvn.transform(dest);
 6375     assert(destx == dest, "where has the allocation result gone?");
 6376 
 6377     array_ideal_length(alloc, ary_type, true);
 6378   }
 6379 }
 6380 
 6381 // Unrelated UCTs between the array allocation and the array copy, which are considered safe by tightly_coupled_allocation(),
 6382 // need to be replaced by an UCT with a state before the array allocation (including the array length). This is necessary
 6383 // because we could hit one of these UCTs (which are executed before the emitted array copy guards and the actual array
 6384 // allocation which is moved down in arraycopy_move_allocation_here()). When later resuming execution in the interpreter,
 6385 // we would have wrongly skipped the array allocation. To prevent this, we resume execution at the array allocation in
 6386 // the interpreter similar to what we are doing for the newly emitted guards for the array copy.
 6387 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc,
 6388                                                                        JVMState* saved_jvms_before_guards) {
 6389   if (saved_jvms_before_guards->map()->control()->is_IfProj()) {
 6390     // There is at least one unrelated uncommon trap which needs to be replaced.
 6391     SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc);
 6392 
 6393     JVMState* saved_jvms = jvms();
 6394     const int saved_reexecute_sp = _reexecute_sp;
 6395     set_jvms(sfpt->jvms());
 6396     _reexecute_sp = jvms()->sp();
 6397 
 6398     replace_unrelated_uncommon_traps_with_alloc_state(saved_jvms_before_guards);
 6399 
 6400     // Restore state
 6401     set_jvms(saved_jvms);
 6402     _reexecute_sp = saved_reexecute_sp;
 6403   }
 6404 }
 6405 
 6406 // Replace the unrelated uncommon traps with new uncommon trap nodes by reusing the action and reason. The new uncommon
 6407 // traps will have the state of the array allocation. Let the old uncommon trap nodes die.
 6408 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards) {
 6409   Node* if_proj = saved_jvms_before_guards->map()->control(); // Start the search right before the newly emitted guards
 6410   while (if_proj->is_IfProj()) {
 6411     CallStaticJavaNode* uncommon_trap = get_uncommon_trap_from_success_proj(if_proj);
 6412     if (uncommon_trap != nullptr) {
 6413       create_new_uncommon_trap(uncommon_trap);
 6414     }
 6415     assert(if_proj->in(0)->is_If(), "must be If");
 6416     if_proj = if_proj->in(0)->in(0);
 6417   }
 6418   assert(if_proj->is_Proj() && if_proj->in(0)->is_Initialize(),
 6419          "must have reached control projection of init node");
 6420 }
 6421 
 6422 void LibraryCallKit::create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call) {
 6423   const int trap_request = uncommon_trap_call->uncommon_trap_request();
 6424   assert(trap_request != 0, "no valid UCT trap request");
 6425   PreserveJVMState pjvms(this);
 6426   set_control(uncommon_trap_call->in(0));
 6427   uncommon_trap(Deoptimization::trap_request_reason(trap_request),
 6428                 Deoptimization::trap_request_action(trap_request));
 6429   assert(stopped(), "Should be stopped");
 6430   _gvn.hash_delete(uncommon_trap_call);
 6431   uncommon_trap_call->set_req(0, top()); // not used anymore, kill it
 6432 }
 6433 
 6434 // Common checks for array sorting intrinsics arguments.
 6435 // Returns `true` if checks passed.
 6436 bool LibraryCallKit::check_array_sort_arguments(Node* elementType, Node* obj, BasicType& bt) {
 6437   // check address of the class
 6438   if (elementType == nullptr || elementType->is_top()) {
 6439     return false;  // dead path
 6440   }
 6441   const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr();
 6442   if (elem_klass == nullptr) {
 6443     return false;  // dead path
 6444   }
 6445   // java_mirror_type() returns non-null for compile-time Class constants only
 6446   ciType* elem_type = elem_klass->java_mirror_type();
 6447   if (elem_type == nullptr) {
 6448     return false;
 6449   }
 6450   bt = elem_type->basic_type();
 6451   // Disable the intrinsic if the CPU does not support SIMD sort
 6452   if (!Matcher::supports_simd_sort(bt)) {
 6453     return false;
 6454   }
 6455   // check address of the array
 6456   if (obj == nullptr || obj->is_top()) {
 6457     return false;  // dead path
 6458   }
 6459   const TypeAryPtr* obj_t = _gvn.type(obj)->isa_aryptr();
 6460   if (obj_t == nullptr || obj_t->elem() == Type::BOTTOM) {
 6461     return false; // failed input validation
 6462   }
 6463   return true;
 6464 }
 6465 
 6466 //------------------------------inline_array_partition-----------------------
 6467 bool LibraryCallKit::inline_array_partition() {
 6468   address stubAddr = StubRoutines::select_array_partition_function();
 6469   if (stubAddr == nullptr) {
 6470     return false; // Intrinsic's stub is not implemented on this platform
 6471   }
 6472   assert(callee()->signature()->size() == 9, "arrayPartition has 8 parameters (one long)");
 6473 
 6474   // no receiver because it is a static method
 6475   Node* elementType     = argument(0);
 6476   Node* obj             = argument(1);
 6477   Node* offset          = argument(2); // long
 6478   Node* fromIndex       = argument(4);
 6479   Node* toIndex         = argument(5);
 6480   Node* indexPivot1     = argument(6);
 6481   Node* indexPivot2     = argument(7);
 6482   // PartitionOperation:  argument(8) is ignored
 6483 
 6484   Node* pivotIndices = nullptr;
 6485   BasicType bt = T_ILLEGAL;
 6486 
 6487   if (!check_array_sort_arguments(elementType, obj, bt)) {
 6488     return false;
 6489   }
 6490   null_check(obj);
 6491   // If obj is dead, only null-path is taken.
 6492   if (stopped()) {
 6493     return true;
 6494   }
 6495   // Set the original stack and the reexecute bit for the interpreter to reexecute
 6496   // the bytecode that invokes DualPivotQuicksort.partition() if deoptimization happens.
 6497   { PreserveReexecuteState preexecs(this);
 6498     jvms()->set_should_reexecute(true);
 6499 
 6500     Node* obj_adr = make_unsafe_address(obj, offset);
 6501 
 6502     // create the pivotIndices array of type int and size = 2
 6503     Node* size = intcon(2);
 6504     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_INT)));
 6505     pivotIndices = new_array(klass_node, size, 0);  // no arguments to push
 6506     AllocateArrayNode* alloc = tightly_coupled_allocation(pivotIndices);
 6507     guarantee(alloc != nullptr, "created above");
 6508     Node* pivotIndices_adr = basic_plus_adr(pivotIndices, arrayOopDesc::base_offset_in_bytes(T_INT));
 6509 
 6510     // pass the basic type enum to the stub
 6511     Node* elemType = intcon(bt);
 6512 
 6513     // Call the stub
 6514     const char *stubName = "array_partition_stub";
 6515     make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_partition_Type(),
 6516                       stubAddr, stubName, TypePtr::BOTTOM,
 6517                       obj_adr, elemType, fromIndex, toIndex, pivotIndices_adr,
 6518                       indexPivot1, indexPivot2);
 6519 
 6520   } // original reexecute is set back here
 6521 
 6522   if (!stopped()) {
 6523     set_result(pivotIndices);
 6524   }
 6525 
 6526   return true;
 6527 }
 6528 
 6529 
 6530 //------------------------------inline_array_sort-----------------------
 6531 bool LibraryCallKit::inline_array_sort() {
 6532   address stubAddr = StubRoutines::select_arraysort_function();
 6533   if (stubAddr == nullptr) {
 6534     return false; // Intrinsic's stub is not implemented on this platform
 6535   }
 6536   assert(callee()->signature()->size() == 7, "arraySort has 6 parameters (one long)");
 6537 
 6538   // no receiver because it is a static method
 6539   Node* elementType     = argument(0);
 6540   Node* obj             = argument(1);
 6541   Node* offset          = argument(2); // long
 6542   Node* fromIndex       = argument(4);
 6543   Node* toIndex         = argument(5);
 6544   // SortOperation:       argument(6) is ignored
 6545 
 6546   BasicType bt = T_ILLEGAL;
 6547 
 6548   if (!check_array_sort_arguments(elementType, obj, bt)) {
 6549     return false;
 6550   }
 6551   null_check(obj);
 6552   // If obj is dead, only null-path is taken.
 6553   if (stopped()) {
 6554     return true;
 6555   }
 6556   Node* obj_adr = make_unsafe_address(obj, offset);
 6557 
 6558   // pass the basic type enum to the stub
 6559   Node* elemType = intcon(bt);
 6560 
 6561   // Call the stub.
 6562   const char *stubName = "arraysort_stub";
 6563   make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_sort_Type(),
 6564                     stubAddr, stubName, TypePtr::BOTTOM,
 6565                     obj_adr, elemType, fromIndex, toIndex);
 6566 
 6567   return true;
 6568 }
 6569 
 6570 
 6571 //------------------------------inline_arraycopy-----------------------
 6572 // public static native void java.lang.System.arraycopy(Object src,  int  srcPos,
 6573 //                                                      Object dest, int destPos,
 6574 //                                                      int length);
 6575 bool LibraryCallKit::inline_arraycopy() {
 6576   // Get the arguments.
 6577   Node* src         = argument(0);  // type: oop
 6578   Node* src_offset  = argument(1);  // type: int
 6579   Node* dest        = argument(2);  // type: oop
 6580   Node* dest_offset = argument(3);  // type: int
 6581   Node* length      = argument(4);  // type: int
 6582 
 6583   uint new_idx = C->unique();
 6584 
 6585   // Check for allocation before we add nodes that would confuse
 6586   // tightly_coupled_allocation()
 6587   AllocateArrayNode* alloc = tightly_coupled_allocation(dest);
 6588 
 6589   int saved_reexecute_sp = -1;
 6590   JVMState* saved_jvms_before_guards = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp);
 6591   // See arraycopy_restore_alloc_state() comment
 6592   // if alloc == null we don't have to worry about a tightly coupled allocation so we can emit all needed guards
 6593   // if saved_jvms_before_guards is not null (then alloc is not null) then we can handle guards and a tightly coupled allocation
 6594   // if saved_jvms_before_guards is null and alloc is not null, we can't emit any guards
 6595   bool can_emit_guards = (alloc == nullptr || saved_jvms_before_guards != nullptr);
 6596 
 6597   // The following tests must be performed
 6598   // (1) src and dest are arrays.
 6599   // (2) src and dest arrays must have elements of the same BasicType
 6600   // (3) src and dest must not be null.
 6601   // (4) src_offset must not be negative.
 6602   // (5) dest_offset must not be negative.
 6603   // (6) length must not be negative.
 6604   // (7) src_offset + length must not exceed length of src.
 6605   // (8) dest_offset + length must not exceed length of dest.
 6606   // (9) each element of an oop array must be assignable
 6607 
 6608   // (3) src and dest must not be null.
 6609   // always do this here because we need the JVM state for uncommon traps
 6610   Node* null_ctl = top();
 6611   src  = saved_jvms_before_guards != nullptr ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY);
 6612   assert(null_ctl->is_top(), "no null control here");
 6613   dest = null_check(dest, T_ARRAY);
 6614 
 6615   if (!can_emit_guards) {
 6616     // if saved_jvms_before_guards is null and alloc is not null, we don't emit any
 6617     // guards but the arraycopy node could still take advantage of a
 6618     // tightly allocated allocation. tightly_coupled_allocation() is
 6619     // called again to make sure it takes the null check above into
 6620     // account: the null check is mandatory and if it caused an
 6621     // uncommon trap to be emitted then the allocation can't be
 6622     // considered tightly coupled in this context.
 6623     alloc = tightly_coupled_allocation(dest);
 6624   }
 6625 
 6626   bool validated = false;
 6627 
 6628   const Type* src_type  = _gvn.type(src);
 6629   const Type* dest_type = _gvn.type(dest);
 6630   const TypeAryPtr* top_src  = src_type->isa_aryptr();
 6631   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
 6632 
 6633   // Do we have the type of src?
 6634   bool has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
 6635   // Do we have the type of dest?
 6636   bool has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
 6637   // Is the type for src from speculation?
 6638   bool src_spec = false;
 6639   // Is the type for dest from speculation?
 6640   bool dest_spec = false;
 6641 
 6642   if ((!has_src || !has_dest) && can_emit_guards) {
 6643     // We don't have sufficient type information, let's see if
 6644     // speculative types can help. We need to have types for both src
 6645     // and dest so that it pays off.
 6646 
 6647     // Do we already have or could we have type information for src
 6648     bool could_have_src = has_src;
 6649     // Do we already have or could we have type information for dest
 6650     bool could_have_dest = has_dest;
 6651 
 6652     ciKlass* src_k = nullptr;
 6653     if (!has_src) {
 6654       src_k = src_type->speculative_type_not_null();
 6655       if (src_k != nullptr && src_k->is_array_klass()) {
 6656         could_have_src = true;
 6657       }
 6658     }
 6659 
 6660     ciKlass* dest_k = nullptr;
 6661     if (!has_dest) {
 6662       dest_k = dest_type->speculative_type_not_null();
 6663       if (dest_k != nullptr && dest_k->is_array_klass()) {
 6664         could_have_dest = true;
 6665       }
 6666     }
 6667 
 6668     if (could_have_src && could_have_dest) {
 6669       // This is going to pay off so emit the required guards
 6670       if (!has_src) {
 6671         src = maybe_cast_profiled_obj(src, src_k, true);
 6672         src_type  = _gvn.type(src);
 6673         top_src  = src_type->isa_aryptr();
 6674         has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
 6675         src_spec = true;
 6676       }
 6677       if (!has_dest) {
 6678         dest = maybe_cast_profiled_obj(dest, dest_k, true);
 6679         dest_type  = _gvn.type(dest);
 6680         top_dest  = dest_type->isa_aryptr();
 6681         has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
 6682         dest_spec = true;
 6683       }
 6684     }
 6685   }
 6686 
 6687   if (has_src && has_dest && can_emit_guards) {
 6688     BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type();
 6689     BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type();
 6690     if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
 6691     if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
 6692 
 6693     if (src_elem == dest_elem && top_src->is_flat() == top_dest->is_flat() && src_elem == T_OBJECT) {
 6694       // If both arrays are object arrays then having the exact types
 6695       // for both will remove the need for a subtype check at runtime
 6696       // before the call and may make it possible to pick a faster copy
 6697       // routine (without a subtype check on every element)
 6698       // Do we have the exact type of src?
 6699       bool could_have_src = src_spec;
 6700       // Do we have the exact type of dest?
 6701       bool could_have_dest = dest_spec;
 6702       ciKlass* src_k = nullptr;
 6703       ciKlass* dest_k = nullptr;
 6704       if (!src_spec) {
 6705         src_k = src_type->speculative_type_not_null();
 6706         if (src_k != nullptr && src_k->is_array_klass()) {
 6707           could_have_src = true;
 6708         }
 6709       }
 6710       if (!dest_spec) {
 6711         dest_k = dest_type->speculative_type_not_null();
 6712         if (dest_k != nullptr && dest_k->is_array_klass()) {
 6713           could_have_dest = true;
 6714         }
 6715       }
 6716       if (could_have_src && could_have_dest) {
 6717         // If we can have both exact types, emit the missing guards
 6718         if (could_have_src && !src_spec) {
 6719           src = maybe_cast_profiled_obj(src, src_k, true);
 6720           src_type = _gvn.type(src);
 6721           top_src = src_type->isa_aryptr();
 6722         }
 6723         if (could_have_dest && !dest_spec) {
 6724           dest = maybe_cast_profiled_obj(dest, dest_k, true);
 6725           dest_type = _gvn.type(dest);
 6726           top_dest = dest_type->isa_aryptr();
 6727         }
 6728       }
 6729     }
 6730   }
 6731 
 6732   ciMethod* trap_method = method();
 6733   int trap_bci = bci();
 6734   if (saved_jvms_before_guards != nullptr) {
 6735     trap_method = alloc->jvms()->method();
 6736     trap_bci = alloc->jvms()->bci();
 6737   }
 6738 
 6739   bool negative_length_guard_generated = false;
 6740 
 6741   if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
 6742       can_emit_guards && !src->is_top() && !dest->is_top()) {
 6743     // validate arguments: enables transformation the ArrayCopyNode
 6744     validated = true;
 6745 
 6746     RegionNode* slow_region = new RegionNode(1);
 6747     record_for_igvn(slow_region);
 6748 
 6749     // (1) src and dest are arrays.
 6750     generate_non_array_guard(load_object_klass(src), slow_region, &src);
 6751     generate_non_array_guard(load_object_klass(dest), slow_region, &dest);
 6752 
 6753     // (2) src and dest arrays must have elements of the same BasicType
 6754     // done at macro expansion or at Ideal transformation time
 6755 
 6756     // (4) src_offset must not be negative.
 6757     generate_negative_guard(src_offset, slow_region);
 6758 
 6759     // (5) dest_offset must not be negative.
 6760     generate_negative_guard(dest_offset, slow_region);
 6761 
 6762     // (7) src_offset + length must not exceed length of src.
 6763     generate_limit_guard(src_offset, length,
 6764                          load_array_length(src),
 6765                          slow_region);
 6766 
 6767     // (8) dest_offset + length must not exceed length of dest.
 6768     generate_limit_guard(dest_offset, length,
 6769                          load_array_length(dest),
 6770                          slow_region);
 6771 
 6772     // (6) length must not be negative.
 6773     // This is also checked in generate_arraycopy() during macro expansion, but
 6774     // we also have to check it here for the case where the ArrayCopyNode will
 6775     // be eliminated by Escape Analysis.
 6776     if (EliminateAllocations) {
 6777       generate_negative_guard(length, slow_region);
 6778       negative_length_guard_generated = true;
 6779     }
 6780 
 6781     // (9) each element of an oop array must be assignable
 6782     Node* dest_klass = load_object_klass(dest);
 6783     Node* refined_dest_klass = dest_klass;
 6784     if (src != dest) {
 6785       dest_klass = load_non_refined_array_klass(refined_dest_klass);
 6786       Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass);
 6787       slow_region->add_req(not_subtype_ctrl);
 6788     }
 6789 
 6790     // TODO 8251971 Improve this. What about atomicity? Make sure this is always folded for type arrays.
 6791     // If destination is null-restricted, source must be null-restricted as well: src_null_restricted || !dst_null_restricted
 6792     Node* src_klass = load_object_klass(src);
 6793     Node* adr_prop_src = basic_plus_adr(top(), src_klass, in_bytes(ArrayKlass::properties_offset()));
 6794     Node* prop_src = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_src,
 6795                                                    _gvn.type(adr_prop_src)->is_ptr(), TypeInt::INT, T_INT,
 6796                                                    MemNode::unordered));
 6797     Node* adr_prop_dest = basic_plus_adr(top(), refined_dest_klass, in_bytes(ArrayKlass::properties_offset()));
 6798     Node* prop_dest = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_dest,
 6799                                                     _gvn.type(adr_prop_dest)->is_ptr(), TypeInt::INT, T_INT,
 6800                                                     MemNode::unordered));
 6801 
 6802     const ArrayProperties props_null_restricted = ArrayProperties::Default().with_null_restricted();
 6803     jint props_value = (jint)props_null_restricted.value();
 6804 
 6805     prop_dest = _gvn.transform(new XorINode(prop_dest, intcon(props_value)));
 6806     prop_src = _gvn.transform(new OrINode(prop_dest, prop_src));
 6807     prop_src = _gvn.transform(new AndINode(prop_src, intcon(props_value)));
 6808 
 6809     Node* chk = _gvn.transform(new CmpINode(prop_src, intcon(props_value)));
 6810     Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::ne));
 6811     generate_fair_guard(tst, slow_region);
 6812 
 6813     // TODO 8251971 This is too strong
 6814     generate_fair_guard(flat_array_test(src), slow_region);
 6815     generate_fair_guard(flat_array_test(dest), slow_region);
 6816 
 6817     {
 6818       PreserveJVMState pjvms(this);
 6819       set_control(_gvn.transform(slow_region));
 6820       uncommon_trap(Deoptimization::Reason_intrinsic,
 6821                     Deoptimization::Action_make_not_entrant);
 6822       assert(stopped(), "Should be stopped");
 6823     }
 6824 
 6825     const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->isa_klassptr();
 6826     if (dest_klass_t == nullptr) {
 6827       // refined_dest_klass may not be an array, which leads to dest_klass being top. This means we
 6828       // are in a dead path.
 6829       uncommon_trap(Deoptimization::Reason_intrinsic,
 6830                     Deoptimization::Action_make_not_entrant);
 6831       return true;
 6832     }
 6833 
 6834     const Type* toop = dest_klass_t->cast_to_exactness(false)->as_instance_type();
 6835     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
 6836     arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx);
 6837   }
 6838 
 6839   if (stopped()) {
 6840     return true;
 6841   }
 6842 
 6843   Node* dest_klass = load_object_klass(dest);
 6844   dest_klass = load_non_refined_array_klass(dest_klass);
 6845 
 6846   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated,
 6847                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
 6848                                           // so the compiler has a chance to eliminate them: during macro expansion,
 6849                                           // we have to set their control (CastPP nodes are eliminated).
 6850                                           load_object_klass(src), dest_klass,
 6851                                           load_array_length(src), load_array_length(dest));
 6852 
 6853   ac->set_arraycopy(validated);
 6854 
 6855   Node* n = _gvn.transform(ac);
 6856   if (n == ac) {
 6857     ac->connect_outputs(this);
 6858   } else {
 6859     assert(validated, "shouldn't transform if all arguments not validated");
 6860     set_all_memory(n);
 6861   }
 6862   clear_upper_avx();
 6863 
 6864 
 6865   return true;
 6866 }
 6867 
 6868 
 6869 // Helper function which determines if an arraycopy immediately follows
 6870 // an allocation, with no intervening tests or other escapes for the object.
 6871 AllocateArrayNode*
 6872 LibraryCallKit::tightly_coupled_allocation(Node* ptr) {
 6873   if (stopped())             return nullptr;  // no fast path
 6874   if (!C->do_aliasing())     return nullptr;  // no MergeMems around
 6875 
 6876   AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr);
 6877   if (alloc == nullptr)  return nullptr;
 6878 
 6879   Node* rawmem = memory(Compile::AliasIdxRaw);
 6880   // Is the allocation's memory state untouched?
 6881   if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) {
 6882     // Bail out if there have been raw-memory effects since the allocation.
 6883     // (Example:  There might have been a call or safepoint.)
 6884     return nullptr;
 6885   }
 6886   rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw);
 6887   if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) {
 6888     return nullptr;
 6889   }
 6890 
 6891   // There must be no unexpected observers of this allocation.
 6892   for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) {
 6893     Node* obs = ptr->fast_out(i);
 6894     if (obs != this->map()) {
 6895       return nullptr;
 6896     }
 6897   }
 6898 
 6899   // This arraycopy must unconditionally follow the allocation of the ptr.
 6900   Node* alloc_ctl = ptr->in(0);
 6901   Node* ctl = control();
 6902   while (ctl != alloc_ctl) {
 6903     // There may be guards which feed into the slow_region.
 6904     // Any other control flow means that we might not get a chance
 6905     // to finish initializing the allocated object.
 6906     // Various low-level checks bottom out in uncommon traps. These
 6907     // are considered safe since we've already checked above that
 6908     // there is no unexpected observer of this allocation.
 6909     if (get_uncommon_trap_from_success_proj(ctl) != nullptr) {
 6910       assert(ctl->in(0)->is_If(), "must be If");
 6911       ctl = ctl->in(0)->in(0);
 6912     } else {
 6913       return nullptr;
 6914     }
 6915   }
 6916 
 6917   // If we get this far, we have an allocation which immediately
 6918   // precedes the arraycopy, and we can take over zeroing the new object.
 6919   // The arraycopy will finish the initialization, and provide
 6920   // a new control state to which we will anchor the destination pointer.
 6921 
 6922   return alloc;
 6923 }
 6924 
 6925 CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* node) {
 6926   if (node->is_IfProj()) {
 6927     IfProjNode* other_proj = node->as_IfProj()->other_if_proj();
 6928     for (DUIterator_Fast jmax, j = other_proj->fast_outs(jmax); j < jmax; j++) {
 6929       Node* obs = other_proj->fast_out(j);
 6930       if (obs->in(0) == other_proj && obs->is_CallStaticJava() &&
 6931           (obs->as_CallStaticJava()->entry_point() == OptoRuntime::uncommon_trap_blob()->entry_point())) {
 6932         return obs->as_CallStaticJava();
 6933       }
 6934     }
 6935   }
 6936   return nullptr;
 6937 }
 6938 
 6939 //-------------inline_encodeISOArray-----------------------------------
 6940 // int sun.nio.cs.ISO_8859_1.Encoder#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
 6941 // int java.lang.StringCoding#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
 6942 // int java.lang.StringCoding#encodeAsciiArray0(char[] sa, int sp, byte[] da, int dp, int len)
 6943 // encode char[] to byte[] in ISO_8859_1 or ASCII
 6944 bool LibraryCallKit::inline_encodeISOArray(bool ascii) {
 6945   assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters");
 6946   // no receiver since it is static method
 6947   Node *src         = argument(0);
 6948   Node *src_offset  = argument(1);
 6949   Node *dst         = argument(2);
 6950   Node *dst_offset  = argument(3);
 6951   Node *length      = argument(4);
 6952 
 6953   // Cast source & target arrays to not-null
 6954   src = must_be_not_null(src, true);
 6955   dst = must_be_not_null(dst, true);
 6956   if (stopped()) {
 6957     return true;
 6958   }
 6959 
 6960   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 6961   const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr();
 6962   if (src_type == nullptr || src_type->elem() == Type::BOTTOM ||
 6963       dst_type == nullptr || dst_type->elem() == Type::BOTTOM) {
 6964     // failed array check
 6965     return false;
 6966   }
 6967 
 6968   // Figure out the size and type of the elements we will be copying.
 6969   BasicType src_elem = src_type->elem()->array_element_basic_type();
 6970   BasicType dst_elem = dst_type->elem()->array_element_basic_type();
 6971   if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) {
 6972     return false;
 6973   }
 6974 
 6975   // Check source & target bounds
 6976   RegionNode* bailout = create_bailout();
 6977   generate_string_range_check(src, src_offset, length, src_elem == T_BYTE, bailout);
 6978   generate_string_range_check(dst, dst_offset, length, false, bailout);
 6979   if (check_bailout(bailout)) {
 6980     return true;
 6981   }
 6982 
 6983   Node* src_start = array_element_address(src, src_offset, T_CHAR);
 6984   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
 6985   // 'src_start' points to src array + scaled offset
 6986   // 'dst_start' points to dst array + scaled offset
 6987 
 6988   // See GraphKit::compress_string
 6989   const TypePtr* adr_type;
 6990   Node* mem = capture_memory(adr_type, src_type, dst_type);
 6991   Node* enc = new EncodeISOArrayNode(control(), mem, adr_type, src_start, dst_start, length, ascii);
 6992   enc = _gvn.transform(enc);
 6993   Node* res_mem = _gvn.transform(new SCMemProjNode(enc));
 6994   memory_effect(res_mem, src_type, dst_type);
 6995 
 6996   set_result(enc);
 6997   clear_upper_avx();
 6998 
 6999   return true;
 7000 }
 7001 
 7002 //-------------inline_multiplyToLen-----------------------------------
 7003 bool LibraryCallKit::inline_multiplyToLen() {
 7004   assert(UseMultiplyToLenIntrinsic, "not implemented on this platform");
 7005 
 7006   address stubAddr = StubRoutines::multiplyToLen();
 7007   if (stubAddr == nullptr) {
 7008     return false; // Intrinsic's stub is not implemented on this platform
 7009   }
 7010   const char* stubName = "multiplyToLen";
 7011 
 7012   assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters");
 7013 
 7014   // no receiver because it is a static method
 7015   Node* x    = argument(0);
 7016   Node* xlen = argument(1);
 7017   Node* y    = argument(2);
 7018   Node* ylen = argument(3);
 7019   Node* z    = argument(4);
 7020 
 7021   x = must_be_not_null(x, true);
 7022   y = must_be_not_null(y, true);
 7023 
 7024   const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr();
 7025   const TypeAryPtr* y_type = y->Value(&_gvn)->isa_aryptr();
 7026   if (x_type == nullptr || x_type->elem() == Type::BOTTOM ||
 7027       y_type == nullptr || y_type->elem() == Type::BOTTOM) {
 7028     // failed array check
 7029     return false;
 7030   }
 7031 
 7032   BasicType x_elem = x_type->elem()->array_element_basic_type();
 7033   BasicType y_elem = y_type->elem()->array_element_basic_type();
 7034   if (x_elem != T_INT || y_elem != T_INT) {
 7035     return false;
 7036   }
 7037 
 7038   Node* x_start = array_element_address(x, intcon(0), x_elem);
 7039   Node* y_start = array_element_address(y, intcon(0), y_elem);
 7040   // 'x_start' points to x array + scaled xlen
 7041   // 'y_start' points to y array + scaled ylen
 7042 
 7043   Node* z_start = array_element_address(z, intcon(0), T_INT);
 7044 
 7045   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7046                                  OptoRuntime::multiplyToLen_Type(),
 7047                                  stubAddr, stubName, TypePtr::BOTTOM,
 7048                                  x_start, xlen, y_start, ylen, z_start);
 7049 
 7050   C->set_has_split_ifs(true); // Has chance for split-if optimization
 7051   set_result(z);
 7052   return true;
 7053 }
 7054 
 7055 //-------------inline_squareToLen------------------------------------
 7056 bool LibraryCallKit::inline_squareToLen() {
 7057   assert(UseSquareToLenIntrinsic, "not implemented on this platform");
 7058 
 7059   address stubAddr = StubRoutines::squareToLen();
 7060   if (stubAddr == nullptr) {
 7061     return false; // Intrinsic's stub is not implemented on this platform
 7062   }
 7063   const char* stubName = "squareToLen";
 7064 
 7065   assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters");
 7066 
 7067   Node* x    = argument(0);
 7068   Node* len  = argument(1);
 7069   Node* z    = argument(2);
 7070   Node* zlen = argument(3);
 7071 
 7072   x = must_be_not_null(x, true);
 7073   z = must_be_not_null(z, true);
 7074 
 7075   const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr();
 7076   const TypeAryPtr* z_type = z->Value(&_gvn)->isa_aryptr();
 7077   if (x_type == nullptr || x_type->elem() == Type::BOTTOM ||
 7078       z_type == nullptr || z_type->elem() == Type::BOTTOM) {
 7079     // failed array check
 7080     return false;
 7081   }
 7082 
 7083   BasicType x_elem = x_type->elem()->array_element_basic_type();
 7084   BasicType z_elem = z_type->elem()->array_element_basic_type();
 7085   if (x_elem != T_INT || z_elem != T_INT) {
 7086     return false;
 7087   }
 7088 
 7089 
 7090   Node* x_start = array_element_address(x, intcon(0), x_elem);
 7091   Node* z_start = array_element_address(z, intcon(0), z_elem);
 7092 
 7093   Node*  call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7094                                   OptoRuntime::squareToLen_Type(),
 7095                                   stubAddr, stubName, TypePtr::BOTTOM,
 7096                                   x_start, len, z_start, zlen);
 7097 
 7098   set_result(z);
 7099   return true;
 7100 }
 7101 
 7102 //-------------inline_mulAdd------------------------------------------
 7103 bool LibraryCallKit::inline_mulAdd() {
 7104   assert(UseMulAddIntrinsic, "not implemented on this platform");
 7105 
 7106   address stubAddr = StubRoutines::mulAdd();
 7107   if (stubAddr == nullptr) {
 7108     return false; // Intrinsic's stub is not implemented on this platform
 7109   }
 7110   const char* stubName = "mulAdd";
 7111 
 7112   assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters");
 7113 
 7114   Node* out      = argument(0);
 7115   Node* in       = argument(1);
 7116   Node* offset   = argument(2);
 7117   Node* len      = argument(3);
 7118   Node* k        = argument(4);
 7119 
 7120   in = must_be_not_null(in, true);
 7121   out = must_be_not_null(out, true);
 7122 
 7123   const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr();
 7124   const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr();
 7125   if (out_type == nullptr || out_type->elem() == Type::BOTTOM ||
 7126        in_type == nullptr ||  in_type->elem() == Type::BOTTOM) {
 7127     // failed array check
 7128     return false;
 7129   }
 7130 
 7131   BasicType out_elem = out_type->elem()->array_element_basic_type();
 7132   BasicType in_elem = in_type->elem()->array_element_basic_type();
 7133   if (out_elem != T_INT || in_elem != T_INT) {
 7134     return false;
 7135   }
 7136 
 7137   Node* outlen = load_array_length(out);
 7138   Node* new_offset = _gvn.transform(new SubINode(outlen, offset));
 7139   Node* out_start = array_element_address(out, intcon(0), out_elem);
 7140   Node* in_start = array_element_address(in, intcon(0), in_elem);
 7141 
 7142   Node*  call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7143                                   OptoRuntime::mulAdd_Type(),
 7144                                   stubAddr, stubName, TypePtr::BOTTOM,
 7145                                   out_start,in_start, new_offset, len, k);
 7146   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7147   set_result(result);
 7148   return true;
 7149 }
 7150 
 7151 //-------------inline_montgomeryMultiply-----------------------------------
 7152 bool LibraryCallKit::inline_montgomeryMultiply() {
 7153   address stubAddr = StubRoutines::montgomeryMultiply();
 7154   if (stubAddr == nullptr) {
 7155     return false; // Intrinsic's stub is not implemented on this platform
 7156   }
 7157 
 7158   assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform");
 7159   const char* stubName = "montgomery_multiply";
 7160 
 7161   assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters");
 7162 
 7163   Node* a    = argument(0);
 7164   Node* b    = argument(1);
 7165   Node* n    = argument(2);
 7166   Node* len  = argument(3);
 7167   Node* inv  = argument(4);
 7168   Node* m    = argument(6);
 7169 
 7170   const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr();
 7171   const TypeAryPtr* b_type = b->Value(&_gvn)->isa_aryptr();
 7172   const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr();
 7173   const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr();
 7174   if (a_type == nullptr || a_type->elem() == Type::BOTTOM ||
 7175       b_type == nullptr || b_type->elem() == Type::BOTTOM ||
 7176       n_type == nullptr || n_type->elem() == Type::BOTTOM ||
 7177       m_type == nullptr || m_type->elem() == Type::BOTTOM) {
 7178     // failed array check
 7179     return false;
 7180   }
 7181 
 7182   BasicType a_elem = a_type->elem()->array_element_basic_type();
 7183   BasicType b_elem = b_type->elem()->array_element_basic_type();
 7184   BasicType n_elem = n_type->elem()->array_element_basic_type();
 7185   BasicType m_elem = m_type->elem()->array_element_basic_type();
 7186   if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
 7187     return false;
 7188   }
 7189 
 7190   // Make the call
 7191   {
 7192     Node* a_start = array_element_address(a, intcon(0), a_elem);
 7193     Node* b_start = array_element_address(b, intcon(0), b_elem);
 7194     Node* n_start = array_element_address(n, intcon(0), n_elem);
 7195     Node* m_start = array_element_address(m, intcon(0), m_elem);
 7196 
 7197     Node* call = make_runtime_call(RC_LEAF,
 7198                                    OptoRuntime::montgomeryMultiply_Type(),
 7199                                    stubAddr, stubName, TypePtr::BOTTOM,
 7200                                    a_start, b_start, n_start, len, inv, top(),
 7201                                    m_start);
 7202     set_result(m);
 7203   }
 7204 
 7205   return true;
 7206 }
 7207 
 7208 bool LibraryCallKit::inline_montgomerySquare() {
 7209   address stubAddr = StubRoutines::montgomerySquare();
 7210   if (stubAddr == nullptr) {
 7211     return false; // Intrinsic's stub is not implemented on this platform
 7212   }
 7213 
 7214   assert(UseMontgomerySquareIntrinsic, "not implemented on this platform");
 7215   const char* stubName = "montgomery_square";
 7216 
 7217   assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters");
 7218 
 7219   Node* a    = argument(0);
 7220   Node* n    = argument(1);
 7221   Node* len  = argument(2);
 7222   Node* inv  = argument(3);
 7223   Node* m    = argument(5);
 7224 
 7225   const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr();
 7226   const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr();
 7227   const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr();
 7228   if (a_type == nullptr || a_type->elem() == Type::BOTTOM ||
 7229       n_type == nullptr || n_type->elem() == Type::BOTTOM ||
 7230       m_type == nullptr || m_type->elem() == Type::BOTTOM) {
 7231     // failed array check
 7232     return false;
 7233   }
 7234 
 7235   BasicType a_elem = a_type->elem()->array_element_basic_type();
 7236   BasicType n_elem = n_type->elem()->array_element_basic_type();
 7237   BasicType m_elem = m_type->elem()->array_element_basic_type();
 7238   if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
 7239     return false;
 7240   }
 7241 
 7242   // Make the call
 7243   {
 7244     Node* a_start = array_element_address(a, intcon(0), a_elem);
 7245     Node* n_start = array_element_address(n, intcon(0), n_elem);
 7246     Node* m_start = array_element_address(m, intcon(0), m_elem);
 7247 
 7248     Node* call = make_runtime_call(RC_LEAF,
 7249                                    OptoRuntime::montgomerySquare_Type(),
 7250                                    stubAddr, stubName, TypePtr::BOTTOM,
 7251                                    a_start, n_start, len, inv, top(),
 7252                                    m_start);
 7253     set_result(m);
 7254   }
 7255 
 7256   return true;
 7257 }
 7258 
 7259 bool LibraryCallKit::inline_bigIntegerShift(bool isRightShift) {
 7260   address stubAddr = nullptr;
 7261   const char* stubName = nullptr;
 7262 
 7263   stubAddr = isRightShift? StubRoutines::bigIntegerRightShift(): StubRoutines::bigIntegerLeftShift();
 7264   if (stubAddr == nullptr) {
 7265     return false; // Intrinsic's stub is not implemented on this platform
 7266   }
 7267 
 7268   stubName = isRightShift? "bigIntegerRightShiftWorker" : "bigIntegerLeftShiftWorker";
 7269 
 7270   assert(callee()->signature()->size() == 5, "expected 5 arguments");
 7271 
 7272   Node* newArr = argument(0);
 7273   Node* oldArr = argument(1);
 7274   Node* newIdx = argument(2);
 7275   Node* shiftCount = argument(3);
 7276   Node* numIter = argument(4);
 7277 
 7278   const TypeAryPtr* newArr_type = newArr->Value(&_gvn)->isa_aryptr();
 7279   const TypeAryPtr* oldArr_type = oldArr->Value(&_gvn)->isa_aryptr();
 7280   if (newArr_type == nullptr || newArr_type->elem() == Type::BOTTOM ||
 7281       oldArr_type == nullptr || oldArr_type->elem() == Type::BOTTOM) {
 7282     return false;
 7283   }
 7284 
 7285   BasicType newArr_elem = newArr_type->elem()->array_element_basic_type();
 7286   BasicType oldArr_elem = oldArr_type->elem()->array_element_basic_type();
 7287   if (newArr_elem != T_INT || oldArr_elem != T_INT) {
 7288     return false;
 7289   }
 7290 
 7291   // Make the call
 7292   {
 7293     Node* newArr_start = array_element_address(newArr, intcon(0), newArr_elem);
 7294     Node* oldArr_start = array_element_address(oldArr, intcon(0), oldArr_elem);
 7295 
 7296     Node* call = make_runtime_call(RC_LEAF,
 7297                                    OptoRuntime::bigIntegerShift_Type(),
 7298                                    stubAddr,
 7299                                    stubName,
 7300                                    TypePtr::BOTTOM,
 7301                                    newArr_start,
 7302                                    oldArr_start,
 7303                                    newIdx,
 7304                                    shiftCount,
 7305                                    numIter);
 7306   }
 7307 
 7308   return true;
 7309 }
 7310 
 7311 //-------------inline_vectorizedMismatch------------------------------
 7312 bool LibraryCallKit::inline_vectorizedMismatch() {
 7313   assert(UseVectorizedMismatchIntrinsic, "not implemented on this platform");
 7314 
 7315   assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters");
 7316   Node* obja    = argument(0); // Object
 7317   Node* aoffset = argument(1); // long
 7318   Node* objb    = argument(3); // Object
 7319   Node* boffset = argument(4); // long
 7320   Node* length  = argument(6); // int
 7321   Node* scale   = argument(7); // int
 7322 
 7323   const TypeAryPtr* obja_t = _gvn.type(obja)->isa_aryptr();
 7324   const TypeAryPtr* objb_t = _gvn.type(objb)->isa_aryptr();
 7325   if (obja_t == nullptr || obja_t->elem() == Type::BOTTOM ||
 7326       objb_t == nullptr || objb_t->elem() == Type::BOTTOM ||
 7327       scale == top()) {
 7328     return false; // failed input validation
 7329   }
 7330 
 7331   Node* obja_adr = make_unsafe_address(obja, aoffset);
 7332   Node* objb_adr = make_unsafe_address(objb, boffset);
 7333 
 7334   // Partial inlining handling for inputs smaller than ArrayOperationPartialInlineSize bytes in size.
 7335   //
 7336   //    inline_limit = ArrayOperationPartialInlineSize / element_size;
 7337   //    if (length <= inline_limit) {
 7338   //      inline_path:
 7339   //        vmask   = VectorMaskGen length
 7340   //        vload1  = LoadVectorMasked obja, vmask
 7341   //        vload2  = LoadVectorMasked objb, vmask
 7342   //        result1 = VectorCmpMasked vload1, vload2, vmask
 7343   //    } else {
 7344   //      call_stub_path:
 7345   //        result2 = call vectorizedMismatch_stub(obja, objb, length, scale)
 7346   //    }
 7347   //    exit_block:
 7348   //      return Phi(result1, result2);
 7349   //
 7350   enum { inline_path = 1,  // input is small enough to process it all at once
 7351          stub_path   = 2,  // input is too large; call into the VM
 7352          PATH_LIMIT  = 3
 7353   };
 7354 
 7355   Node* exit_block = new RegionNode(PATH_LIMIT);
 7356   Node* result_phi = new PhiNode(exit_block, TypeInt::INT);
 7357   Node* memory_phi = new PhiNode(exit_block, Type::MEMORY, TypePtr::BOTTOM);
 7358 
 7359   Node* call_stub_path = control();
 7360 
 7361   BasicType elem_bt = T_ILLEGAL;
 7362 
 7363   const TypeInt* scale_t = _gvn.type(scale)->is_int();
 7364   if (scale_t->is_con()) {
 7365     switch (scale_t->get_con()) {
 7366       case 0: elem_bt = T_BYTE;  break;
 7367       case 1: elem_bt = T_SHORT; break;
 7368       case 2: elem_bt = T_INT;   break;
 7369       case 3: elem_bt = T_LONG;  break;
 7370 
 7371       default: elem_bt = T_ILLEGAL; break; // not supported
 7372     }
 7373   }
 7374 
 7375   int inline_limit = 0;
 7376   bool do_partial_inline = false;
 7377 
 7378   if (elem_bt != T_ILLEGAL && ArrayOperationPartialInlineSize > 0) {
 7379     inline_limit = ArrayOperationPartialInlineSize / type2aelembytes(elem_bt);
 7380     do_partial_inline = inline_limit >= 16;
 7381   }
 7382 
 7383   if (do_partial_inline) {
 7384     assert(elem_bt != T_ILLEGAL, "sanity");
 7385 
 7386     if (Matcher::match_rule_supported_vector(Op_VectorMaskGen,    inline_limit, elem_bt) &&
 7387         Matcher::match_rule_supported_vector(Op_LoadVectorMasked, inline_limit, elem_bt) &&
 7388         Matcher::match_rule_supported_vector(Op_VectorCmpMasked,  inline_limit, elem_bt)) {
 7389 
 7390       const TypeVect* vt = TypeVect::make(elem_bt, inline_limit);
 7391       Node* cmp_length = _gvn.transform(new CmpINode(length, intcon(inline_limit)));
 7392       Node* bol_gt     = _gvn.transform(new BoolNode(cmp_length, BoolTest::gt));
 7393 
 7394       call_stub_path = generate_guard(bol_gt, nullptr, PROB_MIN);
 7395 
 7396       if (!stopped()) {
 7397         Node* casted_length = _gvn.transform(new CastIINode(control(), length, TypeInt::make(0, inline_limit, Type::WidenMin)));
 7398 
 7399         const TypePtr* obja_adr_t = _gvn.type(obja_adr)->isa_ptr();
 7400         const TypePtr* objb_adr_t = _gvn.type(objb_adr)->isa_ptr();
 7401         Node* obja_adr_mem = memory(C->get_alias_index(obja_adr_t));
 7402         Node* objb_adr_mem = memory(C->get_alias_index(objb_adr_t));
 7403 
 7404         Node* vmask      = _gvn.transform(VectorMaskGenNode::make(ConvI2X(casted_length), elem_bt));
 7405         Node* vload_obja = _gvn.transform(new LoadVectorMaskedNode(control(), obja_adr_mem, obja_adr, obja_adr_t, vt, vmask));
 7406         Node* vload_objb = _gvn.transform(new LoadVectorMaskedNode(control(), objb_adr_mem, objb_adr, objb_adr_t, vt, vmask));
 7407         Node* result     = _gvn.transform(new VectorCmpMaskedNode(vload_obja, vload_objb, vmask, TypeInt::INT));
 7408 
 7409         exit_block->init_req(inline_path, control());
 7410         memory_phi->init_req(inline_path, map()->memory());
 7411         result_phi->init_req(inline_path, result);
 7412 
 7413         C->set_max_vector_size(MAX2((uint)ArrayOperationPartialInlineSize, C->max_vector_size()));
 7414         clear_upper_avx();
 7415       }
 7416     }
 7417   }
 7418 
 7419   if (call_stub_path != nullptr) {
 7420     set_control(call_stub_path);
 7421 
 7422     Node* call = make_runtime_call(RC_LEAF,
 7423                                    OptoRuntime::vectorizedMismatch_Type(),
 7424                                    StubRoutines::vectorizedMismatch(), "vectorizedMismatch", TypePtr::BOTTOM,
 7425                                    obja_adr, objb_adr, length, scale);
 7426 
 7427     exit_block->init_req(stub_path, control());
 7428     memory_phi->init_req(stub_path, map()->memory());
 7429     result_phi->init_req(stub_path, _gvn.transform(new ProjNode(call, TypeFunc::Parms)));
 7430   }
 7431 
 7432   exit_block = _gvn.transform(exit_block);
 7433   memory_phi = _gvn.transform(memory_phi);
 7434   result_phi = _gvn.transform(result_phi);
 7435 
 7436   record_for_igvn(exit_block);
 7437   record_for_igvn(memory_phi);
 7438   record_for_igvn(result_phi);
 7439 
 7440   set_control(exit_block);
 7441   set_all_memory(memory_phi);
 7442   set_result(result_phi);
 7443 
 7444   return true;
 7445 }
 7446 
 7447 //------------------------------inline_vectorizedHashcode----------------------------
 7448 bool LibraryCallKit::inline_vectorizedHashCode() {
 7449   assert(UseVectorizedHashCodeIntrinsic, "not implemented on this platform");
 7450 
 7451   assert(callee()->signature()->size() == 5, "vectorizedHashCode has 5 parameters");
 7452   Node* array          = argument(0);
 7453   Node* offset         = argument(1);
 7454   Node* length         = argument(2);
 7455   Node* initialValue   = argument(3);
 7456   Node* basic_type     = argument(4);
 7457 
 7458   if (basic_type == top()) {
 7459     return false; // failed input validation
 7460   }
 7461 
 7462   const TypeInt* basic_type_t = _gvn.type(basic_type)->is_int();
 7463   if (!basic_type_t->is_con()) {
 7464     return false; // Only intrinsify if mode argument is constant
 7465   }
 7466 
 7467   array = must_be_not_null(array, true);
 7468 
 7469   BasicType bt = (BasicType)basic_type_t->get_con();
 7470 
 7471   // Resolve address of first element
 7472   Node* array_start = array_element_address(array, offset, bt);
 7473 
 7474   const TypeAryPtr* in_adr_type = TypeAryPtr::get_array_body_type(bt);
 7475   set_result(_gvn.transform(new VectorizedHashCodeNode(control(), memory(in_adr_type), in_adr_type,
 7476     array_start, length, initialValue, basic_type)));
 7477   clear_upper_avx();
 7478 
 7479   return true;
 7480 }
 7481 
 7482 /**
 7483  * Calculate CRC32 for byte.
 7484  * int java.util.zip.CRC32.update(int crc, int b)
 7485  */
 7486 bool LibraryCallKit::inline_updateCRC32() {
 7487   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7488   assert(callee()->signature()->size() == 2, "update has 2 parameters");
 7489   // no receiver since it is static method
 7490   Node* crc  = argument(0); // type: int
 7491   Node* b    = argument(1); // type: int
 7492 
 7493   /*
 7494    *    int c = ~ crc;
 7495    *    b = timesXtoThe32[(b ^ c) & 0xFF];
 7496    *    b = b ^ (c >>> 8);
 7497    *    crc = ~b;
 7498    */
 7499 
 7500   Node* M1 = intcon(-1);
 7501   crc = _gvn.transform(new XorINode(crc, M1));
 7502   Node* result = _gvn.transform(new XorINode(crc, b));
 7503   result = _gvn.transform(new AndINode(result, intcon(0xFF)));
 7504 
 7505   Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr()));
 7506   Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2)));
 7507   Node* adr = off_heap_plus_addr(base, ConvI2X(offset));
 7508   result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered);
 7509 
 7510   crc = _gvn.transform(new URShiftINode(crc, intcon(8)));
 7511   result = _gvn.transform(new XorINode(crc, result));
 7512   result = _gvn.transform(new XorINode(result, M1));
 7513   set_result(result);
 7514   return true;
 7515 }
 7516 
 7517 /**
 7518  * Calculate CRC32 for byte[] array.
 7519  * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len)
 7520  */
 7521 bool LibraryCallKit::inline_updateBytesCRC32() {
 7522   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7523   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7524   // no receiver since it is static method
 7525   Node* crc     = argument(0); // type: int
 7526   Node* src     = argument(1); // type: oop
 7527   Node* offset  = argument(2); // type: int
 7528   Node* length  = argument(3); // type: int
 7529 
 7530   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7531   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7532     // failed array check
 7533     return false;
 7534   }
 7535 
 7536   // Figure out the size and type of the elements we will be copying.
 7537   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7538   if (src_elem != T_BYTE) {
 7539     return false;
 7540   }
 7541 
 7542   // 'src_start' points to src array + scaled offset
 7543   src = must_be_not_null(src, true);
 7544   Node* src_start = array_element_address(src, offset, src_elem);
 7545 
 7546   // We assume that range check is done by caller.
 7547   // TODO: generate range check (offset+length < src.length) in debug VM.
 7548 
 7549   // Call the stub.
 7550   address stubAddr = StubRoutines::updateBytesCRC32();
 7551   const char *stubName = "updateBytesCRC32";
 7552 
 7553   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
 7554                                  stubAddr, stubName, TypePtr::BOTTOM,
 7555                                  crc, src_start, length);
 7556   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7557   set_result(result);
 7558   return true;
 7559 }
 7560 
 7561 /**
 7562  * Calculate CRC32 for ByteBuffer.
 7563  * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
 7564  */
 7565 bool LibraryCallKit::inline_updateByteBufferCRC32() {
 7566   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7567   assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long");
 7568   // no receiver since it is static method
 7569   Node* crc     = argument(0); // type: int
 7570   Node* src     = argument(1); // type: long
 7571   Node* offset  = argument(3); // type: int
 7572   Node* length  = argument(4); // type: int
 7573 
 7574   src = ConvL2X(src);  // adjust Java long to machine word
 7575   Node* base = _gvn.transform(new CastX2PNode(src));
 7576   offset = ConvI2X(offset);
 7577 
 7578   // 'src_start' points to src array + scaled offset
 7579   Node* src_start = off_heap_plus_addr(base, offset);
 7580 
 7581   // Call the stub.
 7582   address stubAddr = StubRoutines::updateBytesCRC32();
 7583   const char *stubName = "updateBytesCRC32";
 7584 
 7585   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
 7586                                  stubAddr, stubName, TypePtr::BOTTOM,
 7587                                  crc, src_start, length);
 7588   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7589   set_result(result);
 7590   return true;
 7591 }
 7592 
 7593 //------------------------------get_table_from_crc32c_class-----------------------
 7594 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) {
 7595   Node* table = load_field_from_object(nullptr, "byteTable", "[I", /*decorators*/ IN_HEAP, /*is_static*/ true, crc32c_class);
 7596   assert (table != nullptr, "wrong version of java.util.zip.CRC32C");
 7597 
 7598   return table;
 7599 }
 7600 
 7601 //------------------------------inline_updateBytesCRC32C-----------------------
 7602 //
 7603 // Calculate CRC32C for byte[] array.
 7604 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end)
 7605 //
 7606 bool LibraryCallKit::inline_updateBytesCRC32C() {
 7607   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
 7608   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7609   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
 7610   // no receiver since it is a static method
 7611   Node* crc     = argument(0); // type: int
 7612   Node* src     = argument(1); // type: oop
 7613   Node* offset  = argument(2); // type: int
 7614   Node* end     = argument(3); // type: int
 7615 
 7616   Node* length = _gvn.transform(new SubINode(end, offset));
 7617 
 7618   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7619   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7620     // failed array check
 7621     return false;
 7622   }
 7623 
 7624   // Figure out the size and type of the elements we will be copying.
 7625   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7626   if (src_elem != T_BYTE) {
 7627     return false;
 7628   }
 7629 
 7630   // 'src_start' points to src array + scaled offset
 7631   src = must_be_not_null(src, true);
 7632   Node* src_start = array_element_address(src, offset, src_elem);
 7633 
 7634   // static final int[] byteTable in class CRC32C
 7635   Node* table = get_table_from_crc32c_class(callee()->holder());
 7636   table = must_be_not_null(table, true);
 7637   Node* table_start = array_element_address(table, intcon(0), T_INT);
 7638 
 7639   // We assume that range check is done by caller.
 7640   // TODO: generate range check (offset+length < src.length) in debug VM.
 7641 
 7642   // Call the stub.
 7643   address stubAddr = StubRoutines::updateBytesCRC32C();
 7644   const char *stubName = "updateBytesCRC32C";
 7645 
 7646   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
 7647                                  stubAddr, stubName, TypePtr::BOTTOM,
 7648                                  crc, src_start, length, table_start);
 7649   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7650   set_result(result);
 7651   return true;
 7652 }
 7653 
 7654 //------------------------------inline_updateDirectByteBufferCRC32C-----------------------
 7655 //
 7656 // Calculate CRC32C for DirectByteBuffer.
 7657 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end)
 7658 //
 7659 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() {
 7660   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
 7661   assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long");
 7662   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
 7663   // no receiver since it is a static method
 7664   Node* crc     = argument(0); // type: int
 7665   Node* src     = argument(1); // type: long
 7666   Node* offset  = argument(3); // type: int
 7667   Node* end     = argument(4); // type: int
 7668 
 7669   Node* length = _gvn.transform(new SubINode(end, offset));
 7670 
 7671   src = ConvL2X(src);  // adjust Java long to machine word
 7672   Node* base = _gvn.transform(new CastX2PNode(src));
 7673   offset = ConvI2X(offset);
 7674 
 7675   // 'src_start' points to src array + scaled offset
 7676   Node* src_start = off_heap_plus_addr(base, offset);
 7677 
 7678   // static final int[] byteTable in class CRC32C
 7679   Node* table = get_table_from_crc32c_class(callee()->holder());
 7680   table = must_be_not_null(table, true);
 7681   Node* table_start = array_element_address(table, intcon(0), T_INT);
 7682 
 7683   // Call the stub.
 7684   address stubAddr = StubRoutines::updateBytesCRC32C();
 7685   const char *stubName = "updateBytesCRC32C";
 7686 
 7687   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
 7688                                  stubAddr, stubName, TypePtr::BOTTOM,
 7689                                  crc, src_start, length, table_start);
 7690   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7691   set_result(result);
 7692   return true;
 7693 }
 7694 
 7695 //------------------------------inline_updateBytesAdler32----------------------
 7696 //
 7697 // Calculate Adler32 checksum for byte[] array.
 7698 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len)
 7699 //
 7700 bool LibraryCallKit::inline_updateBytesAdler32() {
 7701   assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one
 7702   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7703   assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded");
 7704   // no receiver since it is static method
 7705   Node* crc     = argument(0); // type: int
 7706   Node* src     = argument(1); // type: oop
 7707   Node* offset  = argument(2); // type: int
 7708   Node* length  = argument(3); // type: int
 7709 
 7710   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7711   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7712     // failed array check
 7713     return false;
 7714   }
 7715 
 7716   // Figure out the size and type of the elements we will be copying.
 7717   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7718   if (src_elem != T_BYTE) {
 7719     return false;
 7720   }
 7721 
 7722   // 'src_start' points to src array + scaled offset
 7723   Node* src_start = array_element_address(src, offset, src_elem);
 7724 
 7725   // We assume that range check is done by caller.
 7726   // TODO: generate range check (offset+length < src.length) in debug VM.
 7727 
 7728   // Call the stub.
 7729   address stubAddr = StubRoutines::updateBytesAdler32();
 7730   const char *stubName = "updateBytesAdler32";
 7731 
 7732   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
 7733                                  stubAddr, stubName, TypePtr::BOTTOM,
 7734                                  crc, src_start, length);
 7735   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7736   set_result(result);
 7737   return true;
 7738 }
 7739 
 7740 //------------------------------inline_updateByteBufferAdler32---------------
 7741 //
 7742 // Calculate Adler32 checksum for DirectByteBuffer.
 7743 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len)
 7744 //
 7745 bool LibraryCallKit::inline_updateByteBufferAdler32() {
 7746   assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one
 7747   assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long");
 7748   assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded");
 7749   // no receiver since it is static method
 7750   Node* crc     = argument(0); // type: int
 7751   Node* src     = argument(1); // type: long
 7752   Node* offset  = argument(3); // type: int
 7753   Node* length  = argument(4); // type: int
 7754 
 7755   src = ConvL2X(src);  // adjust Java long to machine word
 7756   Node* base = _gvn.transform(new CastX2PNode(src));
 7757   offset = ConvI2X(offset);
 7758 
 7759   // 'src_start' points to src array + scaled offset
 7760   Node* src_start = off_heap_plus_addr(base, offset);
 7761 
 7762   // Call the stub.
 7763   address stubAddr = StubRoutines::updateBytesAdler32();
 7764   const char *stubName = "updateBytesAdler32";
 7765 
 7766   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
 7767                                  stubAddr, stubName, TypePtr::BOTTOM,
 7768                                  crc, src_start, length);
 7769 
 7770   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7771   set_result(result);
 7772   return true;
 7773 }
 7774 
 7775 //----------------------------inline_reference_get0----------------------------
 7776 // public T java.lang.ref.Reference.get();
 7777 bool LibraryCallKit::inline_reference_get0() {
 7778   const int referent_offset = java_lang_ref_Reference::referent_offset();
 7779 
 7780   // Get the argument:
 7781   Node* reference_obj = null_check_receiver();
 7782   if (stopped()) return true;
 7783 
 7784   DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF;
 7785   Node* result = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;",
 7786                                         decorators, /*is_static*/ false,
 7787                                         env()->Reference_klass());
 7788   if (result == nullptr) return false;
 7789 
 7790   // Add memory barrier to prevent commoning reads from this field
 7791   // across safepoint since GC can change its value.
 7792   insert_mem_bar(Op_MemBarCPUOrder);
 7793 
 7794   set_result(result);
 7795   return true;
 7796 }
 7797 
 7798 //----------------------------inline_reference_refersTo0----------------------------
 7799 // bool java.lang.ref.Reference.refersTo0();
 7800 // bool java.lang.ref.PhantomReference.refersTo0();
 7801 bool LibraryCallKit::inline_reference_refersTo0(bool is_phantom) {
 7802   // Get arguments:
 7803   Node* reference_obj = null_check_receiver();
 7804   Node* other_obj = argument(1);
 7805   if (stopped()) return true;
 7806 
 7807   DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE;
 7808   decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF);
 7809   Node* referent = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;",
 7810                                           decorators, /*is_static*/ false,
 7811                                           env()->Reference_klass());
 7812   if (referent == nullptr) return false;
 7813 
 7814   // Add memory barrier to prevent commoning reads from this field
 7815   // across safepoint since GC can change its value.
 7816   insert_mem_bar(Op_MemBarCPUOrder);
 7817 
 7818   Node* cmp = _gvn.transform(new CmpPNode(referent, other_obj));
 7819   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 7820   IfNode* if_node = create_and_map_if(control(), bol, PROB_FAIR, COUNT_UNKNOWN);
 7821 
 7822   RegionNode* region = new RegionNode(3);
 7823   PhiNode* phi = new PhiNode(region, TypeInt::BOOL);
 7824 
 7825   Node* if_true = _gvn.transform(new IfTrueNode(if_node));
 7826   region->init_req(1, if_true);
 7827   phi->init_req(1, intcon(1));
 7828 
 7829   Node* if_false = _gvn.transform(new IfFalseNode(if_node));
 7830   region->init_req(2, if_false);
 7831   phi->init_req(2, intcon(0));
 7832 
 7833   set_control(_gvn.transform(region));
 7834   record_for_igvn(region);
 7835   set_result(_gvn.transform(phi));
 7836   return true;
 7837 }
 7838 
 7839 //----------------------------inline_reference_clear0----------------------------
 7840 // void java.lang.ref.Reference.clear0();
 7841 // void java.lang.ref.PhantomReference.clear0();
 7842 bool LibraryCallKit::inline_reference_clear0(bool is_phantom) {
 7843   // This matches the implementation in JVM_ReferenceClear, see the comments there.
 7844 
 7845   // Get arguments
 7846   Node* reference_obj = null_check_receiver();
 7847   if (stopped()) return true;
 7848 
 7849   // Common access parameters
 7850   DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE;
 7851   decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF);
 7852   Node* referent_field_addr = basic_plus_adr(reference_obj, java_lang_ref_Reference::referent_offset());
 7853   const TypePtr* referent_field_addr_type = _gvn.type(referent_field_addr)->isa_ptr();
 7854   const Type* val_type = TypeOopPtr::make_from_klass(env()->Object_klass());
 7855 
 7856   Node* referent = access_load_at(reference_obj,
 7857                                   referent_field_addr,
 7858                                   referent_field_addr_type,
 7859                                   val_type,
 7860                                   T_OBJECT,
 7861                                   decorators);
 7862 
 7863   IdealKit ideal(this);
 7864 #define __ ideal.
 7865   __ if_then(referent, BoolTest::ne, null());
 7866     sync_kit(ideal);
 7867     access_store_at(reference_obj,
 7868                     referent_field_addr,
 7869                     referent_field_addr_type,
 7870                     null(),
 7871                     val_type,
 7872                     T_OBJECT,
 7873                     decorators);
 7874     __ sync_kit(this);
 7875   __ end_if();
 7876   final_sync(ideal);
 7877 #undef __
 7878 
 7879   return true;
 7880 }
 7881 
 7882 //-----------------------inline_reference_reachabilityFence-----------------
 7883 // bool java.lang.ref.Reference.reachabilityFence();
 7884 bool LibraryCallKit::inline_reference_reachabilityFence() {
 7885   Node* referent = argument(0);
 7886   insert_reachability_fence(referent);
 7887   return true;
 7888 }
 7889 
 7890 Node* LibraryCallKit::load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString,
 7891                                              DecoratorSet decorators, bool is_static,
 7892                                              ciInstanceKlass* fromKls) {
 7893   if (fromKls == nullptr) {
 7894     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
 7895     assert(tinst != nullptr, "obj is null");
 7896     assert(tinst->is_loaded(), "obj is not loaded");
 7897     fromKls = tinst->instance_klass();
 7898   }
 7899   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
 7900                                               ciSymbol::make(fieldTypeString),
 7901                                               is_static);
 7902 
 7903   assert(field != nullptr, "undefined field %s %s %s", fieldTypeString, fromKls->name()->as_utf8(), fieldName);
 7904   if (field == nullptr) return (Node *) nullptr;
 7905 
 7906   if (is_static) {
 7907     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
 7908     fromObj = makecon(tip);
 7909   }
 7910 
 7911   // Next code  copied from Parse::do_get_xxx():
 7912 
 7913   // Compute address and memory type.
 7914   int offset  = field->offset_in_bytes();
 7915   bool is_vol = field->is_volatile();
 7916   ciType* field_klass = field->type();
 7917   assert(field_klass->is_loaded(), "should be loaded");
 7918   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 7919   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
 7920   assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()),
 7921     "slice of address and input slice don't match");
 7922   BasicType bt = field->layout_type();
 7923 
 7924   // Build the resultant type of the load
 7925   const Type *type;
 7926   if (bt == T_OBJECT) {
 7927     type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 7928   } else {
 7929     type = Type::get_const_basic_type(bt);
 7930   }
 7931 
 7932   if (is_vol) {
 7933     decorators |= MO_SEQ_CST;
 7934   }
 7935 
 7936   return access_load_at(fromObj, adr, adr_type, type, bt, decorators);
 7937 }
 7938 
 7939 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString,
 7940                                                  bool is_exact /* true */, bool is_static /* false */,
 7941                                                  ciInstanceKlass * fromKls /* nullptr */) {
 7942   if (fromKls == nullptr) {
 7943     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
 7944     assert(tinst != nullptr, "obj is null");
 7945     assert(tinst->is_loaded(), "obj is not loaded");
 7946     assert(!is_exact || tinst->klass_is_exact(), "klass not exact");
 7947     fromKls = tinst->instance_klass();
 7948   }
 7949   else {
 7950     assert(is_static, "only for static field access");
 7951   }
 7952   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
 7953     ciSymbol::make(fieldTypeString),
 7954     is_static);
 7955 
 7956   assert(field != nullptr, "undefined field");
 7957   assert(!field->is_volatile(), "not defined for volatile fields");
 7958 
 7959   if (is_static) {
 7960     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
 7961     fromObj = makecon(tip);
 7962   }
 7963 
 7964   // Next code  copied from Parse::do_get_xxx():
 7965 
 7966   // Compute address and memory type.
 7967   int offset = field->offset_in_bytes();
 7968   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
 7969 
 7970   return adr;
 7971 }
 7972 
 7973 //------------------------------inline_aescrypt_Block-----------------------
 7974 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) {
 7975   address stubAddr = nullptr;
 7976   const char *stubName;
 7977   bool is_decrypt = false;
 7978   assert(UseAES, "need AES instruction support");
 7979 
 7980   switch(id) {
 7981   case vmIntrinsics::_aescrypt_encryptBlock:
 7982     stubAddr = StubRoutines::aescrypt_encryptBlock();
 7983     stubName = "aescrypt_encryptBlock";
 7984     break;
 7985   case vmIntrinsics::_aescrypt_decryptBlock:
 7986     stubAddr = StubRoutines::aescrypt_decryptBlock();
 7987     stubName = "aescrypt_decryptBlock";
 7988     is_decrypt = true;
 7989     break;
 7990   default:
 7991     break;
 7992   }
 7993   if (stubAddr == nullptr) return false;
 7994 
 7995   Node* aescrypt_object = argument(0);
 7996   Node* src             = argument(1);
 7997   Node* src_offset      = argument(2);
 7998   Node* dest            = argument(3);
 7999   Node* dest_offset     = argument(4);
 8000 
 8001   src = must_be_not_null(src, true);
 8002   dest = must_be_not_null(dest, true);
 8003 
 8004   // (1) src and dest are arrays.
 8005   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8006   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8007   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8008          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8009 
 8010   // for the quick and dirty code we will skip all the checks.
 8011   // we are just trying to get the call to be generated.
 8012   Node* src_start  = src;
 8013   Node* dest_start = dest;
 8014   if (src_offset != nullptr || dest_offset != nullptr) {
 8015     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8016     src_start  = array_element_address(src,  src_offset,  T_BYTE);
 8017     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8018   }
 8019 
 8020   // now need to get the start of its expanded key array
 8021   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8022   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8023   if (k_start == nullptr) return false;
 8024 
 8025   // Call the stub.
 8026   make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(),
 8027                     stubAddr, stubName, TypePtr::BOTTOM,
 8028                     src_start, dest_start, k_start);
 8029 
 8030   return true;
 8031 }
 8032 
 8033 //------------------------------inline_cipherBlockChaining_AESCrypt-----------------------
 8034 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) {
 8035   address stubAddr = nullptr;
 8036   const char *stubName = nullptr;
 8037   bool is_decrypt = false;
 8038   assert(UseAES, "need AES instruction support");
 8039 
 8040   switch(id) {
 8041   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 8042     stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt();
 8043     stubName = "cipherBlockChaining_encryptAESCrypt";
 8044     break;
 8045   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 8046     stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt();
 8047     stubName = "cipherBlockChaining_decryptAESCrypt";
 8048     is_decrypt = true;
 8049     break;
 8050   default:
 8051     break;
 8052   }
 8053   if (stubAddr == nullptr) return false;
 8054 
 8055   Node* cipherBlockChaining_object = argument(0);
 8056   Node* src                        = argument(1);
 8057   Node* src_offset                 = argument(2);
 8058   Node* len                        = argument(3);
 8059   Node* dest                       = argument(4);
 8060   Node* dest_offset                = argument(5);
 8061 
 8062   src = must_be_not_null(src, false);
 8063   dest = must_be_not_null(dest, false);
 8064 
 8065   // (1) src and dest are arrays.
 8066   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8067   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8068   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8069          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8070 
 8071   // checks are the responsibility of the caller
 8072   Node* src_start  = src;
 8073   Node* dest_start = dest;
 8074   if (src_offset != nullptr || dest_offset != nullptr) {
 8075     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8076     src_start  = array_element_address(src,  src_offset,  T_BYTE);
 8077     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8078   }
 8079 
 8080   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8081   // (because of the predicated logic executed earlier).
 8082   // so we cast it here safely.
 8083   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8084 
 8085   Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8086   if (embeddedCipherObj == nullptr) return false;
 8087 
 8088   // cast it to what we know it will be at runtime
 8089   const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
 8090   assert(tinst != nullptr, "CBC obj is null");
 8091   assert(tinst->is_loaded(), "CBC obj is not loaded");
 8092   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8093   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8094 
 8095   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8096   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8097   const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8098   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8099   aescrypt_object = _gvn.transform(aescrypt_object);
 8100 
 8101   // we need to get the start of the aescrypt_object's expanded key array
 8102   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8103   if (k_start == nullptr) return false;
 8104 
 8105   // similarly, get the start address of the r vector
 8106   Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B");
 8107   if (objRvec == nullptr) return false;
 8108   Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
 8109 
 8110   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8111   Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8112                                      OptoRuntime::cipherBlockChaining_aescrypt_Type(),
 8113                                      stubAddr, stubName, TypePtr::BOTTOM,
 8114                                      src_start, dest_start, k_start, r_start, len);
 8115 
 8116   // return cipher length (int)
 8117   Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms));
 8118   set_result(retvalue);
 8119   return true;
 8120 }
 8121 
 8122 //------------------------------inline_electronicCodeBook_AESCrypt-----------------------
 8123 bool LibraryCallKit::inline_electronicCodeBook_AESCrypt(vmIntrinsics::ID id) {
 8124   address stubAddr = nullptr;
 8125   const char *stubName = nullptr;
 8126   bool is_decrypt = false;
 8127   assert(UseAES, "need AES instruction support");
 8128 
 8129   switch (id) {
 8130   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
 8131     stubAddr = StubRoutines::electronicCodeBook_encryptAESCrypt();
 8132     stubName = "electronicCodeBook_encryptAESCrypt";
 8133     break;
 8134   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
 8135     stubAddr = StubRoutines::electronicCodeBook_decryptAESCrypt();
 8136     stubName = "electronicCodeBook_decryptAESCrypt";
 8137     is_decrypt = true;
 8138     break;
 8139   default:
 8140     break;
 8141   }
 8142 
 8143   if (stubAddr == nullptr) return false;
 8144 
 8145   Node* electronicCodeBook_object = argument(0);
 8146   Node* src                       = argument(1);
 8147   Node* src_offset                = argument(2);
 8148   Node* len                       = argument(3);
 8149   Node* dest                      = argument(4);
 8150   Node* dest_offset               = argument(5);
 8151 
 8152   // (1) src and dest are arrays.
 8153   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8154   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8155   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8156          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8157 
 8158   // checks are the responsibility of the caller
 8159   Node* src_start = src;
 8160   Node* dest_start = dest;
 8161   if (src_offset != nullptr || dest_offset != nullptr) {
 8162     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8163     src_start = array_element_address(src, src_offset, T_BYTE);
 8164     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8165   }
 8166 
 8167   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8168   // (because of the predicated logic executed earlier).
 8169   // so we cast it here safely.
 8170   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8171 
 8172   Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8173   if (embeddedCipherObj == nullptr) return false;
 8174 
 8175   // cast it to what we know it will be at runtime
 8176   const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr();
 8177   assert(tinst != nullptr, "ECB obj is null");
 8178   assert(tinst->is_loaded(), "ECB obj is not loaded");
 8179   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8180   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8181 
 8182   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8183   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8184   const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8185   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8186   aescrypt_object = _gvn.transform(aescrypt_object);
 8187 
 8188   // we need to get the start of the aescrypt_object's expanded key array
 8189   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8190   if (k_start == nullptr) return false;
 8191 
 8192   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8193   Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP,
 8194                                      OptoRuntime::electronicCodeBook_aescrypt_Type(),
 8195                                      stubAddr, stubName, TypePtr::BOTTOM,
 8196                                      src_start, dest_start, k_start, len);
 8197 
 8198   // return cipher length (int)
 8199   Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms));
 8200   set_result(retvalue);
 8201   return true;
 8202 }
 8203 
 8204 //------------------------------inline_counterMode_AESCrypt-----------------------
 8205 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) {
 8206   assert(UseAES, "need AES instruction support");
 8207   if (!UseAESCTRIntrinsics) return false;
 8208 
 8209   address stubAddr = nullptr;
 8210   const char *stubName = nullptr;
 8211   if (id == vmIntrinsics::_counterMode_AESCrypt) {
 8212     stubAddr = StubRoutines::counterMode_AESCrypt();
 8213     stubName = "counterMode_AESCrypt";
 8214   }
 8215   if (stubAddr == nullptr) return false;
 8216 
 8217   Node* counterMode_object = argument(0);
 8218   Node* src = argument(1);
 8219   Node* src_offset = argument(2);
 8220   Node* len = argument(3);
 8221   Node* dest = argument(4);
 8222   Node* dest_offset = argument(5);
 8223 
 8224   // (1) src and dest are arrays.
 8225   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8226   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8227   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8228          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8229 
 8230   // checks are the responsibility of the caller
 8231   Node* src_start = src;
 8232   Node* dest_start = dest;
 8233   if (src_offset != nullptr || dest_offset != nullptr) {
 8234     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8235     src_start = array_element_address(src, src_offset, T_BYTE);
 8236     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8237   }
 8238 
 8239   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8240   // (because of the predicated logic executed earlier).
 8241   // so we cast it here safely.
 8242   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8243   Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8244   if (embeddedCipherObj == nullptr) return false;
 8245   // cast it to what we know it will be at runtime
 8246   const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
 8247   assert(tinst != nullptr, "CTR obj is null");
 8248   assert(tinst->is_loaded(), "CTR obj is not loaded");
 8249   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8250   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8251   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8252   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8253   const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8254   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8255   aescrypt_object = _gvn.transform(aescrypt_object);
 8256   // we need to get the start of the aescrypt_object's expanded key array
 8257   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
 8258   if (k_start == nullptr) return false;
 8259   // similarly, get the start address of the r vector
 8260   Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B");
 8261   if (obj_counter == nullptr) return false;
 8262   Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
 8263 
 8264   Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B");
 8265   if (saved_encCounter == nullptr) return false;
 8266   Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
 8267   Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
 8268 
 8269   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8270   Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8271                                      OptoRuntime::counterMode_aescrypt_Type(),
 8272                                      stubAddr, stubName, TypePtr::BOTTOM,
 8273                                      src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
 8274 
 8275   // return cipher length (int)
 8276   Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms));
 8277   set_result(retvalue);
 8278   return true;
 8279 }
 8280 
 8281 //------------------------------get_key_start_from_aescrypt_object-----------------------
 8282 Node* LibraryCallKit::get_key_start_from_aescrypt_object(Node* aescrypt_object, bool is_decrypt) {
 8283   // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys.
 8284   // Intel's extension is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns.
 8285   // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption.
 8286   // The following platform specific stubs of encryption and decryption use the same round keys.
 8287 #if defined(PPC64) || defined(S390) || defined(RISCV64)
 8288   bool use_decryption_key = false;
 8289 #else
 8290   bool use_decryption_key = is_decrypt;
 8291 #endif
 8292   Node* objAESCryptKey = load_field_from_object(aescrypt_object, use_decryption_key ? "sessionKd" : "sessionKe", "[I");
 8293   assert(objAESCryptKey != nullptr, "wrong version of com.sun.crypto.provider.AES_Crypt");
 8294   if (objAESCryptKey == nullptr) return (Node *) nullptr;
 8295 
 8296   // now have the array, need to get the start address of the selected key array
 8297   Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT);
 8298   return k_start;
 8299 }
 8300 
 8301 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate----------------------------
 8302 // Return node representing slow path of predicate check.
 8303 // the pseudo code we want to emulate with this predicate is:
 8304 // for encryption:
 8305 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8306 // for decryption:
 8307 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8308 //    note cipher==plain is more conservative than the original java code but that's OK
 8309 //
 8310 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) {
 8311   // The receiver was checked for null already.
 8312   Node* objCBC = argument(0);
 8313 
 8314   Node* src = argument(1);
 8315   Node* dest = argument(4);
 8316 
 8317   // Load embeddedCipher field of CipherBlockChaining object.
 8318   Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8319 
 8320   // get AESCrypt klass for instanceOf check
 8321   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8322   // will have same classloader as CipherBlockChaining object
 8323   const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr();
 8324   assert(tinst != nullptr, "CBCobj is null");
 8325   assert(tinst->is_loaded(), "CBCobj is not loaded");
 8326 
 8327   // we want to do an instanceof comparison against the AESCrypt class
 8328   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8329   if (!klass_AESCrypt->is_loaded()) {
 8330     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8331     Node* ctrl = control();
 8332     set_control(top()); // no regular fast path
 8333     return ctrl;
 8334   }
 8335 
 8336   src = must_be_not_null(src, true);
 8337   dest = must_be_not_null(dest, true);
 8338 
 8339   // Resolve oops to stable for CmpP below.
 8340   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8341 
 8342   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8343   Node* cmp_instof  = _gvn.transform(new CmpINode(instof, intcon(1)));
 8344   Node* bool_instof  = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8345 
 8346   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8347 
 8348   // for encryption, we are done
 8349   if (!decrypting)
 8350     return instof_false;  // even if it is null
 8351 
 8352   // for decryption, we need to add a further check to avoid
 8353   // taking the intrinsic path when cipher and plain are the same
 8354   // see the original java code for why.
 8355   RegionNode* region = new RegionNode(3);
 8356   region->init_req(1, instof_false);
 8357 
 8358   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
 8359   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
 8360   Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN);
 8361   region->init_req(2, src_dest_conjoint);
 8362 
 8363   record_for_igvn(region);
 8364   return _gvn.transform(region);
 8365 }
 8366 
 8367 //----------------------------inline_electronicCodeBook_AESCrypt_predicate----------------------------
 8368 // Return node representing slow path of predicate check.
 8369 // the pseudo code we want to emulate with this predicate is:
 8370 // for encryption:
 8371 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8372 // for decryption:
 8373 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8374 //    note cipher==plain is more conservative than the original java code but that's OK
 8375 //
 8376 Node* LibraryCallKit::inline_electronicCodeBook_AESCrypt_predicate(bool decrypting) {
 8377   // The receiver was checked for null already.
 8378   Node* objECB = argument(0);
 8379 
 8380   // Load embeddedCipher field of ElectronicCodeBook object.
 8381   Node* embeddedCipherObj = load_field_from_object(objECB, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8382 
 8383   // get AESCrypt klass for instanceOf check
 8384   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8385   // will have same classloader as ElectronicCodeBook object
 8386   const TypeInstPtr* tinst = _gvn.type(objECB)->isa_instptr();
 8387   assert(tinst != nullptr, "ECBobj is null");
 8388   assert(tinst->is_loaded(), "ECBobj is not loaded");
 8389 
 8390   // we want to do an instanceof comparison against the AESCrypt class
 8391   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8392   if (!klass_AESCrypt->is_loaded()) {
 8393     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8394     Node* ctrl = control();
 8395     set_control(top()); // no regular fast path
 8396     return ctrl;
 8397   }
 8398   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8399 
 8400   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8401   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 8402   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8403 
 8404   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8405 
 8406   // for encryption, we are done
 8407   if (!decrypting)
 8408     return instof_false;  // even if it is null
 8409 
 8410   // for decryption, we need to add a further check to avoid
 8411   // taking the intrinsic path when cipher and plain are the same
 8412   // see the original java code for why.
 8413   RegionNode* region = new RegionNode(3);
 8414   region->init_req(1, instof_false);
 8415   Node* src = argument(1);
 8416   Node* dest = argument(4);
 8417   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
 8418   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
 8419   Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN);
 8420   region->init_req(2, src_dest_conjoint);
 8421 
 8422   record_for_igvn(region);
 8423   return _gvn.transform(region);
 8424 }
 8425 
 8426 //----------------------------inline_counterMode_AESCrypt_predicate----------------------------
 8427 // Return node representing slow path of predicate check.
 8428 // the pseudo code we want to emulate with this predicate is:
 8429 // for encryption:
 8430 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8431 // for decryption:
 8432 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8433 //    note cipher==plain is more conservative than the original java code but that's OK
 8434 //
 8435 
 8436 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() {
 8437   // The receiver was checked for null already.
 8438   Node* objCTR = argument(0);
 8439 
 8440   // Load embeddedCipher field of CipherBlockChaining object.
 8441   Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8442 
 8443   // get AESCrypt klass for instanceOf check
 8444   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8445   // will have same classloader as CipherBlockChaining object
 8446   const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr();
 8447   assert(tinst != nullptr, "CTRobj is null");
 8448   assert(tinst->is_loaded(), "CTRobj is not loaded");
 8449 
 8450   // we want to do an instanceof comparison against the AESCrypt class
 8451   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8452   if (!klass_AESCrypt->is_loaded()) {
 8453     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8454     Node* ctrl = control();
 8455     set_control(top()); // no regular fast path
 8456     return ctrl;
 8457   }
 8458 
 8459   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8460   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8461   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 8462   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8463   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8464 
 8465   return instof_false; // even if it is null
 8466 }
 8467 
 8468 //------------------------------inline_ghash_processBlocks
 8469 bool LibraryCallKit::inline_ghash_processBlocks() {
 8470   address stubAddr;
 8471   const char *stubName;
 8472   assert(UseGHASHIntrinsics, "need GHASH intrinsics support");
 8473 
 8474   stubAddr = StubRoutines::ghash_processBlocks();
 8475   stubName = "ghash_processBlocks";
 8476 
 8477   Node* data           = argument(0);
 8478   Node* offset         = argument(1);
 8479   Node* len            = argument(2);
 8480   Node* state          = argument(3);
 8481   Node* subkeyH        = argument(4);
 8482 
 8483   state = must_be_not_null(state, true);
 8484   subkeyH = must_be_not_null(subkeyH, true);
 8485   data = must_be_not_null(data, true);
 8486 
 8487   Node* state_start  = array_element_address(state, intcon(0), T_LONG);
 8488   assert(state_start, "state is null");
 8489   Node* subkeyH_start  = array_element_address(subkeyH, intcon(0), T_LONG);
 8490   assert(subkeyH_start, "subkeyH is null");
 8491   Node* data_start  = array_element_address(data, offset, T_BYTE);
 8492   assert(data_start, "data is null");
 8493 
 8494   Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP,
 8495                                   OptoRuntime::ghash_processBlocks_Type(),
 8496                                   stubAddr, stubName, TypePtr::BOTTOM,
 8497                                   state_start, subkeyH_start, data_start, len);
 8498   return true;
 8499 }
 8500 
 8501 //------------------------------inline_chacha20Block
 8502 bool LibraryCallKit::inline_chacha20Block() {
 8503   address stubAddr;
 8504   const char *stubName;
 8505   assert(UseChaCha20Intrinsics, "need ChaCha20 intrinsics support");
 8506 
 8507   stubAddr = StubRoutines::chacha20Block();
 8508   stubName = "chacha20Block";
 8509 
 8510   Node* state          = argument(0);
 8511   Node* result         = argument(1);
 8512 
 8513   state = must_be_not_null(state, true);
 8514   result = must_be_not_null(result, true);
 8515 
 8516   Node* state_start  = array_element_address(state, intcon(0), T_INT);
 8517   assert(state_start, "state is null");
 8518   Node* result_start  = array_element_address(result, intcon(0), T_BYTE);
 8519   assert(result_start, "result is null");
 8520 
 8521   Node* cc20Blk = make_runtime_call(RC_LEAF|RC_NO_FP,
 8522                                   OptoRuntime::chacha20Block_Type(),
 8523                                   stubAddr, stubName, TypePtr::BOTTOM,
 8524                                   state_start, result_start);
 8525   // return key stream length (int)
 8526   Node* retvalue = _gvn.transform(new ProjNode(cc20Blk, TypeFunc::Parms));
 8527   set_result(retvalue);
 8528   return true;
 8529 }
 8530 
 8531 //------------------------------inline_kyberNtt
 8532 bool LibraryCallKit::inline_kyberNtt() {
 8533   address stubAddr;
 8534   const char *stubName;
 8535   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8536   assert(callee()->signature()->size() == 2, "kyberNtt has 2 parameters");
 8537 
 8538   stubAddr = StubRoutines::kyberNtt();
 8539   stubName = "kyberNtt";
 8540   if (!stubAddr) return false;
 8541 
 8542   Node* coeffs          = argument(0);
 8543   Node* ntt_zetas        = argument(1);
 8544 
 8545   coeffs = must_be_not_null(coeffs, true);
 8546   ntt_zetas = must_be_not_null(ntt_zetas, true);
 8547 
 8548   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8549   assert(coeffs_start, "coeffs is null");
 8550   Node* ntt_zetas_start  = array_element_address(ntt_zetas, intcon(0), T_SHORT);
 8551   assert(ntt_zetas_start, "ntt_zetas is null");
 8552   Node* kyberNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8553                                   OptoRuntime::kyberNtt_Type(),
 8554                                   stubAddr, stubName, TypePtr::BOTTOM,
 8555                                   coeffs_start, ntt_zetas_start);
 8556   // return an int
 8557   Node* retvalue = _gvn.transform(new ProjNode(kyberNtt, TypeFunc::Parms));
 8558   set_result(retvalue);
 8559   return true;
 8560 }
 8561 
 8562 //------------------------------inline_kyberInverseNtt
 8563 bool LibraryCallKit::inline_kyberInverseNtt() {
 8564   address stubAddr;
 8565   const char *stubName;
 8566   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8567   assert(callee()->signature()->size() == 2, "kyberInverseNtt has 2 parameters");
 8568 
 8569   stubAddr = StubRoutines::kyberInverseNtt();
 8570   stubName = "kyberInverseNtt";
 8571   if (!stubAddr) return false;
 8572 
 8573   Node* coeffs          = argument(0);
 8574   Node* zetas           = argument(1);
 8575 
 8576   coeffs = must_be_not_null(coeffs, true);
 8577   zetas = must_be_not_null(zetas, true);
 8578 
 8579   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8580   assert(coeffs_start, "coeffs is null");
 8581   Node* zetas_start  = array_element_address(zetas, intcon(0), T_SHORT);
 8582   assert(zetas_start, "inverseNtt_zetas is null");
 8583   Node* kyberInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8584                                   OptoRuntime::kyberInverseNtt_Type(),
 8585                                   stubAddr, stubName, TypePtr::BOTTOM,
 8586                                   coeffs_start, zetas_start);
 8587 
 8588   // return an int
 8589   Node* retvalue = _gvn.transform(new ProjNode(kyberInverseNtt, TypeFunc::Parms));
 8590   set_result(retvalue);
 8591   return true;
 8592 }
 8593 
 8594 //------------------------------inline_kyberNttMult
 8595 bool LibraryCallKit::inline_kyberNttMult() {
 8596   address stubAddr;
 8597   const char *stubName;
 8598   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8599   assert(callee()->signature()->size() == 4, "kyberNttMult has 4 parameters");
 8600 
 8601   stubAddr = StubRoutines::kyberNttMult();
 8602   stubName = "kyberNttMult";
 8603   if (!stubAddr) return false;
 8604 
 8605   Node* result          = argument(0);
 8606   Node* ntta            = argument(1);
 8607   Node* nttb            = argument(2);
 8608   Node* zetas           = argument(3);
 8609 
 8610   result = must_be_not_null(result, true);
 8611   ntta = must_be_not_null(ntta, true);
 8612   nttb = must_be_not_null(nttb, true);
 8613   zetas = must_be_not_null(zetas, true);
 8614 
 8615   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8616   assert(result_start, "result is null");
 8617   Node* ntta_start  = array_element_address(ntta, intcon(0), T_SHORT);
 8618   assert(ntta_start, "ntta is null");
 8619   Node* nttb_start  = array_element_address(nttb, intcon(0), T_SHORT);
 8620   assert(nttb_start, "nttb is null");
 8621   Node* zetas_start  = array_element_address(zetas, intcon(0), T_SHORT);
 8622   assert(zetas_start, "nttMult_zetas is null");
 8623   Node* kyberNttMult = make_runtime_call(RC_LEAF|RC_NO_FP,
 8624                                   OptoRuntime::kyberNttMult_Type(),
 8625                                   stubAddr, stubName, TypePtr::BOTTOM,
 8626                                   result_start, ntta_start, nttb_start,
 8627                                   zetas_start);
 8628 
 8629   // return an int
 8630   Node* retvalue = _gvn.transform(new ProjNode(kyberNttMult, TypeFunc::Parms));
 8631   set_result(retvalue);
 8632 
 8633   return true;
 8634 }
 8635 
 8636 //------------------------------inline_kyberAddPoly_2
 8637 bool LibraryCallKit::inline_kyberAddPoly_2() {
 8638   address stubAddr;
 8639   const char *stubName;
 8640   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8641   assert(callee()->signature()->size() == 3, "kyberAddPoly_2 has 3 parameters");
 8642 
 8643   stubAddr = StubRoutines::kyberAddPoly_2();
 8644   stubName = "kyberAddPoly_2";
 8645   if (!stubAddr) return false;
 8646 
 8647   Node* result          = argument(0);
 8648   Node* a               = argument(1);
 8649   Node* b               = argument(2);
 8650 
 8651   result = must_be_not_null(result, true);
 8652   a = must_be_not_null(a, true);
 8653   b = must_be_not_null(b, true);
 8654 
 8655   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8656   assert(result_start, "result is null");
 8657   Node* a_start  = array_element_address(a, intcon(0), T_SHORT);
 8658   assert(a_start, "a is null");
 8659   Node* b_start  = array_element_address(b, intcon(0), T_SHORT);
 8660   assert(b_start, "b is null");
 8661   Node* kyberAddPoly_2 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8662                                   OptoRuntime::kyberAddPoly_2_Type(),
 8663                                   stubAddr, stubName, TypePtr::BOTTOM,
 8664                                   result_start, a_start, b_start);
 8665   // return an int
 8666   Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_2, TypeFunc::Parms));
 8667   set_result(retvalue);
 8668   return true;
 8669 }
 8670 
 8671 //------------------------------inline_kyberAddPoly_3
 8672 bool LibraryCallKit::inline_kyberAddPoly_3() {
 8673   address stubAddr;
 8674   const char *stubName;
 8675   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8676   assert(callee()->signature()->size() == 4, "kyberAddPoly_3 has 4 parameters");
 8677 
 8678   stubAddr = StubRoutines::kyberAddPoly_3();
 8679   stubName = "kyberAddPoly_3";
 8680   if (!stubAddr) return false;
 8681 
 8682   Node* result          = argument(0);
 8683   Node* a               = argument(1);
 8684   Node* b               = argument(2);
 8685   Node* c               = argument(3);
 8686 
 8687   result = must_be_not_null(result, true);
 8688   a = must_be_not_null(a, true);
 8689   b = must_be_not_null(b, true);
 8690   c = must_be_not_null(c, true);
 8691 
 8692   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8693   assert(result_start, "result is null");
 8694   Node* a_start  = array_element_address(a, intcon(0), T_SHORT);
 8695   assert(a_start, "a is null");
 8696   Node* b_start  = array_element_address(b, intcon(0), T_SHORT);
 8697   assert(b_start, "b is null");
 8698   Node* c_start  = array_element_address(c, intcon(0), T_SHORT);
 8699   assert(c_start, "c is null");
 8700   Node* kyberAddPoly_3 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8701                                   OptoRuntime::kyberAddPoly_3_Type(),
 8702                                   stubAddr, stubName, TypePtr::BOTTOM,
 8703                                   result_start, a_start, b_start, c_start);
 8704   // return an int
 8705   Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_3, TypeFunc::Parms));
 8706   set_result(retvalue);
 8707   return true;
 8708 }
 8709 
 8710 //------------------------------inline_kyber12To16
 8711 bool LibraryCallKit::inline_kyber12To16() {
 8712   address stubAddr;
 8713   const char *stubName;
 8714   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8715   assert(callee()->signature()->size() == 4, "kyber12To16 has 4 parameters");
 8716 
 8717   stubAddr = StubRoutines::kyber12To16();
 8718   stubName = "kyber12To16";
 8719   if (!stubAddr) return false;
 8720 
 8721   Node* condensed       = argument(0);
 8722   Node* condensedOffs   = argument(1);
 8723   Node* parsed          = argument(2);
 8724   Node* parsedLength    = argument(3);
 8725 
 8726   condensed = must_be_not_null(condensed, true);
 8727   parsed = must_be_not_null(parsed, true);
 8728 
 8729   Node* condensed_start  = array_element_address(condensed, intcon(0), T_BYTE);
 8730   assert(condensed_start, "condensed is null");
 8731   Node* parsed_start  = array_element_address(parsed, intcon(0), T_SHORT);
 8732   assert(parsed_start, "parsed is null");
 8733   Node* kyber12To16 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8734                                   OptoRuntime::kyber12To16_Type(),
 8735                                   stubAddr, stubName, TypePtr::BOTTOM,
 8736                                   condensed_start, condensedOffs, parsed_start, parsedLength);
 8737   // return an int
 8738   Node* retvalue = _gvn.transform(new ProjNode(kyber12To16, TypeFunc::Parms));
 8739   set_result(retvalue);
 8740   return true;
 8741 
 8742 }
 8743 
 8744 //------------------------------inline_kyberBarrettReduce
 8745 bool LibraryCallKit::inline_kyberBarrettReduce() {
 8746   address stubAddr;
 8747   const char *stubName;
 8748   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8749   assert(callee()->signature()->size() == 1, "kyberBarrettReduce has 1 parameters");
 8750 
 8751   stubAddr = StubRoutines::kyberBarrettReduce();
 8752   stubName = "kyberBarrettReduce";
 8753   if (!stubAddr) return false;
 8754 
 8755   Node* coeffs          = argument(0);
 8756 
 8757   coeffs = must_be_not_null(coeffs, true);
 8758 
 8759   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8760   assert(coeffs_start, "coeffs is null");
 8761   Node* kyberBarrettReduce = make_runtime_call(RC_LEAF|RC_NO_FP,
 8762                                   OptoRuntime::kyberBarrettReduce_Type(),
 8763                                   stubAddr, stubName, TypePtr::BOTTOM,
 8764                                   coeffs_start);
 8765   // return an int
 8766   Node* retvalue = _gvn.transform(new ProjNode(kyberBarrettReduce, TypeFunc::Parms));
 8767   set_result(retvalue);
 8768   return true;
 8769 }
 8770 
 8771 //------------------------------inline_dilithiumAlmostNtt
 8772 bool LibraryCallKit::inline_dilithiumAlmostNtt() {
 8773   address stubAddr;
 8774   const char *stubName;
 8775   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8776   assert(callee()->signature()->size() == 2, "dilithiumAlmostNtt has 2 parameters");
 8777 
 8778   stubAddr = StubRoutines::dilithiumAlmostNtt();
 8779   stubName = "dilithiumAlmostNtt";
 8780   if (!stubAddr) return false;
 8781 
 8782   Node* coeffs          = argument(0);
 8783   Node* ntt_zetas        = argument(1);
 8784 
 8785   coeffs = must_be_not_null(coeffs, true);
 8786   ntt_zetas = must_be_not_null(ntt_zetas, true);
 8787 
 8788   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8789   assert(coeffs_start, "coeffs is null");
 8790   Node* ntt_zetas_start  = array_element_address(ntt_zetas, intcon(0), T_INT);
 8791   assert(ntt_zetas_start, "ntt_zetas is null");
 8792   Node* dilithiumAlmostNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8793                                   OptoRuntime::dilithiumAlmostNtt_Type(),
 8794                                   stubAddr, stubName, TypePtr::BOTTOM,
 8795                                   coeffs_start, ntt_zetas_start);
 8796   // return an int
 8797   Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostNtt, TypeFunc::Parms));
 8798   set_result(retvalue);
 8799   return true;
 8800 }
 8801 
 8802 //------------------------------inline_dilithiumAlmostInverseNtt
 8803 bool LibraryCallKit::inline_dilithiumAlmostInverseNtt() {
 8804   address stubAddr;
 8805   const char *stubName;
 8806   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8807   assert(callee()->signature()->size() == 2, "dilithiumAlmostInverseNtt has 2 parameters");
 8808 
 8809   stubAddr = StubRoutines::dilithiumAlmostInverseNtt();
 8810   stubName = "dilithiumAlmostInverseNtt";
 8811   if (!stubAddr) return false;
 8812 
 8813   Node* coeffs          = argument(0);
 8814   Node* zetas           = argument(1);
 8815 
 8816   coeffs = must_be_not_null(coeffs, true);
 8817   zetas = must_be_not_null(zetas, true);
 8818 
 8819   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8820   assert(coeffs_start, "coeffs is null");
 8821   Node* zetas_start  = array_element_address(zetas, intcon(0), T_INT);
 8822   assert(zetas_start, "inverseNtt_zetas is null");
 8823   Node* dilithiumAlmostInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8824                                   OptoRuntime::dilithiumAlmostInverseNtt_Type(),
 8825                                   stubAddr, stubName, TypePtr::BOTTOM,
 8826                                   coeffs_start, zetas_start);
 8827   // return an int
 8828   Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostInverseNtt, TypeFunc::Parms));
 8829   set_result(retvalue);
 8830   return true;
 8831 }
 8832 
 8833 //------------------------------inline_dilithiumNttMult
 8834 bool LibraryCallKit::inline_dilithiumNttMult() {
 8835   address stubAddr;
 8836   const char *stubName;
 8837   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8838   assert(callee()->signature()->size() == 3, "dilithiumNttMult has 3 parameters");
 8839 
 8840   stubAddr = StubRoutines::dilithiumNttMult();
 8841   stubName = "dilithiumNttMult";
 8842   if (!stubAddr) return false;
 8843 
 8844   Node* result          = argument(0);
 8845   Node* ntta            = argument(1);
 8846   Node* nttb            = argument(2);
 8847   Node* zetas           = argument(3);
 8848 
 8849   result = must_be_not_null(result, true);
 8850   ntta = must_be_not_null(ntta, true);
 8851   nttb = must_be_not_null(nttb, true);
 8852   zetas = must_be_not_null(zetas, true);
 8853 
 8854   Node* result_start  = array_element_address(result, intcon(0), T_INT);
 8855   assert(result_start, "result is null");
 8856   Node* ntta_start  = array_element_address(ntta, intcon(0), T_INT);
 8857   assert(ntta_start, "ntta is null");
 8858   Node* nttb_start  = array_element_address(nttb, intcon(0), T_INT);
 8859   assert(nttb_start, "nttb is null");
 8860   Node* dilithiumNttMult = make_runtime_call(RC_LEAF|RC_NO_FP,
 8861                                   OptoRuntime::dilithiumNttMult_Type(),
 8862                                   stubAddr, stubName, TypePtr::BOTTOM,
 8863                                   result_start, ntta_start, nttb_start);
 8864 
 8865   // return an int
 8866   Node* retvalue = _gvn.transform(new ProjNode(dilithiumNttMult, TypeFunc::Parms));
 8867   set_result(retvalue);
 8868 
 8869   return true;
 8870 }
 8871 
 8872 //------------------------------inline_dilithiumMontMulByConstant
 8873 bool LibraryCallKit::inline_dilithiumMontMulByConstant() {
 8874   address stubAddr;
 8875   const char *stubName;
 8876   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8877   assert(callee()->signature()->size() == 2, "dilithiumMontMulByConstant has 2 parameters");
 8878 
 8879   stubAddr = StubRoutines::dilithiumMontMulByConstant();
 8880   stubName = "dilithiumMontMulByConstant";
 8881   if (!stubAddr) return false;
 8882 
 8883   Node* coeffs          = argument(0);
 8884   Node* constant        = argument(1);
 8885 
 8886   coeffs = must_be_not_null(coeffs, true);
 8887 
 8888   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8889   assert(coeffs_start, "coeffs is null");
 8890   Node* dilithiumMontMulByConstant = make_runtime_call(RC_LEAF|RC_NO_FP,
 8891                                   OptoRuntime::dilithiumMontMulByConstant_Type(),
 8892                                   stubAddr, stubName, TypePtr::BOTTOM,
 8893                                   coeffs_start, constant);
 8894 
 8895   // return an int
 8896   Node* retvalue = _gvn.transform(new ProjNode(dilithiumMontMulByConstant, TypeFunc::Parms));
 8897   set_result(retvalue);
 8898   return true;
 8899 }
 8900 
 8901 
 8902 //------------------------------inline_dilithiumDecomposePoly
 8903 bool LibraryCallKit::inline_dilithiumDecomposePoly() {
 8904   address stubAddr;
 8905   const char *stubName;
 8906   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8907   assert(callee()->signature()->size() == 5, "dilithiumDecomposePoly has 5 parameters");
 8908 
 8909   stubAddr = StubRoutines::dilithiumDecomposePoly();
 8910   stubName = "dilithiumDecomposePoly";
 8911   if (!stubAddr) return false;
 8912 
 8913   Node* input          = argument(0);
 8914   Node* lowPart        = argument(1);
 8915   Node* highPart       = argument(2);
 8916   Node* twoGamma2      = argument(3);
 8917   Node* multiplier     = argument(4);
 8918 
 8919   input = must_be_not_null(input, true);
 8920   lowPart = must_be_not_null(lowPart, true);
 8921   highPart = must_be_not_null(highPart, true);
 8922 
 8923   Node* input_start  = array_element_address(input, intcon(0), T_INT);
 8924   assert(input_start, "input is null");
 8925   Node* lowPart_start  = array_element_address(lowPart, intcon(0), T_INT);
 8926   assert(lowPart_start, "lowPart is null");
 8927   Node* highPart_start  = array_element_address(highPart, intcon(0), T_INT);
 8928   assert(highPart_start, "highPart is null");
 8929 
 8930   Node* dilithiumDecomposePoly = make_runtime_call(RC_LEAF|RC_NO_FP,
 8931                                   OptoRuntime::dilithiumDecomposePoly_Type(),
 8932                                   stubAddr, stubName, TypePtr::BOTTOM,
 8933                                   input_start, lowPart_start, highPart_start,
 8934                                   twoGamma2, multiplier);
 8935 
 8936   // return an int
 8937   Node* retvalue = _gvn.transform(new ProjNode(dilithiumDecomposePoly, TypeFunc::Parms));
 8938   set_result(retvalue);
 8939   return true;
 8940 }
 8941 
 8942 bool LibraryCallKit::inline_base64_encodeBlock() {
 8943   address stubAddr;
 8944   const char *stubName;
 8945   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
 8946   assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters");
 8947   stubAddr = StubRoutines::base64_encodeBlock();
 8948   stubName = "encodeBlock";
 8949 
 8950   if (!stubAddr) return false;
 8951   Node* base64obj = argument(0);
 8952   Node* src = argument(1);
 8953   Node* offset = argument(2);
 8954   Node* len = argument(3);
 8955   Node* dest = argument(4);
 8956   Node* dp = argument(5);
 8957   Node* isURL = argument(6);
 8958 
 8959   src = must_be_not_null(src, true);
 8960   dest = must_be_not_null(dest, true);
 8961 
 8962   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 8963   assert(src_start, "source array is null");
 8964   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
 8965   assert(dest_start, "destination array is null");
 8966 
 8967   Node* base64 = make_runtime_call(RC_LEAF,
 8968                                    OptoRuntime::base64_encodeBlock_Type(),
 8969                                    stubAddr, stubName, TypePtr::BOTTOM,
 8970                                    src_start, offset, len, dest_start, dp, isURL);
 8971   return true;
 8972 }
 8973 
 8974 bool LibraryCallKit::inline_base64_decodeBlock() {
 8975   address stubAddr;
 8976   const char *stubName;
 8977   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
 8978   assert(callee()->signature()->size() == 7, "base64_decodeBlock has 7 parameters");
 8979   stubAddr = StubRoutines::base64_decodeBlock();
 8980   stubName = "decodeBlock";
 8981 
 8982   if (!stubAddr) return false;
 8983   Node* base64obj = argument(0);
 8984   Node* src = argument(1);
 8985   Node* src_offset = argument(2);
 8986   Node* len = argument(3);
 8987   Node* dest = argument(4);
 8988   Node* dest_offset = argument(5);
 8989   Node* isURL = argument(6);
 8990   Node* isMIME = argument(7);
 8991 
 8992   src = must_be_not_null(src, true);
 8993   dest = must_be_not_null(dest, true);
 8994 
 8995   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 8996   assert(src_start, "source array is null");
 8997   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
 8998   assert(dest_start, "destination array is null");
 8999 
 9000   Node* call = make_runtime_call(RC_LEAF,
 9001                                  OptoRuntime::base64_decodeBlock_Type(),
 9002                                  stubAddr, stubName, TypePtr::BOTTOM,
 9003                                  src_start, src_offset, len, dest_start, dest_offset, isURL, isMIME);
 9004   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 9005   set_result(result);
 9006   return true;
 9007 }
 9008 
 9009 bool LibraryCallKit::inline_poly1305_processBlocks() {
 9010   address stubAddr;
 9011   const char *stubName;
 9012   assert(UsePoly1305Intrinsics, "need Poly intrinsics support");
 9013   assert(callee()->signature()->size() == 5, "poly1305_processBlocks has %d parameters", callee()->signature()->size());
 9014   stubAddr = StubRoutines::poly1305_processBlocks();
 9015   stubName = "poly1305_processBlocks";
 9016 
 9017   if (!stubAddr) return false;
 9018   null_check_receiver();  // null-check receiver
 9019   if (stopped())  return true;
 9020 
 9021   Node* input = argument(1);
 9022   Node* input_offset = argument(2);
 9023   Node* len = argument(3);
 9024   Node* alimbs = argument(4);
 9025   Node* rlimbs = argument(5);
 9026 
 9027   input = must_be_not_null(input, true);
 9028   alimbs = must_be_not_null(alimbs, true);
 9029   rlimbs = must_be_not_null(rlimbs, true);
 9030 
 9031   Node* input_start = array_element_address(input, input_offset, T_BYTE);
 9032   assert(input_start, "input array is null");
 9033   Node* acc_start = array_element_address(alimbs, intcon(0), T_LONG);
 9034   assert(acc_start, "acc array is null");
 9035   Node* r_start = array_element_address(rlimbs, intcon(0), T_LONG);
 9036   assert(r_start, "r array is null");
 9037 
 9038   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9039                                  OptoRuntime::poly1305_processBlocks_Type(),
 9040                                  stubAddr, stubName, TypePtr::BOTTOM,
 9041                                  input_start, len, acc_start, r_start);
 9042   return true;
 9043 }
 9044 
 9045 bool LibraryCallKit::inline_intpoly_montgomeryMult_P256() {
 9046   address stubAddr;
 9047   const char *stubName;
 9048   assert(UseIntPolyIntrinsics, "need intpoly intrinsics support");
 9049   assert(callee()->signature()->size() == 3, "intpoly_montgomeryMult_P256 has %d parameters", callee()->signature()->size());
 9050   stubAddr = StubRoutines::intpoly_montgomeryMult_P256();
 9051   stubName = "intpoly_montgomeryMult_P256";
 9052 
 9053   if (!stubAddr) return false;
 9054   null_check_receiver();  // null-check receiver
 9055   if (stopped())  return true;
 9056 
 9057   Node* a = argument(1);
 9058   Node* b = argument(2);
 9059   Node* r = argument(3);
 9060 
 9061   a = must_be_not_null(a, true);
 9062   b = must_be_not_null(b, true);
 9063   r = must_be_not_null(r, true);
 9064 
 9065   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9066   assert(a_start, "a array is null");
 9067   Node* b_start = array_element_address(b, intcon(0), T_LONG);
 9068   assert(b_start, "b array is null");
 9069   Node* r_start = array_element_address(r, intcon(0), T_LONG);
 9070   assert(r_start, "r array is null");
 9071 
 9072   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9073                                  OptoRuntime::intpoly_montgomeryMult_P256_Type(),
 9074                                  stubAddr, stubName, TypePtr::BOTTOM,
 9075                                  a_start, b_start, r_start);
 9076   return true;
 9077 }
 9078 
 9079 bool LibraryCallKit::inline_intpoly_assign() {
 9080   assert(UseIntPolyIntrinsics, "need intpoly intrinsics support");
 9081   assert(callee()->signature()->size() == 3, "intpoly_assign has %d parameters", callee()->signature()->size());
 9082   const char *stubName = "intpoly_assign";
 9083   address stubAddr = StubRoutines::intpoly_assign();
 9084   if (!stubAddr) return false;
 9085 
 9086   Node* set = argument(0);
 9087   Node* a = argument(1);
 9088   Node* b = argument(2);
 9089   Node* arr_length = load_array_length(a);
 9090 
 9091   a = must_be_not_null(a, true);
 9092   b = must_be_not_null(b, true);
 9093 
 9094   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9095   assert(a_start, "a array is null");
 9096   Node* b_start = array_element_address(b, intcon(0), T_LONG);
 9097   assert(b_start, "b array is null");
 9098 
 9099   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9100                                  OptoRuntime::intpoly_assign_Type(),
 9101                                  stubAddr, stubName, TypePtr::BOTTOM,
 9102                                  set, a_start, b_start, arr_length);
 9103   return true;
 9104 }
 9105 
 9106 //------------------------------inline_digestBase_implCompress-----------------------
 9107 //
 9108 // Calculate MD5 for single-block byte[] array.
 9109 // void com.sun.security.provider.MD5.implCompress(byte[] buf, int ofs)
 9110 //
 9111 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
 9112 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
 9113 //
 9114 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
 9115 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
 9116 //
 9117 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array.
 9118 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs)
 9119 //
 9120 // Calculate SHA3 (i.e., SHA3-224 or SHA3-256 or SHA3-384 or SHA3-512) for single-block byte[] array.
 9121 // void com.sun.security.provider.SHA3.implCompress(byte[] buf, int ofs)
 9122 //
 9123 bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
 9124   assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
 9125 
 9126   Node* digestBase_obj = argument(0);
 9127   Node* src            = argument(1); // type oop
 9128   Node* ofs            = argument(2); // type int
 9129 
 9130   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 9131   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 9132     // failed array check
 9133     return false;
 9134   }
 9135   // Figure out the size and type of the elements we will be copying.
 9136   BasicType src_elem = src_type->elem()->array_element_basic_type();
 9137   if (src_elem != T_BYTE) {
 9138     return false;
 9139   }
 9140   // 'src_start' points to src array + offset
 9141   src = must_be_not_null(src, true);
 9142   Node* src_start = array_element_address(src, ofs, src_elem);
 9143   Node* state = nullptr;
 9144   Node* block_size = nullptr;
 9145   address stubAddr;
 9146   const char *stubName;
 9147 
 9148   switch(id) {
 9149   case vmIntrinsics::_md5_implCompress:
 9150     assert(UseMD5Intrinsics, "need MD5 instruction support");
 9151     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9152     stubAddr = StubRoutines::md5_implCompress();
 9153     stubName = "md5_implCompress";
 9154     break;
 9155   case vmIntrinsics::_sha_implCompress:
 9156     assert(UseSHA1Intrinsics, "need SHA1 instruction support");
 9157     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9158     stubAddr = StubRoutines::sha1_implCompress();
 9159     stubName = "sha1_implCompress";
 9160     break;
 9161   case vmIntrinsics::_sha2_implCompress:
 9162     assert(UseSHA256Intrinsics, "need SHA256 instruction support");
 9163     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9164     stubAddr = StubRoutines::sha256_implCompress();
 9165     stubName = "sha256_implCompress";
 9166     break;
 9167   case vmIntrinsics::_sha5_implCompress:
 9168     assert(UseSHA512Intrinsics, "need SHA512 instruction support");
 9169     state = get_state_from_digest_object(digestBase_obj, T_LONG);
 9170     stubAddr = StubRoutines::sha512_implCompress();
 9171     stubName = "sha512_implCompress";
 9172     break;
 9173   case vmIntrinsics::_sha3_implCompress:
 9174     assert(UseSHA3Intrinsics, "need SHA3 instruction support");
 9175     state = get_state_from_digest_object(digestBase_obj, T_LONG);
 9176     stubAddr = StubRoutines::sha3_implCompress();
 9177     stubName = "sha3_implCompress";
 9178     block_size = get_block_size_from_digest_object(digestBase_obj);
 9179     if (block_size == nullptr) return false;
 9180     break;
 9181   default:
 9182     fatal_unexpected_iid(id);
 9183     return false;
 9184   }
 9185   if (state == nullptr) return false;
 9186 
 9187   assert(stubAddr != nullptr, "Stub %s is not generated", stubName);
 9188   if (stubAddr == nullptr) return false;
 9189 
 9190   // Call the stub.
 9191   Node* call;
 9192   if (block_size == nullptr) {
 9193     call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(false),
 9194                              stubAddr, stubName, TypePtr::BOTTOM,
 9195                              src_start, state);
 9196   } else {
 9197     call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(true),
 9198                              stubAddr, stubName, TypePtr::BOTTOM,
 9199                              src_start, state, block_size);
 9200   }
 9201 
 9202   return true;
 9203 }
 9204 
 9205 //------------------------------inline_keccak
 9206 bool LibraryCallKit::inline_keccak(vmIntrinsics::ID id) {
 9207   address stubAddr = nullptr;
 9208   const char *stubName;
 9209   assert(UseSHA3Intrinsics, "need SHA3 intrinsics support");
 9210   assert((id == vmIntrinsics::_double_keccak && callee()->signature()->size() == 2) ||
 9211          (id == vmIntrinsics::_quad_keccak && callee()->signature()->size() == 4),
 9212           "double_keccak wrong number of parameters");
 9213 
 9214   int parmCnt = 0;
 9215   switch (id) {
 9216     case vmIntrinsics::_double_keccak:
 9217       stubAddr = StubRoutines::double_keccak();
 9218       stubName = "double_keccak";
 9219       parmCnt = 2;
 9220       break;
 9221     case vmIntrinsics::_quad_keccak:
 9222       stubAddr = StubRoutines::quad_keccak();
 9223       stubName = "quad_keccak";
 9224       parmCnt = 4;
 9225       break;
 9226     default:
 9227       ShouldNotReachHere();
 9228   }
 9229 
 9230   if (!stubAddr) return false;
 9231 
 9232   Node* state[4];
 9233   for (int i = 0; i<parmCnt; i++) {
 9234       state[i] = must_be_not_null(argument(i), true);
 9235       state[i] = array_element_address(state[i], intcon(0), T_LONG);
 9236       assert(state[i], "state[%d] is null", i);
 9237   }
 9238 
 9239   Node* keccak;
 9240   switch (id) {
 9241     case vmIntrinsics::_double_keccak:
 9242       keccak = make_runtime_call(RC_LEAF|RC_NO_FP,
 9243                                   OptoRuntime::double_keccak_Type(),
 9244                                   stubAddr, stubName, TypePtr::BOTTOM,
 9245                                   state[0], state[1]);
 9246       break;
 9247     case vmIntrinsics::_quad_keccak:
 9248       keccak = make_runtime_call(RC_LEAF|RC_NO_FP,
 9249                                   OptoRuntime::quad_keccak_Type(),
 9250                                   stubAddr, stubName, TypePtr::BOTTOM,
 9251                                   state[0], state[1], state[2], state[3]);
 9252       break;
 9253     default:
 9254       ShouldNotReachHere();
 9255   }
 9256 
 9257   // return an int
 9258   Node* retvalue = _gvn.transform(new ProjNode(keccak, TypeFunc::Parms));
 9259   set_result(retvalue);
 9260   return true;
 9261 }
 9262 
 9263 
 9264 //------------------------------inline_digestBase_implCompressMB-----------------------
 9265 //
 9266 // Calculate MD5/SHA/SHA2/SHA5/SHA3 for multi-block byte[] array.
 9267 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
 9268 //
 9269 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
 9270   assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics,
 9271          "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support");
 9272   assert((uint)predicate < 5, "sanity");
 9273   assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
 9274 
 9275   Node* digestBase_obj = argument(0); // The receiver was checked for null already.
 9276   Node* src            = argument(1); // byte[] array
 9277   Node* ofs            = argument(2); // type int
 9278   Node* limit          = argument(3); // type int
 9279 
 9280   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 9281   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 9282     // failed array check
 9283     return false;
 9284   }
 9285   // Figure out the size and type of the elements we will be copying.
 9286   BasicType src_elem = src_type->elem()->array_element_basic_type();
 9287   if (src_elem != T_BYTE) {
 9288     return false;
 9289   }
 9290   // 'src_start' points to src array + offset
 9291   src = must_be_not_null(src, false);
 9292   Node* src_start = array_element_address(src, ofs, src_elem);
 9293 
 9294   const char* klass_digestBase_name = nullptr;
 9295   const char* stub_name = nullptr;
 9296   address     stub_addr = nullptr;
 9297   BasicType elem_type = T_INT;
 9298 
 9299   switch (predicate) {
 9300   case 0:
 9301     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_md5_implCompress)) {
 9302       klass_digestBase_name = "sun/security/provider/MD5";
 9303       stub_name = "md5_implCompressMB";
 9304       stub_addr = StubRoutines::md5_implCompressMB();
 9305     }
 9306     break;
 9307   case 1:
 9308     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha_implCompress)) {
 9309       klass_digestBase_name = "sun/security/provider/SHA";
 9310       stub_name = "sha1_implCompressMB";
 9311       stub_addr = StubRoutines::sha1_implCompressMB();
 9312     }
 9313     break;
 9314   case 2:
 9315     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha2_implCompress)) {
 9316       klass_digestBase_name = "sun/security/provider/SHA2";
 9317       stub_name = "sha256_implCompressMB";
 9318       stub_addr = StubRoutines::sha256_implCompressMB();
 9319     }
 9320     break;
 9321   case 3:
 9322     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha5_implCompress)) {
 9323       klass_digestBase_name = "sun/security/provider/SHA5";
 9324       stub_name = "sha512_implCompressMB";
 9325       stub_addr = StubRoutines::sha512_implCompressMB();
 9326       elem_type = T_LONG;
 9327     }
 9328     break;
 9329   case 4:
 9330     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha3_implCompress)) {
 9331       klass_digestBase_name = "sun/security/provider/SHA3";
 9332       stub_name = "sha3_implCompressMB";
 9333       stub_addr = StubRoutines::sha3_implCompressMB();
 9334       elem_type = T_LONG;
 9335     }
 9336     break;
 9337   default:
 9338     fatal("unknown DigestBase intrinsic predicate: %d", predicate);
 9339   }
 9340   if (klass_digestBase_name != nullptr) {
 9341     assert(stub_addr != nullptr, "Stub is generated");
 9342     if (stub_addr == nullptr) return false;
 9343 
 9344     // get DigestBase klass to lookup for SHA klass
 9345     const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
 9346     assert(tinst != nullptr, "digestBase_obj is not instance???");
 9347     assert(tinst->is_loaded(), "DigestBase is not loaded");
 9348 
 9349     ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
 9350     assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
 9351     ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
 9352     return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
 9353   }
 9354   return false;
 9355 }
 9356 
 9357 //------------------------------inline_digestBase_implCompressMB-----------------------
 9358 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
 9359                                                       BasicType elem_type, address stubAddr, const char *stubName,
 9360                                                       Node* src_start, Node* ofs, Node* limit) {
 9361   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
 9362   const TypeOopPtr* xtype = aklass->cast_to_exactness(false)->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 9363   Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
 9364   digest_obj = _gvn.transform(digest_obj);
 9365 
 9366   Node* state = get_state_from_digest_object(digest_obj, elem_type);
 9367   if (state == nullptr) return false;
 9368 
 9369   Node* block_size = nullptr;
 9370   if (strcmp("sha3_implCompressMB", stubName) == 0) {
 9371     block_size = get_block_size_from_digest_object(digest_obj);
 9372     if (block_size == nullptr) return false;
 9373   }
 9374 
 9375   // Call the stub.
 9376   Node* call;
 9377   if (block_size == nullptr) {
 9378     call = make_runtime_call(RC_LEAF|RC_NO_FP,
 9379                              OptoRuntime::digestBase_implCompressMB_Type(false),
 9380                              stubAddr, stubName, TypePtr::BOTTOM,
 9381                              src_start, state, ofs, limit);
 9382   } else {
 9383      call = make_runtime_call(RC_LEAF|RC_NO_FP,
 9384                              OptoRuntime::digestBase_implCompressMB_Type(true),
 9385                              stubAddr, stubName, TypePtr::BOTTOM,
 9386                              src_start, state, block_size, ofs, limit);
 9387   }
 9388 
 9389   // return ofs (int)
 9390   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 9391   set_result(result);
 9392 
 9393   return true;
 9394 }
 9395 
 9396 //------------------------------inline_galoisCounterMode_AESCrypt-----------------------
 9397 bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() {
 9398   assert(UseAES, "need AES instruction support");
 9399   address stubAddr = nullptr;
 9400   const char *stubName = nullptr;
 9401   stubAddr = StubRoutines::galoisCounterMode_AESCrypt();
 9402   stubName = "galoisCounterMode_AESCrypt";
 9403 
 9404   if (stubAddr == nullptr) return false;
 9405 
 9406   Node* in      = argument(0);
 9407   Node* inOfs   = argument(1);
 9408   Node* len     = argument(2);
 9409   Node* ct      = argument(3);
 9410   Node* ctOfs   = argument(4);
 9411   Node* out     = argument(5);
 9412   Node* outOfs  = argument(6);
 9413   Node* gctr_object = argument(7);
 9414   Node* ghash_object = argument(8);
 9415 
 9416   // (1) in, ct and out are arrays.
 9417   const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr();
 9418   const TypeAryPtr* ct_type = ct->Value(&_gvn)->isa_aryptr();
 9419   const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr();
 9420   assert( in_type != nullptr &&  in_type->elem() != Type::BOTTOM &&
 9421           ct_type != nullptr &&  ct_type->elem() != Type::BOTTOM &&
 9422          out_type != nullptr && out_type->elem() != Type::BOTTOM, "args are strange");
 9423 
 9424   // checks are the responsibility of the caller
 9425   Node* in_start = in;
 9426   Node* ct_start = ct;
 9427   Node* out_start = out;
 9428   if (inOfs != nullptr || ctOfs != nullptr || outOfs != nullptr) {
 9429     assert(inOfs != nullptr && ctOfs != nullptr && outOfs != nullptr, "");
 9430     in_start = array_element_address(in, inOfs, T_BYTE);
 9431     ct_start = array_element_address(ct, ctOfs, T_BYTE);
 9432     out_start = array_element_address(out, outOfs, T_BYTE);
 9433   }
 9434 
 9435   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 9436   // (because of the predicated logic executed earlier).
 9437   // so we cast it here safely.
 9438   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 9439   Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 9440   Node* counter = load_field_from_object(gctr_object, "counter", "[B");
 9441   Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J");
 9442   Node* state = load_field_from_object(ghash_object, "state", "[J");
 9443 
 9444   if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) {
 9445     return false;
 9446   }
 9447   // cast it to what we know it will be at runtime
 9448   const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr();
 9449   assert(tinst != nullptr, "GCTR obj is null");
 9450   assert(tinst->is_loaded(), "GCTR obj is not loaded");
 9451   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 9452   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 9453   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 9454   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 9455   const TypeOopPtr* xtype = aklass->as_instance_type();
 9456   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 9457   aescrypt_object = _gvn.transform(aescrypt_object);
 9458   // we need to get the start of the aescrypt_object's expanded key array
 9459   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
 9460   if (k_start == nullptr) return false;
 9461   // similarly, get the start address of the r vector
 9462   Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE);
 9463   Node* state_start = array_element_address(state, intcon(0), T_LONG);
 9464   Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG);
 9465 
 9466 
 9467   // Call the stub, passing params
 9468   Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 9469                                OptoRuntime::galoisCounterMode_aescrypt_Type(),
 9470                                stubAddr, stubName, TypePtr::BOTTOM,
 9471                                in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start);
 9472 
 9473   // return cipher length (int)
 9474   Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms));
 9475   set_result(retvalue);
 9476 
 9477   return true;
 9478 }
 9479 
 9480 //----------------------------inline_galoisCounterMode_AESCrypt_predicate----------------------------
 9481 // Return node representing slow path of predicate check.
 9482 // the pseudo code we want to emulate with this predicate is:
 9483 // for encryption:
 9484 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 9485 // for decryption:
 9486 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 9487 //    note cipher==plain is more conservative than the original java code but that's OK
 9488 //
 9489 
 9490 Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() {
 9491   // The receiver was checked for null already.
 9492   Node* objGCTR = argument(7);
 9493   // Load embeddedCipher field of GCTR object.
 9494   Node* embeddedCipherObj = load_field_from_object(objGCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 9495   assert(embeddedCipherObj != nullptr, "embeddedCipherObj is null");
 9496 
 9497   // get AESCrypt klass for instanceOf check
 9498   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 9499   // will have same classloader as CipherBlockChaining object
 9500   const TypeInstPtr* tinst = _gvn.type(objGCTR)->isa_instptr();
 9501   assert(tinst != nullptr, "GCTR obj is null");
 9502   assert(tinst->is_loaded(), "GCTR obj is not loaded");
 9503 
 9504   // we want to do an instanceof comparison against the AESCrypt class
 9505   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 9506   if (!klass_AESCrypt->is_loaded()) {
 9507     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 9508     Node* ctrl = control();
 9509     set_control(top()); // no regular fast path
 9510     return ctrl;
 9511   }
 9512 
 9513   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 9514   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 9515   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 9516   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 9517   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 9518 
 9519   return instof_false; // even if it is null
 9520 }
 9521 
 9522 //------------------------------get_state_from_digest_object-----------------------
 9523 Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) {
 9524   const char* state_type;
 9525   switch (elem_type) {
 9526     case T_BYTE: state_type = "[B"; break;
 9527     case T_INT:  state_type = "[I"; break;
 9528     case T_LONG: state_type = "[J"; break;
 9529     default: ShouldNotReachHere();
 9530   }
 9531   Node* digest_state = load_field_from_object(digest_object, "state", state_type);
 9532   assert (digest_state != nullptr, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3");
 9533   if (digest_state == nullptr) return (Node *) nullptr;
 9534 
 9535   // now have the array, need to get the start address of the state array
 9536   Node* state = array_element_address(digest_state, intcon(0), elem_type);
 9537   return state;
 9538 }
 9539 
 9540 //------------------------------get_block_size_from_sha3_object----------------------------------
 9541 Node * LibraryCallKit::get_block_size_from_digest_object(Node *digest_object) {
 9542   Node* block_size = load_field_from_object(digest_object, "blockSize", "I");
 9543   assert (block_size != nullptr, "sanity");
 9544   return block_size;
 9545 }
 9546 
 9547 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
 9548 // Return node representing slow path of predicate check.
 9549 // the pseudo code we want to emulate with this predicate is:
 9550 //    if (digestBaseObj instanceof MD5/SHA/SHA2/SHA5/SHA3) do_intrinsic, else do_javapath
 9551 //
 9552 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
 9553   assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics,
 9554          "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support");
 9555   assert((uint)predicate < 5, "sanity");
 9556 
 9557   // The receiver was checked for null already.
 9558   Node* digestBaseObj = argument(0);
 9559 
 9560   // get DigestBase klass for instanceOf check
 9561   const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr();
 9562   assert(tinst != nullptr, "digestBaseObj is null");
 9563   assert(tinst->is_loaded(), "DigestBase is not loaded");
 9564 
 9565   const char* klass_name = nullptr;
 9566   switch (predicate) {
 9567   case 0:
 9568     if (UseMD5Intrinsics) {
 9569       // we want to do an instanceof comparison against the MD5 class
 9570       klass_name = "sun/security/provider/MD5";
 9571     }
 9572     break;
 9573   case 1:
 9574     if (UseSHA1Intrinsics) {
 9575       // we want to do an instanceof comparison against the SHA class
 9576       klass_name = "sun/security/provider/SHA";
 9577     }
 9578     break;
 9579   case 2:
 9580     if (UseSHA256Intrinsics) {
 9581       // we want to do an instanceof comparison against the SHA2 class
 9582       klass_name = "sun/security/provider/SHA2";
 9583     }
 9584     break;
 9585   case 3:
 9586     if (UseSHA512Intrinsics) {
 9587       // we want to do an instanceof comparison against the SHA5 class
 9588       klass_name = "sun/security/provider/SHA5";
 9589     }
 9590     break;
 9591   case 4:
 9592     if (UseSHA3Intrinsics) {
 9593       // we want to do an instanceof comparison against the SHA3 class
 9594       klass_name = "sun/security/provider/SHA3";
 9595     }
 9596     break;
 9597   default:
 9598     fatal("unknown SHA intrinsic predicate: %d", predicate);
 9599   }
 9600 
 9601   ciKlass* klass = nullptr;
 9602   if (klass_name != nullptr) {
 9603     klass = tinst->instance_klass()->find_klass(ciSymbol::make(klass_name));
 9604   }
 9605   if ((klass == nullptr) || !klass->is_loaded()) {
 9606     // if none of MD5/SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path
 9607     Node* ctrl = control();
 9608     set_control(top()); // no intrinsic path
 9609     return ctrl;
 9610   }
 9611   ciInstanceKlass* instklass = klass->as_instance_klass();
 9612 
 9613   Node* instof = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass)));
 9614   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 9615   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 9616   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 9617 
 9618   return instof_false;  // even if it is null
 9619 }
 9620 
 9621 //-------------inline_fma-----------------------------------
 9622 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) {
 9623   Node *a = nullptr;
 9624   Node *b = nullptr;
 9625   Node *c = nullptr;
 9626   Node* result = nullptr;
 9627   switch (id) {
 9628   case vmIntrinsics::_fmaD:
 9629     assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each.");
 9630     // no receiver since it is static method
 9631     a = argument(0);
 9632     b = argument(2);
 9633     c = argument(4);
 9634     result = _gvn.transform(new FmaDNode(a, b, c));
 9635     break;
 9636   case vmIntrinsics::_fmaF:
 9637     assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each.");
 9638     a = argument(0);
 9639     b = argument(1);
 9640     c = argument(2);
 9641     result = _gvn.transform(new FmaFNode(a, b, c));
 9642     break;
 9643   default:
 9644     fatal_unexpected_iid(id);  break;
 9645   }
 9646   set_result(result);
 9647   return true;
 9648 }
 9649 
 9650 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) {
 9651   // argument(0) is receiver
 9652   Node* codePoint = argument(1);
 9653   Node* n = nullptr;
 9654 
 9655   switch (id) {
 9656     case vmIntrinsics::_isDigit :
 9657       n = new DigitNode(control(), codePoint);
 9658       break;
 9659     case vmIntrinsics::_isLowerCase :
 9660       n = new LowerCaseNode(control(), codePoint);
 9661       break;
 9662     case vmIntrinsics::_isUpperCase :
 9663       n = new UpperCaseNode(control(), codePoint);
 9664       break;
 9665     case vmIntrinsics::_isWhitespace :
 9666       n = new WhitespaceNode(control(), codePoint);
 9667       break;
 9668     default:
 9669       fatal_unexpected_iid(id);
 9670   }
 9671 
 9672   set_result(_gvn.transform(n));
 9673   return true;
 9674 }
 9675 
 9676 bool LibraryCallKit::inline_profileBoolean() {
 9677   Node* counts = argument(1);
 9678   const TypeAryPtr* ary = nullptr;
 9679   ciArray* aobj = nullptr;
 9680   if (counts->is_Con()
 9681       && (ary = counts->bottom_type()->isa_aryptr()) != nullptr
 9682       && (aobj = ary->const_oop()->as_array()) != nullptr
 9683       && (aobj->length() == 2)) {
 9684     // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively.
 9685     jint false_cnt = aobj->element_value(0).as_int();
 9686     jint  true_cnt = aobj->element_value(1).as_int();
 9687 
 9688     if (C->log() != nullptr) {
 9689       C->log()->elem("observe source='profileBoolean' false='%d' true='%d'",
 9690                      false_cnt, true_cnt);
 9691     }
 9692 
 9693     if (false_cnt + true_cnt == 0) {
 9694       // According to profile, never executed.
 9695       uncommon_trap_exact(Deoptimization::Reason_intrinsic,
 9696                           Deoptimization::Action_reinterpret);
 9697       return true;
 9698     }
 9699 
 9700     // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt)
 9701     // is a number of each value occurrences.
 9702     Node* result = argument(0);
 9703     if (false_cnt == 0 || true_cnt == 0) {
 9704       // According to profile, one value has been never seen.
 9705       int expected_val = (false_cnt == 0) ? 1 : 0;
 9706 
 9707       Node* cmp  = _gvn.transform(new CmpINode(result, intcon(expected_val)));
 9708       Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 9709 
 9710       IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN);
 9711       Node* fast_path = _gvn.transform(new IfTrueNode(check));
 9712       Node* slow_path = _gvn.transform(new IfFalseNode(check));
 9713 
 9714       { // Slow path: uncommon trap for never seen value and then reexecute
 9715         // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows
 9716         // the value has been seen at least once.
 9717         PreserveJVMState pjvms(this);
 9718         PreserveReexecuteState preexecs(this);
 9719         jvms()->set_should_reexecute(true);
 9720 
 9721         set_control(slow_path);
 9722         set_i_o(i_o());
 9723 
 9724         uncommon_trap_exact(Deoptimization::Reason_intrinsic,
 9725                             Deoptimization::Action_reinterpret);
 9726       }
 9727       // The guard for never seen value enables sharpening of the result and
 9728       // returning a constant. It allows to eliminate branches on the same value
 9729       // later on.
 9730       set_control(fast_path);
 9731       result = intcon(expected_val);
 9732     }
 9733     // Stop profiling.
 9734     // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode.
 9735     // By replacing method body with profile data (represented as ProfileBooleanNode
 9736     // on IR level) we effectively disable profiling.
 9737     // It enables full speed execution once optimized code is generated.
 9738     Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt));
 9739     C->record_for_igvn(profile);
 9740     set_result(profile);
 9741     return true;
 9742   } else {
 9743     // Continue profiling.
 9744     // Profile data isn't available at the moment. So, execute method's bytecode version.
 9745     // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod
 9746     // is compiled and counters aren't available since corresponding MethodHandle
 9747     // isn't a compile-time constant.
 9748     return false;
 9749   }
 9750 }
 9751 
 9752 bool LibraryCallKit::inline_isCompileConstant() {
 9753   Node* n = argument(0);
 9754   set_result(n->is_Con() ? intcon(1) : intcon(0));
 9755   return true;
 9756 }
 9757 
 9758 //------------------------------- inline_getObjectSize --------------------------------------
 9759 //
 9760 // Calculate the runtime size of the object/array.
 9761 //   native long sun.instrument.InstrumentationImpl.getObjectSize0(long nativeAgent, Object objectToSize);
 9762 //
 9763 bool LibraryCallKit::inline_getObjectSize() {
 9764   Node* obj = argument(3);
 9765   Node* klass_node = load_object_klass(obj);
 9766 
 9767   jint  layout_con = Klass::_lh_neutral_value;
 9768   Node* layout_val = get_layout_helper(klass_node, layout_con);
 9769   int   layout_is_con = (layout_val == nullptr);
 9770 
 9771   if (layout_is_con) {
 9772     // Layout helper is constant, can figure out things at compile time.
 9773 
 9774     if (Klass::layout_helper_is_instance(layout_con)) {
 9775       // Instance case:  layout_con contains the size itself.
 9776       Node *size = longcon(Klass::layout_helper_size_in_bytes(layout_con));
 9777       set_result(size);
 9778     } else {
 9779       // Array case: size is round(header + element_size*arraylength).
 9780       // Since arraylength is different for every array instance, we have to
 9781       // compute the whole thing at runtime.
 9782 
 9783       Node* arr_length = load_array_length(obj);
 9784 
 9785       int round_mask = MinObjAlignmentInBytes - 1;
 9786       int hsize  = Klass::layout_helper_header_size(layout_con);
 9787       int eshift = Klass::layout_helper_log2_element_size(layout_con);
 9788 
 9789       if ((round_mask & ~right_n_bits(eshift)) == 0) {
 9790         round_mask = 0;  // strength-reduce it if it goes away completely
 9791       }
 9792       assert((hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded");
 9793       Node* header_size = intcon(hsize + round_mask);
 9794 
 9795       Node* lengthx = ConvI2X(arr_length);
 9796       Node* headerx = ConvI2X(header_size);
 9797 
 9798       Node* abody = lengthx;
 9799       if (eshift != 0) {
 9800         abody = _gvn.transform(new LShiftXNode(lengthx, intcon(eshift)));
 9801       }
 9802       Node* size = _gvn.transform( new AddXNode(headerx, abody) );
 9803       if (round_mask != 0) {
 9804         size = _gvn.transform( new AndXNode(size, MakeConX(~round_mask)) );
 9805       }
 9806       size = ConvX2L(size);
 9807       set_result(size);
 9808     }
 9809   } else {
 9810     // Layout helper is not constant, need to test for array-ness at runtime.
 9811 
 9812     enum { _instance_path = 1, _array_path, PATH_LIMIT };
 9813     RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 9814     PhiNode* result_val = new PhiNode(result_reg, TypeLong::LONG);
 9815     record_for_igvn(result_reg);
 9816 
 9817     Node* array_ctl = generate_array_guard(klass_node, nullptr, &obj);
 9818     if (array_ctl != nullptr) {
 9819       // Array case: size is round(header + element_size*arraylength).
 9820       // Since arraylength is different for every array instance, we have to
 9821       // compute the whole thing at runtime.
 9822 
 9823       PreserveJVMState pjvms(this);
 9824       set_control(array_ctl);
 9825       Node* arr_length = load_array_length(obj);
 9826 
 9827       int round_mask = MinObjAlignmentInBytes - 1;
 9828       Node* mask = intcon(round_mask);
 9829 
 9830       Node* hss = intcon(Klass::_lh_header_size_shift);
 9831       Node* hsm = intcon(Klass::_lh_header_size_mask);
 9832       Node* header_size = _gvn.transform(new URShiftINode(layout_val, hss));
 9833       header_size = _gvn.transform(new AndINode(header_size, hsm));
 9834       header_size = _gvn.transform(new AddINode(header_size, mask));
 9835 
 9836       // There is no need to mask or shift this value.
 9837       // The semantics of LShiftINode include an implicit mask to 0x1F.
 9838       assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place");
 9839       Node* elem_shift = layout_val;
 9840 
 9841       Node* lengthx = ConvI2X(arr_length);
 9842       Node* headerx = ConvI2X(header_size);
 9843 
 9844       Node* abody = _gvn.transform(new LShiftXNode(lengthx, elem_shift));
 9845       Node* size = _gvn.transform(new AddXNode(headerx, abody));
 9846       if (round_mask != 0) {
 9847         size = _gvn.transform(new AndXNode(size, MakeConX(~round_mask)));
 9848       }
 9849       size = ConvX2L(size);
 9850 
 9851       result_reg->init_req(_array_path, control());
 9852       result_val->init_req(_array_path, size);
 9853     }
 9854 
 9855     if (!stopped()) {
 9856       // Instance case: the layout helper gives us instance size almost directly,
 9857       // but we need to mask out the _lh_instance_slow_path_bit.
 9858       Node* size = ConvI2X(layout_val);
 9859       assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
 9860       Node* mask = MakeConX(~(intptr_t) right_n_bits(LogBytesPerLong));
 9861       size = _gvn.transform(new AndXNode(size, mask));
 9862       size = ConvX2L(size);
 9863 
 9864       result_reg->init_req(_instance_path, control());
 9865       result_val->init_req(_instance_path, size);
 9866     }
 9867 
 9868     set_result(result_reg, result_val);
 9869   }
 9870 
 9871   return true;
 9872 }
 9873 
 9874 //------------------------------- inline_blackhole --------------------------------------
 9875 //
 9876 // Make sure all arguments to this node are alive.
 9877 // This matches methods that were requested to be blackholed through compile commands.
 9878 //
 9879 bool LibraryCallKit::inline_blackhole() {
 9880   assert(callee()->is_static(), "Should have been checked before: only static methods here");
 9881   assert(callee()->is_empty(), "Should have been checked before: only empty methods here");
 9882   assert(callee()->holder()->is_loaded(), "Should have been checked before: only methods for loaded classes here");
 9883 
 9884   // Blackhole node pinches only the control, not memory. This allows
 9885   // the blackhole to be pinned in the loop that computes blackholed
 9886   // values, but have no other side effects, like breaking the optimizations
 9887   // across the blackhole.
 9888 
 9889   Node* bh = _gvn.transform(new BlackholeNode(control()));
 9890   set_control(_gvn.transform(new ProjNode(bh, TypeFunc::Control)));
 9891 
 9892   // Bind call arguments as blackhole arguments to keep them alive
 9893   uint nargs = callee()->arg_size();
 9894   for (uint i = 0; i < nargs; i++) {
 9895     bh->add_req(argument(i));
 9896   }
 9897 
 9898   return true;
 9899 }
 9900 
 9901 Node* LibraryCallKit::unbox_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* box) {
 9902   const TypeInstPtr* box_type = _gvn.type(box)->isa_instptr();
 9903   if (box_type == nullptr || box_type->instance_klass() != float16_box_type->instance_klass()) {
 9904     return nullptr; // box klass is not Float16
 9905   }
 9906 
 9907   // Null check; get notnull casted pointer
 9908   Node* null_ctl = top();
 9909   Node* not_null_box = null_check_oop(box, &null_ctl, true);
 9910   // If not_null_box is dead, only null-path is taken
 9911   if (stopped()) {
 9912     set_control(null_ctl);
 9913     return nullptr;
 9914   }
 9915   assert(not_null_box->bottom_type()->is_instptr()->maybe_null() == false, "");
 9916   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 9917   Node* adr = basic_plus_adr(not_null_box, field->offset_in_bytes());
 9918   return access_load_at(not_null_box, adr, adr_type, TypeInt::SHORT, T_SHORT, IN_HEAP);
 9919 }
 9920 
 9921 Node* LibraryCallKit::box_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* value) {
 9922   PreserveReexecuteState preexecs(this);
 9923   jvms()->set_should_reexecute(true);
 9924 
 9925   const TypeKlassPtr* klass_type = float16_box_type->as_klass_type();
 9926   Node* klass_node = makecon(klass_type);
 9927   Node* box = new_instance(klass_node);
 9928 
 9929   Node* value_field = basic_plus_adr(box, field->offset_in_bytes());
 9930   const TypePtr* value_adr_type = value_field->bottom_type()->is_ptr();
 9931 
 9932   Node* field_store = _gvn.transform(access_store_at(box,
 9933                                                      value_field,
 9934                                                      value_adr_type,
 9935                                                      value,
 9936                                                      TypeInt::SHORT,
 9937                                                      T_SHORT,
 9938                                                      IN_HEAP));
 9939   set_memory(field_store, value_adr_type);
 9940   return box;
 9941 }
 9942 
 9943 bool LibraryCallKit::inline_fp16_operations(vmIntrinsics::ID id, int num_args) {
 9944   if (!Matcher::match_rule_supported(Op_ReinterpretS2HF) ||
 9945       !Matcher::match_rule_supported(Op_ReinterpretHF2S)) {
 9946     return false;
 9947   }
 9948 
 9949   const TypeInstPtr* box_type = _gvn.type(argument(0))->isa_instptr();
 9950   if (box_type == nullptr || box_type->const_oop() == nullptr) {
 9951     return false;
 9952   }
 9953 
 9954   ciInstanceKlass* float16_klass = box_type->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
 9955   const TypeInstPtr* float16_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, float16_klass);
 9956   ciField* field = float16_klass->get_field_by_name(ciSymbols::value_name(),
 9957                                                     ciSymbols::short_signature(),
 9958                                                     false);
 9959   assert(field != nullptr, "");
 9960 
 9961   // Transformed nodes
 9962   Node* fld1 = nullptr;
 9963   Node* fld2 = nullptr;
 9964   Node* fld3 = nullptr;
 9965   switch(num_args) {
 9966     case 3:
 9967       fld3 = unbox_fp16_value(float16_box_type, field, argument(3));
 9968       if (fld3 == nullptr) {
 9969         return false;
 9970       }
 9971       fld3 = _gvn.transform(new ReinterpretS2HFNode(fld3));
 9972     // fall-through
 9973     case 2:
 9974       fld2 = unbox_fp16_value(float16_box_type, field, argument(2));
 9975       if (fld2 == nullptr) {
 9976         return false;
 9977       }
 9978       fld2 = _gvn.transform(new ReinterpretS2HFNode(fld2));
 9979     // fall-through
 9980     case 1:
 9981       fld1 = unbox_fp16_value(float16_box_type, field, argument(1));
 9982       if (fld1 == nullptr) {
 9983         return false;
 9984       }
 9985       fld1 = _gvn.transform(new ReinterpretS2HFNode(fld1));
 9986       break;
 9987     default: fatal("Unsupported number of arguments %d", num_args);
 9988   }
 9989 
 9990   Node* result = nullptr;
 9991   switch (id) {
 9992     // Unary operations
 9993     case vmIntrinsics::_sqrt_float16:
 9994       result = _gvn.transform(new SqrtHFNode(C, control(), fld1));
 9995       break;
 9996     // Ternary operations
 9997     case vmIntrinsics::_fma_float16:
 9998       result = _gvn.transform(new FmaHFNode(fld1, fld2, fld3));
 9999       break;
10000     default:
10001       fatal_unexpected_iid(id);
10002       break;
10003   }
10004   result = _gvn.transform(new ReinterpretHF2SNode(result));
10005   set_result(box_fp16_value(float16_box_type, field, result));
10006   return true;
10007 }
10008