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::_intpoly_mult_25519:
  696     return inline_intpoly_mult_25519();
  697   case vmIntrinsics::_intpoly_square_25519:
  698     return inline_intpoly_square_25519();
  699   case vmIntrinsics::_encodeISOArray:
  700   case vmIntrinsics::_encodeByteISOArray:
  701     return inline_encodeISOArray(false);
  702   case vmIntrinsics::_encodeAsciiArray:
  703     return inline_encodeISOArray(true);
  704 
  705   case vmIntrinsics::_updateCRC32:
  706     return inline_updateCRC32();
  707   case vmIntrinsics::_updateBytesCRC32:
  708     return inline_updateBytesCRC32();
  709   case vmIntrinsics::_updateByteBufferCRC32:
  710     return inline_updateByteBufferCRC32();
  711 
  712   case vmIntrinsics::_updateBytesCRC32C:
  713     return inline_updateBytesCRC32C();
  714   case vmIntrinsics::_updateDirectByteBufferCRC32C:
  715     return inline_updateDirectByteBufferCRC32C();
  716 
  717   case vmIntrinsics::_updateBytesAdler32:
  718     return inline_updateBytesAdler32();
  719   case vmIntrinsics::_updateByteBufferAdler32:
  720     return inline_updateByteBufferAdler32();
  721 
  722   case vmIntrinsics::_profileBoolean:
  723     return inline_profileBoolean();
  724   case vmIntrinsics::_isCompileConstant:
  725     return inline_isCompileConstant();
  726 
  727   case vmIntrinsics::_countPositives:
  728     return inline_countPositives();
  729 
  730   case vmIntrinsics::_fmaD:
  731   case vmIntrinsics::_fmaF:
  732     return inline_fma(intrinsic_id());
  733 
  734   case vmIntrinsics::_isDigit:
  735   case vmIntrinsics::_isLowerCase:
  736   case vmIntrinsics::_isUpperCase:
  737   case vmIntrinsics::_isWhitespace:
  738     return inline_character_compare(intrinsic_id());
  739 
  740   case vmIntrinsics::_min:
  741   case vmIntrinsics::_max:
  742   case vmIntrinsics::_min_strict:
  743   case vmIntrinsics::_max_strict:
  744   case vmIntrinsics::_minL:
  745   case vmIntrinsics::_maxL:
  746   case vmIntrinsics::_minF:
  747   case vmIntrinsics::_maxF:
  748   case vmIntrinsics::_minD:
  749   case vmIntrinsics::_maxD:
  750   case vmIntrinsics::_minF_strict:
  751   case vmIntrinsics::_maxF_strict:
  752   case vmIntrinsics::_minD_strict:
  753   case vmIntrinsics::_maxD_strict:
  754     return inline_min_max(intrinsic_id());
  755 
  756   case vmIntrinsics::_VectorUnaryOp:
  757     return inline_vector_nary_operation(1);
  758   case vmIntrinsics::_VectorBinaryOp:
  759     return inline_vector_nary_operation(2);
  760   case vmIntrinsics::_VectorUnaryLibOp:
  761     return inline_vector_call(1);
  762   case vmIntrinsics::_VectorBinaryLibOp:
  763     return inline_vector_call(2);
  764   case vmIntrinsics::_VectorTernaryOp:
  765     return inline_vector_nary_operation(3);
  766   case vmIntrinsics::_VectorFromBitsCoerced:
  767     return inline_vector_frombits_coerced();
  768   case vmIntrinsics::_VectorMaskOp:
  769     return inline_vector_mask_operation();
  770   case vmIntrinsics::_VectorLoadOp:
  771     return inline_vector_mem_operation(/*is_store=*/false);
  772   case vmIntrinsics::_VectorLoadMaskedOp:
  773     return inline_vector_mem_masked_operation(/*is_store*/false);
  774   case vmIntrinsics::_VectorStoreOp:
  775     return inline_vector_mem_operation(/*is_store=*/true);
  776   case vmIntrinsics::_VectorStoreMaskedOp:
  777     return inline_vector_mem_masked_operation(/*is_store=*/true);
  778   case vmIntrinsics::_VectorGatherOp:
  779     return inline_vector_gather_scatter(/*is_scatter*/ false);
  780   case vmIntrinsics::_VectorScatterOp:
  781     return inline_vector_gather_scatter(/*is_scatter*/ true);
  782   case vmIntrinsics::_VectorReductionCoerced:
  783     return inline_vector_reduction();
  784   case vmIntrinsics::_VectorTest:
  785     return inline_vector_test();
  786   case vmIntrinsics::_VectorBlend:
  787     return inline_vector_blend();
  788   case vmIntrinsics::_VectorRearrange:
  789     return inline_vector_rearrange();
  790   case vmIntrinsics::_VectorSelectFrom:
  791     return inline_vector_select_from();
  792   case vmIntrinsics::_VectorCompare:
  793     return inline_vector_compare();
  794   case vmIntrinsics::_VectorBroadcastInt:
  795     return inline_vector_broadcast_int();
  796   case vmIntrinsics::_VectorConvert:
  797     return inline_vector_convert();
  798   case vmIntrinsics::_VectorInsert:
  799     return inline_vector_insert();
  800   case vmIntrinsics::_VectorExtract:
  801     return inline_vector_extract();
  802   case vmIntrinsics::_VectorCompressExpand:
  803     return inline_vector_compress_expand();
  804   case vmIntrinsics::_VectorSelectFromTwoVectorOp:
  805     return inline_vector_select_from_two_vectors();
  806   case vmIntrinsics::_IndexVector:
  807     return inline_index_vector();
  808   case vmIntrinsics::_IndexPartiallyInUpperRange:
  809     return inline_index_partially_in_upper_range();
  810 
  811   case vmIntrinsics::_getObjectSize:
  812     return inline_getObjectSize();
  813 
  814   case vmIntrinsics::_blackhole:
  815     return inline_blackhole();
  816 
  817   default:
  818     // If you get here, it may be that someone has added a new intrinsic
  819     // to the list in vmIntrinsics.hpp without implementing it here.
  820 #ifndef PRODUCT
  821     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
  822       tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
  823                     vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id()));
  824     }
  825 #endif
  826     return false;
  827   }
  828 }
  829 
  830 Node* LibraryCallKit::try_to_predicate(int predicate) {
  831   if (!jvms()->has_method()) {
  832     // Root JVMState has a null method.
  833     assert(map()->memory()->Opcode() == Op_Parm, "");
  834     // Insert the memory aliasing node
  835     set_all_memory(reset_memory());
  836   }
  837   assert(merged_memory(), "");
  838 
  839   switch (intrinsic_id()) {
  840   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
  841     return inline_cipherBlockChaining_AESCrypt_predicate(false);
  842   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
  843     return inline_cipherBlockChaining_AESCrypt_predicate(true);
  844   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
  845     return inline_electronicCodeBook_AESCrypt_predicate(false);
  846   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
  847     return inline_electronicCodeBook_AESCrypt_predicate(true);
  848   case vmIntrinsics::_counterMode_AESCrypt:
  849     return inline_counterMode_AESCrypt_predicate();
  850   case vmIntrinsics::_digestBase_implCompressMB:
  851     return inline_digestBase_implCompressMB_predicate(predicate);
  852   case vmIntrinsics::_galoisCounterMode_AESCrypt:
  853     return inline_galoisCounterMode_AESCrypt_predicate();
  854 
  855   default:
  856     // If you get here, it may be that someone has added a new intrinsic
  857     // to the list in vmIntrinsics.hpp without implementing it here.
  858 #ifndef PRODUCT
  859     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
  860       tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)",
  861                     vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id()));
  862     }
  863 #endif
  864     Node* slow_ctl = control();
  865     set_control(top()); // No fast path intrinsic
  866     return slow_ctl;
  867   }
  868 }
  869 
  870 //------------------------------set_result-------------------------------
  871 // Helper function for finishing intrinsics.
  872 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) {
  873   record_for_igvn(region);
  874   set_control(_gvn.transform(region));
  875   set_result( _gvn.transform(value));
  876   assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity");
  877 }
  878 
  879 RegionNode* LibraryCallKit::create_bailout() {
  880   RegionNode* bailout = new RegionNode(1);
  881   record_for_igvn(bailout);
  882   return bailout;
  883 }
  884 
  885 bool LibraryCallKit::check_bailout(RegionNode* bailout) {
  886   if (bailout->req() > 1) {
  887     bailout = _gvn.transform(bailout)->as_Region();
  888     Node* frame = _gvn.transform(new ParmNode(C->start(), TypeFunc::FramePtr));
  889     Node* halt = _gvn.transform(new HaltNode(bailout, frame, "unexpected guard failure in intrinsic"));
  890     C->root()->add_req(halt);
  891   }
  892   return stopped();
  893 }
  894 
  895 //------------------------------generate_guard---------------------------
  896 // Helper function for generating guarded fast-slow graph structures.
  897 // The given 'test', if true, guards a slow path.  If the test fails
  898 // then a fast path can be taken.  (We generally hope it fails.)
  899 // In all cases, GraphKit::control() is updated to the fast path.
  900 // The returned value represents the control for the slow path.
  901 // The return value is never 'top'; it is either a valid control
  902 // or null if it is obvious that the slow path can never be taken.
  903 // Also, if region and the slow control are not null, the slow edge
  904 // is appended to the region.
  905 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) {
  906   if (stopped()) {
  907     // Already short circuited.
  908     return nullptr;
  909   }
  910 
  911   // Build an if node and its projections.
  912   // If test is true we take the slow path, which we assume is uncommon.
  913   if (_gvn.type(test) == TypeInt::ZERO) {
  914     // The slow branch is never taken.  No need to build this guard.
  915     return nullptr;
  916   }
  917 
  918   IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
  919 
  920   Node* if_slow = _gvn.transform(new IfTrueNode(iff));
  921   if (if_slow == top()) {
  922     // The slow branch is never taken.  No need to build this guard.
  923     return nullptr;
  924   }
  925 
  926   if (region != nullptr)
  927     region->add_req(if_slow);
  928 
  929   Node* if_fast = _gvn.transform(new IfFalseNode(iff));
  930   set_control(if_fast);
  931 
  932   return if_slow;
  933 }
  934 
  935 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) {
  936   return generate_guard(test, region, PROB_UNLIKELY_MAG(3));
  937 }
  938 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) {
  939   return generate_guard(test, region, PROB_FAIR);
  940 }
  941 
  942 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region,
  943                                                      Node** pos_index, bool with_opaque) {
  944   if (stopped())
  945     return nullptr;                // already stopped
  946   if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
  947     return nullptr;                // index is already adequately typed
  948   Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0)));
  949   Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
  950   if (with_opaque) {
  951     bol_lt = _gvn.transform(new OpaqueConstantBoolNode(C, bol_lt, false));
  952   }
  953   Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
  954   if (is_neg != nullptr && pos_index != nullptr) {
  955     // Emulate effect of Parse::adjust_map_after_if.
  956     Node* ccast = new CastIINode(control(), index, TypeInt::POS);
  957     (*pos_index) = _gvn.transform(ccast);
  958   }
  959   return is_neg;
  960 }
  961 
  962 // Make sure that 'position' is a valid limit index, in [0..length].
  963 // There are two equivalent plans for checking this:
  964 //   A. (offset + copyLength)  unsigned<=  arrayLength
  965 //   B. offset  <=  (arrayLength - copyLength)
  966 // We require that all of the values above, except for the sum and
  967 // difference, are already known to be non-negative.
  968 // Plan A is robust in the face of overflow, if offset and copyLength
  969 // are both hugely positive.
  970 //
  971 // Plan B is less direct and intuitive, but it does not overflow at
  972 // all, since the difference of two non-negatives is always
  973 // representable.  Whenever Java methods must perform the equivalent
  974 // check they generally use Plan B instead of Plan A.
  975 // For the moment we use Plan A.
  976 inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
  977                                                   Node* subseq_length,
  978                                                   Node* array_length,
  979                                                   RegionNode* region,
  980                                                   bool with_opaque) {
  981   if (stopped())
  982     return nullptr;                // already stopped
  983   bool zero_offset = _gvn.type(offset) == TypeInt::ZERO;
  984   if (zero_offset && subseq_length->eqv_uncast(array_length))
  985     return nullptr;                // common case of whole-array copy
  986   Node* last = subseq_length;
  987   if (!zero_offset)             // last += offset
  988     last = _gvn.transform(new AddINode(last, offset));
  989   Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last));
  990   Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
  991   if (with_opaque) {
  992     bol_lt = _gvn.transform(new OpaqueConstantBoolNode(C, bol_lt, false));
  993   }
  994   Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
  995   return is_over;
  996 }
  997 
  998 // Emit range checks for the given String.value byte array
  999 void LibraryCallKit::generate_string_range_check(Node* array,
 1000                                                  Node* offset,
 1001                                                  Node* count,
 1002                                                  bool char_count,
 1003                                                  RegionNode* region) {
 1004   if (stopped()) {
 1005     return; // already stopped
 1006   }
 1007   if (char_count) {
 1008     // Convert char count to byte count
 1009     count = _gvn.transform(new LShiftINode(count, intcon(1)));
 1010   }
 1011   // Offset and count must not be negative
 1012   generate_negative_guard(offset, region, nullptr, true);
 1013   generate_negative_guard(count, region, nullptr, true);
 1014   // Offset + count must not exceed length of array
 1015   generate_limit_guard(offset, count, load_array_length(array), region, true);
 1016 }
 1017 
 1018 Node* LibraryCallKit::current_thread_helper(Node*& tls_output, ByteSize handle_offset,
 1019                                             bool is_immutable) {
 1020   ciKlass* thread_klass = env()->Thread_klass();
 1021   const Type* thread_type
 1022     = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
 1023 
 1024   Node* thread = _gvn.transform(new ThreadLocalNode());
 1025   Node* p = off_heap_plus_addr(thread, in_bytes(handle_offset));
 1026   tls_output = thread;
 1027 
 1028   Node* thread_obj_handle
 1029     = (is_immutable
 1030       ? LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
 1031         TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered)
 1032       : make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered));
 1033   thread_obj_handle = _gvn.transform(thread_obj_handle);
 1034 
 1035   DecoratorSet decorators = IN_NATIVE;
 1036   if (is_immutable) {
 1037     decorators |= C2_IMMUTABLE_MEMORY;
 1038   }
 1039   return access_load(thread_obj_handle, thread_type, T_OBJECT, decorators);
 1040 }
 1041 
 1042 //--------------------------generate_current_thread--------------------
 1043 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) {
 1044   return current_thread_helper(tls_output, JavaThread::threadObj_offset(),
 1045                                /*is_immutable*/false);
 1046 }
 1047 
 1048 //--------------------------generate_virtual_thread--------------------
 1049 Node* LibraryCallKit::generate_virtual_thread(Node* tls_output) {
 1050   return current_thread_helper(tls_output, JavaThread::vthread_offset(),
 1051                                !C->method()->changes_current_thread());
 1052 }
 1053 
 1054 //------------------------------make_string_method_node------------------------
 1055 // Helper method for String intrinsic functions. This version is called with
 1056 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded
 1057 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes
 1058 // containing the lengths of str1 and str2.
 1059 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) {
 1060   Node* result = nullptr;
 1061   switch (opcode) {
 1062   case Op_StrIndexOf:
 1063     result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES),
 1064                                 str1_start, cnt1, str2_start, cnt2, ae);
 1065     break;
 1066   case Op_StrComp:
 1067     result = new StrCompNode(control(), memory(TypeAryPtr::BYTES),
 1068                              str1_start, cnt1, str2_start, cnt2, ae);
 1069     break;
 1070   case Op_StrEquals:
 1071     // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals').
 1072     // Use the constant length if there is one because optimized match rule may exist.
 1073     result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES),
 1074                                str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae);
 1075     break;
 1076   default:
 1077     ShouldNotReachHere();
 1078     return nullptr;
 1079   }
 1080 
 1081   // All these intrinsics have checks.
 1082   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1083   clear_upper_avx();
 1084 
 1085   return _gvn.transform(result);
 1086 }
 1087 
 1088 //------------------------------inline_string_compareTo------------------------
 1089 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) {
 1090   Node* arg1 = argument(0);
 1091   Node* arg2 = argument(1);
 1092 
 1093   arg1 = must_be_not_null(arg1, true);
 1094   arg2 = must_be_not_null(arg2, true);
 1095 
 1096   // Get start addr and length of first argument
 1097   Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
 1098   Node* arg1_cnt    = load_array_length(arg1);
 1099 
 1100   // Get start addr and length of second argument
 1101   Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
 1102   Node* arg2_cnt    = load_array_length(arg2);
 1103 
 1104   Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
 1105   set_result(result);
 1106   return true;
 1107 }
 1108 
 1109 //------------------------------inline_string_equals------------------------
 1110 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) {
 1111   Node* arg1 = argument(0);
 1112   Node* arg2 = argument(1);
 1113 
 1114   // paths (plus control) merge
 1115   RegionNode* region = new RegionNode(3);
 1116   Node* phi = new PhiNode(region, TypeInt::BOOL);
 1117 
 1118   if (!stopped()) {
 1119 
 1120     arg1 = must_be_not_null(arg1, true);
 1121     arg2 = must_be_not_null(arg2, true);
 1122 
 1123     // Get start addr and length of first argument
 1124     Node* arg1_start  = array_element_address(arg1, intcon(0), T_BYTE);
 1125     Node* arg1_cnt    = load_array_length(arg1);
 1126 
 1127     // Get start addr and length of second argument
 1128     Node* arg2_start  = array_element_address(arg2, intcon(0), T_BYTE);
 1129     Node* arg2_cnt    = load_array_length(arg2);
 1130 
 1131     // Check for arg1_cnt != arg2_cnt
 1132     Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt));
 1133     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
 1134     Node* if_ne = generate_slow_guard(bol, nullptr);
 1135     if (if_ne != nullptr) {
 1136       phi->init_req(2, intcon(0));
 1137       region->init_req(2, if_ne);
 1138     }
 1139 
 1140     // Check for count == 0 is done by assembler code for StrEquals.
 1141 
 1142     if (!stopped()) {
 1143       Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
 1144       phi->init_req(1, equals);
 1145       region->init_req(1, control());
 1146     }
 1147   }
 1148 
 1149   // post merge
 1150   set_control(_gvn.transform(region));
 1151   record_for_igvn(region);
 1152 
 1153   set_result(_gvn.transform(phi));
 1154   return true;
 1155 }
 1156 
 1157 //------------------------------inline_array_equals----------------------------
 1158 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
 1159   assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types");
 1160   Node* arg1 = argument(0);
 1161   Node* arg2 = argument(1);
 1162 
 1163   const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES;
 1164   set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), mtype, arg1, arg2, ae)));
 1165   clear_upper_avx();
 1166 
 1167   return true;
 1168 }
 1169 
 1170 
 1171 //------------------------------inline_countPositives------------------------------
 1172 // int java.lang.StringCoding#countPositives0(byte[] ba, int off, int len)
 1173 bool LibraryCallKit::inline_countPositives() {
 1174   assert(callee()->signature()->size() == 3, "countPositives has 3 parameters");
 1175   // no receiver since it is static method
 1176   Node* ba         = argument(0);
 1177   Node* offset     = argument(1);
 1178   Node* len        = argument(2);
 1179 
 1180   ba = must_be_not_null(ba, true);
 1181   RegionNode* bailout = create_bailout();
 1182   generate_string_range_check(ba, offset, len, false, bailout);
 1183   if (check_bailout(bailout)) {
 1184     return true;
 1185   }
 1186 
 1187   Node* ba_start = array_element_address(ba, offset, T_BYTE);
 1188   Node* result = new CountPositivesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len);
 1189   set_result(_gvn.transform(result));
 1190   clear_upper_avx();
 1191   return true;
 1192 }
 1193 
 1194 bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) {
 1195   Node* index = argument(0);
 1196   Node* length = bt == T_INT ? argument(1) : argument(2);
 1197   if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) {
 1198     return false;
 1199   }
 1200 
 1201   // check that length is positive
 1202   Node* len_pos_cmp = _gvn.transform(CmpNode::make(length, integercon(0, bt), bt));
 1203   Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge));
 1204 
 1205   {
 1206     BuildCutout unless(this, len_pos_bol, PROB_MAX);
 1207     uncommon_trap(Deoptimization::Reason_intrinsic,
 1208                   Deoptimization::Action_make_not_entrant);
 1209   }
 1210 
 1211   if (stopped()) {
 1212     // Length is known to be always negative during compilation and the IR graph so far constructed is good so return success
 1213     return true;
 1214   }
 1215 
 1216   // length is now known positive, add a cast node to make this explicit
 1217   jlong upper_bound = _gvn.type(length)->is_integer(bt)->hi_as_long();
 1218   Node* casted_length = ConstraintCastNode::make_cast_for_basic_type(
 1219       control(), length, TypeInteger::make(0, upper_bound, Type::WidenMax, bt),
 1220       ConstraintCastNode::DependencyType::FloatingNarrowing, bt);
 1221   casted_length = _gvn.transform(casted_length);
 1222   replace_in_map(length, casted_length);
 1223   length = casted_length;
 1224 
 1225   // Use an unsigned comparison for the range check itself
 1226   Node* rc_cmp = _gvn.transform(CmpNode::make(index, length, bt, true));
 1227   BoolTest::mask btest = BoolTest::lt;
 1228   Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest));
 1229   RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN);
 1230   _gvn.set_type(rc, rc->Value(&_gvn));
 1231   if (!rc_bool->is_Con()) {
 1232     record_for_igvn(rc);
 1233   }
 1234   set_control(_gvn.transform(new IfTrueNode(rc)));
 1235   {
 1236     PreserveJVMState pjvms(this);
 1237     set_control(_gvn.transform(new IfFalseNode(rc)));
 1238     uncommon_trap(Deoptimization::Reason_range_check,
 1239                   Deoptimization::Action_make_not_entrant);
 1240   }
 1241 
 1242   if (stopped()) {
 1243     // Range check is known to always fail during compilation and the IR graph so far constructed is good so return success
 1244     return true;
 1245   }
 1246 
 1247   // index is now known to be >= 0 and < length, cast it
 1248   Node* result = ConstraintCastNode::make_cast_for_basic_type(
 1249       control(), index, TypeInteger::make(0, upper_bound, Type::WidenMax, bt),
 1250       ConstraintCastNode::DependencyType::FloatingNarrowing, bt);
 1251   result = _gvn.transform(result);
 1252   set_result(result);
 1253   replace_in_map(index, result);
 1254   return true;
 1255 }
 1256 
 1257 //------------------------------inline_string_indexOf------------------------
 1258 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) {
 1259   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
 1260     return false;
 1261   }
 1262   Node* src = argument(0);
 1263   Node* tgt = argument(1);
 1264 
 1265   // Make the merge point
 1266   RegionNode* result_rgn = new RegionNode(4);
 1267   Node*       result_phi = new PhiNode(result_rgn, TypeInt::INT);
 1268 
 1269   src = must_be_not_null(src, true);
 1270   tgt = must_be_not_null(tgt, true);
 1271 
 1272   // Get start addr and length of source string
 1273   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 1274   Node* src_count = load_array_length(src);
 1275 
 1276   // Get start addr and length of substring
 1277   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
 1278   Node* tgt_count = load_array_length(tgt);
 1279 
 1280   Node* result = nullptr;
 1281   bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr);
 1282 
 1283   if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) {
 1284     // Divide src size by 2 if String is UTF16 encoded
 1285     src_count = _gvn.transform(new RShiftINode(src_count, intcon(1)));
 1286   }
 1287   if (ae == StrIntrinsicNode::UU) {
 1288     // Divide substring size by 2 if String is UTF16 encoded
 1289     tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1)));
 1290   }
 1291 
 1292   if (call_opt_stub) {
 1293     Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(),
 1294                                    StubRoutines::_string_indexof_array[ae],
 1295                                    "stringIndexOf", TypePtr::BOTTOM, src_start,
 1296                                    src_count, tgt_start, tgt_count);
 1297     result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 1298   } else {
 1299     result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count,
 1300                                result_rgn, result_phi, ae);
 1301   }
 1302   if (result != nullptr) {
 1303     result_phi->init_req(3, result);
 1304     result_rgn->init_req(3, control());
 1305   }
 1306   set_control(_gvn.transform(result_rgn));
 1307   record_for_igvn(result_rgn);
 1308   set_result(_gvn.transform(result_phi));
 1309 
 1310   return true;
 1311 }
 1312 
 1313 //-----------------------------inline_string_indexOfI-----------------------
 1314 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) {
 1315   if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
 1316     return false;
 1317   }
 1318 
 1319   assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments");
 1320   Node* src         = argument(0); // byte[]
 1321   Node* src_count   = argument(1); // char count
 1322   Node* tgt         = argument(2); // byte[]
 1323   Node* tgt_count   = argument(3); // char count
 1324   Node* from_index  = argument(4); // char index
 1325 
 1326   src = must_be_not_null(src, true);
 1327   tgt = must_be_not_null(tgt, true);
 1328 
 1329   // Multiply byte array index by 2 if String is UTF16 encoded
 1330   Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
 1331   src_count = _gvn.transform(new SubINode(src_count, from_index));
 1332   Node* src_start = array_element_address(src, src_offset, T_BYTE);
 1333   Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
 1334 
 1335   // Range checks
 1336   RegionNode* bailout = create_bailout();
 1337   generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL, bailout);
 1338   generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU, bailout);
 1339   if (check_bailout(bailout)) {
 1340     return true;
 1341   }
 1342 
 1343   RegionNode* region = new RegionNode(5);
 1344   Node* phi = new PhiNode(region, TypeInt::INT);
 1345   Node* result = nullptr;
 1346 
 1347   bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr);
 1348 
 1349   if (call_opt_stub) {
 1350     Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(),
 1351                                    StubRoutines::_string_indexof_array[ae],
 1352                                    "stringIndexOf", TypePtr::BOTTOM, src_start,
 1353                                    src_count, tgt_start, tgt_count);
 1354     result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 1355   } else {
 1356     result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count,
 1357                                region, phi, ae);
 1358   }
 1359   if (result != nullptr) {
 1360     // The result is index relative to from_index if substring was found, -1 otherwise.
 1361     // Generate code which will fold into cmove.
 1362     Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
 1363     Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
 1364 
 1365     Node* if_lt = generate_slow_guard(bol, nullptr);
 1366     if (if_lt != nullptr) {
 1367       // result == -1
 1368       phi->init_req(3, result);
 1369       region->init_req(3, if_lt);
 1370     }
 1371     if (!stopped()) {
 1372       result = _gvn.transform(new AddINode(result, from_index));
 1373       phi->init_req(4, result);
 1374       region->init_req(4, control());
 1375     }
 1376   }
 1377 
 1378   set_control(_gvn.transform(region));
 1379   record_for_igvn(region);
 1380   set_result(_gvn.transform(phi));
 1381   clear_upper_avx();
 1382 
 1383   return true;
 1384 }
 1385 
 1386 // Create StrIndexOfNode with fast path checks
 1387 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
 1388                                         RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) {
 1389   // Check for substr count > string count
 1390   Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count));
 1391   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt));
 1392   Node* if_gt = generate_slow_guard(bol, nullptr);
 1393   if (if_gt != nullptr) {
 1394     phi->init_req(1, intcon(-1));
 1395     region->init_req(1, if_gt);
 1396   }
 1397   if (!stopped()) {
 1398     // Check for substr count == 0
 1399     cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0)));
 1400     bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 1401     Node* if_zero = generate_slow_guard(bol, nullptr);
 1402     if (if_zero != nullptr) {
 1403       phi->init_req(2, intcon(0));
 1404       region->init_req(2, if_zero);
 1405     }
 1406   }
 1407   if (!stopped()) {
 1408     return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae);
 1409   }
 1410   return nullptr;
 1411 }
 1412 
 1413 //-----------------------------inline_string_indexOfChar-----------------------
 1414 bool LibraryCallKit::inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae) {
 1415   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 1416     return false;
 1417   }
 1418   if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) {
 1419     return false;
 1420   }
 1421   assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments");
 1422   Node* src         = argument(0); // byte[]
 1423   Node* int_ch      = argument(1);
 1424   Node* from_index  = argument(2);
 1425   Node* max         = argument(3);
 1426 
 1427   src = must_be_not_null(src, true);
 1428 
 1429   Node* src_offset = ae == StrIntrinsicNode::L ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
 1430   Node* src_start = array_element_address(src, src_offset, T_BYTE);
 1431   Node* src_count = _gvn.transform(new SubINode(max, from_index));
 1432 
 1433   // Range checks
 1434   RegionNode* bailout = create_bailout();
 1435   generate_string_range_check(src, src_offset, src_count, ae == StrIntrinsicNode::U, bailout);
 1436   if (check_bailout(bailout)) {
 1437     return true;
 1438   }
 1439 
 1440   // Check for int_ch >= 0
 1441   Node* int_ch_cmp = _gvn.transform(new CmpINode(int_ch, intcon(0)));
 1442   Node* int_ch_bol = _gvn.transform(new BoolNode(int_ch_cmp, BoolTest::ge));
 1443   {
 1444     BuildCutout unless(this, int_ch_bol, PROB_MAX);
 1445     uncommon_trap(Deoptimization::Reason_intrinsic,
 1446                   Deoptimization::Action_maybe_recompile);
 1447   }
 1448   if (stopped()) {
 1449     return true;
 1450   }
 1451 
 1452   RegionNode* region = new RegionNode(3);
 1453   Node* phi = new PhiNode(region, TypeInt::INT);
 1454 
 1455   Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, int_ch, ae);
 1456   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1457   _gvn.transform(result);
 1458 
 1459   Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
 1460   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
 1461 
 1462   Node* if_lt = generate_slow_guard(bol, nullptr);
 1463   if (if_lt != nullptr) {
 1464     // result == -1
 1465     phi->init_req(2, result);
 1466     region->init_req(2, if_lt);
 1467   }
 1468   if (!stopped()) {
 1469     result = _gvn.transform(new AddINode(result, from_index));
 1470     phi->init_req(1, result);
 1471     region->init_req(1, control());
 1472   }
 1473   set_control(_gvn.transform(region));
 1474   record_for_igvn(region);
 1475   set_result(_gvn.transform(phi));
 1476   clear_upper_avx();
 1477 
 1478   return true;
 1479 }
 1480 //---------------------------inline_string_copy---------------------
 1481 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[])
 1482 //   int StringUTF16.compress0(char[] src, int srcOff, byte[] dst, int dstOff, int len)
 1483 //   int StringUTF16.compress0(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
 1484 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[])
 1485 //   void StringLatin1.inflate0(byte[] src, int srcOff, char[] dst, int dstOff, int len)
 1486 //   void StringLatin1.inflate0(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
 1487 bool LibraryCallKit::inline_string_copy(bool compress) {
 1488   int nargs = 5;  // 2 oops, 3 ints
 1489   assert(callee()->signature()->size() == nargs, "string copy has 5 arguments");
 1490 
 1491   Node* src         = argument(0);
 1492   Node* src_offset  = argument(1);
 1493   Node* dst         = argument(2);
 1494   Node* dst_offset  = argument(3);
 1495   Node* length      = argument(4);
 1496 
 1497   // Check for allocation before we add nodes that would confuse
 1498   // tightly_coupled_allocation()
 1499   AllocateArrayNode* alloc = tightly_coupled_allocation(dst);
 1500 
 1501   // Figure out the size and type of the elements we will be copying.
 1502   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 1503   const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr();
 1504   if (src_type == nullptr || dst_type == nullptr) {
 1505     return false;
 1506   }
 1507   BasicType src_elem = src_type->elem()->array_element_basic_type();
 1508   BasicType dst_elem = dst_type->elem()->array_element_basic_type();
 1509   assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) ||
 1510          (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)),
 1511          "Unsupported array types for inline_string_copy");
 1512 
 1513   src = must_be_not_null(src, true);
 1514   dst = must_be_not_null(dst, true);
 1515 
 1516   // Convert char[] offsets to byte[] offsets
 1517   bool convert_src = (compress && src_elem == T_BYTE);
 1518   bool convert_dst = (!compress && dst_elem == T_BYTE);
 1519   if (convert_src) {
 1520     src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1)));
 1521   } else if (convert_dst) {
 1522     dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1)));
 1523   }
 1524 
 1525   // Range checks
 1526   RegionNode* bailout = create_bailout();
 1527   generate_string_range_check(src, src_offset, length, convert_src, bailout);
 1528   generate_string_range_check(dst, dst_offset, length, convert_dst, bailout);
 1529   if (check_bailout(bailout)) {
 1530     return true;
 1531   }
 1532 
 1533   Node* src_start = array_element_address(src, src_offset, src_elem);
 1534   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
 1535   // 'src_start' points to src array + scaled offset
 1536   // 'dst_start' points to dst array + scaled offset
 1537   Node* count = nullptr;
 1538   if (compress) {
 1539     count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length);
 1540   } else {
 1541     inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length);
 1542   }
 1543 
 1544   if (alloc != nullptr) {
 1545     if (alloc->maybe_set_complete(&_gvn)) {
 1546       // "You break it, you buy it."
 1547       InitializeNode* init = alloc->initialization();
 1548       assert(init->is_complete(), "we just did this");
 1549       init->set_complete_with_arraycopy();
 1550       assert(dst->is_CheckCastPP(), "sanity");
 1551       assert(dst->in(0)->in(0) == init, "dest pinned");
 1552     }
 1553     // Do not let stores that initialize this object be reordered with
 1554     // a subsequent store that would make this object accessible by
 1555     // other threads.
 1556     // Record what AllocateNode this StoreStore protects so that
 1557     // escape analysis can go from the MemBarStoreStoreNode to the
 1558     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1559     // based on the escape status of the AllocateNode.
 1560     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1561   }
 1562   if (compress) {
 1563     set_result(_gvn.transform(count));
 1564   }
 1565   clear_upper_avx();
 1566 
 1567   return true;
 1568 }
 1569 
 1570 #ifdef _LP64
 1571 #define XTOP ,top() /*additional argument*/
 1572 #else  //_LP64
 1573 #define XTOP        /*no additional argument*/
 1574 #endif //_LP64
 1575 
 1576 //------------------------inline_string_toBytesU--------------------------
 1577 // public static byte[] StringUTF16.toBytes0(char[] value, int off, int len)
 1578 bool LibraryCallKit::inline_string_toBytesU() {
 1579   // Get the arguments.
 1580   assert(callee()->signature()->size() == 3, "character array encoder requires 3 arguments");
 1581   Node* value     = argument(0);
 1582   Node* offset    = argument(1);
 1583   Node* length    = argument(2);
 1584 
 1585   Node* newcopy = nullptr;
 1586 
 1587   // Set the original stack and the reexecute bit for the interpreter to reexecute
 1588   // the bytecode that invokes StringUTF16.toBytes0() if deoptimization happens.
 1589   { PreserveReexecuteState preexecs(this);
 1590     jvms()->set_should_reexecute(true);
 1591 
 1592     value = must_be_not_null(value, true);
 1593     RegionNode* bailout = create_bailout();
 1594     generate_negative_guard(offset, bailout, nullptr, true);
 1595     generate_negative_guard(length, bailout, nullptr, true);
 1596     generate_limit_guard(offset, length, load_array_length(value), bailout, true);
 1597     // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE
 1598     generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout, true);
 1599     if (check_bailout(bailout)) {
 1600       return true;
 1601     }
 1602 
 1603     Node* size = _gvn.transform(new LShiftINode(length, intcon(1)));
 1604     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE)));
 1605     newcopy = new_array(klass_node, size, 0);  // no arguments to push
 1606     AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy);
 1607     guarantee(alloc != nullptr, "created above");
 1608 
 1609     // Calculate starting addresses.
 1610     Node* src_start = array_element_address(value, offset, T_CHAR);
 1611     Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE));
 1612 
 1613     // Check if dst array address is aligned to HeapWordSize
 1614     bool aligned = (arrayOopDesc::base_offset_in_bytes(T_BYTE) % HeapWordSize == 0);
 1615     // If true, then check if src array address is aligned to HeapWordSize
 1616     if (aligned) {
 1617       const TypeInt* toffset = gvn().type(offset)->is_int();
 1618       aligned = toffset->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) +
 1619                                        toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
 1620     }
 1621 
 1622     // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
 1623     const char* copyfunc_name = "arraycopy";
 1624     address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
 1625     Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 1626                       OptoRuntime::fast_arraycopy_Type(),
 1627                       copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
 1628                       src_start, dst_start, ConvI2X(length) XTOP);
 1629     // Do not let reads from the cloned object float above the arraycopy.
 1630     if (alloc->maybe_set_complete(&_gvn)) {
 1631       // "You break it, you buy it."
 1632       InitializeNode* init = alloc->initialization();
 1633       assert(init->is_complete(), "we just did this");
 1634       init->set_complete_with_arraycopy();
 1635       assert(newcopy->is_CheckCastPP(), "sanity");
 1636       assert(newcopy->in(0)->in(0) == init, "dest pinned");
 1637     }
 1638     // Do not let stores that initialize this object be reordered with
 1639     // a subsequent store that would make this object accessible by
 1640     // other threads.
 1641     // Record what AllocateNode this StoreStore protects so that
 1642     // escape analysis can go from the MemBarStoreStoreNode to the
 1643     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1644     // based on the escape status of the AllocateNode.
 1645     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1646   } // original reexecute is set back here
 1647 
 1648   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1649   if (!stopped()) {
 1650     set_result(newcopy);
 1651   }
 1652   clear_upper_avx();
 1653 
 1654   return true;
 1655 }
 1656 
 1657 //------------------------inline_string_getCharsU--------------------------
 1658 // public void StringUTF16.getChars0(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin)
 1659 bool LibraryCallKit::inline_string_getCharsU() {
 1660   assert(callee()->signature()->size() == 5, "StringUTF16.getChars0() has 5 arguments");
 1661   // Get the arguments.
 1662   Node* src       = argument(0);
 1663   Node* src_begin = argument(1);
 1664   Node* src_end   = argument(2); // exclusive offset (i < src_end)
 1665   Node* dst       = argument(3);
 1666   Node* dst_begin = argument(4);
 1667 
 1668   // Check for allocation before we add nodes that would confuse
 1669   // tightly_coupled_allocation()
 1670   AllocateArrayNode* alloc = tightly_coupled_allocation(dst);
 1671 
 1672   // Check if a null path was taken unconditionally.
 1673   src = must_be_not_null(src, true);
 1674   dst = must_be_not_null(dst, true);
 1675   if (stopped()) {
 1676     return true;
 1677   }
 1678 
 1679   // Get length and convert char[] offset to byte[] offset
 1680   Node* length = _gvn.transform(new SubINode(src_end, src_begin));
 1681   src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1)));
 1682 
 1683   // Range checks
 1684   RegionNode* bailout = create_bailout();
 1685   generate_string_range_check(src, src_begin, length, true, bailout);
 1686   generate_string_range_check(dst, dst_begin, length, false, bailout);
 1687   if (check_bailout(bailout)) {
 1688     return true;
 1689   }
 1690 
 1691   // Calculate starting addresses.
 1692   Node* src_start = array_element_address(src, src_begin, T_BYTE);
 1693   Node* dst_start = array_element_address(dst, dst_begin, T_CHAR);
 1694 
 1695   // Check if array addresses are aligned to HeapWordSize
 1696   const TypeInt* tsrc = gvn().type(src_begin)->is_int();
 1697   const TypeInt* tdst = gvn().type(dst_begin)->is_int();
 1698   bool aligned = tsrc->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_BYTE) + tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) &&
 1699                  tdst->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) + tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
 1700 
 1701   // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
 1702   const char* copyfunc_name = "arraycopy";
 1703   address     copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
 1704   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 1705                     OptoRuntime::fast_arraycopy_Type(),
 1706                     copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
 1707                     src_start, dst_start, ConvI2X(length) XTOP);
 1708   // Do not let reads from the cloned object float above the arraycopy.
 1709   if (alloc != nullptr) {
 1710     if (alloc->maybe_set_complete(&_gvn)) {
 1711       // "You break it, you buy it."
 1712       InitializeNode* init = alloc->initialization();
 1713       assert(init->is_complete(), "we just did this");
 1714       init->set_complete_with_arraycopy();
 1715       assert(dst->is_CheckCastPP(), "sanity");
 1716       assert(dst->in(0)->in(0) == init, "dest pinned");
 1717     }
 1718     // Do not let stores that initialize this object be reordered with
 1719     // a subsequent store that would make this object accessible by
 1720     // other threads.
 1721     // Record what AllocateNode this StoreStore protects so that
 1722     // escape analysis can go from the MemBarStoreStoreNode to the
 1723     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 1724     // based on the escape status of the AllocateNode.
 1725     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 1726   } else {
 1727     insert_mem_bar(Op_MemBarCPUOrder);
 1728   }
 1729 
 1730   C->set_has_split_ifs(true); // Has chance for split-if optimization
 1731   return true;
 1732 }
 1733 
 1734 //----------------------inline_string_char_access----------------------------
 1735 // Store/Load char to/from byte[] array.
 1736 // static void StringUTF16.putChar(byte[] val, int index, int c)
 1737 // static char StringUTF16.getChar(byte[] val, int index)
 1738 bool LibraryCallKit::inline_string_char_access(bool is_store) {
 1739   Node* ch;
 1740   if (is_store) {
 1741     assert(callee()->signature()->size() == 3, "StringUTF16.putChar() has 3 arguments");
 1742     ch = argument(2);
 1743   } else {
 1744     assert(callee()->signature()->size() == 2, "StringUTF16.getChar() has 2 arguments");
 1745     ch = nullptr;
 1746   }
 1747   Node* value  = argument(0);
 1748   Node* index  = argument(1);
 1749 
 1750   // This intrinsic accesses byte[] array as char[] array. Computing the offsets
 1751   // correctly requires matched array shapes.
 1752   assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE),
 1753           "sanity: byte[] and char[] bases agree");
 1754   assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2,
 1755           "sanity: byte[] and char[] scales agree");
 1756 
 1757   // Bail when getChar over constants is requested: constant folding would
 1758   // reject folding mismatched char access over byte[]. A normal inlining for getChar
 1759   // Java method would constant fold nicely instead.
 1760   if (!is_store && value->is_Con() && index->is_Con()) {
 1761     return false;
 1762   }
 1763 
 1764   // Save state and restore on bailout
 1765   SavedState old_state(this);
 1766 
 1767   value = must_be_not_null(value, true);
 1768 
 1769   Node* adr = array_element_address(value, index, T_CHAR);
 1770   if (adr->is_top()) {
 1771     return false;
 1772   }
 1773   old_state.discard();
 1774   if (is_store) {
 1775     access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED);
 1776   } else {
 1777     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);
 1778     set_result(ch);
 1779   }
 1780   return true;
 1781 }
 1782 
 1783 
 1784 //------------------------------inline_math-----------------------------------
 1785 // public static double Math.abs(double)
 1786 // public static double Math.sqrt(double)
 1787 // public static double Math.log(double)
 1788 // public static double Math.log10(double)
 1789 // public static double Math.round(double)
 1790 bool LibraryCallKit::inline_double_math(vmIntrinsics::ID id) {
 1791   Node* arg = argument(0);
 1792   Node* n = nullptr;
 1793   switch (id) {
 1794   case vmIntrinsics::_dabs:   n = new AbsDNode(                arg);  break;
 1795   case vmIntrinsics::_dsqrt:
 1796   case vmIntrinsics::_dsqrt_strict:
 1797                               n = new SqrtDNode(C, control(),  arg);  break;
 1798   case vmIntrinsics::_ceil:   n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_ceil); break;
 1799   case vmIntrinsics::_floor:  n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_floor); break;
 1800   case vmIntrinsics::_rint:   n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_rint); break;
 1801   case vmIntrinsics::_roundD: n = new RoundDNode(arg); break;
 1802   case vmIntrinsics::_dcopySign: n = CopySignDNode::make(_gvn, arg, argument(2)); break;
 1803   case vmIntrinsics::_dsignum: n = SignumDNode::make(_gvn, arg); break;
 1804   default:  fatal_unexpected_iid(id);  break;
 1805   }
 1806   set_result(_gvn.transform(n));
 1807   return true;
 1808 }
 1809 
 1810 //------------------------------inline_math-----------------------------------
 1811 // public static float Math.abs(float)
 1812 // public static int Math.abs(int)
 1813 // public static long Math.abs(long)
 1814 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) {
 1815   Node* arg = argument(0);
 1816   Node* n = nullptr;
 1817   switch (id) {
 1818   case vmIntrinsics::_fabs:   n = new AbsFNode(                arg);  break;
 1819   case vmIntrinsics::_iabs:   n = new AbsINode(                arg);  break;
 1820   case vmIntrinsics::_labs:   n = new AbsLNode(                arg);  break;
 1821   case vmIntrinsics::_fcopySign: n = new CopySignFNode(arg, argument(1)); break;
 1822   case vmIntrinsics::_fsignum: n = SignumFNode::make(_gvn, arg); break;
 1823   case vmIntrinsics::_roundF: n = new RoundFNode(arg); break;
 1824   default:  fatal_unexpected_iid(id);  break;
 1825   }
 1826   set_result(_gvn.transform(n));
 1827   return true;
 1828 }
 1829 
 1830 //------------------------------runtime_math-----------------------------
 1831 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
 1832   assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(),
 1833          "must be (DD)D or (D)D type");
 1834 
 1835   // Inputs
 1836   Node* a = argument(0);
 1837   Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? argument(2) : nullptr;
 1838 
 1839   const TypePtr* no_memory_effects = nullptr;
 1840   Node* trig = make_runtime_call(RC_LEAF | RC_PURE, call_type, funcAddr, funcName,
 1841                                  no_memory_effects,
 1842                                  a, top(), b, b ? top() : nullptr);
 1843   Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0));
 1844 #ifdef ASSERT
 1845   Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1));
 1846   assert(value_top == top(), "second value must be top");
 1847 #endif
 1848 
 1849   set_result(value);
 1850   return true;
 1851 }
 1852 
 1853 //------------------------------inline_math_pow-----------------------------
 1854 bool LibraryCallKit::inline_math_pow() {
 1855   Node* base = argument(0);
 1856   Node* exp = argument(2);
 1857 
 1858   CallNode* pow = new PowDNode(C, base, exp);
 1859   set_predefined_input_for_runtime_call(pow);
 1860   pow = _gvn.transform(pow)->as_CallLeafPure();
 1861   set_predefined_output_for_runtime_call(pow);
 1862   Node* result = _gvn.transform(new ProjNode(pow, TypeFunc::Parms + 0));
 1863   record_for_igvn(pow);
 1864   set_result(result);
 1865   return true;
 1866 }
 1867 
 1868 //------------------------------inline_math_native-----------------------------
 1869 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
 1870   switch (id) {
 1871   case vmIntrinsics::_dsin:
 1872     return StubRoutines::dsin() != nullptr ?
 1873       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") :
 1874       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin),   "SIN");
 1875   case vmIntrinsics::_dcos:
 1876     return StubRoutines::dcos() != nullptr ?
 1877       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") :
 1878       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos),   "COS");
 1879   case vmIntrinsics::_dtan:
 1880     return StubRoutines::dtan() != nullptr ?
 1881       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") :
 1882       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN");
 1883   case vmIntrinsics::_dsinh:
 1884     return StubRoutines::dsinh() != nullptr ?
 1885       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsinh(), "dsinh") : false;
 1886   case vmIntrinsics::_dtanh:
 1887     return StubRoutines::dtanh() != nullptr ?
 1888       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtanh(), "dtanh") : false;
 1889   case vmIntrinsics::_dcbrt:
 1890     return StubRoutines::dcbrt() != nullptr ?
 1891       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcbrt(), "dcbrt") : false;
 1892   case vmIntrinsics::_dexp:
 1893     return StubRoutines::dexp() != nullptr ?
 1894       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(),  "dexp") :
 1895       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp),  "EXP");
 1896   case vmIntrinsics::_dlog:
 1897     return StubRoutines::dlog() != nullptr ?
 1898       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") :
 1899       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog),   "LOG");
 1900   case vmIntrinsics::_dlog10:
 1901     return StubRoutines::dlog10() != nullptr ?
 1902       runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") :
 1903       runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10");
 1904 
 1905   case vmIntrinsics::_roundD: return Matcher::match_rule_supported(Op_RoundD) ? inline_double_math(id) : false;
 1906   case vmIntrinsics::_ceil:
 1907   case vmIntrinsics::_floor:
 1908   case vmIntrinsics::_rint:   return Matcher::match_rule_supported(Op_RoundDoubleMode) ? inline_double_math(id) : false;
 1909 
 1910   case vmIntrinsics::_dsqrt:
 1911   case vmIntrinsics::_dsqrt_strict:
 1912                               return Matcher::match_rule_supported(Op_SqrtD) ? inline_double_math(id) : false;
 1913   case vmIntrinsics::_dabs:   return Matcher::has_match_rule(Op_AbsD)   ? inline_double_math(id) : false;
 1914   case vmIntrinsics::_fabs:   return Matcher::match_rule_supported(Op_AbsF)   ? inline_math(id) : false;
 1915   case vmIntrinsics::_iabs:   return Matcher::match_rule_supported(Op_AbsI)   ? inline_math(id) : false;
 1916   case vmIntrinsics::_labs:   return Matcher::match_rule_supported(Op_AbsL)   ? inline_math(id) : false;
 1917 
 1918   case vmIntrinsics::_dpow:      return inline_math_pow();
 1919   case vmIntrinsics::_dcopySign: return inline_double_math(id);
 1920   case vmIntrinsics::_fcopySign: return inline_math(id);
 1921   case vmIntrinsics::_dsignum: return Matcher::match_rule_supported(Op_SignumD) ? inline_double_math(id) : false;
 1922   case vmIntrinsics::_fsignum: return Matcher::match_rule_supported(Op_SignumF) ? inline_math(id) : false;
 1923   case vmIntrinsics::_roundF: return Matcher::match_rule_supported(Op_RoundF) ? inline_math(id) : false;
 1924 
 1925    // These intrinsics are not yet correctly implemented
 1926   case vmIntrinsics::_datan2:
 1927     return false;
 1928 
 1929   default:
 1930     fatal_unexpected_iid(id);
 1931     return false;
 1932   }
 1933 }
 1934 
 1935 //----------------------------inline_notify-----------------------------------*
 1936 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) {
 1937   const TypeFunc* ftype = OptoRuntime::monitor_notify_Type();
 1938   address func;
 1939   if (id == vmIntrinsics::_notify) {
 1940     func = OptoRuntime::monitor_notify_Java();
 1941   } else {
 1942     func = OptoRuntime::monitor_notifyAll_Java();
 1943   }
 1944   Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, nullptr, TypeRawPtr::BOTTOM, argument(0));
 1945   make_slow_call_ex(call, env()->Throwable_klass(), false);
 1946   return true;
 1947 }
 1948 
 1949 
 1950 //----------------------------inline_min_max-----------------------------------
 1951 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
 1952   Node* a = nullptr;
 1953   Node* b = nullptr;
 1954   Node* n = nullptr;
 1955   switch (id) {
 1956     case vmIntrinsics::_min:
 1957     case vmIntrinsics::_max:
 1958     case vmIntrinsics::_minF:
 1959     case vmIntrinsics::_maxF:
 1960     case vmIntrinsics::_minF_strict:
 1961     case vmIntrinsics::_maxF_strict:
 1962     case vmIntrinsics::_min_strict:
 1963     case vmIntrinsics::_max_strict:
 1964       assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each.");
 1965       a = argument(0);
 1966       b = argument(1);
 1967       break;
 1968     case vmIntrinsics::_minD:
 1969     case vmIntrinsics::_maxD:
 1970     case vmIntrinsics::_minD_strict:
 1971     case vmIntrinsics::_maxD_strict:
 1972       assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each.");
 1973       a = argument(0);
 1974       b = argument(2);
 1975       break;
 1976     case vmIntrinsics::_minL:
 1977     case vmIntrinsics::_maxL:
 1978       assert(callee()->signature()->size() == 4, "minL/maxL has 2 parameters of size 2 each.");
 1979       a = argument(0);
 1980       b = argument(2);
 1981       break;
 1982     default:
 1983       fatal_unexpected_iid(id);
 1984       break;
 1985   }
 1986 
 1987   switch (id) {
 1988     case vmIntrinsics::_min:
 1989     case vmIntrinsics::_min_strict:
 1990       n = new MinINode(a, b);
 1991       break;
 1992     case vmIntrinsics::_max:
 1993     case vmIntrinsics::_max_strict:
 1994       n = new MaxINode(a, b);
 1995       break;
 1996     case vmIntrinsics::_minF:
 1997     case vmIntrinsics::_minF_strict:
 1998       n = new MinFNode(a, b);
 1999       break;
 2000     case vmIntrinsics::_maxF:
 2001     case vmIntrinsics::_maxF_strict:
 2002       n = new MaxFNode(a, b);
 2003       break;
 2004     case vmIntrinsics::_minD:
 2005     case vmIntrinsics::_minD_strict:
 2006       n = new MinDNode(a, b);
 2007       break;
 2008     case vmIntrinsics::_maxD:
 2009     case vmIntrinsics::_maxD_strict:
 2010       n = new MaxDNode(a, b);
 2011       break;
 2012     case vmIntrinsics::_minL:
 2013       n = new MinLNode(_gvn.C, a, b);
 2014       break;
 2015     case vmIntrinsics::_maxL:
 2016       n = new MaxLNode(_gvn.C, a, b);
 2017       break;
 2018     default:
 2019       fatal_unexpected_iid(id);
 2020       break;
 2021   }
 2022 
 2023   set_result(_gvn.transform(n));
 2024   return true;
 2025 }
 2026 
 2027 bool LibraryCallKit::inline_math_mathExact(Node* math, Node* test) {
 2028   if (builtin_throw_too_many_traps(Deoptimization::Reason_intrinsic,
 2029                                    env()->ArithmeticException_instance())) {
 2030     // It has been already too many times, but we cannot use builtin_throw (e.g. we care about backtraces),
 2031     // so let's bail out intrinsic rather than risking deopting again.
 2032     return false;
 2033   }
 2034 
 2035   Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) );
 2036   IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
 2037   Node* fast_path = _gvn.transform( new IfFalseNode(check));
 2038   Node* slow_path = _gvn.transform( new IfTrueNode(check) );
 2039 
 2040   {
 2041     PreserveJVMState pjvms(this);
 2042     PreserveReexecuteState preexecs(this);
 2043     jvms()->set_should_reexecute(true);
 2044 
 2045     set_control(slow_path);
 2046     set_i_o(i_o());
 2047 
 2048     builtin_throw(Deoptimization::Reason_intrinsic,
 2049                   env()->ArithmeticException_instance(),
 2050                   /*allow_too_many_traps*/ false);
 2051   }
 2052 
 2053   set_control(fast_path);
 2054   set_result(math);
 2055   return true;
 2056 }
 2057 
 2058 template <typename OverflowOp>
 2059 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) {
 2060   typedef typename OverflowOp::MathOp MathOp;
 2061 
 2062   MathOp* mathOp = new MathOp(arg1, arg2);
 2063   Node* operation = _gvn.transform( mathOp );
 2064   Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) );
 2065   return inline_math_mathExact(operation, ofcheck);
 2066 }
 2067 
 2068 bool LibraryCallKit::inline_math_addExactI(bool is_increment) {
 2069   return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1));
 2070 }
 2071 
 2072 bool LibraryCallKit::inline_math_addExactL(bool is_increment) {
 2073   return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2));
 2074 }
 2075 
 2076 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) {
 2077   return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1));
 2078 }
 2079 
 2080 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) {
 2081   return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2));
 2082 }
 2083 
 2084 bool LibraryCallKit::inline_math_negateExactI() {
 2085   return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0));
 2086 }
 2087 
 2088 bool LibraryCallKit::inline_math_negateExactL() {
 2089   return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0));
 2090 }
 2091 
 2092 bool LibraryCallKit::inline_math_multiplyExactI() {
 2093   return inline_math_overflow<OverflowMulINode>(argument(0), argument(1));
 2094 }
 2095 
 2096 bool LibraryCallKit::inline_math_multiplyExactL() {
 2097   return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2));
 2098 }
 2099 
 2100 bool LibraryCallKit::inline_math_multiplyHigh() {
 2101   set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2))));
 2102   return true;
 2103 }
 2104 
 2105 bool LibraryCallKit::inline_math_unsignedMultiplyHigh() {
 2106   set_result(_gvn.transform(new UMulHiLNode(argument(0), argument(2))));
 2107   return true;
 2108 }
 2109 
 2110 inline int
 2111 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) {
 2112   const TypePtr* base_type = TypePtr::NULL_PTR;
 2113   if (base != nullptr)  base_type = _gvn.type(base)->isa_ptr();
 2114   if (base_type == nullptr) {
 2115     // Unknown type.
 2116     return Type::AnyPtr;
 2117   } else if (_gvn.type(base->uncast()) == TypePtr::NULL_PTR) {
 2118     // Since this is a null+long form, we have to switch to a rawptr.
 2119     base   = _gvn.transform(new CastX2PNode(offset));
 2120     offset = MakeConX(0);
 2121     return Type::RawPtr;
 2122   } else if (base_type->base() == Type::RawPtr) {
 2123     return Type::RawPtr;
 2124   } else if (base_type->isa_oopptr()) {
 2125     // Base is never null => always a heap address.
 2126     if (!TypePtr::NULL_PTR->higher_equal(base_type)) {
 2127       return Type::OopPtr;
 2128     }
 2129     // Offset is small => always a heap address.
 2130     const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
 2131     if (offset_type != nullptr &&
 2132         base_type->offset() == 0 &&     // (should always be?)
 2133         offset_type->_lo >= 0 &&
 2134         !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
 2135       return Type::OopPtr;
 2136     } else if (type == T_OBJECT) {
 2137       // off heap access to an oop doesn't make any sense. Has to be on
 2138       // heap.
 2139       return Type::OopPtr;
 2140     }
 2141     // Otherwise, it might either be oop+off or null+addr.
 2142     return Type::AnyPtr;
 2143   } else {
 2144     // No information:
 2145     return Type::AnyPtr;
 2146   }
 2147 }
 2148 
 2149 Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, BasicType type, bool can_cast) {
 2150   Node* uncasted_base = base;
 2151   int kind = classify_unsafe_addr(uncasted_base, offset, type);
 2152   if (kind == Type::RawPtr) {
 2153     return off_heap_plus_addr(uncasted_base, offset);
 2154   } else if (kind == Type::AnyPtr) {
 2155     assert(base == uncasted_base, "unexpected base change");
 2156     if (can_cast) {
 2157       if (!_gvn.type(base)->speculative_maybe_null() &&
 2158           !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
 2159         // According to profiling, this access is always on
 2160         // heap. Casting the base to not null and thus avoiding membars
 2161         // around the access should allow better optimizations
 2162         Node* null_ctl = top();
 2163         base = null_check_oop(base, &null_ctl, true, true, true);
 2164         assert(null_ctl->is_top(), "no null control here");
 2165         return basic_plus_adr(base, offset);
 2166       } else if (_gvn.type(base)->speculative_always_null() &&
 2167                  !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
 2168         // According to profiling, this access is always off
 2169         // heap.
 2170         base = null_assert(base);
 2171         Node* raw_base = _gvn.transform(new CastX2PNode(offset));
 2172         offset = MakeConX(0);
 2173         return off_heap_plus_addr(raw_base, offset);
 2174       }
 2175     }
 2176     // We don't know if it's an on heap or off heap access. Fall back
 2177     // to raw memory access.
 2178     Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM));
 2179     return off_heap_plus_addr(raw, offset);
 2180   } else {
 2181     assert(base == uncasted_base, "unexpected base change");
 2182     // We know it's an on heap access so base can't be null
 2183     if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) {
 2184       base = must_be_not_null(base, true);
 2185     }
 2186     return basic_plus_adr(base, offset);
 2187   }
 2188 }
 2189 
 2190 //--------------------------inline_number_methods-----------------------------
 2191 // inline int     Integer.numberOfLeadingZeros(int)
 2192 // inline int        Long.numberOfLeadingZeros(long)
 2193 //
 2194 // inline int     Integer.numberOfTrailingZeros(int)
 2195 // inline int        Long.numberOfTrailingZeros(long)
 2196 //
 2197 // inline int     Integer.bitCount(int)
 2198 // inline int        Long.bitCount(long)
 2199 //
 2200 // inline char  Character.reverseBytes(char)
 2201 // inline short     Short.reverseBytes(short)
 2202 // inline int     Integer.reverseBytes(int)
 2203 // inline long       Long.reverseBytes(long)
 2204 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) {
 2205   Node* arg = argument(0);
 2206   Node* n = nullptr;
 2207   switch (id) {
 2208   case vmIntrinsics::_numberOfLeadingZeros_i:   n = new CountLeadingZerosINode( arg); break;
 2209   case vmIntrinsics::_numberOfLeadingZeros_l:   n = new CountLeadingZerosLNode( arg); break;
 2210   case vmIntrinsics::_numberOfTrailingZeros_i:  n = new CountTrailingZerosINode(arg); break;
 2211   case vmIntrinsics::_numberOfTrailingZeros_l:  n = new CountTrailingZerosLNode(arg); break;
 2212   case vmIntrinsics::_bitCount_i:               n = new PopCountINode(          arg); break;
 2213   case vmIntrinsics::_bitCount_l:               n = new PopCountLNode(          arg); break;
 2214   case vmIntrinsics::_reverseBytes_c:           n = new ReverseBytesUSNode(     arg); break;
 2215   case vmIntrinsics::_reverseBytes_s:           n = new ReverseBytesSNode(      arg); break;
 2216   case vmIntrinsics::_reverseBytes_i:           n = new ReverseBytesINode(      arg); break;
 2217   case vmIntrinsics::_reverseBytes_l:           n = new ReverseBytesLNode(      arg); break;
 2218   case vmIntrinsics::_reverse_i:                n = new ReverseINode(           arg); break;
 2219   case vmIntrinsics::_reverse_l:                n = new ReverseLNode(           arg); break;
 2220   default:  fatal_unexpected_iid(id);  break;
 2221   }
 2222   set_result(_gvn.transform(n));
 2223   return true;
 2224 }
 2225 
 2226 //--------------------------inline_bitshuffle_methods-----------------------------
 2227 // inline int Integer.compress(int, int)
 2228 // inline int Integer.expand(int, int)
 2229 // inline long Long.compress(long, long)
 2230 // inline long Long.expand(long, long)
 2231 bool LibraryCallKit::inline_bitshuffle_methods(vmIntrinsics::ID id) {
 2232   Node* n = nullptr;
 2233   switch (id) {
 2234     case vmIntrinsics::_compress_i:  n = new CompressBitsNode(argument(0), argument(1), TypeInt::INT); break;
 2235     case vmIntrinsics::_expand_i:    n = new ExpandBitsNode(argument(0),  argument(1), TypeInt::INT); break;
 2236     case vmIntrinsics::_compress_l:  n = new CompressBitsNode(argument(0), argument(2), TypeLong::LONG); break;
 2237     case vmIntrinsics::_expand_l:    n = new ExpandBitsNode(argument(0), argument(2), TypeLong::LONG); break;
 2238     default:  fatal_unexpected_iid(id);  break;
 2239   }
 2240   set_result(_gvn.transform(n));
 2241   return true;
 2242 }
 2243 
 2244 //--------------------------inline_number_methods-----------------------------
 2245 // inline int Integer.compareUnsigned(int, int)
 2246 // inline int    Long.compareUnsigned(long, long)
 2247 bool LibraryCallKit::inline_compare_unsigned(vmIntrinsics::ID id) {
 2248   Node* arg1 = argument(0);
 2249   Node* arg2 = (id == vmIntrinsics::_compareUnsigned_l) ? argument(2) : argument(1);
 2250   Node* n = nullptr;
 2251   switch (id) {
 2252     case vmIntrinsics::_compareUnsigned_i:   n = new CmpU3Node(arg1, arg2);  break;
 2253     case vmIntrinsics::_compareUnsigned_l:   n = new CmpUL3Node(arg1, arg2); break;
 2254     default:  fatal_unexpected_iid(id);  break;
 2255   }
 2256   set_result(_gvn.transform(n));
 2257   return true;
 2258 }
 2259 
 2260 //--------------------------inline_unsigned_divmod_methods-----------------------------
 2261 // inline int Integer.divideUnsigned(int, int)
 2262 // inline int Integer.remainderUnsigned(int, int)
 2263 // inline long Long.divideUnsigned(long, long)
 2264 // inline long Long.remainderUnsigned(long, long)
 2265 bool LibraryCallKit::inline_divmod_methods(vmIntrinsics::ID id) {
 2266   Node* n = nullptr;
 2267   switch (id) {
 2268     case vmIntrinsics::_divideUnsigned_i: {
 2269       zero_check_int(argument(1));
 2270       // Compile-time detect of null-exception
 2271       if (stopped()) {
 2272         return true; // keep the graph constructed so far
 2273       }
 2274       n = new UDivINode(control(), argument(0), argument(1));
 2275       break;
 2276     }
 2277     case vmIntrinsics::_divideUnsigned_l: {
 2278       zero_check_long(argument(2));
 2279       // Compile-time detect of null-exception
 2280       if (stopped()) {
 2281         return true; // keep the graph constructed so far
 2282       }
 2283       n = new UDivLNode(control(), argument(0), argument(2));
 2284       break;
 2285     }
 2286     case vmIntrinsics::_remainderUnsigned_i: {
 2287       zero_check_int(argument(1));
 2288       // Compile-time detect of null-exception
 2289       if (stopped()) {
 2290         return true; // keep the graph constructed so far
 2291       }
 2292       n = new UModINode(control(), argument(0), argument(1));
 2293       break;
 2294     }
 2295     case vmIntrinsics::_remainderUnsigned_l: {
 2296       zero_check_long(argument(2));
 2297       // Compile-time detect of null-exception
 2298       if (stopped()) {
 2299         return true; // keep the graph constructed so far
 2300       }
 2301       n = new UModLNode(control(), argument(0), argument(2));
 2302       break;
 2303     }
 2304     default:  fatal_unexpected_iid(id);  break;
 2305   }
 2306   set_result(_gvn.transform(n));
 2307   return true;
 2308 }
 2309 
 2310 //----------------------------inline_unsafe_access----------------------------
 2311 
 2312 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
 2313   // Attempt to infer a sharper value type from the offset and base type.
 2314   ciKlass* sharpened_klass = nullptr;
 2315   bool null_free = false;
 2316 
 2317   // See if it is an instance field, with an object type.
 2318   if (alias_type->field() != nullptr) {
 2319     if (alias_type->field()->type()->is_klass()) {
 2320       sharpened_klass = alias_type->field()->type()->as_klass();
 2321       null_free = alias_type->field()->is_null_free();
 2322     }
 2323   }
 2324 
 2325   const TypeOopPtr* result = nullptr;
 2326   // See if it is a narrow oop array.
 2327   if (adr_type->isa_aryptr()) {
 2328     if (adr_type->offset() >= refArrayOopDesc::base_offset_in_bytes()) {
 2329       const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr();
 2330       null_free = adr_type->is_aryptr()->is_null_free();
 2331       if (elem_type != nullptr && elem_type->is_loaded()) {
 2332         // Sharpen the value type.
 2333         result = elem_type;
 2334       }
 2335     }
 2336   }
 2337 
 2338   // The sharpened class might be unloaded if there is no class loader
 2339   // contraint in place.
 2340   if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) {
 2341     // Sharpen the value type.
 2342     result = TypeOopPtr::make_from_klass(sharpened_klass);
 2343     if (null_free) {
 2344       result = result->join_speculative(TypePtr::NOTNULL)->is_oopptr();
 2345     }
 2346   }
 2347   if (result != nullptr) {
 2348 #ifndef PRODUCT
 2349     if (C->print_intrinsics() || C->print_inlining()) {
 2350       tty->print("  from base type:  ");  adr_type->dump(); tty->cr();
 2351       tty->print("  sharpened value: ");  result->dump();    tty->cr();
 2352     }
 2353 #endif
 2354   }
 2355   return result;
 2356 }
 2357 
 2358 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) {
 2359   switch (kind) {
 2360       case Relaxed:
 2361         return MO_UNORDERED;
 2362       case Opaque:
 2363         return MO_RELAXED;
 2364       case Acquire:
 2365         return MO_ACQUIRE;
 2366       case Release:
 2367         return MO_RELEASE;
 2368       case Volatile:
 2369         return MO_SEQ_CST;
 2370       default:
 2371         ShouldNotReachHere();
 2372         return 0;
 2373   }
 2374 }
 2375 
 2376 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) {
 2377   if (callee()->is_static())  return false;  // caller must have the capability!
 2378   DecoratorSet decorators = C2_UNSAFE_ACCESS;
 2379   guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads");
 2380   guarantee( is_store || kind != Release, "Release accesses can be produced only for stores");
 2381   assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
 2382 
 2383   if (is_reference_type(type)) {
 2384     decorators |= ON_UNKNOWN_OOP_REF;
 2385   }
 2386 
 2387   if (unaligned) {
 2388     decorators |= C2_UNALIGNED;
 2389   }
 2390 
 2391 #ifndef PRODUCT
 2392   {
 2393     ResourceMark rm;
 2394     // Check the signatures.
 2395     ciSignature* sig = callee()->signature();
 2396 #ifdef ASSERT
 2397     if (!is_store) {
 2398       // Object getReference(Object base, int/long offset), etc.
 2399       BasicType rtype = sig->return_type()->basic_type();
 2400       assert(rtype == type, "getter must return the expected value");
 2401       assert(sig->count() == 2, "oop getter has 2 arguments");
 2402       assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
 2403       assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
 2404     } else {
 2405       // void putReference(Object base, int/long offset, Object x), etc.
 2406       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
 2407       assert(sig->count() == 3, "oop putter has 3 arguments");
 2408       assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
 2409       assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
 2410       BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
 2411       assert(vtype == type, "putter must accept the expected value");
 2412     }
 2413 #endif // ASSERT
 2414  }
 2415 #endif //PRODUCT
 2416 
 2417   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 2418 
 2419   Node* receiver = argument(0);  // type: oop
 2420 
 2421   // Build address expression.
 2422   Node* heap_base_oop = top();
 2423 
 2424   // The base is either a Java object or a value produced by Unsafe.staticFieldBase
 2425   Node* base = argument(1);  // type: oop
 2426   // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
 2427   Node* offset = argument(2);  // type: long
 2428   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
 2429   // to be plain byte offsets, which are also the same as those accepted
 2430   // by oopDesc::field_addr.
 2431   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 2432          "fieldOffset must be byte-scaled");
 2433 
 2434   if (base->is_InlineType()) {
 2435     assert(!is_store, "InlineTypeNodes are non-larval value objects");
 2436     InlineTypeNode* vt = base->as_InlineType();
 2437     if (offset->is_Con()) {
 2438       long off = find_long_con(offset, 0);
 2439       ciInlineKlass* vk = vt->type()->inline_klass();
 2440       if ((long)(int)off != off || !vk->contains_field_offset(off)) {
 2441         return false;
 2442       }
 2443 
 2444       ciField* field = vk->get_non_flat_field_by_offset(off);
 2445       if (field != nullptr) {
 2446         BasicType bt = type2field[field->type()->basic_type()];
 2447         if (bt == T_ARRAY || bt == T_NARROWOOP) {
 2448           bt = T_OBJECT;
 2449         }
 2450         if (bt == type && !field->is_flat()) {
 2451           Node* value = vt->field_value_by_offset(off, false);
 2452           const Type* value_type = _gvn.type(value);
 2453           if (value_type->is_inlinetypeptr()) {
 2454             value = InlineTypeNode::make_from_oop(this, value, value_type->inline_klass());
 2455           }
 2456           set_result(value);
 2457           return true;
 2458         }
 2459       }
 2460     }
 2461     {
 2462       // Re-execute the unsafe access if allocation triggers deoptimization.
 2463       PreserveReexecuteState preexecs(this);
 2464       jvms()->set_should_reexecute(true);
 2465       vt = vt->buffer(this);
 2466     }
 2467     base = vt->get_oop();
 2468   }
 2469 
 2470   // 32-bit machines ignore the high half!
 2471   offset = ConvL2X(offset);
 2472 
 2473   // Save state and restore on bailout
 2474   SavedState old_state(this);
 2475 
 2476   Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed);
 2477   assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly");
 2478 
 2479   bool is_non_heap_access = (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR);
 2480   if (is_non_heap_access) {
 2481     if (type != T_OBJECT) {
 2482       decorators |= IN_NATIVE; // off-heap primitive access
 2483     } else {
 2484       return false; // off-heap oop accesses are not supported
 2485     }
 2486   } else {
 2487     heap_base_oop = base; // on-heap or mixed access
 2488   }
 2489 
 2490   // Can base be null? Otherwise, always on-heap access.
 2491   bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base));
 2492 
 2493   assert(!is_non_heap_access || can_access_non_heap, "sanity"); // is_non_heap_access implies can_access_non_heap
 2494 
 2495   if (!can_access_non_heap) {
 2496     decorators |= IN_HEAP;
 2497   }
 2498 
 2499   Node* val = is_store ? argument(4) : nullptr;
 2500 
 2501   const TypePtr* adr_type = _gvn.type(adr)->isa_ptr();
 2502   if (adr_type == TypePtr::NULL_PTR) {
 2503     return false; // off-heap access with zero address
 2504   }
 2505 
 2506   // Try to categorize the address.
 2507   Compile::AliasType* alias_type = C->alias_type(adr_type);
 2508   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
 2509 
 2510   assert((alias_type->index() == Compile::AliasIdxRaw) ==
 2511          (is_non_heap_access || (can_access_non_heap && alias_type->field() == nullptr)), "wrong alias");
 2512 
 2513   if (alias_type->adr_type() == TypeInstPtr::KLASS ||
 2514       alias_type->adr_type() == TypeAryPtr::RANGE) {
 2515     return false; // not supported
 2516   }
 2517 
 2518   bool mismatched = false;
 2519   BasicType bt = T_ILLEGAL;
 2520   ciField* field = nullptr;
 2521   if (adr_type->isa_instptr()) {
 2522     const TypeInstPtr* instptr = adr_type->is_instptr();
 2523     ciInstanceKlass* k = instptr->instance_klass();
 2524     int off = instptr->offset();
 2525     if (instptr->const_oop() != nullptr &&
 2526         k == ciEnv::current()->Class_klass() &&
 2527         instptr->offset() >= (k->size_helper() * wordSize)) {
 2528       k = instptr->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
 2529       field = k->get_field_by_offset(off, true);
 2530     } else {
 2531       field = k->get_non_flat_field_by_offset(off);
 2532     }
 2533     if (field != nullptr) {
 2534       bt = type2field[field->type()->basic_type()];
 2535     }
 2536     if (bt != alias_type->basic_type()) {
 2537       // Type mismatch. Is it an access to a nested flat field?
 2538       field = k->get_field_by_offset(off, false);
 2539       if (field != nullptr) {
 2540         bt = type2field[field->type()->basic_type()];
 2541       }
 2542     }
 2543     assert(bt == alias_type->basic_type(), "should match");
 2544   } else {
 2545     bt = alias_type->basic_type();
 2546   }
 2547 
 2548   if (bt != T_ILLEGAL) {
 2549     assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
 2550     if (bt == T_BYTE && adr_type->isa_aryptr()) {
 2551       // Alias type doesn't differentiate between byte[] and boolean[]).
 2552       // Use address type to get the element type.
 2553       bt = adr_type->is_aryptr()->elem()->array_element_basic_type();
 2554     }
 2555     if (is_reference_type(bt, true)) {
 2556       // accessing an array field with getReference is not a mismatch
 2557       bt = T_OBJECT;
 2558     }
 2559     if ((bt == T_OBJECT) != (type == T_OBJECT)) {
 2560       // Don't intrinsify mismatched object accesses
 2561       return false;
 2562     }
 2563     mismatched = (bt != type);
 2564   } else if (alias_type->adr_type()->isa_oopptr()) {
 2565     mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
 2566   }
 2567 
 2568   old_state.discard();
 2569   assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched");
 2570 
 2571   if (mismatched) {
 2572     decorators |= C2_MISMATCHED;
 2573   }
 2574 
 2575   // First guess at the value type.
 2576   const Type *value_type = Type::get_const_basic_type(type);
 2577 
 2578   // Figure out the memory ordering.
 2579   decorators |= mo_decorator_for_access_kind(kind);
 2580 
 2581   if (!is_store) {
 2582     if (type == T_OBJECT) {
 2583       const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
 2584       if (tjp != nullptr) {
 2585         value_type = tjp;
 2586       }
 2587     } else if (type == T_BOOLEAN) {
 2588       if (mismatched || alias_type->index() == Compile::AliasIdxRaw) {
 2589         value_type = TypeInt::UBYTE;
 2590       }
 2591     }
 2592   }
 2593 
 2594   receiver = null_check(receiver);
 2595   if (stopped()) {
 2596     return true;
 2597   }
 2598   // Heap pointers get a null-check from the interpreter,
 2599   // as a courtesy.  However, this is not guaranteed by Unsafe,
 2600   // and it is not possible to fully distinguish unintended nulls
 2601   // from intended ones in this API.
 2602 
 2603   if (!is_store) {
 2604     Node* p = nullptr;
 2605     // Try to constant fold a load from a constant field
 2606 
 2607     if (heap_base_oop != top() && field != nullptr && field->is_constant() && !field->is_flat() && !mismatched) {
 2608       // final or stable field
 2609       p = make_constant_from_field(field, heap_base_oop);
 2610     }
 2611 
 2612     if (p == nullptr) { // Could not constant fold the load
 2613       p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators);
 2614       const TypeOopPtr* ptr = value_type->make_oopptr();
 2615       if (ptr != nullptr && ptr->is_inlinetypeptr()) {
 2616         // Load a non-flattened inline type from memory
 2617         p = InlineTypeNode::make_from_oop(this, p, ptr->inline_klass());
 2618       }
 2619     }
 2620     if (type == T_ADDRESS) {
 2621       p = gvn().transform(new CastP2XNode(nullptr, p));
 2622       p = ConvX2UL(p);
 2623     } else if (type == T_BOOLEAN) {
 2624       // Truncate boolean values returned by unsafe operations.
 2625       p = gvn().transform(new AndINode(p, gvn().intcon(0x1)));
 2626     }
 2627     // The load node has the control of the preceding MemBarCPUOrder.  All
 2628     // following nodes will have the control of the MemBarCPUOrder inserted at
 2629     // the end of this method.  So, pushing the load onto the stack at a later
 2630     // point is fine.
 2631     set_result(p);
 2632   } else {
 2633     if (bt == T_ADDRESS) {
 2634       // Repackage the long as a pointer.
 2635       val = ConvL2X(val);
 2636       val = gvn().transform(new CastX2PNode(val));
 2637     }
 2638     access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators);
 2639   }
 2640 
 2641   return true;
 2642 }
 2643 
 2644 bool LibraryCallKit::inline_unsafe_flat_access(bool is_store, AccessKind kind) {
 2645 #ifdef ASSERT
 2646   {
 2647     ResourceMark rm;
 2648     // Check the signatures.
 2649     ciSignature* sig = callee()->signature();
 2650     assert(sig->type_at(0)->basic_type() == T_OBJECT, "base should be object, but is %s", type2name(sig->type_at(0)->basic_type()));
 2651     assert(sig->type_at(1)->basic_type() == T_LONG, "offset should be long, but is %s", type2name(sig->type_at(1)->basic_type()));
 2652     assert(sig->type_at(2)->basic_type() == T_INT, "layout kind should be int, but is %s", type2name(sig->type_at(3)->basic_type()));
 2653     assert(sig->type_at(3)->basic_type() == T_OBJECT, "value klass should be object, but is %s", type2name(sig->type_at(4)->basic_type()));
 2654     if (is_store) {
 2655       assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value, but returns %s", type2name(sig->return_type()->basic_type()));
 2656       assert(sig->count() == 5, "flat putter should have 5 arguments, but has %d", sig->count());
 2657       assert(sig->type_at(4)->basic_type() == T_OBJECT, "put value should be object, but is %s", type2name(sig->type_at(5)->basic_type()));
 2658     } else {
 2659       assert(sig->return_type()->basic_type() == T_OBJECT, "getter must return an object, but returns %s", type2name(sig->return_type()->basic_type()));
 2660       assert(sig->count() == 4, "flat getter should have 4 arguments, but has %d", sig->count());
 2661     }
 2662  }
 2663 #endif // ASSERT
 2664 
 2665   assert(kind == Relaxed, "Only plain accesses for now");
 2666   if (callee()->is_static()) {
 2667     // caller must have the capability!
 2668     return false;
 2669   }
 2670   C->set_has_unsafe_access(true);
 2671 
 2672   const TypeInstPtr* value_klass_node = _gvn.type(argument(5))->isa_instptr();
 2673   if (value_klass_node == nullptr || value_klass_node->const_oop() == nullptr) {
 2674     // parameter valueType is not a constant
 2675     return false;
 2676   }
 2677   ciType* mirror_type = value_klass_node->const_oop()->as_instance()->java_mirror_type();
 2678   if (!mirror_type->is_inlinetype()) {
 2679     // Dead code
 2680     return false;
 2681   }
 2682   ciInlineKlass* value_klass = mirror_type->as_inline_klass();
 2683 
 2684   const TypeInt* layout_type = _gvn.type(argument(4))->isa_int();
 2685   if (layout_type == nullptr || !layout_type->is_con()) {
 2686     // parameter layoutKind is not a constant
 2687     return false;
 2688   }
 2689   assert(layout_type->get_con() >= static_cast<int>(LayoutKind::REFERENCE) &&
 2690          layout_type->get_con() < static_cast<int>(LayoutKind::UNKNOWN),
 2691          "invalid layoutKind %d", layout_type->get_con());
 2692   LayoutKind layout = static_cast<LayoutKind>(layout_type->get_con());
 2693   assert(layout == LayoutKind::REFERENCE || layout == LayoutKind::NULL_FREE_NON_ATOMIC_FLAT ||
 2694          layout == LayoutKind::NULL_FREE_ATOMIC_FLAT || layout == LayoutKind::NULLABLE_ATOMIC_FLAT,
 2695          "unexpected layoutKind %d", layout_type->get_con());
 2696 
 2697   null_check(argument(0));
 2698   if (stopped()) {
 2699     return true;
 2700   }
 2701 
 2702   Node* base = must_be_not_null(argument(1), true);
 2703   Node* offset = argument(2);
 2704   const Type* base_type = _gvn.type(base);
 2705 
 2706   Node* ptr;
 2707   bool immutable_memory = false;
 2708   DecoratorSet decorators = C2_UNSAFE_ACCESS | IN_HEAP | MO_UNORDERED;
 2709   if (base_type->isa_instptr()) {
 2710     const TypeLong* offset_type = _gvn.type(offset)->isa_long();
 2711     if (offset_type == nullptr || !offset_type->is_con()) {
 2712       // Offset into a non-array should be a constant
 2713       decorators |= C2_MISMATCHED;
 2714     } else {
 2715       int offset_con = checked_cast<int>(offset_type->get_con());
 2716       ciInstanceKlass* base_klass = base_type->is_instptr()->instance_klass();
 2717       ciField* field = base_klass->get_non_flat_field_by_offset(offset_con);
 2718       if (field == nullptr) {
 2719         assert(!base_klass->is_final(), "non-existence field at offset %d of class %s", offset_con, base_klass->name()->as_utf8());
 2720         decorators |= C2_MISMATCHED;
 2721       } else {
 2722         assert(field->type() == value_klass, "field at offset %d of %s is of type %s, but valueType is %s",
 2723                offset_con, base_klass->name()->as_utf8(), field->type()->name(), value_klass->name()->as_utf8());
 2724         immutable_memory = field->is_strict() && field->is_final();
 2725 
 2726         if (base->is_InlineType()) {
 2727           assert(!is_store, "Cannot store into a non-larval value object");
 2728           set_result(base->as_InlineType()->field_value_by_offset(offset_con, false));
 2729           return true;
 2730         }
 2731       }
 2732     }
 2733 
 2734     if (base->is_InlineType()) {
 2735       assert(!is_store, "Cannot store into a non-larval value object");
 2736       base = base->as_InlineType()->buffer(this, true);
 2737     }
 2738     ptr = basic_plus_adr(base, ConvL2X(offset));
 2739   } else if (base_type->isa_aryptr()) {
 2740     decorators |= IS_ARRAY;
 2741     if (layout == LayoutKind::REFERENCE) {
 2742       if (!base_type->is_aryptr()->is_not_flat()) {
 2743         const TypeAryPtr* array_type = base_type->is_aryptr()->cast_to_not_flat();
 2744         // TODO 8350865 This should be a CheckCastPP, can we add a test?
 2745         Node* new_base = _gvn.transform(new CastPPNode(control(), base, array_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2746         replace_in_map(base, new_base);
 2747         base = new_base;
 2748       }
 2749       ptr = basic_plus_adr(base, ConvL2X(offset));
 2750     } else {
 2751       if (UseArrayFlattening) {
 2752         // Flat array must have an exact type
 2753         bool is_null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2754         bool is_atomic = LayoutKindHelper::is_atomic_flat(layout);
 2755         Node* new_base = cast_to_flat_array_exact(base, value_klass, is_null_free, is_atomic);
 2756         replace_in_map(base, new_base);
 2757         base = new_base;
 2758         ptr = basic_plus_adr(base, ConvL2X(offset));
 2759         const TypeAryPtr* ptr_type = _gvn.type(ptr)->is_aryptr();
 2760         if (ptr_type->field_offset().get() != 0) {
 2761           // TODO 8350865 This should be a CheckCastPP, can we add a test?
 2762           ptr = _gvn.transform(new CastPPNode(control(), ptr, ptr_type->with_field_offset(0), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2763         }
 2764       } else {
 2765         uncommon_trap(Deoptimization::Reason_intrinsic,
 2766                       Deoptimization::Action_none);
 2767         return true;
 2768       }
 2769     }
 2770   } else {
 2771     decorators |= C2_MISMATCHED;
 2772     ptr = basic_plus_adr(base, ConvL2X(offset));
 2773   }
 2774 
 2775   if (is_store) {
 2776     Node* value = argument(6);
 2777     const Type* value_type = _gvn.type(value);
 2778     if (!value_type->is_inlinetypeptr()) {
 2779       value_type = Type::get_const_type(value_klass)->filter_speculative(value_type);
 2780       Node* new_value = _gvn.transform(new CheckCastPPNode(control(), value, value_type, ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 2781       new_value = InlineTypeNode::make_from_oop(this, new_value, value_klass);
 2782       replace_in_map(value, new_value);
 2783       value = new_value;
 2784     }
 2785 
 2786     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());
 2787     if (layout == LayoutKind::REFERENCE) {
 2788       const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
 2789       access_store_at(base, ptr, ptr_type, value, value_type, T_OBJECT, decorators);
 2790     } else {
 2791       bool atomic = LayoutKindHelper::is_atomic_flat(layout);
 2792       bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2793       value->as_InlineType()->store_flat(this, base, ptr, atomic, immutable_memory, null_free, decorators);
 2794     }
 2795 
 2796     return true;
 2797   } else {
 2798     decorators |= (C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD);
 2799     InlineTypeNode* result;
 2800     if (layout == LayoutKind::REFERENCE) {
 2801       const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr();
 2802       Node* oop = access_load_at(base, ptr, ptr_type, Type::get_const_type(value_klass), T_OBJECT, decorators);
 2803       result = InlineTypeNode::make_from_oop(this, oop, value_klass);
 2804     } else {
 2805       bool atomic = LayoutKindHelper::is_atomic_flat(layout);
 2806       bool null_free = !LayoutKindHelper::is_nullable_flat(layout);
 2807       result = InlineTypeNode::make_from_flat(this, value_klass, base, ptr, atomic, immutable_memory, null_free, decorators);
 2808     }
 2809 
 2810     set_result(result);
 2811     return true;
 2812   }
 2813 }
 2814 
 2815 //----------------------------inline_unsafe_load_store----------------------------
 2816 // This method serves a couple of different customers (depending on LoadStoreKind):
 2817 //
 2818 // LS_cmp_swap:
 2819 //
 2820 //   boolean compareAndSetReference(Object o, long offset, Object expected, Object x);
 2821 //   boolean compareAndSetInt(   Object o, long offset, int    expected, int    x);
 2822 //   boolean compareAndSetLong(  Object o, long offset, long   expected, long   x);
 2823 //
 2824 // LS_cmp_swap_weak:
 2825 //
 2826 //   boolean weakCompareAndSetReference(       Object o, long offset, Object expected, Object x);
 2827 //   boolean weakCompareAndSetReferencePlain(  Object o, long offset, Object expected, Object x);
 2828 //   boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x);
 2829 //   boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x);
 2830 //
 2831 //   boolean weakCompareAndSetInt(          Object o, long offset, int    expected, int    x);
 2832 //   boolean weakCompareAndSetIntPlain(     Object o, long offset, int    expected, int    x);
 2833 //   boolean weakCompareAndSetIntAcquire(   Object o, long offset, int    expected, int    x);
 2834 //   boolean weakCompareAndSetIntRelease(   Object o, long offset, int    expected, int    x);
 2835 //
 2836 //   boolean weakCompareAndSetLong(         Object o, long offset, long   expected, long   x);
 2837 //   boolean weakCompareAndSetLongPlain(    Object o, long offset, long   expected, long   x);
 2838 //   boolean weakCompareAndSetLongAcquire(  Object o, long offset, long   expected, long   x);
 2839 //   boolean weakCompareAndSetLongRelease(  Object o, long offset, long   expected, long   x);
 2840 //
 2841 // LS_cmp_exchange:
 2842 //
 2843 //   Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x);
 2844 //   Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x);
 2845 //   Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x);
 2846 //
 2847 //   Object compareAndExchangeIntVolatile(   Object o, long offset, Object expected, Object x);
 2848 //   Object compareAndExchangeIntAcquire(    Object o, long offset, Object expected, Object x);
 2849 //   Object compareAndExchangeIntRelease(    Object o, long offset, Object expected, Object x);
 2850 //
 2851 //   Object compareAndExchangeLongVolatile(  Object o, long offset, Object expected, Object x);
 2852 //   Object compareAndExchangeLongAcquire(   Object o, long offset, Object expected, Object x);
 2853 //   Object compareAndExchangeLongRelease(   Object o, long offset, Object expected, Object x);
 2854 //
 2855 // LS_get_add:
 2856 //
 2857 //   int  getAndAddInt( Object o, long offset, int  delta)
 2858 //   long getAndAddLong(Object o, long offset, long delta)
 2859 //
 2860 // LS_get_set:
 2861 //
 2862 //   int    getAndSet(Object o, long offset, int    newValue)
 2863 //   long   getAndSet(Object o, long offset, long   newValue)
 2864 //   Object getAndSet(Object o, long offset, Object newValue)
 2865 //
 2866 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) {
 2867   // This basic scheme here is the same as inline_unsafe_access, but
 2868   // differs in enough details that combining them would make the code
 2869   // overly confusing.  (This is a true fact! I originally combined
 2870   // them, but even I was confused by it!) As much code/comments as
 2871   // possible are retained from inline_unsafe_access though to make
 2872   // the correspondences clearer. - dl
 2873 
 2874   if (callee()->is_static())  return false;  // caller must have the capability!
 2875 
 2876   DecoratorSet decorators = C2_UNSAFE_ACCESS;
 2877   decorators |= mo_decorator_for_access_kind(access_kind);
 2878 
 2879 #ifndef PRODUCT
 2880   BasicType rtype;
 2881   {
 2882     ResourceMark rm;
 2883     // Check the signatures.
 2884     ciSignature* sig = callee()->signature();
 2885     rtype = sig->return_type()->basic_type();
 2886     switch(kind) {
 2887       case LS_get_add:
 2888       case LS_get_set: {
 2889       // Check the signatures.
 2890 #ifdef ASSERT
 2891       assert(rtype == type, "get and set must return the expected type");
 2892       assert(sig->count() == 3, "get and set has 3 arguments");
 2893       assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object");
 2894       assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long");
 2895       assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta");
 2896       assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation");
 2897 #endif // ASSERT
 2898         break;
 2899       }
 2900       case LS_cmp_swap:
 2901       case LS_cmp_swap_weak: {
 2902       // Check the signatures.
 2903 #ifdef ASSERT
 2904       assert(rtype == T_BOOLEAN, "CAS must return boolean");
 2905       assert(sig->count() == 4, "CAS has 4 arguments");
 2906       assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
 2907       assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
 2908 #endif // ASSERT
 2909         break;
 2910       }
 2911       case LS_cmp_exchange: {
 2912       // Check the signatures.
 2913 #ifdef ASSERT
 2914       assert(rtype == type, "CAS must return the expected type");
 2915       assert(sig->count() == 4, "CAS has 4 arguments");
 2916       assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
 2917       assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
 2918 #endif // ASSERT
 2919         break;
 2920       }
 2921       default:
 2922         ShouldNotReachHere();
 2923     }
 2924   }
 2925 #endif //PRODUCT
 2926 
 2927   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 2928 
 2929   // Get arguments:
 2930   Node* receiver = nullptr;
 2931   Node* base     = nullptr;
 2932   Node* offset   = nullptr;
 2933   Node* oldval   = nullptr;
 2934   Node* newval   = nullptr;
 2935   switch(kind) {
 2936     case LS_cmp_swap:
 2937     case LS_cmp_swap_weak:
 2938     case LS_cmp_exchange: {
 2939       const bool two_slot_type = type2size[type] == 2;
 2940       receiver = argument(0);  // type: oop
 2941       base     = argument(1);  // type: oop
 2942       offset   = argument(2);  // type: long
 2943       oldval   = argument(4);  // type: oop, int, or long
 2944       newval   = argument(two_slot_type ? 6 : 5);  // type: oop, int, or long
 2945       break;
 2946     }
 2947     case LS_get_add:
 2948     case LS_get_set: {
 2949       receiver = argument(0);  // type: oop
 2950       base     = argument(1);  // type: oop
 2951       offset   = argument(2);  // type: long
 2952       oldval   = nullptr;
 2953       newval   = argument(4);  // type: oop, int, or long
 2954       break;
 2955     }
 2956     default:
 2957       ShouldNotReachHere();
 2958   }
 2959 
 2960   // Build field offset expression.
 2961   // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
 2962   // to be plain byte offsets, which are also the same as those accepted
 2963   // by oopDesc::field_addr.
 2964   assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
 2965   // 32-bit machines ignore the high half of long offsets
 2966   offset = ConvL2X(offset);
 2967   // Save state and restore on bailout
 2968   SavedState old_state(this);
 2969   Node* adr = make_unsafe_address(base, offset,type, false);
 2970   const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
 2971 
 2972   Compile::AliasType* alias_type = C->alias_type(adr_type);
 2973   BasicType bt = alias_type->basic_type();
 2974   if (bt != T_ILLEGAL &&
 2975       (is_reference_type(bt) != (type == T_OBJECT))) {
 2976     // Don't intrinsify mismatched object accesses.
 2977     return false;
 2978   }
 2979 
 2980   old_state.discard();
 2981 
 2982   // For CAS, unlike inline_unsafe_access, there seems no point in
 2983   // trying to refine types. Just use the coarse types here.
 2984   assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
 2985   const Type *value_type = Type::get_const_basic_type(type);
 2986 
 2987   switch (kind) {
 2988     case LS_get_set:
 2989     case LS_cmp_exchange: {
 2990       if (type == T_OBJECT) {
 2991         const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
 2992         if (tjp != nullptr) {
 2993           value_type = tjp;
 2994         }
 2995       }
 2996       break;
 2997     }
 2998     case LS_cmp_swap:
 2999     case LS_cmp_swap_weak:
 3000     case LS_get_add:
 3001       break;
 3002     default:
 3003       ShouldNotReachHere();
 3004   }
 3005 
 3006   // Null check receiver.
 3007   receiver = null_check(receiver);
 3008   if (stopped()) {
 3009     return true;
 3010   }
 3011 
 3012   int alias_idx = C->get_alias_index(adr_type);
 3013 
 3014   if (is_reference_type(type)) {
 3015     decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF;
 3016 
 3017     if (oldval != nullptr && oldval->is_InlineType()) {
 3018       // Re-execute the unsafe access if allocation triggers deoptimization.
 3019       PreserveReexecuteState preexecs(this);
 3020       jvms()->set_should_reexecute(true);
 3021       oldval = oldval->as_InlineType()->buffer(this)->get_oop();
 3022     }
 3023     if (newval != nullptr && newval->is_InlineType()) {
 3024       // Re-execute the unsafe access if allocation triggers deoptimization.
 3025       PreserveReexecuteState preexecs(this);
 3026       jvms()->set_should_reexecute(true);
 3027       newval = newval->as_InlineType()->buffer(this)->get_oop();
 3028     }
 3029 
 3030     // Transformation of a value which could be null pointer (CastPP #null)
 3031     // could be delayed during Parse (for example, in adjust_map_after_if()).
 3032     // Execute transformation here to avoid barrier generation in such case.
 3033     if (_gvn.type(newval) == TypePtr::NULL_PTR)
 3034       newval = _gvn.makecon(TypePtr::NULL_PTR);
 3035 
 3036     if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) {
 3037       // Refine the value to a null constant, when it is known to be null
 3038       oldval = _gvn.makecon(TypePtr::NULL_PTR);
 3039     }
 3040   }
 3041 
 3042   Node* result = nullptr;
 3043   switch (kind) {
 3044     case LS_cmp_exchange: {
 3045       result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx,
 3046                                             oldval, newval, value_type, type, decorators);
 3047       break;
 3048     }
 3049     case LS_cmp_swap_weak:
 3050       decorators |= C2_WEAK_CMPXCHG;
 3051     case LS_cmp_swap: {
 3052       result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx,
 3053                                              oldval, newval, value_type, type, decorators);
 3054       break;
 3055     }
 3056     case LS_get_set: {
 3057       result = access_atomic_xchg_at(base, adr, adr_type, alias_idx,
 3058                                      newval, value_type, type, decorators);
 3059       break;
 3060     }
 3061     case LS_get_add: {
 3062       result = access_atomic_add_at(base, adr, adr_type, alias_idx,
 3063                                     newval, value_type, type, decorators);
 3064       break;
 3065     }
 3066     default:
 3067       ShouldNotReachHere();
 3068   }
 3069 
 3070   assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match");
 3071   set_result(result);
 3072   return true;
 3073 }
 3074 
 3075 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) {
 3076   // Regardless of form, don't allow previous ld/st to move down,
 3077   // then issue acquire, release, or volatile mem_bar.
 3078   insert_mem_bar(Op_MemBarCPUOrder);
 3079   switch(id) {
 3080     case vmIntrinsics::_loadFence:
 3081       insert_mem_bar(Op_LoadFence);
 3082       return true;
 3083     case vmIntrinsics::_storeFence:
 3084       insert_mem_bar(Op_StoreFence);
 3085       return true;
 3086     case vmIntrinsics::_storeStoreFence:
 3087       insert_mem_bar(Op_StoreStoreFence);
 3088       return true;
 3089     case vmIntrinsics::_fullFence:
 3090       insert_mem_bar(Op_MemBarFull);
 3091       return true;
 3092     default:
 3093       fatal_unexpected_iid(id);
 3094       return false;
 3095   }
 3096 }
 3097 
 3098 // private native int arrayInstanceBaseOffset0(Object[] array);
 3099 bool LibraryCallKit::inline_arrayInstanceBaseOffset() {
 3100   Node* array = argument(1);
 3101   Node* klass_node = load_object_klass(array);
 3102 
 3103   jint  layout_con = Klass::_lh_neutral_value;
 3104   Node* layout_val = get_layout_helper(klass_node, layout_con);
 3105   int   layout_is_con = (layout_val == nullptr);
 3106 
 3107   Node* header_size = nullptr;
 3108   if (layout_is_con) {
 3109     int hsize = Klass::layout_helper_header_size(layout_con);
 3110     header_size = intcon(hsize);
 3111   } else {
 3112     Node* hss = intcon(Klass::_lh_header_size_shift);
 3113     Node* hsm = intcon(Klass::_lh_header_size_mask);
 3114     header_size = _gvn.transform(new URShiftINode(layout_val, hss));
 3115     header_size = _gvn.transform(new AndINode(header_size, hsm));
 3116   }
 3117   set_result(header_size);
 3118   return true;
 3119 }
 3120 
 3121 // private native int arrayInstanceIndexScale0(Object[] array);
 3122 bool LibraryCallKit::inline_arrayInstanceIndexScale() {
 3123   Node* array = argument(1);
 3124   Node* klass_node = load_object_klass(array);
 3125 
 3126   jint  layout_con = Klass::_lh_neutral_value;
 3127   Node* layout_val = get_layout_helper(klass_node, layout_con);
 3128   int   layout_is_con = (layout_val == nullptr);
 3129 
 3130   Node* element_size = nullptr;
 3131   if (layout_is_con) {
 3132     int log_element_size  = Klass::layout_helper_log2_element_size(layout_con);
 3133     int elem_size = 1 << log_element_size;
 3134     element_size = intcon(elem_size);
 3135   } else {
 3136     Node* ess = intcon(Klass::_lh_log2_element_size_shift);
 3137     Node* esm = intcon(Klass::_lh_log2_element_size_mask);
 3138     Node* log_element_size = _gvn.transform(new URShiftINode(layout_val, ess));
 3139     log_element_size = _gvn.transform(new AndINode(log_element_size, esm));
 3140     element_size = _gvn.transform(new LShiftINode(intcon(1), log_element_size));
 3141   }
 3142   set_result(element_size);
 3143   return true;
 3144 }
 3145 
 3146 // private native int arrayLayout0(Object[] array);
 3147 bool LibraryCallKit::inline_arrayLayout() {
 3148   RegionNode* region = new RegionNode(2);
 3149   Node* phi = new PhiNode(region, TypeInt::POS);
 3150 
 3151   Node* array = argument(1);
 3152   Node* klass_node = load_object_klass(array);
 3153   generate_refArray_guard(klass_node, region);
 3154   if (region->req() == 3) {
 3155     phi->add_req(intcon((jint)LayoutKind::REFERENCE));
 3156   }
 3157 
 3158   int layout_kind_offset = in_bytes(FlatArrayKlass::layout_kind_offset());
 3159   Node* layout_kind_addr = basic_plus_adr(top(), klass_node, layout_kind_offset);
 3160   Node* layout_kind = make_load(nullptr, layout_kind_addr, TypeInt::POS, T_INT, MemNode::unordered);
 3161 
 3162   region->init_req(1, control());
 3163   phi->init_req(1, layout_kind);
 3164 
 3165   set_control(_gvn.transform(region));
 3166   set_result(_gvn.transform(phi));
 3167   return true;
 3168 }
 3169 
 3170 // private native int[] getFieldMap0(Class <?> c);
 3171 //   int offset = c._klass._acmp_maps_offset;
 3172 //   return (int[])c.obj_field(offset);
 3173 bool LibraryCallKit::inline_getFieldMap() {
 3174   Node* mirror = argument(1);
 3175   Node* klass = load_klass_from_mirror(mirror, false, nullptr, 0);
 3176 
 3177   int field_map_offset_offset = in_bytes(InstanceKlass::acmp_maps_offset_offset());
 3178   Node* field_map_offset_addr = basic_plus_adr(top(), klass, field_map_offset_offset);
 3179   Node* field_map_offset = make_load(nullptr, field_map_offset_addr, TypeInt::INT, T_INT, MemNode::unordered);
 3180   field_map_offset = _gvn.transform(ConvI2L(field_map_offset));
 3181 
 3182   Node* map_addr = basic_plus_adr(mirror, field_map_offset);
 3183   const TypeAryPtr* val_type = TypeAryPtr::INTS->cast_to_ptr_type(TypePtr::NotNull)->with_offset(0);
 3184   Node* map = access_load_at(mirror, map_addr, TypeAryPtr::INTS, val_type, T_ARRAY, IN_HEAP | MO_UNORDERED);
 3185 
 3186   set_result(map);
 3187   return true;
 3188 }
 3189 
 3190 bool LibraryCallKit::inline_onspinwait() {
 3191   insert_mem_bar(Op_OnSpinWait);
 3192   return true;
 3193 }
 3194 
 3195 bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
 3196   if (!kls->is_Con()) {
 3197     return true;
 3198   }
 3199   const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr();
 3200   if (klsptr == nullptr) {
 3201     return true;
 3202   }
 3203   ciInstanceKlass* ik = klsptr->instance_klass();
 3204   // don't need a guard for a klass that is already initialized
 3205   return !ik->is_initialized();
 3206 }
 3207 
 3208 //----------------------------inline_unsafe_writeback0-------------------------
 3209 // public native void Unsafe.writeback0(long address)
 3210 bool LibraryCallKit::inline_unsafe_writeback0() {
 3211   if (!Matcher::has_match_rule(Op_CacheWB)) {
 3212     return false;
 3213   }
 3214 #ifndef PRODUCT
 3215   assert(Matcher::has_match_rule(Op_CacheWBPreSync), "found match rule for CacheWB but not CacheWBPreSync");
 3216   assert(Matcher::has_match_rule(Op_CacheWBPostSync), "found match rule for CacheWB but not CacheWBPostSync");
 3217   ciSignature* sig = callee()->signature();
 3218   assert(sig->type_at(0)->basic_type() == T_LONG, "Unsafe_writeback0 address is long!");
 3219 #endif
 3220   null_check_receiver();  // null-check, then ignore
 3221   Node *addr = argument(1);
 3222   addr = new CastX2PNode(addr);
 3223   addr = _gvn.transform(addr);
 3224   Node *flush = new CacheWBNode(control(), memory(TypeRawPtr::BOTTOM), addr);
 3225   flush = _gvn.transform(flush);
 3226   set_memory(flush, TypeRawPtr::BOTTOM);
 3227   return true;
 3228 }
 3229 
 3230 //----------------------------inline_unsafe_writeback0-------------------------
 3231 // public native void Unsafe.writeback0(long address)
 3232 bool LibraryCallKit::inline_unsafe_writebackSync0(bool is_pre) {
 3233   if (is_pre && !Matcher::has_match_rule(Op_CacheWBPreSync)) {
 3234     return false;
 3235   }
 3236   if (!is_pre && !Matcher::has_match_rule(Op_CacheWBPostSync)) {
 3237     return false;
 3238   }
 3239 #ifndef PRODUCT
 3240   assert(Matcher::has_match_rule(Op_CacheWB),
 3241          (is_pre ? "found match rule for CacheWBPreSync but not CacheWB"
 3242                 : "found match rule for CacheWBPostSync but not CacheWB"));
 3243 
 3244 #endif
 3245   null_check_receiver();  // null-check, then ignore
 3246   Node *sync;
 3247   if (is_pre) {
 3248     sync = new CacheWBPreSyncNode(control(), memory(TypeRawPtr::BOTTOM));
 3249   } else {
 3250     sync = new CacheWBPostSyncNode(control(), memory(TypeRawPtr::BOTTOM));
 3251   }
 3252   sync = _gvn.transform(sync);
 3253   set_memory(sync, TypeRawPtr::BOTTOM);
 3254   return true;
 3255 }
 3256 
 3257 //----------------------------inline_unsafe_allocate---------------------------
 3258 // public native Object Unsafe.allocateInstance(Class<?> cls);
 3259 bool LibraryCallKit::inline_unsafe_allocate() {
 3260 
 3261 #if INCLUDE_JVMTI
 3262   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 3263     return false;
 3264   }
 3265 #endif //INCLUDE_JVMTI
 3266 
 3267   if (callee()->is_static())  return false;  // caller must have the capability!
 3268 
 3269   null_check_receiver();  // null-check, then ignore
 3270   Node* cls = null_check(argument(1));
 3271   if (stopped())  return true;
 3272 
 3273   Node* kls = load_klass_from_mirror(cls, false, nullptr, 0);
 3274   kls = null_check(kls);
 3275   if (stopped())  return true;  // argument was like int.class
 3276 
 3277 #if INCLUDE_JVMTI
 3278     // Don't try to access new allocated obj in the intrinsic.
 3279     // It causes perfomance issues even when jvmti event VmObjectAlloc is disabled.
 3280     // Deoptimize and allocate in interpreter instead.
 3281     Node* addr = makecon(TypeRawPtr::make((address) &JvmtiExport::_should_notify_object_alloc));
 3282     Node* should_post_vm_object_alloc = make_load(this->control(), addr, TypeInt::INT, T_INT, MemNode::unordered);
 3283     Node* chk = _gvn.transform(new CmpINode(should_post_vm_object_alloc, intcon(0)));
 3284     Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
 3285     {
 3286       BuildCutout unless(this, tst, PROB_MAX);
 3287       uncommon_trap(Deoptimization::Reason_intrinsic,
 3288                     Deoptimization::Action_make_not_entrant);
 3289     }
 3290     if (stopped()) {
 3291       return true;
 3292     }
 3293 #endif //INCLUDE_JVMTI
 3294 
 3295   Node* test = nullptr;
 3296   if (LibraryCallKit::klass_needs_init_guard(kls)) {
 3297     // Note:  The argument might still be an illegal value like
 3298     // Serializable.class or Object[].class.   The runtime will handle it.
 3299     // But we must make an explicit check for initialization.
 3300     Node* insp = off_heap_plus_addr(kls, in_bytes(InstanceKlass::init_state_offset()));
 3301     // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
 3302     // can generate code to load it as unsigned byte.
 3303     Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire);
 3304     Node* bits = intcon(InstanceKlass::fully_initialized);
 3305     test = _gvn.transform(new SubINode(inst, bits));
 3306     // The 'test' is non-zero if we need to take a slow path.
 3307   }
 3308   Node* obj = new_instance(kls, test);
 3309   set_result(obj);
 3310   return true;
 3311 }
 3312 
 3313 //------------------------inline_native_time_funcs--------------
 3314 // inline code for System.currentTimeMillis() and System.nanoTime()
 3315 // these have the same type and signature
 3316 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
 3317   const TypeFunc* tf = OptoRuntime::void_long_Type();
 3318   const TypePtr* no_memory_effects = nullptr;
 3319   Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
 3320   Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0));
 3321 #ifdef ASSERT
 3322   Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1));
 3323   assert(value_top == top(), "second value must be top");
 3324 #endif
 3325   set_result(value);
 3326   return true;
 3327 }
 3328 
 3329 //--------------------inline_native_vthread_start_transition--------------------
 3330 // inline void startTransition(boolean is_mount);
 3331 // inline void startFinalTransition();
 3332 // Pseudocode of implementation:
 3333 //
 3334 // java_lang_Thread::set_is_in_vthread_transition(vthread, true);
 3335 // carrier->set_is_in_vthread_transition(true);
 3336 // OrderAccess::storeload();
 3337 // int disable_requests = java_lang_Thread::vthread_transition_disable_count(vthread)
 3338 //                        + global_vthread_transition_disable_count();
 3339 // if (disable_requests > 0) {
 3340 //   slow path: runtime call
 3341 // }
 3342 bool LibraryCallKit::inline_native_vthread_start_transition(address funcAddr, const char* funcName, bool is_final_transition) {
 3343   Node* vt_oop = must_be_not_null(argument(0), true); // VirtualThread this argument
 3344   IdealKit ideal(this);
 3345 
 3346   Node* thread = ideal.thread();
 3347   Node* jt_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_in_vthread_transition_offset()));
 3348   Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_vthread_transition_offset());
 3349   access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), ideal.ConI(1), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3350   access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), ideal.ConI(1), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3351   insert_mem_bar(Op_MemBarStoreLoad);
 3352   ideal.sync_kit(this);
 3353 
 3354   Node* global_disable_addr = makecon(TypeRawPtr::make((address)MountUnmountDisabler::global_vthread_transition_disable_count_address()));
 3355   Node* global_disable = ideal.load(ideal.ctrl(), global_disable_addr, TypeInt::INT, T_INT, Compile::AliasIdxRaw, true /*require_atomic_access*/);
 3356   Node* vt_disable_addr = basic_plus_adr(vt_oop, java_lang_Thread::vthread_transition_disable_count_offset());
 3357   const TypePtr* vt_disable_addr_t = _gvn.type(vt_disable_addr)->is_ptr();
 3358   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*/);
 3359   Node* disabled = _gvn.transform(new AddINode(global_disable, vt_disable));
 3360 
 3361   ideal.if_then(disabled, BoolTest::ne, ideal.ConI(0)); {
 3362     sync_kit(ideal);
 3363     Node* is_mount = is_final_transition ? ideal.ConI(0) : argument(1);
 3364     const TypeFunc* tf = OptoRuntime::vthread_transition_Type();
 3365     make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, is_mount);
 3366     ideal.sync_kit(this);
 3367   }
 3368   ideal.end_if();
 3369 
 3370   final_sync(ideal);
 3371   return true;
 3372 }
 3373 
 3374 bool LibraryCallKit::inline_native_vthread_end_transition(address funcAddr, const char* funcName, bool is_first_transition) {
 3375   Node* vt_oop = must_be_not_null(argument(0), true); // VirtualThread this argument
 3376   IdealKit ideal(this);
 3377 
 3378   Node* _notify_jvmti_addr = makecon(TypeRawPtr::make((address)MountUnmountDisabler::notify_jvmti_events_address()));
 3379   Node* _notify_jvmti = ideal.load(ideal.ctrl(), _notify_jvmti_addr, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw);
 3380 
 3381   ideal.if_then(_notify_jvmti, BoolTest::eq, ideal.ConI(1)); {
 3382     sync_kit(ideal);
 3383     Node* is_mount = is_first_transition ? ideal.ConI(1) : argument(1);
 3384     const TypeFunc* tf = OptoRuntime::vthread_transition_Type();
 3385     make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, is_mount);
 3386     ideal.sync_kit(this);
 3387   } ideal.else_(); {
 3388     Node* thread = ideal.thread();
 3389     Node* jt_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_in_vthread_transition_offset()));
 3390     Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_vthread_transition_offset());
 3391 
 3392     sync_kit(ideal);
 3393     access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), ideal.ConI(0), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3394     access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), ideal.ConI(0), TypeInt::BOOL, T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3395     ideal.sync_kit(this);
 3396   } ideal.end_if();
 3397 
 3398   final_sync(ideal);
 3399   return true;
 3400 }
 3401 
 3402 #if INCLUDE_JVMTI
 3403 
 3404 // Always update the is_disable_suspend bit.
 3405 bool LibraryCallKit::inline_native_notify_jvmti_sync() {
 3406   if (!DoJVMTIVirtualThreadTransitions) {
 3407     return true;
 3408   }
 3409   IdealKit ideal(this);
 3410 
 3411   {
 3412     // unconditionally update the is_disable_suspend bit in current JavaThread
 3413     Node* thread = ideal.thread();
 3414     Node* arg = argument(0); // argument for notification
 3415     Node* addr = off_heap_plus_addr(thread, in_bytes(JavaThread::is_disable_suspend_offset()));
 3416     const TypePtr *addr_type = _gvn.type(addr)->isa_ptr();
 3417 
 3418     sync_kit(ideal);
 3419     access_store_at(nullptr, addr, addr_type, arg, _gvn.type(arg), T_BOOLEAN, IN_NATIVE | MO_UNORDERED);
 3420     ideal.sync_kit(this);
 3421   }
 3422   final_sync(ideal);
 3423 
 3424   return true;
 3425 }
 3426 
 3427 #endif // INCLUDE_JVMTI
 3428 
 3429 #ifdef JFR_HAVE_INTRINSICS
 3430 
 3431 /**
 3432  * if oop->klass != null
 3433  *   // normal class
 3434  *   epoch = _epoch_state ? 2 : 1
 3435  *   if oop->klass->trace_id & ((epoch << META_SHIFT) | epoch)) != epoch {
 3436  *     ... // enter slow path when the klass is first recorded or the epoch of JFR shifts
 3437  *   }
 3438  *   id = oop->klass->trace_id >> TRACE_ID_SHIFT // normal class path
 3439  * else
 3440  *   // primitive class
 3441  *   if oop->array_klass != null
 3442  *     id = (oop->array_klass->trace_id >> TRACE_ID_SHIFT) + 1 // primitive class path
 3443  *   else
 3444  *     id = LAST_TYPE_ID + 1 // void class path
 3445  *   if (!signaled)
 3446  *     signaled = true
 3447  */
 3448 bool LibraryCallKit::inline_native_classID() {
 3449   Node* cls = argument(0);
 3450 
 3451   IdealKit ideal(this);
 3452 #define __ ideal.
 3453   IdealVariable result(ideal); __ declarations_done();
 3454   Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(),
 3455                                                  basic_plus_adr(cls, java_lang_Class::klass_offset()),
 3456                                                  TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 3457 
 3458 
 3459   __ if_then(kls, BoolTest::ne, null()); {
 3460     Node* kls_trace_id_addr = basic_plus_adr(kls, in_bytes(KLASS_TRACE_ID_OFFSET));
 3461     Node* kls_trace_id_raw = ideal.load(ideal.ctrl(), kls_trace_id_addr,TypeLong::LONG, T_LONG, Compile::AliasIdxRaw);
 3462 
 3463     Node* epoch_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_address()));
 3464     Node* epoch = ideal.load(ideal.ctrl(), epoch_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw);
 3465     epoch = _gvn.transform(new LShiftLNode(longcon(1), epoch));
 3466     Node* mask = _gvn.transform(new LShiftLNode(epoch, intcon(META_SHIFT)));
 3467     mask = _gvn.transform(new OrLNode(mask, epoch));
 3468     Node* kls_trace_id_raw_and_mask = _gvn.transform(new AndLNode(kls_trace_id_raw, mask));
 3469 
 3470     float unlikely  = PROB_UNLIKELY(0.999);
 3471     __ if_then(kls_trace_id_raw_and_mask, BoolTest::ne, epoch, unlikely); {
 3472       sync_kit(ideal);
 3473       make_runtime_call(RC_LEAF,
 3474                         OptoRuntime::class_id_load_barrier_Type(),
 3475                         CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::load_barrier),
 3476                         "class id load barrier",
 3477                         TypePtr::BOTTOM,
 3478                         kls);
 3479       ideal.sync_kit(this);
 3480     } __ end_if();
 3481 
 3482     ideal.set(result,  _gvn.transform(new URShiftLNode(kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT))));
 3483   } __ else_(); {
 3484     Node* array_kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(),
 3485                                                    basic_plus_adr(cls, java_lang_Class::array_klass_offset()),
 3486                                                    TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 3487     __ if_then(array_kls, BoolTest::ne, null()); {
 3488       Node* array_kls_trace_id_addr = basic_plus_adr(array_kls, in_bytes(KLASS_TRACE_ID_OFFSET));
 3489       Node* array_kls_trace_id_raw = ideal.load(ideal.ctrl(), array_kls_trace_id_addr, TypeLong::LONG, T_LONG, Compile::AliasIdxRaw);
 3490       Node* array_kls_trace_id = _gvn.transform(new URShiftLNode(array_kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT)));
 3491       ideal.set(result, _gvn.transform(new AddLNode(array_kls_trace_id, longcon(1))));
 3492     } __ else_(); {
 3493       // void class case
 3494       ideal.set(result, longcon(LAST_TYPE_ID + 1));
 3495     } __ end_if();
 3496 
 3497     Node* signaled_flag_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::signal_address()));
 3498     Node* signaled = ideal.load(ideal.ctrl(), signaled_flag_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw, true, MemNode::acquire);
 3499     __ if_then(signaled, BoolTest::ne, ideal.ConI(1)); {
 3500       ideal.store(ideal.ctrl(), signaled_flag_address, ideal.ConI(1), T_BOOLEAN, Compile::AliasIdxRaw, MemNode::release, true);
 3501     } __ end_if();
 3502   } __ end_if();
 3503 
 3504   final_sync(ideal);
 3505   set_result(ideal.value(result));
 3506 #undef __
 3507   return true;
 3508 }
 3509 
 3510 //------------------------inline_native_jvm_commit------------------
 3511 bool LibraryCallKit::inline_native_jvm_commit() {
 3512   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3513 
 3514   // Save input memory and i_o state.
 3515   Node* input_memory_state = reset_memory();
 3516   set_all_memory(input_memory_state);
 3517   Node* input_io_state = i_o();
 3518 
 3519   // TLS.
 3520   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 3521   // Jfr java buffer.
 3522   Node* java_buffer_offset = _gvn.transform(AddPNode::make_off_heap(tls_ptr, MakeConX(in_bytes(JAVA_BUFFER_OFFSET_JFR))));
 3523   Node* java_buffer = _gvn.transform(new LoadPNode(control(), input_memory_state, java_buffer_offset, TypePtr::BOTTOM, TypeRawPtr::NOTNULL, MemNode::unordered));
 3524   Node* java_buffer_pos_offset = _gvn.transform(AddPNode::make_off_heap(java_buffer, MakeConX(in_bytes(JFR_BUFFER_POS_OFFSET))));
 3525 
 3526   // Load the current value of the notified field in the JfrThreadLocal.
 3527   Node* notified_offset = off_heap_plus_addr(tls_ptr, in_bytes(NOTIFY_OFFSET_JFR));
 3528   Node* notified = make_load(control(), notified_offset, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered);
 3529 
 3530   // Test for notification.
 3531   Node* notified_cmp = _gvn.transform(new CmpINode(notified, _gvn.intcon(1)));
 3532   Node* test_notified = _gvn.transform(new BoolNode(notified_cmp, BoolTest::eq));
 3533   IfNode* iff_notified = create_and_map_if(control(), test_notified, PROB_MIN, COUNT_UNKNOWN);
 3534 
 3535   // True branch, is notified.
 3536   Node* is_notified = _gvn.transform(new IfTrueNode(iff_notified));
 3537   set_control(is_notified);
 3538 
 3539   // Reset notified state.
 3540   store_to_memory(control(), notified_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::unordered);
 3541   Node* notified_reset_memory = reset_memory();
 3542 
 3543   // 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.
 3544   Node* current_pos_X = _gvn.transform(new LoadXNode(control(), input_memory_state, java_buffer_pos_offset, TypeRawPtr::NOTNULL, TypeX_X, MemNode::unordered));
 3545   // Convert the machine-word to a long.
 3546   Node* current_pos = ConvX2L(current_pos_X);
 3547 
 3548   // False branch, not notified.
 3549   Node* not_notified = _gvn.transform(new IfFalseNode(iff_notified));
 3550   set_control(not_notified);
 3551   set_all_memory(input_memory_state);
 3552 
 3553   // Arg is the next position as a long.
 3554   Node* arg = argument(0);
 3555   // Convert long to machine-word.
 3556   Node* next_pos_X = ConvL2X(arg);
 3557 
 3558   // Store the next_position to the underlying jfr java buffer.
 3559   store_to_memory(control(), java_buffer_pos_offset, next_pos_X, LP64_ONLY(T_LONG) NOT_LP64(T_INT), MemNode::release);
 3560 
 3561   Node* commit_memory = reset_memory();
 3562   set_all_memory(commit_memory);
 3563 
 3564   // 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.
 3565   Node* java_buffer_flags_offset = _gvn.transform(AddPNode::make_off_heap(java_buffer, MakeConX(in_bytes(JFR_BUFFER_FLAGS_OFFSET))));
 3566   Node* flags = make_load(control(), java_buffer_flags_offset, TypeInt::UBYTE, T_BYTE, MemNode::unordered);
 3567   Node* lease_constant = _gvn.intcon(4);
 3568 
 3569   // And flags with lease constant.
 3570   Node* lease = _gvn.transform(new AndINode(flags, lease_constant));
 3571 
 3572   // Branch on lease to conditionalize returning the leased java buffer.
 3573   Node* lease_cmp = _gvn.transform(new CmpINode(lease, lease_constant));
 3574   Node* test_lease = _gvn.transform(new BoolNode(lease_cmp, BoolTest::eq));
 3575   IfNode* iff_lease = create_and_map_if(control(), test_lease, PROB_MIN, COUNT_UNKNOWN);
 3576 
 3577   // False branch, not a lease.
 3578   Node* not_lease = _gvn.transform(new IfFalseNode(iff_lease));
 3579 
 3580   // True branch, is lease.
 3581   Node* is_lease = _gvn.transform(new IfTrueNode(iff_lease));
 3582   set_control(is_lease);
 3583 
 3584   // Make a runtime call, which can safepoint, to return the leased buffer. This updates both the JfrThreadLocal and the Java event writer oop.
 3585   Node* call_return_lease = make_runtime_call(RC_NO_LEAF,
 3586                                               OptoRuntime::void_void_Type(),
 3587                                               SharedRuntime::jfr_return_lease(),
 3588                                               "return_lease", TypePtr::BOTTOM);
 3589   Node* call_return_lease_control = _gvn.transform(new ProjNode(call_return_lease, TypeFunc::Control));
 3590 
 3591   RegionNode* lease_compare_rgn = new RegionNode(PATH_LIMIT);
 3592   record_for_igvn(lease_compare_rgn);
 3593   PhiNode* lease_compare_mem = new PhiNode(lease_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3594   record_for_igvn(lease_compare_mem);
 3595   PhiNode* lease_compare_io = new PhiNode(lease_compare_rgn, Type::ABIO);
 3596   record_for_igvn(lease_compare_io);
 3597   PhiNode* lease_result_value = new PhiNode(lease_compare_rgn, TypeLong::LONG);
 3598   record_for_igvn(lease_result_value);
 3599 
 3600   // Update control and phi nodes.
 3601   lease_compare_rgn->init_req(_true_path, call_return_lease_control);
 3602   lease_compare_rgn->init_req(_false_path, not_lease);
 3603 
 3604   lease_compare_mem->init_req(_true_path, reset_memory());
 3605   lease_compare_mem->init_req(_false_path, commit_memory);
 3606 
 3607   lease_compare_io->init_req(_true_path, i_o());
 3608   lease_compare_io->init_req(_false_path, input_io_state);
 3609 
 3610   lease_result_value->init_req(_true_path, _gvn.longcon(0)); // if the lease was returned, return 0L.
 3611   lease_result_value->init_req(_false_path, arg); // if not lease, return new updated position.
 3612 
 3613   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 3614   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3615   PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO);
 3616   PhiNode* result_value = new PhiNode(result_rgn, TypeLong::LONG);
 3617 
 3618   // Update control and phi nodes.
 3619   result_rgn->init_req(_true_path, is_notified);
 3620   result_rgn->init_req(_false_path, _gvn.transform(lease_compare_rgn));
 3621 
 3622   result_mem->init_req(_true_path, notified_reset_memory);
 3623   result_mem->init_req(_false_path, _gvn.transform(lease_compare_mem));
 3624 
 3625   result_io->init_req(_true_path, input_io_state);
 3626   result_io->init_req(_false_path, _gvn.transform(lease_compare_io));
 3627 
 3628   result_value->init_req(_true_path, current_pos);
 3629   result_value->init_req(_false_path, _gvn.transform(lease_result_value));
 3630 
 3631   // Set output state.
 3632   set_control(_gvn.transform(result_rgn));
 3633   set_all_memory(_gvn.transform(result_mem));
 3634   set_i_o(_gvn.transform(result_io));
 3635   set_result(result_rgn, result_value);
 3636   return true;
 3637 }
 3638 
 3639 /*
 3640  * The intrinsic is a model of this pseudo-code:
 3641  *
 3642  * JfrThreadLocal* const tl = Thread::jfr_thread_local()
 3643  * jobject h_event_writer = tl->java_event_writer();
 3644  * if (h_event_writer == nullptr) {
 3645  *   return nullptr;
 3646  * }
 3647  * oop threadObj = Thread::threadObj();
 3648  * oop vthread = java_lang_Thread::vthread(threadObj);
 3649  * traceid tid;
 3650  * bool pinVirtualThread;
 3651  * bool excluded;
 3652  * if (vthread != threadObj) {  // i.e. current thread is virtual
 3653  *   tid = java_lang_Thread::tid(vthread);
 3654  *   u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(vthread);
 3655  *   pinVirtualThread = VMContinuations;
 3656  *   excluded = vthread_epoch_raw & excluded_mask;
 3657  *   if (!excluded) {
 3658  *     traceid current_epoch = JfrTraceIdEpoch::current_generation();
 3659  *     u2 vthread_epoch = vthread_epoch_raw & epoch_mask;
 3660  *     if (vthread_epoch != current_epoch) {
 3661  *       write_checkpoint();
 3662  *     }
 3663  *   }
 3664  * } else {
 3665  *   tid = java_lang_Thread::tid(threadObj);
 3666  *   u2 thread_epoch_raw = java_lang_Thread::jfr_epoch(threadObj);
 3667  *   pinVirtualThread = false;
 3668  *   excluded = thread_epoch_raw & excluded_mask;
 3669  * }
 3670  * oop event_writer = JNIHandles::resolve_non_null(h_event_writer);
 3671  * traceid tid_in_event_writer = getField(event_writer, "threadID");
 3672  * if (tid_in_event_writer != tid) {
 3673  *   setField(event_writer, "pinVirtualThread", pinVirtualThread);
 3674  *   setField(event_writer, "excluded", excluded);
 3675  *   setField(event_writer, "threadID", tid);
 3676  * }
 3677  * return event_writer
 3678  */
 3679 bool LibraryCallKit::inline_native_getEventWriter() {
 3680   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3681 
 3682   // Save input memory and i_o state.
 3683   Node* input_memory_state = reset_memory();
 3684   set_all_memory(input_memory_state);
 3685   Node* input_io_state = i_o();
 3686 
 3687   // The most significant bit of the u2 is used to denote thread exclusion
 3688   Node* excluded_shift = _gvn.intcon(15);
 3689   Node* excluded_mask = _gvn.intcon(1 << 15);
 3690   // The epoch generation is the range [1-32767]
 3691   Node* epoch_mask = _gvn.intcon(32767);
 3692 
 3693   // TLS
 3694   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 3695 
 3696   // Load the address of java event writer jobject handle from the jfr_thread_local structure.
 3697   Node* jobj_ptr = off_heap_plus_addr(tls_ptr, in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR));
 3698 
 3699   // Load the eventwriter jobject handle.
 3700   Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
 3701 
 3702   // Null check the jobject handle.
 3703   Node* jobj_cmp_null = _gvn.transform(new CmpPNode(jobj, null()));
 3704   Node* test_jobj_not_equal_null = _gvn.transform(new BoolNode(jobj_cmp_null, BoolTest::ne));
 3705   IfNode* iff_jobj_not_equal_null = create_and_map_if(control(), test_jobj_not_equal_null, PROB_MAX, COUNT_UNKNOWN);
 3706 
 3707   // False path, jobj is null.
 3708   Node* jobj_is_null = _gvn.transform(new IfFalseNode(iff_jobj_not_equal_null));
 3709 
 3710   // True path, jobj is not null.
 3711   Node* jobj_is_not_null = _gvn.transform(new IfTrueNode(iff_jobj_not_equal_null));
 3712 
 3713   set_control(jobj_is_not_null);
 3714 
 3715   // Load the threadObj for the CarrierThread.
 3716   Node* threadObj = generate_current_thread(tls_ptr);
 3717 
 3718   // Load the vthread.
 3719   Node* vthread = generate_virtual_thread(tls_ptr);
 3720 
 3721   // If vthread != threadObj, this is a virtual thread.
 3722   Node* vthread_cmp_threadObj = _gvn.transform(new CmpPNode(vthread, threadObj));
 3723   Node* test_vthread_not_equal_threadObj = _gvn.transform(new BoolNode(vthread_cmp_threadObj, BoolTest::ne));
 3724   IfNode* iff_vthread_not_equal_threadObj =
 3725     create_and_map_if(jobj_is_not_null, test_vthread_not_equal_threadObj, PROB_FAIR, COUNT_UNKNOWN);
 3726 
 3727   // False branch, fallback to threadObj.
 3728   Node* vthread_equal_threadObj = _gvn.transform(new IfFalseNode(iff_vthread_not_equal_threadObj));
 3729   set_control(vthread_equal_threadObj);
 3730 
 3731   // Load the tid field from the vthread object.
 3732   Node* thread_obj_tid = load_field_from_object(threadObj, "tid", "J");
 3733 
 3734   // Load the raw epoch value from the threadObj.
 3735   Node* threadObj_epoch_offset = basic_plus_adr(threadObj, java_lang_Thread::jfr_epoch_offset());
 3736   Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset,
 3737                                              _gvn.type(threadObj_epoch_offset)->isa_ptr(),
 3738                                              TypeInt::CHAR, T_CHAR,
 3739                                              IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 3740 
 3741   // Mask off the excluded information from the epoch.
 3742   Node * threadObj_is_excluded = _gvn.transform(new AndINode(threadObj_epoch_raw, excluded_mask));
 3743 
 3744   // True branch, this is a virtual thread.
 3745   Node* vthread_not_equal_threadObj = _gvn.transform(new IfTrueNode(iff_vthread_not_equal_threadObj));
 3746   set_control(vthread_not_equal_threadObj);
 3747 
 3748   // Load the tid field from the vthread object.
 3749   Node* vthread_tid = load_field_from_object(vthread, "tid", "J");
 3750 
 3751   // Continuation support determines if a virtual thread should be pinned.
 3752   Node* global_addr = makecon(TypeRawPtr::make((address)&VMContinuations));
 3753   Node* continuation_support = make_load(control(), global_addr, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered);
 3754 
 3755   // Load the raw epoch value from the vthread.
 3756   Node* vthread_epoch_offset = basic_plus_adr(vthread, java_lang_Thread::jfr_epoch_offset());
 3757   Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, _gvn.type(vthread_epoch_offset)->is_ptr(),
 3758                                            TypeInt::CHAR, T_CHAR,
 3759                                            IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 3760 
 3761   // Mask off the excluded information from the epoch.
 3762   Node * vthread_is_excluded = _gvn.transform(new AndINode(vthread_epoch_raw, excluded_mask));
 3763 
 3764   // Branch on excluded to conditionalize updating the epoch for the virtual thread.
 3765   Node* is_excluded_cmp = _gvn.transform(new CmpINode(vthread_is_excluded, excluded_mask));
 3766   Node* test_not_excluded = _gvn.transform(new BoolNode(is_excluded_cmp, BoolTest::ne));
 3767   IfNode* iff_not_excluded = create_and_map_if(control(), test_not_excluded, PROB_MAX, COUNT_UNKNOWN);
 3768 
 3769   // False branch, vthread is excluded, no need to write epoch info.
 3770   Node* excluded = _gvn.transform(new IfFalseNode(iff_not_excluded));
 3771 
 3772   // True branch, vthread is included, update epoch info.
 3773   Node* included = _gvn.transform(new IfTrueNode(iff_not_excluded));
 3774   set_control(included);
 3775 
 3776   // Get epoch value.
 3777   Node* epoch = _gvn.transform(new AndINode(vthread_epoch_raw, epoch_mask));
 3778 
 3779   // Load the current epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR.
 3780   Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address()));
 3781   Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered);
 3782 
 3783   // Compare the epoch in the vthread to the current epoch generation.
 3784   Node* const epoch_cmp = _gvn.transform(new CmpUNode(current_epoch_generation, epoch));
 3785   Node* test_epoch_not_equal = _gvn.transform(new BoolNode(epoch_cmp, BoolTest::ne));
 3786   IfNode* iff_epoch_not_equal = create_and_map_if(control(), test_epoch_not_equal, PROB_FAIR, COUNT_UNKNOWN);
 3787 
 3788   // False path, epoch is equal, checkpoint information is valid.
 3789   Node* epoch_is_equal = _gvn.transform(new IfFalseNode(iff_epoch_not_equal));
 3790 
 3791   // True path, epoch is not equal, write a checkpoint for the vthread.
 3792   Node* epoch_is_not_equal = _gvn.transform(new IfTrueNode(iff_epoch_not_equal));
 3793 
 3794   set_control(epoch_is_not_equal);
 3795 
 3796   // Make a runtime call, which can safepoint, to write a checkpoint for the vthread for this epoch.
 3797   // The call also updates the native thread local thread id and the vthread with the current epoch.
 3798   Node* call_write_checkpoint = make_runtime_call(RC_NO_LEAF,
 3799                                                   OptoRuntime::jfr_write_checkpoint_Type(),
 3800                                                   SharedRuntime::jfr_write_checkpoint(),
 3801                                                   "write_checkpoint", TypePtr::BOTTOM);
 3802   Node* call_write_checkpoint_control = _gvn.transform(new ProjNode(call_write_checkpoint, TypeFunc::Control));
 3803 
 3804   // vthread epoch != current epoch
 3805   RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT);
 3806   record_for_igvn(epoch_compare_rgn);
 3807   PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3808   record_for_igvn(epoch_compare_mem);
 3809   PhiNode* epoch_compare_io = new PhiNode(epoch_compare_rgn, Type::ABIO);
 3810   record_for_igvn(epoch_compare_io);
 3811 
 3812   // Update control and phi nodes.
 3813   epoch_compare_rgn->init_req(_true_path, call_write_checkpoint_control);
 3814   epoch_compare_rgn->init_req(_false_path, epoch_is_equal);
 3815   epoch_compare_mem->init_req(_true_path, reset_memory());
 3816   epoch_compare_mem->init_req(_false_path, input_memory_state);
 3817   epoch_compare_io->init_req(_true_path, i_o());
 3818   epoch_compare_io->init_req(_false_path, input_io_state);
 3819 
 3820   // excluded != true
 3821   RegionNode* exclude_compare_rgn = new RegionNode(PATH_LIMIT);
 3822   record_for_igvn(exclude_compare_rgn);
 3823   PhiNode* exclude_compare_mem = new PhiNode(exclude_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3824   record_for_igvn(exclude_compare_mem);
 3825   PhiNode* exclude_compare_io = new PhiNode(exclude_compare_rgn, Type::ABIO);
 3826   record_for_igvn(exclude_compare_io);
 3827 
 3828   // Update control and phi nodes.
 3829   exclude_compare_rgn->init_req(_true_path, _gvn.transform(epoch_compare_rgn));
 3830   exclude_compare_rgn->init_req(_false_path, excluded);
 3831   exclude_compare_mem->init_req(_true_path, _gvn.transform(epoch_compare_mem));
 3832   exclude_compare_mem->init_req(_false_path, input_memory_state);
 3833   exclude_compare_io->init_req(_true_path, _gvn.transform(epoch_compare_io));
 3834   exclude_compare_io->init_req(_false_path, input_io_state);
 3835 
 3836   // vthread != threadObj
 3837   RegionNode* vthread_compare_rgn = new RegionNode(PATH_LIMIT);
 3838   record_for_igvn(vthread_compare_rgn);
 3839   PhiNode* vthread_compare_mem = new PhiNode(vthread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3840   PhiNode* vthread_compare_io = new PhiNode(vthread_compare_rgn, Type::ABIO);
 3841   record_for_igvn(vthread_compare_io);
 3842   PhiNode* tid = new PhiNode(vthread_compare_rgn, TypeLong::LONG);
 3843   record_for_igvn(tid);
 3844   PhiNode* exclusion = new PhiNode(vthread_compare_rgn, TypeInt::CHAR);
 3845   record_for_igvn(exclusion);
 3846   PhiNode* pinVirtualThread = new PhiNode(vthread_compare_rgn, TypeInt::BOOL);
 3847   record_for_igvn(pinVirtualThread);
 3848 
 3849   // Update control and phi nodes.
 3850   vthread_compare_rgn->init_req(_true_path, _gvn.transform(exclude_compare_rgn));
 3851   vthread_compare_rgn->init_req(_false_path, vthread_equal_threadObj);
 3852   vthread_compare_mem->init_req(_true_path, _gvn.transform(exclude_compare_mem));
 3853   vthread_compare_mem->init_req(_false_path, input_memory_state);
 3854   vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io));
 3855   vthread_compare_io->init_req(_false_path, input_io_state);
 3856   tid->init_req(_true_path, vthread_tid);
 3857   tid->init_req(_false_path, thread_obj_tid);
 3858   exclusion->init_req(_true_path, vthread_is_excluded);
 3859   exclusion->init_req(_false_path, threadObj_is_excluded);
 3860   pinVirtualThread->init_req(_true_path, continuation_support);
 3861   pinVirtualThread->init_req(_false_path, _gvn.intcon(0));
 3862 
 3863   // Update branch state.
 3864   set_control(_gvn.transform(vthread_compare_rgn));
 3865   set_all_memory(_gvn.transform(vthread_compare_mem));
 3866   set_i_o(_gvn.transform(vthread_compare_io));
 3867 
 3868   // Load the event writer oop by dereferencing the jobject handle.
 3869   ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter"));
 3870   assert(klass_EventWriter->is_loaded(), "invariant");
 3871   ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass();
 3872   const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter);
 3873   const TypeOopPtr* const xtype = aklass->as_exact_instance_type();
 3874   Node* jobj_untagged = _gvn.transform(AddPNode::make_off_heap(jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global)));
 3875   Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD);
 3876 
 3877   // Load the current thread id from the event writer object.
 3878   Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J");
 3879   // Get the field offset to, conditionally, store an updated tid value later.
 3880   Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false);
 3881   // Get the field offset to, conditionally, store an updated exclusion value later.
 3882   Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false);
 3883   // Get the field offset to, conditionally, store an updated pinVirtualThread value later.
 3884   Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false);
 3885 
 3886   RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT);
 3887   record_for_igvn(event_writer_tid_compare_rgn);
 3888   PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3889   record_for_igvn(event_writer_tid_compare_mem);
 3890   PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO);
 3891   record_for_igvn(event_writer_tid_compare_io);
 3892 
 3893   // Compare the current tid from the thread object to what is currently stored in the event writer object.
 3894   Node* const tid_cmp = _gvn.transform(new CmpLNode(event_writer_tid, _gvn.transform(tid)));
 3895   Node* test_tid_not_equal = _gvn.transform(new BoolNode(tid_cmp, BoolTest::ne));
 3896   IfNode* iff_tid_not_equal = create_and_map_if(_gvn.transform(vthread_compare_rgn), test_tid_not_equal, PROB_FAIR, COUNT_UNKNOWN);
 3897 
 3898   // False path, tids are the same.
 3899   Node* tid_is_equal = _gvn.transform(new IfFalseNode(iff_tid_not_equal));
 3900 
 3901   // True path, tid is not equal, need to update the tid in the event writer.
 3902   Node* tid_is_not_equal = _gvn.transform(new IfTrueNode(iff_tid_not_equal));
 3903   record_for_igvn(tid_is_not_equal);
 3904 
 3905   // Store the pin state to the event writer.
 3906   store_to_memory(tid_is_not_equal, event_writer_pin_field, _gvn.transform(pinVirtualThread), T_BOOLEAN, MemNode::unordered);
 3907 
 3908   // Store the exclusion state to the event writer.
 3909   Node* excluded_bool = _gvn.transform(new URShiftINode(_gvn.transform(exclusion), excluded_shift));
 3910   store_to_memory(tid_is_not_equal, event_writer_excluded_field, excluded_bool, T_BOOLEAN, MemNode::unordered);
 3911 
 3912   // Store the tid to the event writer.
 3913   store_to_memory(tid_is_not_equal, event_writer_tid_field, tid, T_LONG, MemNode::unordered);
 3914 
 3915   // Update control and phi nodes.
 3916   event_writer_tid_compare_rgn->init_req(_true_path, tid_is_not_equal);
 3917   event_writer_tid_compare_rgn->init_req(_false_path, tid_is_equal);
 3918   event_writer_tid_compare_mem->init_req(_true_path, reset_memory());
 3919   event_writer_tid_compare_mem->init_req(_false_path, _gvn.transform(vthread_compare_mem));
 3920   event_writer_tid_compare_io->init_req(_true_path, i_o());
 3921   event_writer_tid_compare_io->init_req(_false_path, _gvn.transform(vthread_compare_io));
 3922 
 3923   // Result of top level CFG, Memory, IO and Value.
 3924   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 3925   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 3926   PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO);
 3927   PhiNode* result_value = new PhiNode(result_rgn, TypeInstPtr::BOTTOM);
 3928 
 3929   // Result control.
 3930   result_rgn->init_req(_true_path, _gvn.transform(event_writer_tid_compare_rgn));
 3931   result_rgn->init_req(_false_path, jobj_is_null);
 3932 
 3933   // Result memory.
 3934   result_mem->init_req(_true_path, _gvn.transform(event_writer_tid_compare_mem));
 3935   result_mem->init_req(_false_path, input_memory_state);
 3936 
 3937   // Result IO.
 3938   result_io->init_req(_true_path, _gvn.transform(event_writer_tid_compare_io));
 3939   result_io->init_req(_false_path, input_io_state);
 3940 
 3941   // Result value.
 3942   result_value->init_req(_true_path, event_writer); // return event writer oop
 3943   result_value->init_req(_false_path, null()); // return null
 3944 
 3945   // Set output state.
 3946   set_control(_gvn.transform(result_rgn));
 3947   set_all_memory(_gvn.transform(result_mem));
 3948   set_i_o(_gvn.transform(result_io));
 3949   set_result(result_rgn, result_value);
 3950   return true;
 3951 }
 3952 
 3953 /*
 3954  * The intrinsic is a model of this pseudo-code:
 3955  *
 3956  * JfrThreadLocal* const tl = thread->jfr_thread_local();
 3957  * if (carrierThread != thread) { // is virtual thread
 3958  *   const u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(thread);
 3959  *   bool excluded = vthread_epoch_raw & excluded_mask;
 3960  *   AtomicAccess::store(&tl->_contextual_tid, java_lang_Thread::tid(thread));
 3961  *   AtomicAccess::store(&tl->_contextual_thread_excluded, is_excluded);
 3962  *   if (!excluded) {
 3963  *     const u2 vthread_epoch = vthread_epoch_raw & epoch_mask;
 3964  *     AtomicAccess::store(&tl->_vthread_epoch, vthread_epoch);
 3965  *   }
 3966  *   AtomicAccess::release_store(&tl->_vthread, true);
 3967  *   return;
 3968  * }
 3969  * AtomicAccess::release_store(&tl->_vthread, false);
 3970  */
 3971 void LibraryCallKit::extend_setCurrentThread(Node* jt, Node* thread) {
 3972   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 3973 
 3974   Node* input_memory_state = reset_memory();
 3975   set_all_memory(input_memory_state);
 3976 
 3977   // The most significant bit of the u2 is used to denote thread exclusion
 3978   Node* excluded_mask = _gvn.intcon(1 << 15);
 3979   // The epoch generation is the range [1-32767]
 3980   Node* epoch_mask = _gvn.intcon(32767);
 3981 
 3982   Node* const carrierThread = generate_current_thread(jt);
 3983   // If thread != carrierThread, this is a virtual thread.
 3984   Node* thread_cmp_carrierThread = _gvn.transform(new CmpPNode(thread, carrierThread));
 3985   Node* test_thread_not_equal_carrierThread = _gvn.transform(new BoolNode(thread_cmp_carrierThread, BoolTest::ne));
 3986   IfNode* iff_thread_not_equal_carrierThread =
 3987     create_and_map_if(control(), test_thread_not_equal_carrierThread, PROB_FAIR, COUNT_UNKNOWN);
 3988 
 3989   Node* vthread_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_OFFSET_JFR));
 3990 
 3991   // False branch, is carrierThread.
 3992   Node* thread_equal_carrierThread = _gvn.transform(new IfFalseNode(iff_thread_not_equal_carrierThread));
 3993   // Store release
 3994   Node* vthread_false_memory = store_to_memory(thread_equal_carrierThread, vthread_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::release, true);
 3995 
 3996   set_all_memory(input_memory_state);
 3997 
 3998   // True branch, is virtual thread.
 3999   Node* thread_not_equal_carrierThread = _gvn.transform(new IfTrueNode(iff_thread_not_equal_carrierThread));
 4000   set_control(thread_not_equal_carrierThread);
 4001 
 4002   // Load the raw epoch value from the vthread.
 4003   Node* epoch_offset = basic_plus_adr(thread, java_lang_Thread::jfr_epoch_offset());
 4004   Node* epoch_raw = access_load_at(thread, epoch_offset, _gvn.type(epoch_offset)->is_ptr(), TypeInt::CHAR, T_CHAR,
 4005                                    IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
 4006 
 4007   // Mask off the excluded information from the epoch.
 4008   Node * const is_excluded = _gvn.transform(new AndINode(epoch_raw, excluded_mask));
 4009 
 4010   // Load the tid field from the thread.
 4011   Node* tid = load_field_from_object(thread, "tid", "J");
 4012 
 4013   // Store the vthread tid to the jfr thread local.
 4014   Node* thread_id_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_ID_OFFSET_JFR));
 4015   Node* tid_memory = store_to_memory(control(), thread_id_offset, tid, T_LONG, MemNode::unordered, true);
 4016 
 4017   // Branch is_excluded to conditionalize updating the epoch .
 4018   Node* excluded_cmp = _gvn.transform(new CmpINode(is_excluded, excluded_mask));
 4019   Node* test_excluded = _gvn.transform(new BoolNode(excluded_cmp, BoolTest::eq));
 4020   IfNode* iff_excluded = create_and_map_if(control(), test_excluded, PROB_MIN, COUNT_UNKNOWN);
 4021 
 4022   // True branch, vthread is excluded, no need to write epoch info.
 4023   Node* excluded = _gvn.transform(new IfTrueNode(iff_excluded));
 4024   set_control(excluded);
 4025   Node* vthread_is_excluded = _gvn.intcon(1);
 4026 
 4027   // False branch, vthread is included, update epoch info.
 4028   Node* included = _gvn.transform(new IfFalseNode(iff_excluded));
 4029   set_control(included);
 4030   Node* vthread_is_included = _gvn.intcon(0);
 4031 
 4032   // Get epoch value.
 4033   Node* epoch = _gvn.transform(new AndINode(epoch_raw, epoch_mask));
 4034 
 4035   // Store the vthread epoch to the jfr thread local.
 4036   Node* vthread_epoch_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EPOCH_OFFSET_JFR));
 4037   Node* included_memory = store_to_memory(control(), vthread_epoch_offset, epoch, T_CHAR, MemNode::unordered, true);
 4038 
 4039   RegionNode* excluded_rgn = new RegionNode(PATH_LIMIT);
 4040   record_for_igvn(excluded_rgn);
 4041   PhiNode* excluded_mem = new PhiNode(excluded_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4042   record_for_igvn(excluded_mem);
 4043   PhiNode* exclusion = new PhiNode(excluded_rgn, TypeInt::BOOL);
 4044   record_for_igvn(exclusion);
 4045 
 4046   // Merge the excluded control and memory.
 4047   excluded_rgn->init_req(_true_path, excluded);
 4048   excluded_rgn->init_req(_false_path, included);
 4049   excluded_mem->init_req(_true_path, tid_memory);
 4050   excluded_mem->init_req(_false_path, included_memory);
 4051   exclusion->init_req(_true_path, vthread_is_excluded);
 4052   exclusion->init_req(_false_path, vthread_is_included);
 4053 
 4054   // Set intermediate state.
 4055   set_control(_gvn.transform(excluded_rgn));
 4056   set_all_memory(excluded_mem);
 4057 
 4058   // Store the vthread exclusion state to the jfr thread local.
 4059   Node* thread_local_excluded_offset = off_heap_plus_addr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EXCLUDED_OFFSET_JFR));
 4060   store_to_memory(control(), thread_local_excluded_offset, _gvn.transform(exclusion), T_BOOLEAN, MemNode::unordered, true);
 4061 
 4062   // Store release
 4063   Node * vthread_true_memory = store_to_memory(control(), vthread_offset, _gvn.intcon(1), T_BOOLEAN, MemNode::release, true);
 4064 
 4065   RegionNode* thread_compare_rgn = new RegionNode(PATH_LIMIT);
 4066   record_for_igvn(thread_compare_rgn);
 4067   PhiNode* thread_compare_mem = new PhiNode(thread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4068   record_for_igvn(thread_compare_mem);
 4069   PhiNode* vthread = new PhiNode(thread_compare_rgn, TypeInt::BOOL);
 4070   record_for_igvn(vthread);
 4071 
 4072   // Merge the thread_compare control and memory.
 4073   thread_compare_rgn->init_req(_true_path, control());
 4074   thread_compare_rgn->init_req(_false_path, thread_equal_carrierThread);
 4075   thread_compare_mem->init_req(_true_path, vthread_true_memory);
 4076   thread_compare_mem->init_req(_false_path, vthread_false_memory);
 4077 
 4078   // Set output state.
 4079   set_control(_gvn.transform(thread_compare_rgn));
 4080   set_all_memory(_gvn.transform(thread_compare_mem));
 4081 }
 4082 
 4083 //------------------------inline_native_try_update_epoch------------------
 4084 //
 4085 // The generated code is a function of the argument type.
 4086 //
 4087 bool LibraryCallKit::inline_native_try_update_epoch() {
 4088   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 4089 
 4090   // Save input memory.
 4091   Node* input_memory_state = reset_memory();
 4092   set_all_memory(input_memory_state);
 4093 
 4094   // Argument is an oop whose class has an injected instance field,
 4095   // called 'jfr_epoch' of type T_INT, used for holding a jfr epoch value.
 4096   Node* oop = argument(0);
 4097   const TypeInstPtr* tinst = _gvn.type(oop)->isa_instptr();
 4098   assert(tinst != nullptr, "oop is null");
 4099   assert(tinst->is_loaded(), "klass is not loaded");
 4100   ciInstanceKlass* const ik = tinst->instance_klass();
 4101 
 4102   ciField* const field = ik->get_injected_instance_field_by_name(ciSymbol::make("jfr_epoch"),
 4103                                                                  ciSymbol::make("I"));
 4104 
 4105   assert(field != nullptr, "field 'jfr_epoch' of type I not injected in klass %s", ik->name()->as_utf8());
 4106 
 4107   const int jfr_epoch_field_offset = field->offset_in_bytes();
 4108   Node* oop_epoch_field_offset = basic_plus_adr(oop, jfr_epoch_field_offset);
 4109   const TypePtr* adr_type = _gvn.type(oop_epoch_field_offset)->isa_ptr();
 4110   const int alias_idx = C->get_alias_index(adr_type);
 4111   BasicType bt = field->layout_type();
 4112   const Type * oop_epoch_field_type = Type::get_const_basic_type(bt);
 4113 
 4114   // Load the epoch value from the oop.
 4115   Node* oop_epoch = access_load_at(oop,
 4116                                    oop_epoch_field_offset,
 4117                                    adr_type, oop_epoch_field_type,
 4118                                    bt, IN_HEAP | MO_UNORDERED);
 4119 
 4120   // Load the current JFR epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR.
 4121   Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address()));
 4122   Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered);
 4123 
 4124   // Compare the epoch in the oop against the current JFR epoch generation.
 4125   Node* const epochs_cmp = _gvn.transform(new CmpINode(current_epoch_generation, oop_epoch));
 4126   Node* epochs_equal_test = _gvn.transform(new BoolNode(epochs_cmp, BoolTest::eq));
 4127   IfNode* iff_epochs_equal = create_and_map_if(control(), epochs_equal_test, PROB_LIKELY(0.999), COUNT_UNKNOWN);
 4128 
 4129   // True path.
 4130   Node* epochs_are_equal = _gvn.transform(new IfTrueNode(iff_epochs_equal));
 4131 
 4132   // False path.
 4133   Node* epochs_are_not_equal = _gvn.transform(new IfFalseNode(iff_epochs_equal));
 4134 
 4135   set_control(_gvn.transform(epochs_are_not_equal));
 4136 
 4137   // Attempt to cas the current JFR epoch generation into the oop epoch field.
 4138   DecoratorSet decorators = IN_HEAP;
 4139   decorators |= mo_decorator_for_access_kind(Volatile);
 4140 
 4141   Node* result = access_atomic_cmpxchg_val_at(oop,
 4142                                               oop_epoch_field_offset,
 4143                                               adr_type, alias_idx,
 4144                                               oop_epoch, // expected value
 4145                                               current_epoch_generation, // new value
 4146                                               oop_epoch_field_type,
 4147                                               bt,
 4148                                               decorators);
 4149 
 4150   // Compare the result of the cas operation to the expected value.
 4151   Node* const cas_cmp_to_expected_value = _gvn.transform(new CmpINode(result, oop_epoch));
 4152   Node* cas_operation_test = _gvn.transform(new BoolNode(cas_cmp_to_expected_value, BoolTest::eq));
 4153   IfNode* iff_cas_success = create_and_map_if(control(), cas_operation_test, PROB_LIKELY(0.999), COUNT_UNKNOWN);
 4154 
 4155   // True path.
 4156   Node* cas_success = _gvn.transform(new IfTrueNode(iff_cas_success));
 4157 
 4158   // False path.
 4159   Node* cas_failure = _gvn.transform(new IfFalseNode(iff_cas_success));
 4160 
 4161   // Cas result region and phi nodes.
 4162   RegionNode* cas_operation_rgn = new RegionNode(PATH_LIMIT);
 4163   record_for_igvn(cas_operation_rgn);
 4164   PhiNode* cas_operation_mem = new PhiNode(cas_operation_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4165   record_for_igvn(cas_operation_mem);
 4166   PhiNode* cas_result = new PhiNode(cas_operation_rgn, TypeInt::BOOL);
 4167   record_for_igvn(cas_result);
 4168 
 4169   cas_operation_rgn->init_req(_true_path, _gvn.transform(cas_success));
 4170   cas_operation_rgn->init_req(_false_path, _gvn.transform(cas_failure));
 4171   cas_operation_mem->init_req(_true_path, reset_memory());
 4172   cas_operation_mem->init_req(_false_path, input_memory_state);
 4173   cas_result->init_req(_true_path, _gvn.intcon(1));
 4174   cas_result->init_req(_false_path, _gvn.intcon(0));
 4175 
 4176   // Epoch compare region and phi nodes.
 4177   RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT);
 4178   record_for_igvn(epoch_compare_rgn);
 4179   PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4180   record_for_igvn(epoch_compare_mem);
 4181   PhiNode* result_value = new PhiNode(epoch_compare_rgn, TypeInt::BOOL);
 4182   record_for_igvn(result_value);
 4183 
 4184   epoch_compare_rgn->init_req(_true_path, _gvn.transform(epochs_are_equal));
 4185   epoch_compare_rgn->init_req(_false_path, _gvn.transform(cas_operation_rgn));
 4186   epoch_compare_mem->init_req(_true_path, _gvn.transform(input_memory_state));
 4187   epoch_compare_mem->init_req(_false_path, _gvn.transform(cas_operation_mem));
 4188   result_value->init_req(_true_path, _gvn.intcon(0));
 4189   result_value->init_req(_false_path, _gvn.transform(cas_result));
 4190 
 4191   // Set output state.
 4192   set_result(epoch_compare_rgn, result_value);
 4193   set_all_memory(_gvn.transform(epoch_compare_mem));
 4194 
 4195   return true;
 4196 }
 4197 
 4198 #endif // JFR_HAVE_INTRINSICS
 4199 
 4200 //------------------------inline_native_currentCarrierThread------------------
 4201 bool LibraryCallKit::inline_native_currentCarrierThread() {
 4202   Node* junk = nullptr;
 4203   set_result(generate_current_thread(junk));
 4204   return true;
 4205 }
 4206 
 4207 //------------------------inline_native_currentThread------------------
 4208 bool LibraryCallKit::inline_native_currentThread() {
 4209   Node* junk = nullptr;
 4210   set_result(generate_virtual_thread(junk));
 4211   return true;
 4212 }
 4213 
 4214 //------------------------inline_native_setVthread------------------
 4215 bool LibraryCallKit::inline_native_setCurrentThread() {
 4216   assert(C->method()->changes_current_thread(),
 4217          "method changes current Thread but is not annotated ChangesCurrentThread");
 4218   Node* arr = argument(1);
 4219   Node* thread = _gvn.transform(new ThreadLocalNode());
 4220   Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::vthread_offset()));
 4221   Node* thread_obj_handle
 4222     = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered);
 4223   const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr();
 4224   access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED);
 4225 
 4226   // Change the _monitor_owner_id of the JavaThread
 4227   Node* tid = load_field_from_object(arr, "tid", "J");
 4228   Node* monitor_owner_id_offset = off_heap_plus_addr(thread, in_bytes(JavaThread::monitor_owner_id_offset()));
 4229   store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true);
 4230 
 4231   JFR_ONLY(extend_setCurrentThread(thread, arr);)
 4232   return true;
 4233 }
 4234 
 4235 const Type* LibraryCallKit::scopedValueCache_type() {
 4236   ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass());
 4237   const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass());
 4238   const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
 4239 
 4240   // Because we create the scopedValue cache lazily we have to make the
 4241   // type of the result BotPTR.
 4242   bool xk = etype->klass_is_exact();
 4243   const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, TypeAryPtr::Offset(0));
 4244   return objects_type;
 4245 }
 4246 
 4247 Node* LibraryCallKit::scopedValueCache_helper() {
 4248   Node* thread = _gvn.transform(new ThreadLocalNode());
 4249   Node* p = off_heap_plus_addr(thread, in_bytes(JavaThread::scopedValueCache_offset()));
 4250   // We cannot use immutable_memory() because we might flip onto a
 4251   // different carrier thread, at which point we'll need to use that
 4252   // carrier thread's cache.
 4253   // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(),
 4254   //       TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered));
 4255   return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered);
 4256 }
 4257 
 4258 //------------------------inline_native_scopedValueCache------------------
 4259 bool LibraryCallKit::inline_native_scopedValueCache() {
 4260   Node* cache_obj_handle = scopedValueCache_helper();
 4261   const Type* objects_type = scopedValueCache_type();
 4262   set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE));
 4263 
 4264   return true;
 4265 }
 4266 
 4267 //------------------------inline_native_setScopedValueCache------------------
 4268 bool LibraryCallKit::inline_native_setScopedValueCache() {
 4269   Node* arr = argument(0);
 4270   Node* cache_obj_handle = scopedValueCache_helper();
 4271   const Type* objects_type = scopedValueCache_type();
 4272 
 4273   const TypePtr *adr_type = _gvn.type(cache_obj_handle)->isa_ptr();
 4274   access_store_at(nullptr, cache_obj_handle, adr_type, arr, objects_type, T_OBJECT, IN_NATIVE | MO_UNORDERED);
 4275 
 4276   return true;
 4277 }
 4278 
 4279 //------------------------inline_native_Continuation_pin and unpin-----------
 4280 
 4281 // Shared implementation routine for both pin and unpin.
 4282 bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
 4283   enum { _true_path = 1, _false_path = 2, PATH_LIMIT };
 4284 
 4285   // Save input memory.
 4286   Node* input_memory_state = reset_memory();
 4287   set_all_memory(input_memory_state);
 4288 
 4289   // TLS
 4290   Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
 4291   Node* last_continuation_offset = off_heap_plus_addr(tls_ptr, in_bytes(JavaThread::cont_entry_offset()));
 4292   Node* last_continuation = make_load(control(), last_continuation_offset, last_continuation_offset->get_ptr_type(), T_ADDRESS, MemNode::unordered);
 4293 
 4294   // Null check the last continuation object.
 4295   Node* continuation_cmp_null = _gvn.transform(new CmpPNode(last_continuation, null()));
 4296   Node* test_continuation_not_equal_null = _gvn.transform(new BoolNode(continuation_cmp_null, BoolTest::ne));
 4297   IfNode* iff_continuation_not_equal_null = create_and_map_if(control(), test_continuation_not_equal_null, PROB_MAX, COUNT_UNKNOWN);
 4298 
 4299   // False path, last continuation is null.
 4300   Node* continuation_is_null = _gvn.transform(new IfFalseNode(iff_continuation_not_equal_null));
 4301 
 4302   // True path, last continuation is not null.
 4303   Node* continuation_is_not_null = _gvn.transform(new IfTrueNode(iff_continuation_not_equal_null));
 4304 
 4305   set_control(continuation_is_not_null);
 4306 
 4307   // Load the pin count from the last continuation.
 4308   Node* pin_count_offset = off_heap_plus_addr(last_continuation, in_bytes(ContinuationEntry::pin_count_offset()));
 4309   Node* pin_count = make_load(control(), pin_count_offset, TypeInt::INT, T_INT, MemNode::unordered);
 4310 
 4311   // The loaded pin count is compared against a context specific rhs for over/underflow detection.
 4312   Node* pin_count_rhs;
 4313   if (unpin) {
 4314     pin_count_rhs = _gvn.intcon(0);
 4315   } else {
 4316     pin_count_rhs = _gvn.intcon(UINT32_MAX);
 4317   }
 4318   Node* pin_count_cmp = _gvn.transform(new CmpUNode(pin_count, pin_count_rhs));
 4319   Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq));
 4320   IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN);
 4321 
 4322   // True branch, pin count over/underflow.
 4323   Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow));
 4324   {
 4325     // Trap (but not deoptimize (Action_none)) and continue in the interpreter
 4326     // which will throw IllegalStateException for pin count over/underflow.
 4327     // No memory changed so far - we can use memory create by reset_memory()
 4328     // at the beginning of this intrinsic. No need to call reset_memory() again.
 4329     PreserveJVMState pjvms(this);
 4330     set_control(pin_count_over_underflow);
 4331     uncommon_trap(Deoptimization::Reason_intrinsic,
 4332                   Deoptimization::Action_none);
 4333     assert(stopped(), "invariant");
 4334   }
 4335 
 4336   // False branch, no pin count over/underflow. Increment or decrement pin count and store back.
 4337   Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow));
 4338   set_control(valid_pin_count);
 4339 
 4340   Node* next_pin_count;
 4341   if (unpin) {
 4342     next_pin_count = _gvn.transform(new SubINode(pin_count, _gvn.intcon(1)));
 4343   } else {
 4344     next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1)));
 4345   }
 4346 
 4347   store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
 4348 
 4349   // Result of top level CFG and Memory.
 4350   RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
 4351   record_for_igvn(result_rgn);
 4352   PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM);
 4353   record_for_igvn(result_mem);
 4354 
 4355   result_rgn->init_req(_true_path, valid_pin_count);
 4356   result_rgn->init_req(_false_path, continuation_is_null);
 4357   result_mem->init_req(_true_path, reset_memory());
 4358   result_mem->init_req(_false_path, input_memory_state);
 4359 
 4360   // Set output state.
 4361   set_control(_gvn.transform(result_rgn));
 4362   set_all_memory(_gvn.transform(result_mem));
 4363 
 4364   return true;
 4365 }
 4366 
 4367 //---------------------------load_mirror_from_klass----------------------------
 4368 // Given a klass oop, load its java mirror (a java.lang.Class oop).
 4369 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
 4370   Node* p = off_heap_plus_addr(klass, in_bytes(Klass::java_mirror_offset()));
 4371   Node* load = make_load(nullptr, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
 4372   // mirror = ((OopHandle)mirror)->resolve();
 4373   return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE);
 4374 }
 4375 
 4376 //-----------------------load_klass_from_mirror_common-------------------------
 4377 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
 4378 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
 4379 // and branch to the given path on the region.
 4380 // If never_see_null, take an uncommon trap on null, so we can optimistically
 4381 // compile for the non-null case.
 4382 // If the region is null, force never_see_null = true.
 4383 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
 4384                                                     bool never_see_null,
 4385                                                     RegionNode* region,
 4386                                                     int null_path,
 4387                                                     int offset) {
 4388   if (region == nullptr)  never_see_null = true;
 4389   Node* p = basic_plus_adr(mirror, offset);
 4390   const TypeKlassPtr*  kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
 4391   Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type));
 4392   Node* null_ctl = top();
 4393   kls = null_check_oop(kls, &null_ctl, never_see_null);
 4394   if (region != nullptr) {
 4395     // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
 4396     region->init_req(null_path, null_ctl);
 4397   } else {
 4398     assert(null_ctl == top(), "no loose ends");
 4399   }
 4400   return kls;
 4401 }
 4402 
 4403 //--------------------(inline_native_Class_query helpers)---------------------
 4404 // Use this for JVM_ACC_INTERFACE.
 4405 // Fall through if (mods & mask) == bits, take the guard otherwise.
 4406 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region,
 4407                                                  ByteSize offset, const Type* type, BasicType bt) {
 4408   // Branch around if the given klass has the given modifier bit set.
 4409   // Like generate_guard, adds a new path onto the region.
 4410   Node* modp = off_heap_plus_addr(kls, in_bytes(offset));
 4411   Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered);
 4412   Node* mask = intcon(modifier_mask);
 4413   Node* bits = intcon(modifier_bits);
 4414   Node* mbit = _gvn.transform(new AndINode(mods, mask));
 4415   Node* cmp  = _gvn.transform(new CmpINode(mbit, bits));
 4416   Node* bol  = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
 4417   return generate_fair_guard(bol, region);
 4418 }
 4419 
 4420 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
 4421   return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region,
 4422                                     InstanceKlass::access_flags_offset(), TypeInt::CHAR, T_CHAR);
 4423 }
 4424 
 4425 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast.
 4426 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
 4427   return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region,
 4428                                     Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN);
 4429 }
 4430 
 4431 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) {
 4432   return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region);
 4433 }
 4434 
 4435 //-------------------------inline_native_Class_query-------------------
 4436 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
 4437   const Type* return_type = TypeInt::BOOL;
 4438   Node* prim_return_value = top();  // what happens if it's a primitive class?
 4439   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 4440   bool expect_prim = false;     // most of these guys expect to work on refs
 4441 
 4442   enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
 4443 
 4444   Node* mirror = argument(0);
 4445   Node* obj    = top();
 4446 
 4447   switch (id) {
 4448   case vmIntrinsics::_isInstance:
 4449     // nothing is an instance of a primitive type
 4450     prim_return_value = intcon(0);
 4451     obj = argument(1);
 4452     break;
 4453   case vmIntrinsics::_isHidden:
 4454     prim_return_value = intcon(0);
 4455     break;
 4456   case vmIntrinsics::_getSuperclass:
 4457     prim_return_value = null();
 4458     return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
 4459     break;
 4460   default:
 4461     fatal_unexpected_iid(id);
 4462     break;
 4463   }
 4464 
 4465   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
 4466   if (mirror_con == nullptr)  return false;  // cannot happen?
 4467 
 4468 #ifndef PRODUCT
 4469   if (C->print_intrinsics() || C->print_inlining()) {
 4470     ciType* k = mirror_con->java_mirror_type();
 4471     if (k) {
 4472       tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id()));
 4473       k->print_name();
 4474       tty->cr();
 4475     }
 4476   }
 4477 #endif
 4478 
 4479   // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
 4480   RegionNode* region = new RegionNode(PATH_LIMIT);
 4481   record_for_igvn(region);
 4482   PhiNode* phi = new PhiNode(region, return_type);
 4483 
 4484   // The mirror will never be null of Reflection.getClassAccessFlags, however
 4485   // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
 4486   // if it is. See bug 4774291.
 4487 
 4488   // For Reflection.getClassAccessFlags(), the null check occurs in
 4489   // the wrong place; see inline_unsafe_access(), above, for a similar
 4490   // situation.
 4491   mirror = null_check(mirror);
 4492   // If mirror or obj is dead, only null-path is taken.
 4493   if (stopped())  return true;
 4494 
 4495   if (expect_prim)  never_see_null = false;  // expect nulls (meaning prims)
 4496 
 4497   // Now load the mirror's klass metaobject, and null-check it.
 4498   // Side-effects region with the control path if the klass is null.
 4499   Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path);
 4500   // If kls is null, we have a primitive mirror.
 4501   phi->init_req(_prim_path, prim_return_value);
 4502   if (stopped()) { set_result(region, phi); return true; }
 4503   bool safe_for_replace = (region->in(_prim_path) == top());
 4504 
 4505   Node* p;  // handy temp
 4506   Node* null_ctl;
 4507 
 4508   // Now that we have the non-null klass, we can perform the real query.
 4509   // For constant classes, the query will constant-fold in LoadNode::Value.
 4510   Node* query_value = top();
 4511   switch (id) {
 4512   case vmIntrinsics::_isInstance:
 4513     // nothing is an instance of a primitive type
 4514     query_value = gen_instanceof(obj, kls, safe_for_replace);
 4515     break;
 4516 
 4517   case vmIntrinsics::_isHidden:
 4518     // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.)
 4519     if (generate_hidden_class_guard(kls, region) != nullptr)
 4520       // A guard was added.  If the guard is taken, it was an hidden class.
 4521       phi->add_req(intcon(1));
 4522     // If we fall through, it's a plain class.
 4523     query_value = intcon(0);
 4524     break;
 4525 
 4526 
 4527   case vmIntrinsics::_getSuperclass:
 4528     // The rules here are somewhat unfortunate, but we can still do better
 4529     // with random logic than with a JNI call.
 4530     // Interfaces store null or Object as _super, but must report null.
 4531     // Arrays store an intermediate super as _super, but must report Object.
 4532     // Other types can report the actual _super.
 4533     // (To verify this code sequence, check the asserts in JVM_IsInterface.)
 4534     if (generate_array_guard(kls, region) != nullptr) {
 4535       // A guard was added.  If the guard is taken, it was an array.
 4536       phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
 4537     }
 4538     // Check for interface after array since this checks AccessFlags offset into InstanceKlass.
 4539     // In other words, we are accessing subtype-specific information, so we need to determine the subtype first.
 4540     if (generate_interface_guard(kls, region) != nullptr) {
 4541       // A guard was added.  If the guard is taken, it was an interface.
 4542       phi->add_req(null());
 4543     }
 4544     // If we fall through, it's a plain class.  Get its _super.
 4545     if (!stopped()) {
 4546       p = basic_plus_adr(top(), kls, in_bytes(Klass::super_offset()));
 4547       kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 4548       null_ctl = top();
 4549       kls = null_check_oop(kls, &null_ctl);
 4550       if (null_ctl != top()) {
 4551         // If the guard is taken, Object.superClass is null (both klass and mirror).
 4552         region->add_req(null_ctl);
 4553         phi   ->add_req(null());
 4554       }
 4555       if (!stopped()) {
 4556         query_value = load_mirror_from_klass(kls);
 4557       }
 4558     }
 4559     break;
 4560 
 4561   default:
 4562     fatal_unexpected_iid(id);
 4563     break;
 4564   }
 4565 
 4566   // Fall-through is the normal case of a query to a real class.
 4567   phi->init_req(1, query_value);
 4568   region->init_req(1, control());
 4569 
 4570   C->set_has_split_ifs(true); // Has chance for split-if optimization
 4571   set_result(region, phi);
 4572   return true;
 4573 }
 4574 
 4575 
 4576 //-------------------------inline_Class_cast-------------------
 4577 bool LibraryCallKit::inline_Class_cast() {
 4578   Node* mirror = argument(0); // Class
 4579   Node* obj    = argument(1);
 4580   const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
 4581   if (mirror_con == nullptr) {
 4582     return false;  // dead path (mirror->is_top()).
 4583   }
 4584   if (obj == nullptr || obj->is_top()) {
 4585     return false;  // dead path
 4586   }
 4587   const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr();
 4588 
 4589   // First, see if Class.cast() can be folded statically.
 4590   // java_mirror_type() returns non-null for compile-time Class constants.
 4591   ciType* tm = mirror_con->java_mirror_type();
 4592   if (tm != nullptr && tm->is_klass() &&
 4593       tp != nullptr) {
 4594     if (!tp->is_loaded()) {
 4595       // Don't use intrinsic when class is not loaded.
 4596       return false;
 4597     } else {
 4598       const TypeKlassPtr* tklass = TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces);
 4599       int static_res = C->static_subtype_check(tklass, tp->as_klass_type());
 4600       if (static_res == Compile::SSC_always_true) {
 4601         // isInstance() is true - fold the code.
 4602         set_result(obj);
 4603         return true;
 4604       } else if (static_res == Compile::SSC_always_false) {
 4605         // Don't use intrinsic, have to throw ClassCastException.
 4606         // If the reference is null, the non-intrinsic bytecode will
 4607         // be optimized appropriately.
 4608         return false;
 4609       }
 4610     }
 4611   }
 4612 
 4613   // Bailout intrinsic and do normal inlining if exception path is frequent.
 4614   if (too_many_traps(Deoptimization::Reason_intrinsic)) {
 4615     return false;
 4616   }
 4617 
 4618   // Generate dynamic checks.
 4619   // Class.cast() is java implementation of _checkcast bytecode.
 4620   // Do checkcast (Parse::do_checkcast()) optimizations here.
 4621 
 4622   mirror = null_check(mirror);
 4623   // If mirror is dead, only null-path is taken.
 4624   if (stopped()) {
 4625     return true;
 4626   }
 4627 
 4628   // Not-subtype or the mirror's klass ptr is nullptr (in case it is a primitive).
 4629   enum { _bad_type_path = 1, _prim_path = 2, _npe_path = 3, PATH_LIMIT };
 4630   RegionNode* region = new RegionNode(PATH_LIMIT);
 4631   record_for_igvn(region);
 4632 
 4633   // Now load the mirror's klass metaobject, and null-check it.
 4634   // If kls is null, we have a primitive mirror and
 4635   // nothing is an instance of a primitive type.
 4636   Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path);
 4637 
 4638   Node* res = top();
 4639   Node* io = i_o();
 4640   Node* mem = merged_memory();
 4641   SafePointNode* new_cast_failure_map = nullptr;
 4642 
 4643   if (!stopped()) {
 4644 
 4645     Node* bad_type_ctrl = top();
 4646     // Do checkcast optimizations.
 4647     res = gen_checkcast(obj, kls, &bad_type_ctrl, &new_cast_failure_map);
 4648     region->init_req(_bad_type_path, bad_type_ctrl);
 4649   }
 4650   if (region->in(_prim_path) != top() ||
 4651       region->in(_bad_type_path) != top() ||
 4652       region->in(_npe_path) != top()) {
 4653     // Let Interpreter throw ClassCastException.
 4654     PreserveJVMState pjvms(this);
 4655     if (new_cast_failure_map != nullptr) {
 4656       // The current map on the success path could have been modified. Use the dedicated failure path map.
 4657       set_map(new_cast_failure_map);
 4658     }
 4659     set_control(_gvn.transform(region));
 4660     // Set IO and memory because gen_checkcast may override them when buffering inline types
 4661     set_i_o(io);
 4662     set_all_memory(mem);
 4663     uncommon_trap(Deoptimization::Reason_intrinsic,
 4664                   Deoptimization::Action_maybe_recompile);
 4665   }
 4666   if (!stopped()) {
 4667     set_result(res);
 4668   }
 4669   return true;
 4670 }
 4671 
 4672 
 4673 //--------------------------inline_native_subtype_check------------------------
 4674 // This intrinsic takes the JNI calls out of the heart of
 4675 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
 4676 bool LibraryCallKit::inline_native_subtype_check() {
 4677   // Pull both arguments off the stack.
 4678   Node* args[2];                // two java.lang.Class mirrors: superc, subc
 4679   args[0] = argument(0);
 4680   args[1] = argument(1);
 4681   Node* klasses[2];             // corresponding Klasses: superk, subk
 4682   klasses[0] = klasses[1] = top();
 4683 
 4684   enum {
 4685     // A full decision tree on {superc is prim, subc is prim}:
 4686     _prim_0_path = 1,           // {P,N} => false
 4687                                 // {P,P} & superc!=subc => false
 4688     _prim_same_path,            // {P,P} & superc==subc => true
 4689     _prim_1_path,               // {N,P} => false
 4690     _ref_subtype_path,          // {N,N} & subtype check wins => true
 4691     _both_ref_path,             // {N,N} & subtype check loses => false
 4692     PATH_LIMIT
 4693   };
 4694 
 4695   RegionNode* region = new RegionNode(PATH_LIMIT);
 4696   RegionNode* prim_region = new RegionNode(2);
 4697   Node*       phi    = new PhiNode(region, TypeInt::BOOL);
 4698   record_for_igvn(region);
 4699   record_for_igvn(prim_region);
 4700 
 4701   const TypePtr* adr_type = TypeRawPtr::BOTTOM;   // memory type of loads
 4702   const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL;
 4703   int class_klass_offset = java_lang_Class::klass_offset();
 4704 
 4705   // First null-check both mirrors and load each mirror's klass metaobject.
 4706   int which_arg;
 4707   for (which_arg = 0; which_arg <= 1; which_arg++) {
 4708     Node* arg = args[which_arg];
 4709     arg = null_check(arg);
 4710     if (stopped())  break;
 4711     args[which_arg] = arg;
 4712 
 4713     Node* p = basic_plus_adr(arg, class_klass_offset);
 4714     Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
 4715     klasses[which_arg] = _gvn.transform(kls);
 4716   }
 4717 
 4718   // Having loaded both klasses, test each for null.
 4719   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 4720   for (which_arg = 0; which_arg <= 1; which_arg++) {
 4721     Node* kls = klasses[which_arg];
 4722     Node* null_ctl = top();
 4723     kls = null_check_oop(kls, &null_ctl, never_see_null);
 4724     if (which_arg == 0) {
 4725       prim_region->init_req(1, null_ctl);
 4726     } else {
 4727       region->init_req(_prim_1_path, null_ctl);
 4728     }
 4729     if (stopped())  break;
 4730     klasses[which_arg] = kls;
 4731   }
 4732 
 4733   if (!stopped()) {
 4734     // now we have two reference types, in klasses[0..1]
 4735     Node* subk   = klasses[1];  // the argument to isAssignableFrom
 4736     Node* superk = klasses[0];  // the receiver
 4737     region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
 4738     region->set_req(_ref_subtype_path, control());
 4739   }
 4740 
 4741   // If both operands are primitive (both klasses null), then
 4742   // we must return true when they are identical primitives.
 4743   // It is convenient to test this after the first null klass check.
 4744   // This path is also used if superc is a value mirror.
 4745   set_control(_gvn.transform(prim_region));
 4746   if (!stopped()) {
 4747     // Since superc is primitive, make a guard for the superc==subc case.
 4748     Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1]));
 4749     Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq));
 4750     generate_fair_guard(bol_eq, region);
 4751     if (region->req() == PATH_LIMIT+1) {
 4752       // A guard was added.  If the added guard is taken, superc==subc.
 4753       region->swap_edges(PATH_LIMIT, _prim_same_path);
 4754       region->del_req(PATH_LIMIT);
 4755     }
 4756     region->set_req(_prim_0_path, control()); // Not equal after all.
 4757   }
 4758 
 4759   // these are the only paths that produce 'true':
 4760   phi->set_req(_prim_same_path,   intcon(1));
 4761   phi->set_req(_ref_subtype_path, intcon(1));
 4762 
 4763   // pull together the cases:
 4764   assert(region->req() == PATH_LIMIT, "sane region");
 4765   for (uint i = 1; i < region->req(); i++) {
 4766     Node* ctl = region->in(i);
 4767     if (ctl == nullptr || ctl == top()) {
 4768       region->set_req(i, top());
 4769       phi   ->set_req(i, top());
 4770     } else if (phi->in(i) == nullptr) {
 4771       phi->set_req(i, intcon(0)); // all other paths produce 'false'
 4772     }
 4773   }
 4774 
 4775   set_control(_gvn.transform(region));
 4776   set_result(_gvn.transform(phi));
 4777   return true;
 4778 }
 4779 
 4780 //---------------------generate_array_guard_common------------------------
 4781 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind, Node** obj) {
 4782 
 4783   if (stopped()) {
 4784     return nullptr;
 4785   }
 4786 
 4787   // Like generate_guard, adds a new path onto the region.
 4788   jint  layout_con = 0;
 4789   Node* layout_val = get_layout_helper(kls, layout_con);
 4790   if (layout_val == nullptr) {
 4791     bool query = 0;
 4792     switch(kind) {
 4793       case RefArray:       query = Klass::layout_helper_is_refArray(layout_con); break;
 4794       case NonRefArray:    query = !Klass::layout_helper_is_refArray(layout_con); break;
 4795       case TypeArray:      query = Klass::layout_helper_is_typeArray(layout_con); break;
 4796       case AnyArray:       query = Klass::layout_helper_is_array(layout_con); break;
 4797       case NonArray:       query = !Klass::layout_helper_is_array(layout_con); break;
 4798       default:
 4799         ShouldNotReachHere();
 4800     }
 4801     if (!query) {
 4802       return nullptr;                       // never a branch
 4803     } else {                             // always a branch
 4804       Node* always_branch = control();
 4805       if (region != nullptr)
 4806         region->add_req(always_branch);
 4807       set_control(top());
 4808       return always_branch;
 4809     }
 4810   }
 4811   unsigned int value = 0;
 4812   BoolTest::mask btest = BoolTest::illegal;
 4813   switch(kind) {
 4814     case RefArray:
 4815     case NonRefArray: {
 4816       value = Klass::_lh_array_tag_ref_value;
 4817       layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
 4818       btest = (kind == RefArray) ? BoolTest::eq : BoolTest::ne;
 4819       break;
 4820     }
 4821     case TypeArray: {
 4822       value = Klass::_lh_array_tag_type_value;
 4823       layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift)));
 4824       btest = BoolTest::eq;
 4825       break;
 4826     }
 4827     case AnyArray:    value = Klass::_lh_neutral_value; btest = BoolTest::lt; break;
 4828     case NonArray:    value = Klass::_lh_neutral_value; btest = BoolTest::gt; break;
 4829     default:
 4830       ShouldNotReachHere();
 4831   }
 4832   // Now test the correct condition.
 4833   jint nval = (jint)value;
 4834   Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval)));
 4835   Node* bol = _gvn.transform(new BoolNode(cmp, btest));
 4836   Node* ctrl = generate_fair_guard(bol, region);
 4837   Node* is_array_ctrl = kind == NonArray ? control() : ctrl;
 4838   if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) {
 4839     // Keep track of the fact that 'obj' is an array to prevent
 4840     // array specific accesses from floating above the guard.
 4841     *obj = _gvn.transform(new CheckCastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM));
 4842   }
 4843   return ctrl;
 4844 }
 4845 
 4846 // public static native Object[] ValueClass::newNullRestrictedAtomicArray(Class<?> componentType, int length, Object initVal);
 4847 // public static native Object[] ValueClass::newNullRestrictedNonAtomicArray(Class<?> componentType, int length, Object initVal);
 4848 // public static native Object[] ValueClass::newNullableAtomicArray(Class<?> componentType, int length);
 4849 bool LibraryCallKit::inline_newArray(bool null_free, bool atomic) {
 4850   assert(null_free || atomic, "nullable implies atomic");
 4851   Node* componentType = argument(0);
 4852   Node* length = argument(1);
 4853   Node* init_val = null_free ? argument(2) : nullptr;
 4854 
 4855   const TypeInstPtr* tp = _gvn.type(componentType)->isa_instptr();
 4856   if (tp != nullptr) {
 4857     ciInstanceKlass* ik = tp->instance_klass();
 4858     if (ik == C->env()->Class_klass()) {
 4859       ciType* t = tp->java_mirror_type();
 4860       if (t != nullptr && t->is_inlinetype()) {
 4861 
 4862         ciArrayKlass* array_klass = ciArrayKlass::make(t, null_free, atomic, true);
 4863         assert(array_klass->is_elem_null_free() == null_free, "inconsistency");
 4864 
 4865         // TODO 8350865 ZGC needs card marks on initializing oop stores
 4866         if ((UseZGC || UseShenandoahGC) && null_free && !array_klass->is_flat_array_klass()) {
 4867           return false;
 4868         }
 4869 
 4870         if (array_klass->is_loaded() && array_klass->element_klass()->as_inline_klass()->is_initialized()) {
 4871           const TypeAryKlassPtr* array_klass_type = TypeAryKlassPtr::make(array_klass, Type::trust_interfaces);
 4872           if (null_free) {
 4873             if (init_val->is_InlineType()) {
 4874               if (array_klass_type->is_flat() && init_val->as_InlineType()->is_all_zero(&gvn(), /* flat */ true)) {
 4875                 // Zeroing is enough because the init value is the all-zero value
 4876                 init_val = nullptr;
 4877               } else {
 4878                 init_val = init_val->as_InlineType()->buffer(this);
 4879               }
 4880             }
 4881             if (init_val != nullptr) {
 4882 #ifdef ASSERT
 4883               init_val = null_check(init_val);
 4884               Node* wrong_type_ctl = gen_subtype_check(init_val, makecon(TypeKlassPtr::make(array_klass->element_klass())));
 4885               {
 4886                 PreserveJVMState pjvms(this);
 4887                 set_control(wrong_type_ctl);
 4888                 halt(control(), frameptr(), "incompatible type for initVal in newArray");
 4889                 stop_and_kill_map();
 4890               }
 4891 #endif
 4892               init_val = _gvn.transform(new CheckCastPPNode(control(), init_val, TypeOopPtr::make_from_klass(array_klass->element_klass()), ConstraintCastNode::DependencyType::NonFloatingNarrowing));
 4893             }
 4894           }
 4895           Node* obj = new_array(makecon(array_klass_type), length, 0, nullptr, false, init_val);
 4896           const TypeAryPtr* arytype = gvn().type(obj)->is_aryptr();
 4897           assert(arytype->is_null_free() == null_free, "inconsistency");
 4898           assert(arytype->is_not_null_free() == !null_free, "inconsistency");
 4899           set_result(obj);
 4900           return true;
 4901         }
 4902       }
 4903     }
 4904   }
 4905   return false;
 4906 }
 4907 
 4908 // public static native boolean ValueClass::isFlatArray(Object array);
 4909 // public static native boolean ValueClass::isNullRestrictedArray(Object array);
 4910 // public static native boolean ValueClass::isAtomicArray(Object array);
 4911 bool LibraryCallKit::inline_getArrayProperties(ArrayPropertiesCheck check) {
 4912   Node* array = argument(0);
 4913 
 4914   Node* bol;
 4915   switch(check) {
 4916     case IsFlat:
 4917       bol = flat_array_test(load_object_klass(array));
 4918       break;
 4919     case IsNullRestricted:
 4920       bol = null_free_array_test(array);
 4921       break;
 4922     case IsAtomic: {
 4923       // See conditions in JVM_IsAtomicArray
 4924       // 1. If not flat, then atomic, or else...
 4925       RegionNode* atomic_region = new RegionNode(1);
 4926       RegionNode* non_atomic_region = new RegionNode(1);
 4927       Node* array_klass = load_object_klass(array);
 4928       Node* is_flat_bol = flat_array_test(array_klass);
 4929       IfNode* iff_is_flat = create_and_xform_if(control(), is_flat_bol, PROB_FAIR, COUNT_UNKNOWN);
 4930       atomic_region->add_req(_gvn.transform(new IfFalseNode(iff_is_flat)));
 4931       set_control(_gvn.transform(new IfTrueNode(iff_is_flat)));
 4932 
 4933       // 2. ...if the layout is atomic, then atomic, or else...
 4934       Node* layout_kind = atomic_layout_array_test_and_get_layout_kind(array, atomic_region);
 4935 
 4936       // 3. ...if the element type is naturally atomic and null-free OR empty and nullable, then atomic, or else...
 4937       int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset());
 4938       Node* array_element_klass_addr = off_heap_plus_addr(array_klass, element_klass_offset);
 4939       Node* array_element_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), array_element_klass_addr, _gvn.type(array_klass)->is_klassptr()));
 4940       int klass_flags_offset = in_bytes(InstanceKlass::misc_flags_offset() + InstanceKlassFlags::flags_offset());
 4941       Node* array_element_klass_flags_addr = off_heap_plus_addr(array_element_klass, klass_flags_offset);
 4942       Node* array_element_klass_flags = make_load(control(), array_element_klass_flags_addr, TypeInt::INT, T_INT, MemNode::unordered);
 4943 
 4944       // Here, layout can only be non-atomic, otherwise atomic_layout_array_test_and_get_layout_kind already decides the array to be atomic.
 4945       Node* is_null_free_cmp = _gvn.transform(new CmpINode(layout_kind, intcon(static_cast<jint>(LayoutKind::NULL_FREE_NON_ATOMIC_FLAT))));
 4946       Node* is_null_free_bol = _gvn.transform(new BoolNode(is_null_free_cmp, BoolTest::eq));
 4947       IfNode* iff_is_null_free_bol = create_and_xform_if(control(), is_null_free_bol, PROB_FAIR, COUNT_UNKNOWN);
 4948       Node* is_null_free_ctl = _gvn.transform(new IfTrueNode(iff_is_null_free_bol));
 4949       Node* is_nullable_ctl = _gvn.transform(new IfFalseNode(iff_is_null_free_bol));
 4950 
 4951       Node* is_naturally_atomic_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_naturally_atomic)));
 4952       Node* is_naturally_atomic_cmp = _gvn.transform(new CmpINode(is_naturally_atomic_flag, intcon(0)));
 4953       Node* is_naturally_atomic_bol = _gvn.transform(new BoolNode(is_naturally_atomic_cmp, BoolTest::ne));
 4954       IfNode* iff_is_naturally_atomic = create_and_xform_if(is_null_free_ctl, is_naturally_atomic_bol, PROB_FAIR, COUNT_UNKNOWN);
 4955       Node* is_naturally_atomic_ctl = _gvn.transform(new IfTrueNode(iff_is_naturally_atomic));
 4956       Node* is_not_naturally_atomic_ctl = _gvn.transform(new IfFalseNode(iff_is_naturally_atomic));
 4957       atomic_region->add_req(is_naturally_atomic_ctl);
 4958       non_atomic_region->add_req(is_not_naturally_atomic_ctl);
 4959 
 4960       Node* is_empty_inline_type_flag = _gvn.transform(new AndINode(array_element_klass_flags, intcon(InstanceKlassFlags::_misc_is_empty_inline_type)));
 4961       Node* is_empty_inline_type_cmp = _gvn.transform(new CmpINode(is_empty_inline_type_flag, intcon(0)));
 4962       Node* is_empty_inline_type_bol = _gvn.transform(new BoolNode(is_empty_inline_type_cmp, BoolTest::ne));
 4963       IfNode* iff_is_empty_inline_type = create_and_xform_if(is_nullable_ctl, is_empty_inline_type_bol, PROB_FAIR, COUNT_UNKNOWN);
 4964       Node* is_empty_inline_type_ctl = _gvn.transform(new IfTrueNode(iff_is_empty_inline_type));
 4965       Node* is_nonempty_inline_type_ctl = _gvn.transform(new IfFalseNode(iff_is_empty_inline_type));
 4966       atomic_region->add_req(is_empty_inline_type_ctl);
 4967       non_atomic_region->add_req(is_nonempty_inline_type_ctl);
 4968 
 4969       // ...non-atomic, but we tried everything.
 4970       RegionNode* decision = new RegionNode(3);
 4971       decision->set_req(1, _gvn.transform(atomic_region));
 4972       decision->set_req(2, _gvn.transform(non_atomic_region));
 4973       PhiNode* result = PhiNode::make(decision, intcon(1), TypeInt::BOOL);
 4974       result->set_req(2, intcon(0));
 4975       set_control(_gvn.transform(decision));
 4976       set_result(_gvn.transform(result));
 4977       return true;
 4978     }
 4979     default:
 4980       ShouldNotReachHere();
 4981   }
 4982 
 4983   Node* res = gvn().transform(new CMoveINode(bol, intcon(0), intcon(1), TypeInt::BOOL));
 4984   set_result(res);
 4985   return true;
 4986 }
 4987 
 4988 // Load the default refined array klass from an ObjArrayKlass. This relies on the first entry in the
 4989 // '_next_refined_array_klass' linked list being the default (see ObjArrayKlass::klass_with_properties).
 4990 Node* LibraryCallKit::load_default_refined_array_klass(Node* klass_node, bool type_array_guard) {
 4991   RegionNode* region = new RegionNode(2);
 4992   Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT_OR_NULL);
 4993 
 4994   if (type_array_guard) {
 4995     generate_typeArray_guard(klass_node, region);
 4996     if (region->req() == 3) {
 4997       phi->add_req(klass_node);
 4998     }
 4999   }
 5000   Node* adr_refined_klass = basic_plus_adr(top(), klass_node, in_bytes(ObjArrayKlass::next_refined_array_klass_offset()));
 5001   Node* refined_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), adr_refined_klass, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL));
 5002 
 5003   // Can be null if not initialized yet, just deopt
 5004   Node* null_ctl = top();
 5005   refined_klass = null_check_oop(refined_klass, &null_ctl, /* never_see_null= */ true);
 5006 
 5007   region->init_req(1, control());
 5008   phi->init_req(1, refined_klass);
 5009 
 5010   set_control(_gvn.transform(region));
 5011   return _gvn.transform(phi);
 5012 }
 5013 
 5014 // Load the non-refined array klass from an ObjArrayKlass.
 5015 Node* LibraryCallKit::load_non_refined_array_klass(Node* klass_node) {
 5016   const TypeAryKlassPtr* ary_klass_ptr = _gvn.type(klass_node)->isa_aryklassptr();
 5017   if (ary_klass_ptr != nullptr && ary_klass_ptr->klass_is_exact()) {
 5018     return _gvn.makecon(ary_klass_ptr->cast_to_refined_array_klass_ptr(false));
 5019   }
 5020 
 5021   RegionNode* region = new RegionNode(2);
 5022   Node* phi = new PhiNode(region, TypeInstKlassPtr::OBJECT);
 5023 
 5024   generate_typeArray_guard(klass_node, region);
 5025   if (region->req() == 3) {
 5026     phi->add_req(klass_node);
 5027   }
 5028   Node* super_adr = basic_plus_adr(top(), klass_node, in_bytes(Klass::super_offset()));
 5029   Node* super_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), super_adr, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT));
 5030 
 5031   region->init_req(1, control());
 5032   phi->init_req(1, super_klass);
 5033 
 5034   set_control(_gvn.transform(region));
 5035   return _gvn.transform(phi);
 5036 }
 5037 
 5038 //-----------------------inline_native_newArray--------------------------
 5039 // private static native Object java.lang.reflect.Array.newArray(Class<?> componentType, int length);
 5040 // private        native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size);
 5041 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) {
 5042   Node* mirror;
 5043   Node* count_val;
 5044   if (uninitialized) {
 5045     null_check_receiver();
 5046     mirror    = argument(1);
 5047     count_val = argument(2);
 5048   } else {
 5049     mirror    = argument(0);
 5050     count_val = argument(1);
 5051   }
 5052 
 5053   mirror = null_check(mirror);
 5054   // If mirror or obj is dead, only null-path is taken.
 5055   if (stopped())  return true;
 5056 
 5057   enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
 5058   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 5059   PhiNode*    result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
 5060   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
 5061   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 5062 
 5063   bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
 5064   Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null,
 5065                                                   result_reg, _slow_path);
 5066   Node* normal_ctl   = control();
 5067   Node* no_array_ctl = result_reg->in(_slow_path);
 5068 
 5069   // Generate code for the slow case.  We make a call to newArray().
 5070   set_control(no_array_ctl);
 5071   if (!stopped()) {
 5072     // Either the input type is void.class, or else the
 5073     // array klass has not yet been cached.  Either the
 5074     // ensuing call will throw an exception, or else it
 5075     // will cache the array klass for next time.
 5076     PreserveJVMState pjvms(this);
 5077     CallJavaNode* slow_call = nullptr;
 5078     if (uninitialized) {
 5079       // Generate optimized virtual call (holder class 'Unsafe' is final)
 5080       slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true);
 5081     } else {
 5082       slow_call = generate_method_call_static(vmIntrinsics::_newArray, true);
 5083     }
 5084     Node* slow_result = set_results_for_java_call(slow_call);
 5085     // this->control() comes from set_results_for_java_call
 5086     result_reg->set_req(_slow_path, control());
 5087     result_val->set_req(_slow_path, slow_result);
 5088     result_io ->set_req(_slow_path, i_o());
 5089     result_mem->set_req(_slow_path, reset_memory());
 5090   }
 5091 
 5092   set_control(normal_ctl);
 5093   if (!stopped()) {
 5094     // Normal case:  The array type has been cached in the java.lang.Class.
 5095     // The following call works fine even if the array type is polymorphic.
 5096     // It could be a dynamic mix of int[], boolean[], Object[], etc.
 5097 
 5098     klass_node = load_default_refined_array_klass(klass_node);
 5099 
 5100     Node* obj = new_array(klass_node, count_val, 0);  // no arguments to push
 5101     result_reg->init_req(_normal_path, control());
 5102     result_val->init_req(_normal_path, obj);
 5103     result_io ->init_req(_normal_path, i_o());
 5104     result_mem->init_req(_normal_path, reset_memory());
 5105 
 5106     if (uninitialized) {
 5107       // Mark the allocation so that zeroing is skipped
 5108       AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj);
 5109       alloc->maybe_set_complete(&_gvn);
 5110     }
 5111   }
 5112 
 5113   // Return the combined state.
 5114   set_i_o(        _gvn.transform(result_io)  );
 5115   set_all_memory( _gvn.transform(result_mem));
 5116 
 5117   C->set_has_split_ifs(true); // Has chance for split-if optimization
 5118   set_result(result_reg, result_val);
 5119   return true;
 5120 }
 5121 
 5122 //----------------------inline_native_getLength--------------------------
 5123 // public static native int java.lang.reflect.Array.getLength(Object array);
 5124 bool LibraryCallKit::inline_native_getLength() {
 5125   if (too_many_traps(Deoptimization::Reason_intrinsic))  return false;
 5126 
 5127   Node* array = null_check(argument(0));
 5128   // If array is dead, only null-path is taken.
 5129   if (stopped())  return true;
 5130 
 5131   // Deoptimize if it is a non-array.
 5132   Node* non_array = generate_non_array_guard(load_object_klass(array), nullptr, &array);
 5133 
 5134   if (non_array != nullptr) {
 5135     PreserveJVMState pjvms(this);
 5136     set_control(non_array);
 5137     uncommon_trap(Deoptimization::Reason_intrinsic,
 5138                   Deoptimization::Action_maybe_recompile);
 5139   }
 5140 
 5141   // If control is dead, only non-array-path is taken.
 5142   if (stopped())  return true;
 5143 
 5144   // The works fine even if the array type is polymorphic.
 5145   // It could be a dynamic mix of int[], boolean[], Object[], etc.
 5146   Node* result = load_array_length(array);
 5147 
 5148   C->set_has_split_ifs(true);  // Has chance for split-if optimization
 5149   set_result(result);
 5150   return true;
 5151 }
 5152 
 5153 //------------------------inline_array_copyOf----------------------------
 5154 // public static <T,U> T[] java.util.Arrays.copyOf(     U[] original, int newLength,         Class<? extends T[]> newType);
 5155 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from,      int to, Class<? extends T[]> newType);
 5156 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) {
 5157   if (too_many_traps(Deoptimization::Reason_intrinsic))  return false;
 5158 
 5159   // Get the arguments.
 5160   Node* original          = argument(0);
 5161   Node* start             = is_copyOfRange? argument(1): intcon(0);
 5162   Node* end               = is_copyOfRange? argument(2): argument(1);
 5163   Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
 5164 
 5165   Node* newcopy = nullptr;
 5166 
 5167   // Set the original stack and the reexecute bit for the interpreter to reexecute
 5168   // the bytecode that invokes Arrays.copyOf if deoptimization happens.
 5169   { PreserveReexecuteState preexecs(this);
 5170     jvms()->set_should_reexecute(true);
 5171 
 5172     array_type_mirror = null_check(array_type_mirror);
 5173     original          = null_check(original);
 5174 
 5175     // Check if a null path was taken unconditionally.
 5176     if (stopped())  return true;
 5177 
 5178     Node* orig_length = load_array_length(original);
 5179 
 5180     RegionNode* bailout = new RegionNode(2);
 5181     record_for_igvn(bailout);
 5182 
 5183     Node* klass_node = load_klass_from_mirror(array_type_mirror, false, bailout, 1);
 5184     if (stopped()) {
 5185       // Arrays.copyOf() uses a generic Class parameter which is erased to the raw type Class. This also allows
 5186       // passing in primitive class mirrors like int.class which do not have corresponding Klass* pointers.
 5187       // In these cases, klass_node will be top. Emit a trap to throw in the interpreter in this case.
 5188       bail_out_from_array_copyOf(bailout);
 5189       return true;
 5190     }
 5191 
 5192     klass_node = null_check(klass_node);
 5193 
 5194     const TypeAryPtr* src_t = _gvn.type(original)->is_aryptr();
 5195     const TypeKlassPtr* dest_klass_t = _gvn.type(klass_node)->is_klassptr()->is_klassptr();
 5196 
 5197     Node* success_proj;
 5198     if (should_bail_out_on_non_ref_arrays(src_t, dest_klass_t)) {
 5199       success_proj = generate_non_refArray_guard(klass_node, bailout);
 5200     } else {
 5201       success_proj = generate_typeArray_guard(klass_node, bailout);
 5202     }
 5203 
 5204     Node* refined_klass_node = load_default_refined_array_klass(klass_node, /* type_array_guard= */ false);
 5205 
 5206     if (success_proj != nullptr) {
 5207       // Improve the klass node's type from the new optimistic assumption:
 5208       ciKlass* ak = ciArrayKlass::make(env()->Object_klass());
 5209       bool not_flat = !UseArrayFlattening;
 5210       bool not_null_free = !Arguments::is_valhalla_enabled();
 5211       const Type* akls = TypeAryKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0), Type::trust_interfaces, not_flat, not_null_free, false, false, not_flat, true);
 5212       Node* cast = new CastPPNode(control(), refined_klass_node, akls);
 5213       refined_klass_node = _gvn.transform(cast);
 5214     }
 5215 
 5216     // Bail out if either start or end is negative.
 5217     generate_negative_guard(start, bailout, &start);
 5218     generate_negative_guard(end,   bailout, &end);
 5219 
 5220     Node* length = end;
 5221     if (_gvn.type(start) != TypeInt::ZERO) {
 5222       length = _gvn.transform(new SubINode(end, start));
 5223     }
 5224 
 5225     // Bail out if length is negative (i.e., if start > end).
 5226     // Without this the new_array would throw
 5227     // NegativeArraySizeException but IllegalArgumentException is what
 5228     // should be thrown
 5229     generate_negative_guard(length, bailout, &length);
 5230 
 5231     // Handle inline type arrays
 5232     // TODO 8251971 This is too strong
 5233     generate_fair_guard(flat_array_test(load_object_klass(original)), bailout);
 5234     generate_fair_guard(flat_array_test(refined_klass_node), bailout);
 5235     generate_fair_guard(null_free_array_test(original), bailout);
 5236 
 5237     // Bail out if start is larger than the original length
 5238     Node* orig_tail = _gvn.transform(new SubINode(orig_length, start));
 5239     generate_negative_guard(orig_tail, bailout, &orig_tail);
 5240 
 5241     if (bailout->req() > 1) {
 5242       bail_out_from_array_copyOf(bailout);
 5243     }
 5244 
 5245     if (!stopped()) {
 5246       // How many elements will we copy from the original?
 5247       // The answer is MinI(orig_tail, length).
 5248       Node* moved = _gvn.transform(new MinINode(orig_tail, length));
 5249 
 5250       // Generate a direct call to the right arraycopy function(s).
 5251       // We know the copy is disjoint but we might not know if the
 5252       // oop stores need checking.
 5253       // Extreme case:  Arrays.copyOf((Integer[])x, 10, String[].class).
 5254       // This will fail a store-check if x contains any non-nulls.
 5255 
 5256       // ArrayCopyNode:Ideal may transform the ArrayCopyNode to
 5257       // loads/stores but it is legal only if we're sure the
 5258       // Arrays.copyOf would succeed. So we need all input arguments
 5259       // to the copyOf to be validated, including that the copy to the
 5260       // new array won't trigger an ArrayStoreException. That subtype
 5261       // check can be optimized if we know something on the type of
 5262       // the input array from type speculation.
 5263       if (_gvn.type(klass_node)->singleton()) {
 5264         const TypeKlassPtr* subk = _gvn.type(load_object_klass(original))->is_klassptr();
 5265         const TypeKlassPtr* superk = _gvn.type(klass_node)->is_klassptr();
 5266 
 5267         int test = C->static_subtype_check(superk, subk);
 5268         if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) {
 5269           const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr();
 5270           if (t_original->speculative_type() != nullptr) {
 5271             original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true);
 5272           }
 5273         }
 5274       }
 5275 
 5276       bool validated = false;
 5277       // Reason_class_check rather than Reason_intrinsic because we
 5278       // want to intrinsify even if this traps.
 5279       if (!too_many_traps(Deoptimization::Reason_class_check)) {
 5280         Node* not_subtype_ctrl = gen_subtype_check(original, klass_node);
 5281 
 5282         if (not_subtype_ctrl != top()) {
 5283           PreserveJVMState pjvms(this);
 5284           set_control(not_subtype_ctrl);
 5285           uncommon_trap(Deoptimization::Reason_class_check,
 5286                         Deoptimization::Action_make_not_entrant);
 5287           assert(stopped(), "Should be stopped");
 5288         }
 5289         validated = true;
 5290       }
 5291 
 5292       if (!stopped()) {
 5293         newcopy = new_array(refined_klass_node, length, 0);  // no arguments to push
 5294 
 5295         ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true,
 5296                                                 load_object_klass(original), klass_node);
 5297         if (!is_copyOfRange) {
 5298           ac->set_copyof(validated);
 5299         } else {
 5300           ac->set_copyofrange(validated);
 5301         }
 5302         Node* n = _gvn.transform(ac);
 5303         if (n == ac) {
 5304           ac->connect_outputs(this);
 5305         } else {
 5306           assert(validated, "shouldn't transform if all arguments not validated");
 5307           set_all_memory(n);
 5308         }
 5309       }
 5310     }
 5311   } // original reexecute is set back here
 5312 
 5313   C->set_has_split_ifs(true); // Has chance for split-if optimization
 5314   if (!stopped()) {
 5315     set_result(newcopy);
 5316   }
 5317   return true;
 5318 }
 5319 
 5320 void LibraryCallKit::bail_out_from_array_copyOf(RegionNode* bailout_region) {
 5321   PreserveJVMState pjvms(this);
 5322   set_control(_gvn.transform(bailout_region));
 5323   uncommon_trap(Deoptimization::Reason_intrinsic,
 5324                 Deoptimization::Action_maybe_recompile);
 5325 }
 5326 
 5327 bool LibraryCallKit::should_bail_out_on_non_ref_arrays(const TypeAryPtr* src_type, const TypeKlassPtr* dest_klass_type) {
 5328   const TypeAryKlassPtr* dest_ary_klass_type = dest_klass_type->isa_aryklassptr();
 5329   if (dest_ary_klass_type == nullptr) {
 5330     // Dest klass is not known to be an array class. There are multiple cases:
 5331     // - Primitive class mirror: We already bailed out before.
 5332     // - Instance class mirror: We should bail out.
 5333     // - java.lang.Object (possible due to type erasure): Could be anything including primitive or instance class mirror
 5334     //   or also flat arrays. Bail out.
 5335     return true;
 5336   }
 5337 
 5338   if (UseArrayFlattening) {
 5339     // The remaining checks revolve around array flatness. Without array flatness, we don't need the stronger non-ref
 5340     // runtime check excluding flat arrays.
 5341     return false;
 5342   }
 5343 
 5344   // We now know that src and dest are proper array pointers.
 5345   const bool src_maybe_flat = !src_type->is_not_flat();
 5346   const bool dest_maybe_flat = !dest_ary_klass_type->is_not_flat();
 5347 
 5348   // We could have abstract flat value class arrays whose layout we don't know. Bail out.
 5349   const bool can_src_be_abstract_flat_value_class_array = src_maybe_flat && !src_type->elem()->is_inlinetypeptr();
 5350   const bool can_dest_be_abstract_flat_value_class_array = dest_maybe_flat &&
 5351                                                            !dest_ary_klass_type->elem()->is_instklassptr()->instance_klass()->is_inlinetype();
 5352   if (can_src_be_abstract_flat_value_class_array || can_dest_be_abstract_flat_value_class_array) {
 5353     return true;
 5354   }
 5355 
 5356   // Value class array may have object field that would require a write barrier. Conservatively bail out.
 5357   // TODO 8251971: Optimize for the case when flat src/dst are later found to not contain
 5358   //               oops (i.e., move this check to the macro expansion phase).
 5359   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 5360   if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, false, false, BarrierSetC2::Parsing)) {
 5361     // No barriers required.
 5362     return false;
 5363   }
 5364 
 5365   const bool can_src_be_flat_with_oops = src_maybe_flat && src_type->elem()->inline_klass()->contains_oops();
 5366   const bool can_dest_be_flat_with_oops = dest_maybe_flat && dest_ary_klass_type->elem()->is_instklassptr()->instance_klass()->as_inline_klass()->contains_oops();
 5367   if (can_src_be_flat_with_oops || can_dest_be_flat_with_oops) {
 5368     return true;
 5369   }
 5370 
 5371   // Can handle remaining flat arrays.
 5372   return false;
 5373 }
 5374 
 5375 //----------------------generate_virtual_guard---------------------------
 5376 // Helper for hashCode and clone.  Peeks inside the vtable to avoid a call.
 5377 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
 5378                                              RegionNode* slow_region) {
 5379   ciMethod* method = callee();
 5380   int vtable_index = method->vtable_index();
 5381   assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
 5382          "bad index %d", vtable_index);
 5383   // Get the Method* out of the appropriate vtable entry.
 5384   int entry_offset = in_bytes(Klass::vtable_start_offset()) +
 5385                      vtable_index*vtableEntry::size_in_bytes() +
 5386                      in_bytes(vtableEntry::method_offset());
 5387   Node* entry_addr = off_heap_plus_addr(obj_klass, entry_offset);
 5388   Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered);
 5389 
 5390   // Compare the target method with the expected method (e.g., Object.hashCode).
 5391   const TypePtr* native_call_addr = TypeMetadataPtr::make(method);
 5392 
 5393   Node* native_call = makecon(native_call_addr);
 5394   Node* chk_native  = _gvn.transform(new CmpPNode(target_call, native_call));
 5395   Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne));
 5396 
 5397   return generate_slow_guard(test_native, slow_region);
 5398 }
 5399 
 5400 //-----------------------generate_method_call----------------------------
 5401 // Use generate_method_call to make a slow-call to the real
 5402 // method if the fast path fails.  An alternative would be to
 5403 // use a stub like OptoRuntime::slow_arraycopy_Java.
 5404 // This only works for expanding the current library call,
 5405 // not another intrinsic.  (E.g., don't use this for making an
 5406 // arraycopy call inside of the copyOf intrinsic.)
 5407 CallJavaNode*
 5408 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) {
 5409   // When compiling the intrinsic method itself, do not use this technique.
 5410   guarantee(callee() != C->method(), "cannot make slow-call to self");
 5411 
 5412   ciMethod* method = callee();
 5413   // ensure the JVMS we have will be correct for this call
 5414   guarantee(method_id == method->intrinsic_id(), "must match");
 5415 
 5416   const TypeFunc* tf = TypeFunc::make(method);
 5417   if (res_not_null) {
 5418     assert(tf->return_type() == T_OBJECT, "");
 5419     const TypeTuple* range = tf->range_cc();
 5420     const Type** fields = TypeTuple::fields(range->cnt());
 5421     fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL);
 5422     const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields);
 5423     tf = TypeFunc::make(tf->domain_cc(), new_range);
 5424   }
 5425   CallJavaNode* slow_call;
 5426   if (is_static) {
 5427     assert(!is_virtual, "");
 5428     slow_call = new CallStaticJavaNode(C, tf,
 5429                            SharedRuntime::get_resolve_static_call_stub(), method);
 5430   } else if (is_virtual) {
 5431     assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
 5432     int vtable_index = Method::invalid_vtable_index;
 5433     if (UseInlineCaches) {
 5434       // Suppress the vtable call
 5435     } else {
 5436       // hashCode and clone are not a miranda methods,
 5437       // so the vtable index is fixed.
 5438       // No need to use the linkResolver to get it.
 5439        vtable_index = method->vtable_index();
 5440        assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index,
 5441               "bad index %d", vtable_index);
 5442     }
 5443     slow_call = new CallDynamicJavaNode(tf,
 5444                           SharedRuntime::get_resolve_virtual_call_stub(),
 5445                           method, vtable_index);
 5446   } else {  // neither virtual nor static:  opt_virtual
 5447     assert(!gvn().type(argument(0))->maybe_null(), "should not be null");
 5448     slow_call = new CallStaticJavaNode(C, tf,
 5449                                 SharedRuntime::get_resolve_opt_virtual_call_stub(), method);
 5450     slow_call->set_optimized_virtual(true);
 5451   }
 5452   if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) {
 5453     // To be able to issue a direct call (optimized virtual or virtual)
 5454     // and skip a call to MH.linkTo*/invokeBasic adapter, additional information
 5455     // about the method being invoked should be attached to the call site to
 5456     // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C).
 5457     slow_call->set_override_symbolic_info(true);
 5458   }
 5459   set_arguments_for_java_call(slow_call);
 5460   set_edges_for_java_call(slow_call);
 5461   return slow_call;
 5462 }
 5463 
 5464 
 5465 /**
 5466  * Build special case code for calls to hashCode on an object. This call may
 5467  * be virtual (invokevirtual) or bound (invokespecial). For each case we generate
 5468  * slightly different code.
 5469  */
 5470 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
 5471   assert(is_static == callee()->is_static(), "correct intrinsic selection");
 5472   assert(!(is_virtual && is_static), "either virtual, special, or static");
 5473 
 5474   enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
 5475 
 5476   RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 5477   PhiNode*    result_val = new PhiNode(result_reg, TypeInt::INT);
 5478   PhiNode*    result_io  = new PhiNode(result_reg, Type::ABIO);
 5479   PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 5480   Node* obj = argument(0);
 5481 
 5482   // Don't intrinsify hashcode on inline types for now.
 5483   // The "is locked" runtime check also subsumes the inline type check (as inline types cannot be locked) and goes to the slow path.
 5484   if (gvn().type(obj)->is_inlinetypeptr()) {
 5485     return false;
 5486   }
 5487 
 5488   if (!is_static) {
 5489     // Check for hashing null object
 5490     obj = null_check_receiver();
 5491     if (stopped())  return true;        // unconditionally null
 5492     result_reg->init_req(_null_path, top());
 5493     result_val->init_req(_null_path, top());
 5494   } else {
 5495     // Do a null check, and return zero if null.
 5496     // System.identityHashCode(null) == 0
 5497     Node* null_ctl = top();
 5498     obj = null_check_oop(obj, &null_ctl);
 5499     result_reg->init_req(_null_path, null_ctl);
 5500     result_val->init_req(_null_path, _gvn.intcon(0));
 5501   }
 5502 
 5503   // Unconditionally null?  Then return right away.
 5504   if (stopped()) {
 5505     set_control( result_reg->in(_null_path));
 5506     if (!stopped())
 5507       set_result(result_val->in(_null_path));
 5508     return true;
 5509   }
 5510 
 5511   // We only go to the fast case code if we pass a number of guards.  The
 5512   // paths which do not pass are accumulated in the slow_region.
 5513   RegionNode* slow_region = new RegionNode(1);
 5514   record_for_igvn(slow_region);
 5515 
 5516   // If this is a virtual call, we generate a funny guard.  We pull out
 5517   // the vtable entry corresponding to hashCode() from the target object.
 5518   // If the target method which we are calling happens to be the native
 5519   // Object hashCode() method, we pass the guard.  We do not need this
 5520   // guard for non-virtual calls -- the caller is known to be the native
 5521   // Object hashCode().
 5522   if (is_virtual) {
 5523     // After null check, get the object's klass.
 5524     Node* obj_klass = load_object_klass(obj);
 5525     generate_virtual_guard(obj_klass, slow_region);
 5526   }
 5527 
 5528   // Get the header out of the object, use LoadMarkNode when available
 5529   Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
 5530   // The control of the load must be null. Otherwise, the load can move before
 5531   // the null check after castPP removal.
 5532   Node* no_ctrl = nullptr;
 5533   Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered);
 5534 
 5535   if (!UseObjectMonitorTable) {
 5536     // Test the header to see if it is safe to read w.r.t. locking.
 5537     // We cannot use the inline type mask as this may check bits that are overridden
 5538     // by an object monitor's pointer when inflating locking.
 5539     Node *lock_mask      = _gvn.MakeConX(markWord::lock_mask_in_place);
 5540     Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask));
 5541     Node *monitor_val   = _gvn.MakeConX(markWord::monitor_value);
 5542     Node *chk_monitor   = _gvn.transform(new CmpXNode(lmasked_header, monitor_val));
 5543     Node *test_monitor  = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq));
 5544 
 5545     generate_slow_guard(test_monitor, slow_region);
 5546   }
 5547 
 5548   // Get the hash value and check to see that it has been properly assigned.
 5549   // We depend on hash_mask being at most 32 bits and avoid the use of
 5550   // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
 5551   // vm: see markWord.hpp.
 5552   Node *hash_mask      = _gvn.intcon(markWord::hash_mask);
 5553   Node *hash_shift     = _gvn.intcon(markWord::hash_shift);
 5554   Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift));
 5555   // This hack lets the hash bits live anywhere in the mark object now, as long
 5556   // as the shift drops the relevant bits into the low 32 bits.  Note that
 5557   // Java spec says that HashCode is an int so there's no point in capturing
 5558   // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
 5559   hshifted_header      = ConvX2I(hshifted_header);
 5560   Node *hash_val       = _gvn.transform(new AndINode(hshifted_header, hash_mask));
 5561 
 5562   Node *no_hash_val    = _gvn.intcon(markWord::no_hash);
 5563   Node *chk_assigned   = _gvn.transform(new CmpINode( hash_val, no_hash_val));
 5564   Node *test_assigned  = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq));
 5565 
 5566   generate_slow_guard(test_assigned, slow_region);
 5567 
 5568   Node* init_mem = reset_memory();
 5569   // fill in the rest of the null path:
 5570   result_io ->init_req(_null_path, i_o());
 5571   result_mem->init_req(_null_path, init_mem);
 5572 
 5573   result_val->init_req(_fast_path, hash_val);
 5574   result_reg->init_req(_fast_path, control());
 5575   result_io ->init_req(_fast_path, i_o());
 5576   result_mem->init_req(_fast_path, init_mem);
 5577 
 5578   // Generate code for the slow case.  We make a call to hashCode().
 5579   set_control(_gvn.transform(slow_region));
 5580   if (!stopped()) {
 5581     // No need for PreserveJVMState, because we're using up the present state.
 5582     set_all_memory(init_mem);
 5583     vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode;
 5584     CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false);
 5585     Node* slow_result = set_results_for_java_call(slow_call);
 5586     // this->control() comes from set_results_for_java_call
 5587     result_reg->init_req(_slow_path, control());
 5588     result_val->init_req(_slow_path, slow_result);
 5589     result_io  ->set_req(_slow_path, i_o());
 5590     result_mem ->set_req(_slow_path, reset_memory());
 5591   }
 5592 
 5593   // Return the combined state.
 5594   set_i_o(        _gvn.transform(result_io)  );
 5595   set_all_memory( _gvn.transform(result_mem));
 5596 
 5597   set_result(result_reg, result_val);
 5598   return true;
 5599 }
 5600 
 5601 //---------------------------inline_native_getClass----------------------------
 5602 // public final native Class<?> java.lang.Object.getClass();
 5603 //
 5604 // Build special case code for calls to getClass on an object.
 5605 bool LibraryCallKit::inline_native_getClass() {
 5606   Node* obj = argument(0);
 5607   if (obj->is_InlineType()) {
 5608     const Type* t = _gvn.type(obj);
 5609     if (t->maybe_null()) {
 5610       null_check(obj);
 5611     }
 5612     set_result(makecon(TypeInstPtr::make(t->inline_klass()->java_mirror())));
 5613     return true;
 5614   }
 5615   obj = null_check_receiver();
 5616   if (stopped())  return true;
 5617   set_result(load_mirror_from_klass(load_object_klass(obj)));
 5618   return true;
 5619 }
 5620 
 5621 //-----------------inline_native_Reflection_getCallerClass---------------------
 5622 // public static native Class<?> sun.reflect.Reflection.getCallerClass();
 5623 //
 5624 // In the presence of deep enough inlining, getCallerClass() becomes a no-op.
 5625 //
 5626 // NOTE: This code must perform the same logic as JVM_GetCallerClass
 5627 // in that it must skip particular security frames and checks for
 5628 // caller sensitive methods.
 5629 bool LibraryCallKit::inline_native_Reflection_getCallerClass() {
 5630 #ifndef PRODUCT
 5631   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5632     tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass");
 5633   }
 5634 #endif
 5635 
 5636   if (!jvms()->has_method()) {
 5637 #ifndef PRODUCT
 5638     if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5639       tty->print_cr("  Bailing out because intrinsic was inlined at top level");
 5640     }
 5641 #endif
 5642     return false;
 5643   }
 5644 
 5645   // Walk back up the JVM state to find the caller at the required
 5646   // depth.
 5647   JVMState* caller_jvms = jvms();
 5648 
 5649   // Cf. JVM_GetCallerClass
 5650   // NOTE: Start the loop at depth 1 because the current JVM state does
 5651   // not include the Reflection.getCallerClass() frame.
 5652   for (int n = 1; caller_jvms != nullptr; caller_jvms = caller_jvms->caller(), n++) {
 5653     ciMethod* m = caller_jvms->method();
 5654     switch (n) {
 5655     case 0:
 5656       fatal("current JVM state does not include the Reflection.getCallerClass frame");
 5657       break;
 5658     case 1:
 5659       // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass).
 5660       if (!m->caller_sensitive()) {
 5661 #ifndef PRODUCT
 5662         if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5663           tty->print_cr("  Bailing out: CallerSensitive annotation expected at frame %d", n);
 5664         }
 5665 #endif
 5666         return false;  // bail-out; let JVM_GetCallerClass do the work
 5667       }
 5668       break;
 5669     default:
 5670       if (!m->is_ignored_by_security_stack_walk()) {
 5671         // We have reached the desired frame; return the holder class.
 5672         // Acquire method holder as java.lang.Class and push as constant.
 5673         ciInstanceKlass* caller_klass = caller_jvms->method()->holder();
 5674         ciInstance* caller_mirror = caller_klass->java_mirror();
 5675         set_result(makecon(TypeInstPtr::make(caller_mirror)));
 5676 
 5677 #ifndef PRODUCT
 5678         if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5679           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());
 5680           tty->print_cr("  JVM state at this point:");
 5681           for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) {
 5682             ciMethod* m = jvms()->of_depth(i)->method();
 5683             tty->print_cr("   %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8());
 5684           }
 5685         }
 5686 #endif
 5687         return true;
 5688       }
 5689       break;
 5690     }
 5691   }
 5692 
 5693 #ifndef PRODUCT
 5694   if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
 5695     tty->print_cr("  Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth());
 5696     tty->print_cr("  JVM state at this point:");
 5697     for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) {
 5698       ciMethod* m = jvms()->of_depth(i)->method();
 5699       tty->print_cr("   %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8());
 5700     }
 5701   }
 5702 #endif
 5703 
 5704   return false;  // bail-out; let JVM_GetCallerClass do the work
 5705 }
 5706 
 5707 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
 5708   Node* arg = argument(0);
 5709   Node* result = nullptr;
 5710 
 5711   switch (id) {
 5712   case vmIntrinsics::_floatToRawIntBits:    result = new MoveF2INode(arg);  break;
 5713   case vmIntrinsics::_intBitsToFloat:       result = new MoveI2FNode(arg);  break;
 5714   case vmIntrinsics::_doubleToRawLongBits:  result = new MoveD2LNode(arg);  break;
 5715   case vmIntrinsics::_longBitsToDouble:     result = new MoveL2DNode(arg);  break;
 5716   case vmIntrinsics::_floatToFloat16:       result = new ConvF2HFNode(arg); break;
 5717   case vmIntrinsics::_float16ToFloat:       result = new ConvHF2FNode(arg); break;
 5718 
 5719   case vmIntrinsics::_doubleToLongBits: {
 5720     // two paths (plus control) merge in a wood
 5721     RegionNode *r = new RegionNode(3);
 5722     Node *phi = new PhiNode(r, TypeLong::LONG);
 5723 
 5724     Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg));
 5725     // Build the boolean node
 5726     Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne));
 5727 
 5728     // Branch either way.
 5729     // NaN case is less traveled, which makes all the difference.
 5730     IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
 5731     Node *opt_isnan = _gvn.transform(ifisnan);
 5732     assert( opt_isnan->is_If(), "Expect an IfNode");
 5733     IfNode *opt_ifisnan = (IfNode*)opt_isnan;
 5734     Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan));
 5735 
 5736     set_control(iftrue);
 5737 
 5738     static const jlong nan_bits = CONST64(0x7ff8000000000000);
 5739     Node *slow_result = longcon(nan_bits); // return NaN
 5740     phi->init_req(1, _gvn.transform( slow_result ));
 5741     r->init_req(1, iftrue);
 5742 
 5743     // Else fall through
 5744     Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan));
 5745     set_control(iffalse);
 5746 
 5747     phi->init_req(2, _gvn.transform(new MoveD2LNode(arg)));
 5748     r->init_req(2, iffalse);
 5749 
 5750     // Post merge
 5751     set_control(_gvn.transform(r));
 5752     record_for_igvn(r);
 5753 
 5754     C->set_has_split_ifs(true); // Has chance for split-if optimization
 5755     result = phi;
 5756     assert(result->bottom_type()->isa_long(), "must be");
 5757     break;
 5758   }
 5759 
 5760   case vmIntrinsics::_floatToIntBits: {
 5761     // two paths (plus control) merge in a wood
 5762     RegionNode *r = new RegionNode(3);
 5763     Node *phi = new PhiNode(r, TypeInt::INT);
 5764 
 5765     Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg));
 5766     // Build the boolean node
 5767     Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne));
 5768 
 5769     // Branch either way.
 5770     // NaN case is less traveled, which makes all the difference.
 5771     IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
 5772     Node *opt_isnan = _gvn.transform(ifisnan);
 5773     assert( opt_isnan->is_If(), "Expect an IfNode");
 5774     IfNode *opt_ifisnan = (IfNode*)opt_isnan;
 5775     Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan));
 5776 
 5777     set_control(iftrue);
 5778 
 5779     static const jint nan_bits = 0x7fc00000;
 5780     Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN
 5781     phi->init_req(1, _gvn.transform( slow_result ));
 5782     r->init_req(1, iftrue);
 5783 
 5784     // Else fall through
 5785     Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan));
 5786     set_control(iffalse);
 5787 
 5788     phi->init_req(2, _gvn.transform(new MoveF2INode(arg)));
 5789     r->init_req(2, iffalse);
 5790 
 5791     // Post merge
 5792     set_control(_gvn.transform(r));
 5793     record_for_igvn(r);
 5794 
 5795     C->set_has_split_ifs(true); // Has chance for split-if optimization
 5796     result = phi;
 5797     assert(result->bottom_type()->isa_int(), "must be");
 5798     break;
 5799   }
 5800 
 5801   default:
 5802     fatal_unexpected_iid(id);
 5803     break;
 5804   }
 5805   set_result(_gvn.transform(result));
 5806   return true;
 5807 }
 5808 
 5809 bool LibraryCallKit::inline_fp_range_check(vmIntrinsics::ID id) {
 5810   Node* arg = argument(0);
 5811   Node* result = nullptr;
 5812 
 5813   switch (id) {
 5814   case vmIntrinsics::_floatIsInfinite:
 5815     result = new IsInfiniteFNode(arg);
 5816     break;
 5817   case vmIntrinsics::_floatIsFinite:
 5818     result = new IsFiniteFNode(arg);
 5819     break;
 5820   case vmIntrinsics::_doubleIsInfinite:
 5821     result = new IsInfiniteDNode(arg);
 5822     break;
 5823   case vmIntrinsics::_doubleIsFinite:
 5824     result = new IsFiniteDNode(arg);
 5825     break;
 5826   default:
 5827     fatal_unexpected_iid(id);
 5828     break;
 5829   }
 5830   set_result(_gvn.transform(result));
 5831   return true;
 5832 }
 5833 
 5834 //----------------------inline_unsafe_copyMemory-------------------------
 5835 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
 5836 
 5837 static bool has_wide_mem(PhaseGVN& gvn, Node* addr, Node* base) {
 5838   const TypeAryPtr* addr_t = gvn.type(addr)->isa_aryptr();
 5839   const Type*       base_t = gvn.type(base);
 5840 
 5841   bool in_native = (base_t == TypePtr::NULL_PTR);
 5842   bool in_heap   = !TypePtr::NULL_PTR->higher_equal(base_t);
 5843   bool is_mixed  = !in_heap && !in_native;
 5844 
 5845   if (is_mixed) {
 5846     return true; // mixed accesses can touch both on-heap and off-heap memory
 5847   }
 5848   if (in_heap) {
 5849     bool is_prim_array = (addr_t != nullptr) && (addr_t->elem() != Type::BOTTOM);
 5850     if (!is_prim_array) {
 5851       // Though Unsafe.copyMemory() ensures at runtime for on-heap accesses that base is a primitive array,
 5852       // there's not enough type information available to determine proper memory slice for it.
 5853       return true;
 5854     }
 5855   }
 5856   return false;
 5857 }
 5858 
 5859 bool LibraryCallKit::inline_unsafe_copyMemory() {
 5860   if (callee()->is_static())  return false;  // caller must have the capability!
 5861   null_check_receiver();  // null-check receiver
 5862   if (stopped())  return true;
 5863 
 5864   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 5865 
 5866   Node* src_base =         argument(1);  // type: oop
 5867   Node* src_off  = ConvL2X(argument(2)); // type: long
 5868   Node* dst_base =         argument(4);  // type: oop
 5869   Node* dst_off  = ConvL2X(argument(5)); // type: long
 5870   Node* size     = ConvL2X(argument(7)); // type: long
 5871 
 5872   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 5873          "fieldOffset must be byte-scaled");
 5874 
 5875   Node* src_addr = make_unsafe_address(src_base, src_off);
 5876   Node* dst_addr = make_unsafe_address(dst_base, dst_off);
 5877 
 5878   Node* thread = _gvn.transform(new ThreadLocalNode());
 5879   Node* doing_unsafe_access_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::doing_unsafe_access_offset()));
 5880   BasicType doing_unsafe_access_bt = T_BYTE;
 5881   assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented");
 5882 
 5883   // update volatile field
 5884   store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered);
 5885 
 5886   int flags = RC_LEAF | RC_NO_FP;
 5887 
 5888   const TypePtr* dst_type = TypePtr::BOTTOM;
 5889 
 5890   // Adjust memory effects of the runtime call based on input values.
 5891   if (!has_wide_mem(_gvn, src_addr, src_base) &&
 5892       !has_wide_mem(_gvn, dst_addr, dst_base)) {
 5893     dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory
 5894 
 5895     const TypePtr* src_type = _gvn.type(src_addr)->is_ptr();
 5896     if (C->get_alias_index(src_type) == C->get_alias_index(dst_type)) {
 5897       flags |= RC_NARROW_MEM; // narrow in memory
 5898     }
 5899   }
 5900 
 5901   // Call it.  Note that the length argument is not scaled.
 5902   make_runtime_call(flags,
 5903                     OptoRuntime::fast_arraycopy_Type(),
 5904                     StubRoutines::unsafe_arraycopy(),
 5905                     "unsafe_arraycopy",
 5906                     dst_type,
 5907                     src_addr, dst_addr, size XTOP);
 5908 
 5909   store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered);
 5910 
 5911   return true;
 5912 }
 5913 
 5914 // unsafe_setmemory(void *base, ulong offset, size_t length, char fill_value);
 5915 // Fill 'length' bytes starting from 'base[offset]' with 'fill_value'
 5916 bool LibraryCallKit::inline_unsafe_setMemory() {
 5917   if (callee()->is_static())  return false;  // caller must have the capability!
 5918   null_check_receiver();  // null-check receiver
 5919   if (stopped())  return true;
 5920 
 5921   C->set_has_unsafe_access(true);  // Mark eventual nmethod as "unsafe".
 5922 
 5923   Node* dst_base =         argument(1);  // type: oop
 5924   Node* dst_off  = ConvL2X(argument(2)); // type: long
 5925   Node* size     = ConvL2X(argument(4)); // type: long
 5926   Node* byte     =         argument(6);  // type: byte
 5927 
 5928   assert(Unsafe_field_offset_to_byte_offset(11) == 11,
 5929          "fieldOffset must be byte-scaled");
 5930 
 5931   Node* dst_addr = make_unsafe_address(dst_base, dst_off);
 5932 
 5933   Node* thread = _gvn.transform(new ThreadLocalNode());
 5934   Node* doing_unsafe_access_addr = off_heap_plus_addr(thread, in_bytes(JavaThread::doing_unsafe_access_offset()));
 5935   BasicType doing_unsafe_access_bt = T_BYTE;
 5936   assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented");
 5937 
 5938   // update volatile field
 5939   store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered);
 5940 
 5941   int flags = RC_LEAF | RC_NO_FP;
 5942 
 5943   const TypePtr* dst_type = TypePtr::BOTTOM;
 5944 
 5945   // Adjust memory effects of the runtime call based on input values.
 5946   if (!has_wide_mem(_gvn, dst_addr, dst_base)) {
 5947     dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory
 5948 
 5949     flags |= RC_NARROW_MEM; // narrow in memory
 5950   }
 5951 
 5952   // Call it.  Note that the length argument is not scaled.
 5953   make_runtime_call(flags,
 5954                     OptoRuntime::unsafe_setmemory_Type(),
 5955                     StubRoutines::unsafe_setmemory(),
 5956                     "unsafe_setmemory",
 5957                     dst_type,
 5958                     dst_addr, size XTOP, byte);
 5959 
 5960   store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered);
 5961 
 5962   return true;
 5963 }
 5964 
 5965 #undef XTOP
 5966 
 5967 //------------------------clone_coping-----------------------------------
 5968 // Helper function for inline_native_clone.
 5969 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) {
 5970   assert(obj_size != nullptr, "");
 5971   Node* raw_obj = alloc_obj->in(1);
 5972   assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), "");
 5973 
 5974   AllocateNode* alloc = nullptr;
 5975   if (ReduceBulkZeroing &&
 5976       // If we are implementing an array clone without knowing its source type
 5977       // (can happen when compiling the array-guarded branch of a reflective
 5978       // Object.clone() invocation), initialize the array within the allocation.
 5979       // This is needed because some GCs (e.g. ZGC) might fall back in this case
 5980       // to a runtime clone call that assumes fully initialized source arrays.
 5981       (!is_array || obj->get_ptr_type()->isa_aryptr() != nullptr)) {
 5982     // We will be completely responsible for initializing this object -
 5983     // mark Initialize node as complete.
 5984     alloc = AllocateNode::Ideal_allocation(alloc_obj);
 5985     // The object was just allocated - there should be no any stores!
 5986     guarantee(alloc != nullptr && alloc->maybe_set_complete(&_gvn), "");
 5987     // Mark as complete_with_arraycopy so that on AllocateNode
 5988     // expansion, we know this AllocateNode is initialized by an array
 5989     // copy and a StoreStore barrier exists after the array copy.
 5990     alloc->initialization()->set_complete_with_arraycopy();
 5991   }
 5992 
 5993   Node* size = _gvn.transform(obj_size);
 5994   access_clone(obj, alloc_obj, size, is_array);
 5995 
 5996   // Do not let reads from the cloned object float above the arraycopy.
 5997   if (alloc != nullptr) {
 5998     // Do not let stores that initialize this object be reordered with
 5999     // a subsequent store that would make this object accessible by
 6000     // other threads.
 6001     // Record what AllocateNode this StoreStore protects so that
 6002     // escape analysis can go from the MemBarStoreStoreNode to the
 6003     // AllocateNode and eliminate the MemBarStoreStoreNode if possible
 6004     // based on the escape status of the AllocateNode.
 6005     insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
 6006   } else {
 6007     insert_mem_bar(Op_MemBarCPUOrder);
 6008   }
 6009 }
 6010 
 6011 //------------------------inline_native_clone----------------------------
 6012 // protected native Object java.lang.Object.clone();
 6013 //
 6014 // Here are the simple edge cases:
 6015 //  null receiver => normal trap
 6016 //  virtual and clone was overridden => slow path to out-of-line clone
 6017 //  not cloneable or finalizer => slow path to out-of-line Object.clone
 6018 //
 6019 // The general case has two steps, allocation and copying.
 6020 // Allocation has two cases, and uses GraphKit::new_instance or new_array.
 6021 //
 6022 // Copying also has two cases, oop arrays and everything else.
 6023 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
 6024 // Everything else uses the tight inline loop supplied by CopyArrayNode.
 6025 //
 6026 // These steps fold up nicely if and when the cloned object's klass
 6027 // can be sharply typed as an object array, a type array, or an instance.
 6028 //
 6029 bool LibraryCallKit::inline_native_clone(bool is_virtual) {
 6030   PhiNode* result_val;
 6031 
 6032   // Set the reexecute bit for the interpreter to reexecute
 6033   // the bytecode that invokes Object.clone if deoptimization happens.
 6034   { PreserveReexecuteState preexecs(this);
 6035     jvms()->set_should_reexecute(true);
 6036 
 6037     Node* obj = argument(0);
 6038     obj = null_check_receiver();
 6039     if (stopped())  return true;
 6040 
 6041     const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr();
 6042     if (obj_type->is_inlinetypeptr()) {
 6043       // If the object to clone is an inline type, we can simply return it (i.e. a nop) since inline types have
 6044       // no identity.
 6045       set_result(obj);
 6046       return true;
 6047     }
 6048 
 6049     // If we are going to clone an instance, we need its exact type to
 6050     // know the number and types of fields to convert the clone to
 6051     // loads/stores. Maybe a speculative type can help us.
 6052     if (!obj_type->klass_is_exact() &&
 6053         obj_type->speculative_type() != nullptr &&
 6054         obj_type->speculative_type()->is_instance_klass() &&
 6055         !obj_type->speculative_type()->is_inlinetype()) {
 6056       ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass();
 6057       if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem &&
 6058           !spec_ik->has_injected_fields()) {
 6059         if (!obj_type->isa_instptr() ||
 6060             obj_type->is_instptr()->instance_klass()->has_subklass()) {
 6061           obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false);
 6062         }
 6063       }
 6064     }
 6065 
 6066     // Conservatively insert a memory barrier on all memory slices.
 6067     // Do not let writes into the original float below the clone.
 6068     insert_mem_bar(Op_MemBarCPUOrder);
 6069 
 6070     // paths into result_reg:
 6071     enum {
 6072       _slow_path = 1,     // out-of-line call to clone method (virtual or not)
 6073       _objArray_path,     // plain array allocation, plus arrayof_oop_arraycopy
 6074       _array_path,        // plain array allocation, plus arrayof_long_arraycopy
 6075       _instance_path,     // plain instance allocation, plus arrayof_long_arraycopy
 6076       PATH_LIMIT
 6077     };
 6078     RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 6079     result_val             = new PhiNode(result_reg, TypeInstPtr::NOTNULL);
 6080     PhiNode*    result_i_o = new PhiNode(result_reg, Type::ABIO);
 6081     PhiNode*    result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM);
 6082     record_for_igvn(result_reg);
 6083 
 6084     Node* obj_klass = load_object_klass(obj);
 6085     // We only go to the fast case code if we pass a number of guards.
 6086     // The paths which do not pass are accumulated in the slow_region.
 6087     RegionNode* slow_region = new RegionNode(1);
 6088     record_for_igvn(slow_region);
 6089 
 6090     Node* array_obj = obj;
 6091     Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj);
 6092     if (array_ctl != nullptr) {
 6093       // It's an array.
 6094       PreserveJVMState pjvms(this);
 6095       set_control(array_ctl);
 6096 
 6097       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 6098       const TypeAryPtr* ary_ptr = obj_type->isa_aryptr();
 6099       if (UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Expansion) &&
 6100           obj_type->can_be_inline_array() &&
 6101           (ary_ptr == nullptr || (!ary_ptr->is_not_flat() && (!ary_ptr->is_flat() || ary_ptr->elem()->inline_klass()->contains_oops())))) {
 6102         // Flat inline type array may have object field that would require a
 6103         // write barrier. Conservatively, go to slow path.
 6104         generate_fair_guard(flat_array_test(obj_klass), slow_region);
 6105       }
 6106 
 6107       if (!stopped()) {
 6108         Node* obj_length = load_array_length(array_obj);
 6109         Node* array_size = nullptr; // Size of the array without object alignment padding.
 6110         Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true);
 6111 
 6112         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 6113         if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) {
 6114           // If it is an oop array, it requires very special treatment,
 6115           // because gc barriers are required when accessing the array.
 6116           Node* is_obja = generate_refArray_guard(obj_klass, (RegionNode*)nullptr);
 6117           if (is_obja != nullptr) {
 6118             PreserveJVMState pjvms2(this);
 6119             set_control(is_obja);
 6120             // Generate a direct call to the right arraycopy function(s).
 6121             // Clones are always tightly coupled.
 6122             ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false);
 6123             ac->set_clone_oop_array();
 6124             Node* n = _gvn.transform(ac);
 6125             assert(n == ac, "cannot disappear");
 6126             ac->connect_outputs(this, /*deoptimize_on_exception=*/true);
 6127 
 6128             result_reg->init_req(_objArray_path, control());
 6129             result_val->init_req(_objArray_path, alloc_obj);
 6130             result_i_o ->set_req(_objArray_path, i_o());
 6131             result_mem ->set_req(_objArray_path, reset_memory());
 6132           }
 6133         }
 6134         // Otherwise, there are no barriers to worry about.
 6135         // (We can dispense with card marks if we know the allocation
 6136         //  comes out of eden (TLAB)...  In fact, ReduceInitialCardMarks
 6137         //  causes the non-eden paths to take compensating steps to
 6138         //  simulate a fresh allocation, so that no further
 6139         //  card marks are required in compiled code to initialize
 6140         //  the object.)
 6141 
 6142         if (!stopped()) {
 6143           copy_to_clone(obj, alloc_obj, array_size, true);
 6144 
 6145           // Present the results of the copy.
 6146           result_reg->init_req(_array_path, control());
 6147           result_val->init_req(_array_path, alloc_obj);
 6148           result_i_o ->set_req(_array_path, i_o());
 6149           result_mem ->set_req(_array_path, reset_memory());
 6150         }
 6151       }
 6152     }
 6153 
 6154     if (!stopped()) {
 6155       // It's an instance (we did array above).  Make the slow-path tests.
 6156       // If this is a virtual call, we generate a funny guard.  We grab
 6157       // the vtable entry corresponding to clone() from the target object.
 6158       // If the target method which we are calling happens to be the
 6159       // Object clone() method, we pass the guard.  We do not need this
 6160       // guard for non-virtual calls; the caller is known to be the native
 6161       // Object clone().
 6162       if (is_virtual) {
 6163         generate_virtual_guard(obj_klass, slow_region);
 6164       }
 6165 
 6166       // The object must be easily cloneable and must not have a finalizer.
 6167       // Both of these conditions may be checked in a single test.
 6168       // We could optimize the test further, but we don't care.
 6169       generate_misc_flags_guard(obj_klass,
 6170                                 // Test both conditions:
 6171                                 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer,
 6172                                 // Must be cloneable but not finalizer:
 6173                                 KlassFlags::_misc_is_cloneable_fast,
 6174                                 slow_region);
 6175     }
 6176 
 6177     if (!stopped()) {
 6178       // It's an instance, and it passed the slow-path tests.
 6179       PreserveJVMState pjvms(this);
 6180       Node* obj_size = nullptr; // Total object size, including object alignment padding.
 6181       // Need to deoptimize on exception from allocation since Object.clone intrinsic
 6182       // is reexecuted if deoptimization occurs and there could be problems when merging
 6183       // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false).
 6184       Node* alloc_obj = new_instance(obj_klass, nullptr, &obj_size, /*deoptimize_on_exception=*/true);
 6185 
 6186       copy_to_clone(obj, alloc_obj, obj_size, false);
 6187 
 6188       // Present the results of the slow call.
 6189       result_reg->init_req(_instance_path, control());
 6190       result_val->init_req(_instance_path, alloc_obj);
 6191       result_i_o ->set_req(_instance_path, i_o());
 6192       result_mem ->set_req(_instance_path, reset_memory());
 6193     }
 6194 
 6195     // Generate code for the slow case.  We make a call to clone().
 6196     set_control(_gvn.transform(slow_region));
 6197     if (!stopped()) {
 6198       PreserveJVMState pjvms(this);
 6199       CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual, false, true);
 6200       // We need to deoptimize on exception (see comment above)
 6201       Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true);
 6202       // this->control() comes from set_results_for_java_call
 6203       result_reg->init_req(_slow_path, control());
 6204       result_val->init_req(_slow_path, slow_result);
 6205       result_i_o ->set_req(_slow_path, i_o());
 6206       result_mem ->set_req(_slow_path, reset_memory());
 6207     }
 6208 
 6209     // Return the combined state.
 6210     set_control(    _gvn.transform(result_reg));
 6211     set_i_o(        _gvn.transform(result_i_o));
 6212     set_all_memory( _gvn.transform(result_mem));
 6213   } // original reexecute is set back here
 6214 
 6215   set_result(_gvn.transform(result_val));
 6216   return true;
 6217 }
 6218 
 6219 // If we have a tightly coupled allocation, the arraycopy may take care
 6220 // of the array initialization. If one of the guards we insert between
 6221 // the allocation and the arraycopy causes a deoptimization, an
 6222 // uninitialized array will escape the compiled method. To prevent that
 6223 // we set the JVM state for uncommon traps between the allocation and
 6224 // the arraycopy to the state before the allocation so, in case of
 6225 // deoptimization, we'll reexecute the allocation and the
 6226 // initialization.
 6227 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) {
 6228   if (alloc != nullptr) {
 6229     ciMethod* trap_method = alloc->jvms()->method();
 6230     int trap_bci = alloc->jvms()->bci();
 6231 
 6232     if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
 6233         !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) {
 6234       // Make sure there's no store between the allocation and the
 6235       // arraycopy otherwise visible side effects could be rexecuted
 6236       // in case of deoptimization and cause incorrect execution.
 6237       bool no_interfering_store = true;
 6238       Node* mem = alloc->in(TypeFunc::Memory);
 6239       if (mem->is_MergeMem()) {
 6240         for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) {
 6241           Node* n = mms.memory();
 6242           if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
 6243             assert(n->is_Store(), "what else?");
 6244             no_interfering_store = false;
 6245             break;
 6246           }
 6247         }
 6248       } else {
 6249         for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) {
 6250           Node* n = mms.memory();
 6251           if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) {
 6252             assert(n->is_Store(), "what else?");
 6253             no_interfering_store = false;
 6254             break;
 6255           }
 6256         }
 6257       }
 6258 
 6259       if (no_interfering_store) {
 6260         SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc);
 6261 
 6262         JVMState* saved_jvms = jvms();
 6263         saved_reexecute_sp = _reexecute_sp;
 6264 
 6265         set_jvms(sfpt->jvms());
 6266         _reexecute_sp = jvms()->sp();
 6267 
 6268         return saved_jvms;
 6269       }
 6270     }
 6271   }
 6272   return nullptr;
 6273 }
 6274 
 6275 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack
 6276 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter.
 6277 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const {
 6278   JVMState* old_jvms = alloc->jvms()->clone_shallow(C);
 6279   uint size = alloc->req();
 6280   SafePointNode* sfpt = new SafePointNode(size, old_jvms);
 6281   old_jvms->set_map(sfpt);
 6282   for (uint i = 0; i < size; i++) {
 6283     sfpt->init_req(i, alloc->in(i));
 6284   }
 6285   int adjustment = 1;
 6286   const TypeAryKlassPtr* ary_klass_ptr = alloc->in(AllocateNode::KlassNode)->bottom_type()->is_aryklassptr();
 6287   if (ary_klass_ptr->is_null_free()) {
 6288     // A null-free, tightly coupled array allocation can only come from LibraryCallKit::inline_newArray which
 6289     // also requires the componentType and initVal on stack for re-execution.
 6290     // Re-create and push the componentType.
 6291     ciArrayKlass* klass = ary_klass_ptr->exact_klass()->as_array_klass();
 6292     ciInstance* instance = klass->component_mirror_instance();
 6293     const TypeInstPtr* t_instance = TypeInstPtr::make(instance);
 6294     sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), makecon(t_instance));
 6295     adjustment++;
 6296   }
 6297   // re-push array length for deoptimization
 6298   sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment - 1, alloc->in(AllocateNode::ALength));
 6299   if (ary_klass_ptr->is_null_free()) {
 6300     // Re-create and push the initVal.
 6301     Node* init_val = alloc->in(AllocateNode::InitValue);
 6302     if (init_val == nullptr) {
 6303       init_val = InlineTypeNode::make_all_zero(_gvn, ary_klass_ptr->elem()->is_instklassptr()->instance_klass()->as_inline_klass());
 6304     } else if (UseCompressedOops) {
 6305       init_val = _gvn.transform(new DecodeNNode(init_val, init_val->bottom_type()->make_ptr()));
 6306     }
 6307     sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment, init_val);
 6308     adjustment++;
 6309   }
 6310   old_jvms->set_sp(old_jvms->sp() + adjustment);
 6311   old_jvms->set_monoff(old_jvms->monoff() + adjustment);
 6312   old_jvms->set_scloff(old_jvms->scloff() + adjustment);
 6313   old_jvms->set_endoff(old_jvms->endoff() + adjustment);
 6314   old_jvms->set_should_reexecute(true);
 6315 
 6316   sfpt->set_i_o(map()->i_o());
 6317   sfpt->set_memory(map()->memory());
 6318   sfpt->set_control(map()->control());
 6319   return sfpt;
 6320 }
 6321 
 6322 // In case of a deoptimization, we restart execution at the
 6323 // allocation, allocating a new array. We would leave an uninitialized
 6324 // array in the heap that GCs wouldn't expect. Move the allocation
 6325 // after the traps so we don't allocate the array if we
 6326 // deoptimize. This is possible because tightly_coupled_allocation()
 6327 // guarantees there's no observer of the allocated array at this point
 6328 // and the control flow is simple enough.
 6329 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards,
 6330                                                     int saved_reexecute_sp, uint new_idx) {
 6331   if (saved_jvms_before_guards != nullptr && !stopped()) {
 6332     replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards);
 6333 
 6334     assert(alloc != nullptr, "only with a tightly coupled allocation");
 6335     // restore JVM state to the state at the arraycopy
 6336     saved_jvms_before_guards->map()->set_control(map()->control());
 6337     assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?");
 6338     assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?");
 6339     // If we've improved the types of some nodes (null check) while
 6340     // emitting the guards, propagate them to the current state
 6341     map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx);
 6342     set_jvms(saved_jvms_before_guards);
 6343     _reexecute_sp = saved_reexecute_sp;
 6344 
 6345     // Remove the allocation from above the guards
 6346     CallProjections* callprojs = alloc->extract_projections(true);
 6347     InitializeNode* init = alloc->initialization();
 6348     Node* alloc_mem = alloc->in(TypeFunc::Memory);
 6349     C->gvn_replace_by(callprojs->fallthrough_ioproj, alloc->in(TypeFunc::I_O));
 6350     init->replace_mem_projs_by(alloc_mem, C);
 6351 
 6352     // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below
 6353     // the allocation (i.e. is only valid if the allocation succeeds):
 6354     // 1) replace CastIINode with AllocateArrayNode's length here
 6355     // 2) Create CastIINode again once allocation has moved (see below) at the end of this method
 6356     //
 6357     // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate
 6358     // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy)
 6359     Node* init_control = init->proj_out(TypeFunc::Control);
 6360     Node* alloc_length = alloc->Ideal_length();
 6361 #ifdef ASSERT
 6362     Node* prev_cast = nullptr;
 6363 #endif
 6364     for (uint i = 0; i < init_control->outcnt(); i++) {
 6365       Node* init_out = init_control->raw_out(i);
 6366       if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) {
 6367 #ifdef ASSERT
 6368         if (prev_cast == nullptr) {
 6369           prev_cast = init_out;
 6370         } else {
 6371           if (prev_cast->cmp(*init_out) == false) {
 6372             prev_cast->dump();
 6373             init_out->dump();
 6374             assert(false, "not equal CastIINode");
 6375           }
 6376         }
 6377 #endif
 6378         C->gvn_replace_by(init_out, alloc_length);
 6379       }
 6380     }
 6381     C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0));
 6382 
 6383     // move the allocation here (after the guards)
 6384     _gvn.hash_delete(alloc);
 6385     alloc->set_req(TypeFunc::Control, control());
 6386     alloc->set_req(TypeFunc::I_O, i_o());
 6387     Node *mem = reset_memory();
 6388     set_all_memory(mem);
 6389     alloc->set_req(TypeFunc::Memory, mem);
 6390     set_control(init->proj_out_or_null(TypeFunc::Control));
 6391     set_i_o(callprojs->fallthrough_ioproj);
 6392 
 6393     // Update memory as done in GraphKit::set_output_for_allocation()
 6394     const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength));
 6395     const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_exact_instance_type();
 6396     if (ary_type->isa_aryptr() && length_type != nullptr) {
 6397       ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
 6398     }
 6399     const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot);
 6400     int            elemidx  = C->get_alias_index(telemref);
 6401     // Need to properly move every memory projection for the Initialize
 6402 #ifdef ASSERT
 6403     int mark_idx = C->get_alias_index(ary_type->add_offset(oopDesc::mark_offset_in_bytes()));
 6404     int klass_idx = C->get_alias_index(ary_type->add_offset(oopDesc::klass_offset_in_bytes()));
 6405 #endif
 6406     auto move_proj = [&](ProjNode* proj) {
 6407       int alias_idx = C->get_alias_index(proj->adr_type());
 6408       assert(alias_idx == Compile::AliasIdxRaw ||
 6409              alias_idx == elemidx ||
 6410              alias_idx == mark_idx ||
 6411              alias_idx == klass_idx, "should be raw memory or array element type");
 6412       set_memory(proj, alias_idx);
 6413     };
 6414     init->for_each_proj(move_proj, TypeFunc::Memory);
 6415 
 6416     Node* allocx = _gvn.transform(alloc);
 6417     assert(allocx == alloc, "where has the allocation gone?");
 6418     assert(dest->is_CheckCastPP(), "not an allocation result?");
 6419 
 6420     _gvn.hash_delete(dest);
 6421     dest->set_req(0, control());
 6422     Node* destx = _gvn.transform(dest);
 6423     assert(destx == dest, "where has the allocation result gone?");
 6424 
 6425     array_ideal_length(alloc, ary_type, true);
 6426   }
 6427 }
 6428 
 6429 // Unrelated UCTs between the array allocation and the array copy, which are considered safe by tightly_coupled_allocation(),
 6430 // need to be replaced by an UCT with a state before the array allocation (including the array length). This is necessary
 6431 // because we could hit one of these UCTs (which are executed before the emitted array copy guards and the actual array
 6432 // allocation which is moved down in arraycopy_move_allocation_here()). When later resuming execution in the interpreter,
 6433 // we would have wrongly skipped the array allocation. To prevent this, we resume execution at the array allocation in
 6434 // the interpreter similar to what we are doing for the newly emitted guards for the array copy.
 6435 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc,
 6436                                                                        JVMState* saved_jvms_before_guards) {
 6437   if (saved_jvms_before_guards->map()->control()->is_IfProj()) {
 6438     // There is at least one unrelated uncommon trap which needs to be replaced.
 6439     SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc);
 6440 
 6441     JVMState* saved_jvms = jvms();
 6442     const int saved_reexecute_sp = _reexecute_sp;
 6443     set_jvms(sfpt->jvms());
 6444     _reexecute_sp = jvms()->sp();
 6445 
 6446     replace_unrelated_uncommon_traps_with_alloc_state(saved_jvms_before_guards);
 6447 
 6448     // Restore state
 6449     set_jvms(saved_jvms);
 6450     _reexecute_sp = saved_reexecute_sp;
 6451   }
 6452 }
 6453 
 6454 // Replace the unrelated uncommon traps with new uncommon trap nodes by reusing the action and reason. The new uncommon
 6455 // traps will have the state of the array allocation. Let the old uncommon trap nodes die.
 6456 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards) {
 6457   Node* if_proj = saved_jvms_before_guards->map()->control(); // Start the search right before the newly emitted guards
 6458   while (if_proj->is_IfProj()) {
 6459     CallStaticJavaNode* uncommon_trap = get_uncommon_trap_from_success_proj(if_proj);
 6460     if (uncommon_trap != nullptr) {
 6461       create_new_uncommon_trap(uncommon_trap);
 6462     }
 6463     assert(if_proj->in(0)->is_If(), "must be If");
 6464     if_proj = if_proj->in(0)->in(0);
 6465   }
 6466   assert(if_proj->is_Proj() && if_proj->in(0)->is_Initialize(),
 6467          "must have reached control projection of init node");
 6468 }
 6469 
 6470 void LibraryCallKit::create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call) {
 6471   const int trap_request = uncommon_trap_call->uncommon_trap_request();
 6472   assert(trap_request != 0, "no valid UCT trap request");
 6473   PreserveJVMState pjvms(this);
 6474   set_control(uncommon_trap_call->in(0));
 6475   uncommon_trap(Deoptimization::trap_request_reason(trap_request),
 6476                 Deoptimization::trap_request_action(trap_request));
 6477   assert(stopped(), "Should be stopped");
 6478   _gvn.hash_delete(uncommon_trap_call);
 6479   uncommon_trap_call->set_req(0, top()); // not used anymore, kill it
 6480 }
 6481 
 6482 // Common checks for array sorting intrinsics arguments.
 6483 // Returns `true` if checks passed.
 6484 bool LibraryCallKit::check_array_sort_arguments(Node* elementType, Node* obj, BasicType& bt) {
 6485   // check address of the class
 6486   if (elementType == nullptr || elementType->is_top()) {
 6487     return false;  // dead path
 6488   }
 6489   const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr();
 6490   if (elem_klass == nullptr) {
 6491     return false;  // dead path
 6492   }
 6493   // java_mirror_type() returns non-null for compile-time Class constants only
 6494   ciType* elem_type = elem_klass->java_mirror_type();
 6495   if (elem_type == nullptr) {
 6496     return false;
 6497   }
 6498   bt = elem_type->basic_type();
 6499   // Disable the intrinsic if the CPU does not support SIMD sort
 6500   if (!Matcher::supports_simd_sort(bt)) {
 6501     return false;
 6502   }
 6503   // check address of the array
 6504   if (obj == nullptr || obj->is_top()) {
 6505     return false;  // dead path
 6506   }
 6507   const TypeAryPtr* obj_t = _gvn.type(obj)->isa_aryptr();
 6508   if (obj_t == nullptr || obj_t->elem() == Type::BOTTOM) {
 6509     return false; // failed input validation
 6510   }
 6511   return true;
 6512 }
 6513 
 6514 //------------------------------inline_array_partition-----------------------
 6515 bool LibraryCallKit::inline_array_partition() {
 6516   address stubAddr = StubRoutines::select_array_partition_function();
 6517   if (stubAddr == nullptr) {
 6518     return false; // Intrinsic's stub is not implemented on this platform
 6519   }
 6520   assert(callee()->signature()->size() == 9, "arrayPartition has 8 parameters (one long)");
 6521 
 6522   // no receiver because it is a static method
 6523   Node* elementType     = argument(0);
 6524   Node* obj             = argument(1);
 6525   Node* offset          = argument(2); // long
 6526   Node* fromIndex       = argument(4);
 6527   Node* toIndex         = argument(5);
 6528   Node* indexPivot1     = argument(6);
 6529   Node* indexPivot2     = argument(7);
 6530   // PartitionOperation:  argument(8) is ignored
 6531 
 6532   Node* pivotIndices = nullptr;
 6533   BasicType bt = T_ILLEGAL;
 6534 
 6535   if (!check_array_sort_arguments(elementType, obj, bt)) {
 6536     return false;
 6537   }
 6538   null_check(obj);
 6539   // If obj is dead, only null-path is taken.
 6540   if (stopped()) {
 6541     return true;
 6542   }
 6543   // Set the original stack and the reexecute bit for the interpreter to reexecute
 6544   // the bytecode that invokes DualPivotQuicksort.partition() if deoptimization happens.
 6545   { PreserveReexecuteState preexecs(this);
 6546     jvms()->set_should_reexecute(true);
 6547 
 6548     Node* obj_adr = make_unsafe_address(obj, offset);
 6549 
 6550     // create the pivotIndices array of type int and size = 2
 6551     Node* size = intcon(2);
 6552     Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_INT)));
 6553     pivotIndices = new_array(klass_node, size, 0);  // no arguments to push
 6554     AllocateArrayNode* alloc = tightly_coupled_allocation(pivotIndices);
 6555     guarantee(alloc != nullptr, "created above");
 6556     Node* pivotIndices_adr = basic_plus_adr(pivotIndices, arrayOopDesc::base_offset_in_bytes(T_INT));
 6557 
 6558     // pass the basic type enum to the stub
 6559     Node* elemType = intcon(bt);
 6560 
 6561     // Call the stub
 6562     const char *stubName = "array_partition_stub";
 6563     make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_partition_Type(),
 6564                       stubAddr, stubName, TypePtr::BOTTOM,
 6565                       obj_adr, elemType, fromIndex, toIndex, pivotIndices_adr,
 6566                       indexPivot1, indexPivot2);
 6567 
 6568   } // original reexecute is set back here
 6569 
 6570   if (!stopped()) {
 6571     set_result(pivotIndices);
 6572   }
 6573 
 6574   return true;
 6575 }
 6576 
 6577 
 6578 //------------------------------inline_array_sort-----------------------
 6579 bool LibraryCallKit::inline_array_sort() {
 6580   address stubAddr = StubRoutines::select_arraysort_function();
 6581   if (stubAddr == nullptr) {
 6582     return false; // Intrinsic's stub is not implemented on this platform
 6583   }
 6584   assert(callee()->signature()->size() == 7, "arraySort has 6 parameters (one long)");
 6585 
 6586   // no receiver because it is a static method
 6587   Node* elementType     = argument(0);
 6588   Node* obj             = argument(1);
 6589   Node* offset          = argument(2); // long
 6590   Node* fromIndex       = argument(4);
 6591   Node* toIndex         = argument(5);
 6592   // SortOperation:       argument(6) is ignored
 6593 
 6594   BasicType bt = T_ILLEGAL;
 6595 
 6596   if (!check_array_sort_arguments(elementType, obj, bt)) {
 6597     return false;
 6598   }
 6599   null_check(obj);
 6600   // If obj is dead, only null-path is taken.
 6601   if (stopped()) {
 6602     return true;
 6603   }
 6604   Node* obj_adr = make_unsafe_address(obj, offset);
 6605 
 6606   // pass the basic type enum to the stub
 6607   Node* elemType = intcon(bt);
 6608 
 6609   // Call the stub.
 6610   const char *stubName = "arraysort_stub";
 6611   make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_sort_Type(),
 6612                     stubAddr, stubName, TypePtr::BOTTOM,
 6613                     obj_adr, elemType, fromIndex, toIndex);
 6614 
 6615   return true;
 6616 }
 6617 
 6618 
 6619 //------------------------------inline_arraycopy-----------------------
 6620 // public static native void java.lang.System.arraycopy(Object src,  int  srcPos,
 6621 //                                                      Object dest, int destPos,
 6622 //                                                      int length);
 6623 bool LibraryCallKit::inline_arraycopy() {
 6624   // Get the arguments.
 6625   Node* src         = argument(0);  // type: oop
 6626   Node* src_offset  = argument(1);  // type: int
 6627   Node* dest        = argument(2);  // type: oop
 6628   Node* dest_offset = argument(3);  // type: int
 6629   Node* length      = argument(4);  // type: int
 6630 
 6631   uint new_idx = C->unique();
 6632 
 6633   // Check for allocation before we add nodes that would confuse
 6634   // tightly_coupled_allocation()
 6635   AllocateArrayNode* alloc = tightly_coupled_allocation(dest);
 6636 
 6637   int saved_reexecute_sp = -1;
 6638   JVMState* saved_jvms_before_guards = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp);
 6639   // See arraycopy_restore_alloc_state() comment
 6640   // if alloc == null we don't have to worry about a tightly coupled allocation so we can emit all needed guards
 6641   // if saved_jvms_before_guards is not null (then alloc is not null) then we can handle guards and a tightly coupled allocation
 6642   // if saved_jvms_before_guards is null and alloc is not null, we can't emit any guards
 6643   bool can_emit_guards = (alloc == nullptr || saved_jvms_before_guards != nullptr);
 6644 
 6645   // The following tests must be performed
 6646   // (1) src and dest are arrays.
 6647   // (2) src and dest arrays must have elements of the same BasicType
 6648   // (3) src and dest must not be null.
 6649   // (4) src_offset must not be negative.
 6650   // (5) dest_offset must not be negative.
 6651   // (6) length must not be negative.
 6652   // (7) src_offset + length must not exceed length of src.
 6653   // (8) dest_offset + length must not exceed length of dest.
 6654   // (9) each element of an oop array must be assignable
 6655 
 6656   // (3) src and dest must not be null.
 6657   // always do this here because we need the JVM state for uncommon traps
 6658   Node* null_ctl = top();
 6659   src  = saved_jvms_before_guards != nullptr ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY);
 6660   assert(null_ctl->is_top(), "no null control here");
 6661   dest = null_check(dest, T_ARRAY);
 6662 
 6663   if (!can_emit_guards) {
 6664     // if saved_jvms_before_guards is null and alloc is not null, we don't emit any
 6665     // guards but the arraycopy node could still take advantage of a
 6666     // tightly allocated allocation. tightly_coupled_allocation() is
 6667     // called again to make sure it takes the null check above into
 6668     // account: the null check is mandatory and if it caused an
 6669     // uncommon trap to be emitted then the allocation can't be
 6670     // considered tightly coupled in this context.
 6671     alloc = tightly_coupled_allocation(dest);
 6672   }
 6673 
 6674   bool validated = false;
 6675 
 6676   const Type* src_type  = _gvn.type(src);
 6677   const Type* dest_type = _gvn.type(dest);
 6678   const TypeAryPtr* top_src  = src_type->isa_aryptr();
 6679   const TypeAryPtr* top_dest = dest_type->isa_aryptr();
 6680 
 6681   // Do we have the type of src?
 6682   bool has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
 6683   // Do we have the type of dest?
 6684   bool has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
 6685   // Is the type for src from speculation?
 6686   bool src_spec = false;
 6687   // Is the type for dest from speculation?
 6688   bool dest_spec = false;
 6689 
 6690   if ((!has_src || !has_dest) && can_emit_guards) {
 6691     // We don't have sufficient type information, let's see if
 6692     // speculative types can help. We need to have types for both src
 6693     // and dest so that it pays off.
 6694 
 6695     // Do we already have or could we have type information for src
 6696     bool could_have_src = has_src;
 6697     // Do we already have or could we have type information for dest
 6698     bool could_have_dest = has_dest;
 6699 
 6700     ciKlass* src_k = nullptr;
 6701     if (!has_src) {
 6702       src_k = src_type->speculative_type_not_null();
 6703       if (src_k != nullptr && src_k->is_array_klass()) {
 6704         could_have_src = true;
 6705       }
 6706     }
 6707 
 6708     ciKlass* dest_k = nullptr;
 6709     if (!has_dest) {
 6710       dest_k = dest_type->speculative_type_not_null();
 6711       if (dest_k != nullptr && dest_k->is_array_klass()) {
 6712         could_have_dest = true;
 6713       }
 6714     }
 6715 
 6716     if (could_have_src && could_have_dest) {
 6717       // This is going to pay off so emit the required guards
 6718       if (!has_src) {
 6719         src = maybe_cast_profiled_obj(src, src_k, true);
 6720         src_type  = _gvn.type(src);
 6721         top_src  = src_type->isa_aryptr();
 6722         has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM);
 6723         src_spec = true;
 6724       }
 6725       if (!has_dest) {
 6726         dest = maybe_cast_profiled_obj(dest, dest_k, true);
 6727         dest_type  = _gvn.type(dest);
 6728         top_dest  = dest_type->isa_aryptr();
 6729         has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM);
 6730         dest_spec = true;
 6731       }
 6732     }
 6733   }
 6734 
 6735   if (has_src && has_dest && can_emit_guards) {
 6736     BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type();
 6737     BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type();
 6738     if (is_reference_type(src_elem, true)) src_elem = T_OBJECT;
 6739     if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT;
 6740 
 6741     if (src_elem == dest_elem && top_src->is_flat() == top_dest->is_flat() && src_elem == T_OBJECT) {
 6742       // If both arrays are object arrays then having the exact types
 6743       // for both will remove the need for a subtype check at runtime
 6744       // before the call and may make it possible to pick a faster copy
 6745       // routine (without a subtype check on every element)
 6746       // Do we have the exact type of src?
 6747       bool could_have_src = src_spec;
 6748       // Do we have the exact type of dest?
 6749       bool could_have_dest = dest_spec;
 6750       ciKlass* src_k = nullptr;
 6751       ciKlass* dest_k = nullptr;
 6752       if (!src_spec) {
 6753         src_k = src_type->speculative_type_not_null();
 6754         if (src_k != nullptr && src_k->is_array_klass()) {
 6755           could_have_src = true;
 6756         }
 6757       }
 6758       if (!dest_spec) {
 6759         dest_k = dest_type->speculative_type_not_null();
 6760         if (dest_k != nullptr && dest_k->is_array_klass()) {
 6761           could_have_dest = true;
 6762         }
 6763       }
 6764       if (could_have_src && could_have_dest) {
 6765         // If we can have both exact types, emit the missing guards
 6766         if (could_have_src && !src_spec) {
 6767           src = maybe_cast_profiled_obj(src, src_k, true);
 6768           src_type = _gvn.type(src);
 6769           top_src = src_type->isa_aryptr();
 6770         }
 6771         if (could_have_dest && !dest_spec) {
 6772           dest = maybe_cast_profiled_obj(dest, dest_k, true);
 6773           dest_type = _gvn.type(dest);
 6774           top_dest = dest_type->isa_aryptr();
 6775         }
 6776       }
 6777     }
 6778   }
 6779 
 6780   ciMethod* trap_method = method();
 6781   int trap_bci = bci();
 6782   if (saved_jvms_before_guards != nullptr) {
 6783     trap_method = alloc->jvms()->method();
 6784     trap_bci = alloc->jvms()->bci();
 6785   }
 6786 
 6787   bool negative_length_guard_generated = false;
 6788 
 6789   if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) &&
 6790       can_emit_guards && !src->is_top() && !dest->is_top()) {
 6791     // validate arguments: enables transformation the ArrayCopyNode
 6792     validated = true;
 6793 
 6794     RegionNode* slow_region = new RegionNode(1);
 6795     record_for_igvn(slow_region);
 6796 
 6797     // (1) src and dest are arrays.
 6798     generate_non_array_guard(load_object_klass(src), slow_region, &src);
 6799     generate_non_array_guard(load_object_klass(dest), slow_region, &dest);
 6800 
 6801     // (2) src and dest arrays must have elements of the same BasicType
 6802     // done at macro expansion or at Ideal transformation time
 6803 
 6804     // (4) src_offset must not be negative.
 6805     generate_negative_guard(src_offset, slow_region);
 6806 
 6807     // (5) dest_offset must not be negative.
 6808     generate_negative_guard(dest_offset, slow_region);
 6809 
 6810     // (7) src_offset + length must not exceed length of src.
 6811     generate_limit_guard(src_offset, length,
 6812                          load_array_length(src),
 6813                          slow_region);
 6814 
 6815     // (8) dest_offset + length must not exceed length of dest.
 6816     generate_limit_guard(dest_offset, length,
 6817                          load_array_length(dest),
 6818                          slow_region);
 6819 
 6820     // (6) length must not be negative.
 6821     // This is also checked in generate_arraycopy() during macro expansion, but
 6822     // we also have to check it here for the case where the ArrayCopyNode will
 6823     // be eliminated by Escape Analysis.
 6824     if (EliminateAllocations) {
 6825       generate_negative_guard(length, slow_region);
 6826       negative_length_guard_generated = true;
 6827     }
 6828 
 6829     // (9) each element of an oop array must be assignable
 6830     Node* dest_klass = load_object_klass(dest);
 6831     Node* refined_dest_klass = dest_klass;
 6832     if (src != dest) {
 6833       dest_klass = load_non_refined_array_klass(refined_dest_klass);
 6834       Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass);
 6835       slow_region->add_req(not_subtype_ctrl);
 6836     }
 6837 
 6838     // TODO 8251971 Improve this. What about atomicity? Make sure this is always folded for type arrays.
 6839     // If destination is null-restricted, source must be null-restricted as well: src_null_restricted || !dst_null_restricted
 6840     Node* src_klass = load_object_klass(src);
 6841     Node* adr_prop_src = basic_plus_adr(top(), src_klass, in_bytes(ArrayKlass::properties_offset()));
 6842     Node* prop_src = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_src,
 6843                                                    _gvn.type(adr_prop_src)->is_ptr(), TypeInt::INT, T_INT,
 6844                                                    MemNode::unordered));
 6845     Node* adr_prop_dest = basic_plus_adr(top(), refined_dest_klass, in_bytes(ArrayKlass::properties_offset()));
 6846     Node* prop_dest = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_prop_dest,
 6847                                                     _gvn.type(adr_prop_dest)->is_ptr(), TypeInt::INT, T_INT,
 6848                                                     MemNode::unordered));
 6849 
 6850     const ArrayProperties props_null_restricted = ArrayProperties::Default().with_null_restricted();
 6851     jint props_value = (jint)props_null_restricted.value();
 6852 
 6853     prop_dest = _gvn.transform(new XorINode(prop_dest, intcon(props_value)));
 6854     prop_src = _gvn.transform(new OrINode(prop_dest, prop_src));
 6855     prop_src = _gvn.transform(new AndINode(prop_src, intcon(props_value)));
 6856 
 6857     Node* chk = _gvn.transform(new CmpINode(prop_src, intcon(props_value)));
 6858     Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::ne));
 6859     generate_fair_guard(tst, slow_region);
 6860 
 6861     // TODO 8251971 This is too strong
 6862     generate_fair_guard(flat_array_test(src), slow_region);
 6863     generate_fair_guard(flat_array_test(dest), slow_region);
 6864 
 6865     {
 6866       PreserveJVMState pjvms(this);
 6867       set_control(_gvn.transform(slow_region));
 6868       uncommon_trap(Deoptimization::Reason_intrinsic,
 6869                     Deoptimization::Action_make_not_entrant);
 6870       assert(stopped(), "Should be stopped");
 6871     }
 6872 
 6873     const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->isa_klassptr();
 6874     if (dest_klass_t == nullptr) {
 6875       // refined_dest_klass may not be an array, which leads to dest_klass being top. This means we
 6876       // are in a dead path.
 6877       uncommon_trap(Deoptimization::Reason_intrinsic,
 6878                     Deoptimization::Action_make_not_entrant);
 6879       return true;
 6880     }
 6881 
 6882     const Type* toop = dest_klass_t->as_subtype_instance_type();
 6883     src = _gvn.transform(new CheckCastPPNode(control(), src, toop));
 6884     arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx);
 6885   }
 6886 
 6887   if (stopped()) {
 6888     return true;
 6889   }
 6890 
 6891   Node* dest_klass = load_object_klass(dest);
 6892   dest_klass = load_non_refined_array_klass(dest_klass);
 6893 
 6894   ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated,
 6895                                           // Create LoadRange and LoadKlass nodes for use during macro expansion here
 6896                                           // so the compiler has a chance to eliminate them: during macro expansion,
 6897                                           // we have to set their control (CastPP nodes are eliminated).
 6898                                           load_object_klass(src), dest_klass,
 6899                                           load_array_length(src), load_array_length(dest));
 6900 
 6901   ac->set_arraycopy(validated);
 6902 
 6903   Node* n = _gvn.transform(ac);
 6904   if (n == ac) {
 6905     ac->connect_outputs(this);
 6906   } else {
 6907     assert(validated, "shouldn't transform if all arguments not validated");
 6908     set_all_memory(n);
 6909   }
 6910   clear_upper_avx();
 6911 
 6912 
 6913   return true;
 6914 }
 6915 
 6916 
 6917 // Helper function which determines if an arraycopy immediately follows
 6918 // an allocation, with no intervening tests or other escapes for the object.
 6919 AllocateArrayNode*
 6920 LibraryCallKit::tightly_coupled_allocation(Node* ptr) {
 6921   if (stopped())             return nullptr;  // no fast path
 6922   if (!C->do_aliasing())     return nullptr;  // no MergeMems around
 6923 
 6924   AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr);
 6925   if (alloc == nullptr)  return nullptr;
 6926 
 6927   Node* rawmem = memory(Compile::AliasIdxRaw);
 6928   // Is the allocation's memory state untouched?
 6929   if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) {
 6930     // Bail out if there have been raw-memory effects since the allocation.
 6931     // (Example:  There might have been a call or safepoint.)
 6932     return nullptr;
 6933   }
 6934   rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw);
 6935   if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) {
 6936     return nullptr;
 6937   }
 6938 
 6939   // There must be no unexpected observers of this allocation.
 6940   for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) {
 6941     Node* obs = ptr->fast_out(i);
 6942     if (obs != this->map()) {
 6943       return nullptr;
 6944     }
 6945   }
 6946 
 6947   // This arraycopy must unconditionally follow the allocation of the ptr.
 6948   Node* alloc_ctl = ptr->in(0);
 6949   Node* ctl = control();
 6950   while (ctl != alloc_ctl) {
 6951     // There may be guards which feed into the slow_region.
 6952     // Any other control flow means that we might not get a chance
 6953     // to finish initializing the allocated object.
 6954     // Various low-level checks bottom out in uncommon traps. These
 6955     // are considered safe since we've already checked above that
 6956     // there is no unexpected observer of this allocation.
 6957     if (get_uncommon_trap_from_success_proj(ctl) != nullptr) {
 6958       assert(ctl->in(0)->is_If(), "must be If");
 6959       ctl = ctl->in(0)->in(0);
 6960     } else {
 6961       return nullptr;
 6962     }
 6963   }
 6964 
 6965   // If we get this far, we have an allocation which immediately
 6966   // precedes the arraycopy, and we can take over zeroing the new object.
 6967   // The arraycopy will finish the initialization, and provide
 6968   // a new control state to which we will anchor the destination pointer.
 6969 
 6970   return alloc;
 6971 }
 6972 
 6973 CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* node) {
 6974   if (node->is_IfProj()) {
 6975     IfProjNode* other_proj = node->as_IfProj()->other_if_proj();
 6976     for (DUIterator_Fast jmax, j = other_proj->fast_outs(jmax); j < jmax; j++) {
 6977       Node* obs = other_proj->fast_out(j);
 6978       if (obs->in(0) == other_proj && obs->is_CallStaticJava() &&
 6979           (obs->as_CallStaticJava()->entry_point() == OptoRuntime::uncommon_trap_blob()->entry_point())) {
 6980         return obs->as_CallStaticJava();
 6981       }
 6982     }
 6983   }
 6984   return nullptr;
 6985 }
 6986 
 6987 //-------------inline_encodeISOArray-----------------------------------
 6988 // int sun.nio.cs.ISO_8859_1.Encoder#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
 6989 // int java.lang.StringCoding#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
 6990 // int java.lang.StringCoding#encodeAsciiArray0(char[] sa, int sp, byte[] da, int dp, int len)
 6991 // encode char[] to byte[] in ISO_8859_1 or ASCII
 6992 bool LibraryCallKit::inline_encodeISOArray(bool ascii) {
 6993   assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters");
 6994   // no receiver since it is static method
 6995   Node *src         = argument(0);
 6996   Node *src_offset  = argument(1);
 6997   Node *dst         = argument(2);
 6998   Node *dst_offset  = argument(3);
 6999   Node *length      = argument(4);
 7000 
 7001   // Cast source & target arrays to not-null
 7002   src = must_be_not_null(src, true);
 7003   dst = must_be_not_null(dst, true);
 7004   if (stopped()) {
 7005     return true;
 7006   }
 7007 
 7008   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7009   const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr();
 7010   if (src_type == nullptr || src_type->elem() == Type::BOTTOM ||
 7011       dst_type == nullptr || dst_type->elem() == Type::BOTTOM) {
 7012     // failed array check
 7013     return false;
 7014   }
 7015 
 7016   // Figure out the size and type of the elements we will be copying.
 7017   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7018   BasicType dst_elem = dst_type->elem()->array_element_basic_type();
 7019   if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) {
 7020     return false;
 7021   }
 7022 
 7023   // Check source & target bounds
 7024   RegionNode* bailout = create_bailout();
 7025   generate_string_range_check(src, src_offset, length, src_elem == T_BYTE, bailout);
 7026   generate_string_range_check(dst, dst_offset, length, false, bailout);
 7027   if (check_bailout(bailout)) {
 7028     return true;
 7029   }
 7030 
 7031   Node* src_start = array_element_address(src, src_offset, T_CHAR);
 7032   Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
 7033   // 'src_start' points to src array + scaled offset
 7034   // 'dst_start' points to dst array + scaled offset
 7035 
 7036   // See GraphKit::compress_string
 7037   const TypePtr* adr_type;
 7038   Node* mem = capture_memory(adr_type, src_type, dst_type);
 7039   Node* enc = new EncodeISOArrayNode(control(), mem, adr_type, src_start, dst_start, length, ascii);
 7040   enc = _gvn.transform(enc);
 7041   Node* res_mem = _gvn.transform(new SCMemProjNode(enc));
 7042   memory_effect(res_mem, src_type, dst_type);
 7043 
 7044   set_result(enc);
 7045   clear_upper_avx();
 7046 
 7047   return true;
 7048 }
 7049 
 7050 //-------------inline_multiplyToLen-----------------------------------
 7051 bool LibraryCallKit::inline_multiplyToLen() {
 7052   assert(UseMultiplyToLenIntrinsic, "not implemented on this platform");
 7053 
 7054   address stubAddr = StubRoutines::multiplyToLen();
 7055   if (stubAddr == nullptr) {
 7056     return false; // Intrinsic's stub is not implemented on this platform
 7057   }
 7058   const char* stubName = "multiplyToLen";
 7059 
 7060   assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters");
 7061 
 7062   // no receiver because it is a static method
 7063   Node* x    = argument(0);
 7064   Node* xlen = argument(1);
 7065   Node* y    = argument(2);
 7066   Node* ylen = argument(3);
 7067   Node* z    = argument(4);
 7068 
 7069   x = must_be_not_null(x, true);
 7070   y = must_be_not_null(y, true);
 7071 
 7072   const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr();
 7073   const TypeAryPtr* y_type = y->Value(&_gvn)->isa_aryptr();
 7074   if (x_type == nullptr || x_type->elem() == Type::BOTTOM ||
 7075       y_type == nullptr || y_type->elem() == Type::BOTTOM) {
 7076     // failed array check
 7077     return false;
 7078   }
 7079 
 7080   BasicType x_elem = x_type->elem()->array_element_basic_type();
 7081   BasicType y_elem = y_type->elem()->array_element_basic_type();
 7082   if (x_elem != T_INT || y_elem != T_INT) {
 7083     return false;
 7084   }
 7085 
 7086   Node* x_start = array_element_address(x, intcon(0), x_elem);
 7087   Node* y_start = array_element_address(y, intcon(0), y_elem);
 7088   // 'x_start' points to x array + scaled xlen
 7089   // 'y_start' points to y array + scaled ylen
 7090 
 7091   Node* z_start = array_element_address(z, intcon(0), T_INT);
 7092 
 7093   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7094                                  OptoRuntime::multiplyToLen_Type(),
 7095                                  stubAddr, stubName, TypePtr::BOTTOM,
 7096                                  x_start, xlen, y_start, ylen, z_start);
 7097 
 7098   C->set_has_split_ifs(true); // Has chance for split-if optimization
 7099   set_result(z);
 7100   return true;
 7101 }
 7102 
 7103 //-------------inline_squareToLen------------------------------------
 7104 bool LibraryCallKit::inline_squareToLen() {
 7105   assert(UseSquareToLenIntrinsic, "not implemented on this platform");
 7106 
 7107   address stubAddr = StubRoutines::squareToLen();
 7108   if (stubAddr == nullptr) {
 7109     return false; // Intrinsic's stub is not implemented on this platform
 7110   }
 7111   const char* stubName = "squareToLen";
 7112 
 7113   assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters");
 7114 
 7115   Node* x    = argument(0);
 7116   Node* len  = argument(1);
 7117   Node* z    = argument(2);
 7118   Node* zlen = argument(3);
 7119 
 7120   x = must_be_not_null(x, true);
 7121   z = must_be_not_null(z, true);
 7122 
 7123   const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr();
 7124   const TypeAryPtr* z_type = z->Value(&_gvn)->isa_aryptr();
 7125   if (x_type == nullptr || x_type->elem() == Type::BOTTOM ||
 7126       z_type == nullptr || z_type->elem() == Type::BOTTOM) {
 7127     // failed array check
 7128     return false;
 7129   }
 7130 
 7131   BasicType x_elem = x_type->elem()->array_element_basic_type();
 7132   BasicType z_elem = z_type->elem()->array_element_basic_type();
 7133   if (x_elem != T_INT || z_elem != T_INT) {
 7134     return false;
 7135   }
 7136 
 7137 
 7138   Node* x_start = array_element_address(x, intcon(0), x_elem);
 7139   Node* z_start = array_element_address(z, intcon(0), z_elem);
 7140 
 7141   Node*  call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7142                                   OptoRuntime::squareToLen_Type(),
 7143                                   stubAddr, stubName, TypePtr::BOTTOM,
 7144                                   x_start, len, z_start, zlen);
 7145 
 7146   set_result(z);
 7147   return true;
 7148 }
 7149 
 7150 //-------------inline_mulAdd------------------------------------------
 7151 bool LibraryCallKit::inline_mulAdd() {
 7152   assert(UseMulAddIntrinsic, "not implemented on this platform");
 7153 
 7154   address stubAddr = StubRoutines::mulAdd();
 7155   if (stubAddr == nullptr) {
 7156     return false; // Intrinsic's stub is not implemented on this platform
 7157   }
 7158   const char* stubName = "mulAdd";
 7159 
 7160   assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters");
 7161 
 7162   Node* out      = argument(0);
 7163   Node* in       = argument(1);
 7164   Node* offset   = argument(2);
 7165   Node* len      = argument(3);
 7166   Node* k        = argument(4);
 7167 
 7168   in = must_be_not_null(in, true);
 7169   out = must_be_not_null(out, true);
 7170 
 7171   const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr();
 7172   const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr();
 7173   if (out_type == nullptr || out_type->elem() == Type::BOTTOM ||
 7174        in_type == nullptr ||  in_type->elem() == Type::BOTTOM) {
 7175     // failed array check
 7176     return false;
 7177   }
 7178 
 7179   BasicType out_elem = out_type->elem()->array_element_basic_type();
 7180   BasicType in_elem = in_type->elem()->array_element_basic_type();
 7181   if (out_elem != T_INT || in_elem != T_INT) {
 7182     return false;
 7183   }
 7184 
 7185   Node* outlen = load_array_length(out);
 7186   Node* new_offset = _gvn.transform(new SubINode(outlen, offset));
 7187   Node* out_start = array_element_address(out, intcon(0), out_elem);
 7188   Node* in_start = array_element_address(in, intcon(0), in_elem);
 7189 
 7190   Node*  call = make_runtime_call(RC_LEAF|RC_NO_FP,
 7191                                   OptoRuntime::mulAdd_Type(),
 7192                                   stubAddr, stubName, TypePtr::BOTTOM,
 7193                                   out_start,in_start, new_offset, len, k);
 7194   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7195   set_result(result);
 7196   return true;
 7197 }
 7198 
 7199 //-------------inline_montgomeryMultiply-----------------------------------
 7200 bool LibraryCallKit::inline_montgomeryMultiply() {
 7201   address stubAddr = StubRoutines::montgomeryMultiply();
 7202   if (stubAddr == nullptr) {
 7203     return false; // Intrinsic's stub is not implemented on this platform
 7204   }
 7205 
 7206   assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform");
 7207   const char* stubName = "montgomery_multiply";
 7208 
 7209   assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters");
 7210 
 7211   Node* a    = argument(0);
 7212   Node* b    = argument(1);
 7213   Node* n    = argument(2);
 7214   Node* len  = argument(3);
 7215   Node* inv  = argument(4);
 7216   Node* m    = argument(6);
 7217 
 7218   const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr();
 7219   const TypeAryPtr* b_type = b->Value(&_gvn)->isa_aryptr();
 7220   const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr();
 7221   const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr();
 7222   if (a_type == nullptr || a_type->elem() == Type::BOTTOM ||
 7223       b_type == nullptr || b_type->elem() == Type::BOTTOM ||
 7224       n_type == nullptr || n_type->elem() == Type::BOTTOM ||
 7225       m_type == nullptr || m_type->elem() == Type::BOTTOM) {
 7226     // failed array check
 7227     return false;
 7228   }
 7229 
 7230   BasicType a_elem = a_type->elem()->array_element_basic_type();
 7231   BasicType b_elem = b_type->elem()->array_element_basic_type();
 7232   BasicType n_elem = n_type->elem()->array_element_basic_type();
 7233   BasicType m_elem = m_type->elem()->array_element_basic_type();
 7234   if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
 7235     return false;
 7236   }
 7237 
 7238   // Make the call
 7239   {
 7240     Node* a_start = array_element_address(a, intcon(0), a_elem);
 7241     Node* b_start = array_element_address(b, intcon(0), b_elem);
 7242     Node* n_start = array_element_address(n, intcon(0), n_elem);
 7243     Node* m_start = array_element_address(m, intcon(0), m_elem);
 7244 
 7245     Node* call = make_runtime_call(RC_LEAF,
 7246                                    OptoRuntime::montgomeryMultiply_Type(),
 7247                                    stubAddr, stubName, TypePtr::BOTTOM,
 7248                                    a_start, b_start, n_start, len, inv, top(),
 7249                                    m_start);
 7250     set_result(m);
 7251   }
 7252 
 7253   return true;
 7254 }
 7255 
 7256 bool LibraryCallKit::inline_montgomerySquare() {
 7257   address stubAddr = StubRoutines::montgomerySquare();
 7258   if (stubAddr == nullptr) {
 7259     return false; // Intrinsic's stub is not implemented on this platform
 7260   }
 7261 
 7262   assert(UseMontgomerySquareIntrinsic, "not implemented on this platform");
 7263   const char* stubName = "montgomery_square";
 7264 
 7265   assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters");
 7266 
 7267   Node* a    = argument(0);
 7268   Node* n    = argument(1);
 7269   Node* len  = argument(2);
 7270   Node* inv  = argument(3);
 7271   Node* m    = argument(5);
 7272 
 7273   const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr();
 7274   const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr();
 7275   const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr();
 7276   if (a_type == nullptr || a_type->elem() == Type::BOTTOM ||
 7277       n_type == nullptr || n_type->elem() == Type::BOTTOM ||
 7278       m_type == nullptr || m_type->elem() == Type::BOTTOM) {
 7279     // failed array check
 7280     return false;
 7281   }
 7282 
 7283   BasicType a_elem = a_type->elem()->array_element_basic_type();
 7284   BasicType n_elem = n_type->elem()->array_element_basic_type();
 7285   BasicType m_elem = m_type->elem()->array_element_basic_type();
 7286   if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) {
 7287     return false;
 7288   }
 7289 
 7290   // Make the call
 7291   {
 7292     Node* a_start = array_element_address(a, intcon(0), a_elem);
 7293     Node* n_start = array_element_address(n, intcon(0), n_elem);
 7294     Node* m_start = array_element_address(m, intcon(0), m_elem);
 7295 
 7296     Node* call = make_runtime_call(RC_LEAF,
 7297                                    OptoRuntime::montgomerySquare_Type(),
 7298                                    stubAddr, stubName, TypePtr::BOTTOM,
 7299                                    a_start, n_start, len, inv, top(),
 7300                                    m_start);
 7301     set_result(m);
 7302   }
 7303 
 7304   return true;
 7305 }
 7306 
 7307 bool LibraryCallKit::inline_bigIntegerShift(bool isRightShift) {
 7308   address stubAddr = nullptr;
 7309   const char* stubName = nullptr;
 7310 
 7311   stubAddr = isRightShift? StubRoutines::bigIntegerRightShift(): StubRoutines::bigIntegerLeftShift();
 7312   if (stubAddr == nullptr) {
 7313     return false; // Intrinsic's stub is not implemented on this platform
 7314   }
 7315 
 7316   stubName = isRightShift? "bigIntegerRightShiftWorker" : "bigIntegerLeftShiftWorker";
 7317 
 7318   assert(callee()->signature()->size() == 5, "expected 5 arguments");
 7319 
 7320   Node* newArr = argument(0);
 7321   Node* oldArr = argument(1);
 7322   Node* newIdx = argument(2);
 7323   Node* shiftCount = argument(3);
 7324   Node* numIter = argument(4);
 7325 
 7326   const TypeAryPtr* newArr_type = newArr->Value(&_gvn)->isa_aryptr();
 7327   const TypeAryPtr* oldArr_type = oldArr->Value(&_gvn)->isa_aryptr();
 7328   if (newArr_type == nullptr || newArr_type->elem() == Type::BOTTOM ||
 7329       oldArr_type == nullptr || oldArr_type->elem() == Type::BOTTOM) {
 7330     return false;
 7331   }
 7332 
 7333   BasicType newArr_elem = newArr_type->elem()->array_element_basic_type();
 7334   BasicType oldArr_elem = oldArr_type->elem()->array_element_basic_type();
 7335   if (newArr_elem != T_INT || oldArr_elem != T_INT) {
 7336     return false;
 7337   }
 7338 
 7339   // Make the call
 7340   {
 7341     Node* newArr_start = array_element_address(newArr, intcon(0), newArr_elem);
 7342     Node* oldArr_start = array_element_address(oldArr, intcon(0), oldArr_elem);
 7343 
 7344     Node* call = make_runtime_call(RC_LEAF,
 7345                                    OptoRuntime::bigIntegerShift_Type(),
 7346                                    stubAddr,
 7347                                    stubName,
 7348                                    TypePtr::BOTTOM,
 7349                                    newArr_start,
 7350                                    oldArr_start,
 7351                                    newIdx,
 7352                                    shiftCount,
 7353                                    numIter);
 7354   }
 7355 
 7356   return true;
 7357 }
 7358 
 7359 //-------------inline_vectorizedMismatch------------------------------
 7360 bool LibraryCallKit::inline_vectorizedMismatch() {
 7361   assert(UseVectorizedMismatchIntrinsic, "not implemented on this platform");
 7362 
 7363   assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters");
 7364   Node* obja    = argument(0); // Object
 7365   Node* aoffset = argument(1); // long
 7366   Node* objb    = argument(3); // Object
 7367   Node* boffset = argument(4); // long
 7368   Node* length  = argument(6); // int
 7369   Node* scale   = argument(7); // int
 7370 
 7371   const TypeAryPtr* obja_t = _gvn.type(obja)->isa_aryptr();
 7372   const TypeAryPtr* objb_t = _gvn.type(objb)->isa_aryptr();
 7373   if (obja_t == nullptr || obja_t->elem() == Type::BOTTOM ||
 7374       objb_t == nullptr || objb_t->elem() == Type::BOTTOM ||
 7375       scale == top()) {
 7376     return false; // failed input validation
 7377   }
 7378 
 7379   Node* obja_adr = make_unsafe_address(obja, aoffset);
 7380   Node* objb_adr = make_unsafe_address(objb, boffset);
 7381 
 7382   // Partial inlining handling for inputs smaller than ArrayOperationPartialInlineSize bytes in size.
 7383   //
 7384   //    inline_limit = ArrayOperationPartialInlineSize / element_size;
 7385   //    if (length <= inline_limit) {
 7386   //      inline_path:
 7387   //        vmask   = VectorMaskGen length
 7388   //        vload1  = LoadVectorMasked obja, vmask
 7389   //        vload2  = LoadVectorMasked objb, vmask
 7390   //        result1 = VectorCmpMasked vload1, vload2, vmask
 7391   //    } else {
 7392   //      call_stub_path:
 7393   //        result2 = call vectorizedMismatch_stub(obja, objb, length, scale)
 7394   //    }
 7395   //    exit_block:
 7396   //      return Phi(result1, result2);
 7397   //
 7398   enum { inline_path = 1,  // input is small enough to process it all at once
 7399          stub_path   = 2,  // input is too large; call into the VM
 7400          PATH_LIMIT  = 3
 7401   };
 7402 
 7403   Node* exit_block = new RegionNode(PATH_LIMIT);
 7404   Node* result_phi = new PhiNode(exit_block, TypeInt::INT);
 7405   Node* memory_phi = new PhiNode(exit_block, Type::MEMORY, TypePtr::BOTTOM);
 7406 
 7407   Node* call_stub_path = control();
 7408 
 7409   BasicType elem_bt = T_ILLEGAL;
 7410 
 7411   const TypeInt* scale_t = _gvn.type(scale)->is_int();
 7412   if (scale_t->is_con()) {
 7413     switch (scale_t->get_con()) {
 7414       case 0: elem_bt = T_BYTE;  break;
 7415       case 1: elem_bt = T_SHORT; break;
 7416       case 2: elem_bt = T_INT;   break;
 7417       case 3: elem_bt = T_LONG;  break;
 7418 
 7419       default: elem_bt = T_ILLEGAL; break; // not supported
 7420     }
 7421   }
 7422 
 7423   int inline_limit = 0;
 7424   bool do_partial_inline = false;
 7425 
 7426   if (elem_bt != T_ILLEGAL && ArrayOperationPartialInlineSize > 0) {
 7427     inline_limit = ArrayOperationPartialInlineSize / type2aelembytes(elem_bt);
 7428     do_partial_inline = inline_limit >= 16;
 7429   }
 7430 
 7431   if (do_partial_inline) {
 7432     assert(elem_bt != T_ILLEGAL, "sanity");
 7433 
 7434     if (Matcher::match_rule_supported_vector(Op_VectorMaskGen,    inline_limit, elem_bt) &&
 7435         Matcher::match_rule_supported_vector(Op_LoadVectorMasked, inline_limit, elem_bt) &&
 7436         Matcher::match_rule_supported_vector(Op_VectorCmpMasked,  inline_limit, elem_bt)) {
 7437 
 7438       const TypeVect* vt = TypeVect::make(elem_bt, inline_limit);
 7439       Node* cmp_length = _gvn.transform(new CmpINode(length, intcon(inline_limit)));
 7440       Node* bol_gt     = _gvn.transform(new BoolNode(cmp_length, BoolTest::gt));
 7441 
 7442       call_stub_path = generate_guard(bol_gt, nullptr, PROB_MIN);
 7443 
 7444       if (!stopped()) {
 7445         Node* casted_length = _gvn.transform(new CastIINode(control(), length, TypeInt::make(0, inline_limit, Type::WidenMin)));
 7446 
 7447         const TypePtr* obja_adr_t = _gvn.type(obja_adr)->isa_ptr();
 7448         const TypePtr* objb_adr_t = _gvn.type(objb_adr)->isa_ptr();
 7449         Node* obja_adr_mem = memory(C->get_alias_index(obja_adr_t));
 7450         Node* objb_adr_mem = memory(C->get_alias_index(objb_adr_t));
 7451 
 7452         Node* vmask      = _gvn.transform(VectorMaskGenNode::make(ConvI2X(casted_length), elem_bt));
 7453         Node* vload_obja = _gvn.transform(new LoadVectorMaskedNode(control(), obja_adr_mem, obja_adr, obja_adr_t, vt, vmask));
 7454         Node* vload_objb = _gvn.transform(new LoadVectorMaskedNode(control(), objb_adr_mem, objb_adr, objb_adr_t, vt, vmask));
 7455         Node* result     = _gvn.transform(new VectorCmpMaskedNode(vload_obja, vload_objb, vmask, TypeInt::INT));
 7456 
 7457         exit_block->init_req(inline_path, control());
 7458         memory_phi->init_req(inline_path, map()->memory());
 7459         result_phi->init_req(inline_path, result);
 7460 
 7461         C->set_max_vector_size(MAX2((uint)ArrayOperationPartialInlineSize, C->max_vector_size()));
 7462         clear_upper_avx();
 7463       }
 7464     }
 7465   }
 7466 
 7467   if (call_stub_path != nullptr) {
 7468     set_control(call_stub_path);
 7469 
 7470     Node* call = make_runtime_call(RC_LEAF,
 7471                                    OptoRuntime::vectorizedMismatch_Type(),
 7472                                    StubRoutines::vectorizedMismatch(), "vectorizedMismatch", TypePtr::BOTTOM,
 7473                                    obja_adr, objb_adr, length, scale);
 7474 
 7475     exit_block->init_req(stub_path, control());
 7476     memory_phi->init_req(stub_path, map()->memory());
 7477     result_phi->init_req(stub_path, _gvn.transform(new ProjNode(call, TypeFunc::Parms)));
 7478   }
 7479 
 7480   exit_block = _gvn.transform(exit_block);
 7481   memory_phi = _gvn.transform(memory_phi);
 7482   result_phi = _gvn.transform(result_phi);
 7483 
 7484   record_for_igvn(exit_block);
 7485   record_for_igvn(memory_phi);
 7486   record_for_igvn(result_phi);
 7487 
 7488   set_control(exit_block);
 7489   set_all_memory(memory_phi);
 7490   set_result(result_phi);
 7491 
 7492   return true;
 7493 }
 7494 
 7495 //------------------------------inline_vectorizedHashcode----------------------------
 7496 bool LibraryCallKit::inline_vectorizedHashCode() {
 7497   assert(UseVectorizedHashCodeIntrinsic, "not implemented on this platform");
 7498 
 7499   assert(callee()->signature()->size() == 5, "vectorizedHashCode has 5 parameters");
 7500   Node* array          = argument(0);
 7501   Node* offset         = argument(1);
 7502   Node* length         = argument(2);
 7503   Node* initialValue   = argument(3);
 7504   Node* basic_type     = argument(4);
 7505 
 7506   if (basic_type == top()) {
 7507     return false; // failed input validation
 7508   }
 7509 
 7510   const TypeInt* basic_type_t = _gvn.type(basic_type)->is_int();
 7511   if (!basic_type_t->is_con()) {
 7512     return false; // Only intrinsify if mode argument is constant
 7513   }
 7514 
 7515   array = must_be_not_null(array, true);
 7516 
 7517   BasicType bt = (BasicType)basic_type_t->get_con();
 7518 
 7519   // Resolve address of first element
 7520   Node* array_start = array_element_address(array, offset, bt);
 7521 
 7522   const TypeAryPtr* in_adr_type = TypeAryPtr::get_array_body_type(bt);
 7523   set_result(_gvn.transform(new VectorizedHashCodeNode(control(), memory(in_adr_type), in_adr_type,
 7524     array_start, length, initialValue, basic_type)));
 7525   clear_upper_avx();
 7526 
 7527   return true;
 7528 }
 7529 
 7530 /**
 7531  * Calculate CRC32 for byte.
 7532  * int java.util.zip.CRC32.update(int crc, int b)
 7533  */
 7534 bool LibraryCallKit::inline_updateCRC32() {
 7535   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7536   assert(callee()->signature()->size() == 2, "update has 2 parameters");
 7537   // no receiver since it is static method
 7538   Node* crc  = argument(0); // type: int
 7539   Node* b    = argument(1); // type: int
 7540 
 7541   /*
 7542    *    int c = ~ crc;
 7543    *    b = timesXtoThe32[(b ^ c) & 0xFF];
 7544    *    b = b ^ (c >>> 8);
 7545    *    crc = ~b;
 7546    */
 7547 
 7548   Node* M1 = intcon(-1);
 7549   crc = _gvn.transform(new XorINode(crc, M1));
 7550   Node* result = _gvn.transform(new XorINode(crc, b));
 7551   result = _gvn.transform(new AndINode(result, intcon(0xFF)));
 7552 
 7553   Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr()));
 7554   Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2)));
 7555   Node* adr = off_heap_plus_addr(base, ConvI2X(offset));
 7556   result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered);
 7557 
 7558   crc = _gvn.transform(new URShiftINode(crc, intcon(8)));
 7559   result = _gvn.transform(new XorINode(crc, result));
 7560   result = _gvn.transform(new XorINode(result, M1));
 7561   set_result(result);
 7562   return true;
 7563 }
 7564 
 7565 /**
 7566  * Calculate CRC32 for byte[] array.
 7567  * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len)
 7568  */
 7569 bool LibraryCallKit::inline_updateBytesCRC32() {
 7570   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7571   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7572   // no receiver since it is static method
 7573   Node* crc     = argument(0); // type: int
 7574   Node* src     = argument(1); // type: oop
 7575   Node* offset  = argument(2); // type: int
 7576   Node* length  = argument(3); // type: int
 7577 
 7578   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7579   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7580     // failed array check
 7581     return false;
 7582   }
 7583 
 7584   // Figure out the size and type of the elements we will be copying.
 7585   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7586   if (src_elem != T_BYTE) {
 7587     return false;
 7588   }
 7589 
 7590   // 'src_start' points to src array + scaled offset
 7591   src = must_be_not_null(src, true);
 7592   Node* src_start = array_element_address(src, offset, src_elem);
 7593 
 7594   // We assume that range check is done by caller.
 7595   // TODO: generate range check (offset+length < src.length) in debug VM.
 7596 
 7597   // Call the stub.
 7598   address stubAddr = StubRoutines::updateBytesCRC32();
 7599   const char *stubName = "updateBytesCRC32";
 7600 
 7601   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
 7602                                  stubAddr, stubName, TypePtr::BOTTOM,
 7603                                  crc, src_start, length);
 7604   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7605   set_result(result);
 7606   return true;
 7607 }
 7608 
 7609 /**
 7610  * Calculate CRC32 for ByteBuffer.
 7611  * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
 7612  */
 7613 bool LibraryCallKit::inline_updateByteBufferCRC32() {
 7614   assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support");
 7615   assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long");
 7616   // no receiver since it is static method
 7617   Node* crc     = argument(0); // type: int
 7618   Node* src     = argument(1); // type: long
 7619   Node* offset  = argument(3); // type: int
 7620   Node* length  = argument(4); // type: int
 7621 
 7622   src = ConvL2X(src);  // adjust Java long to machine word
 7623   Node* base = _gvn.transform(new CastX2PNode(src));
 7624   offset = ConvI2X(offset);
 7625 
 7626   // 'src_start' points to src array + scaled offset
 7627   Node* src_start = off_heap_plus_addr(base, offset);
 7628 
 7629   // Call the stub.
 7630   address stubAddr = StubRoutines::updateBytesCRC32();
 7631   const char *stubName = "updateBytesCRC32";
 7632 
 7633   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(),
 7634                                  stubAddr, stubName, TypePtr::BOTTOM,
 7635                                  crc, src_start, length);
 7636   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7637   set_result(result);
 7638   return true;
 7639 }
 7640 
 7641 //------------------------------get_table_from_crc32c_class-----------------------
 7642 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) {
 7643   Node* table = load_field_from_object(nullptr, "byteTable", "[I", /*decorators*/ IN_HEAP, /*is_static*/ true, crc32c_class);
 7644   assert (table != nullptr, "wrong version of java.util.zip.CRC32C");
 7645 
 7646   return table;
 7647 }
 7648 
 7649 //------------------------------inline_updateBytesCRC32C-----------------------
 7650 //
 7651 // Calculate CRC32C for byte[] array.
 7652 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end)
 7653 //
 7654 bool LibraryCallKit::inline_updateBytesCRC32C() {
 7655   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
 7656   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7657   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
 7658   // no receiver since it is a static method
 7659   Node* crc     = argument(0); // type: int
 7660   Node* src     = argument(1); // type: oop
 7661   Node* offset  = argument(2); // type: int
 7662   Node* end     = argument(3); // type: int
 7663 
 7664   Node* length = _gvn.transform(new SubINode(end, offset));
 7665 
 7666   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7667   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7668     // failed array check
 7669     return false;
 7670   }
 7671 
 7672   // Figure out the size and type of the elements we will be copying.
 7673   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7674   if (src_elem != T_BYTE) {
 7675     return false;
 7676   }
 7677 
 7678   // 'src_start' points to src array + scaled offset
 7679   src = must_be_not_null(src, true);
 7680   Node* src_start = array_element_address(src, offset, src_elem);
 7681 
 7682   // static final int[] byteTable in class CRC32C
 7683   Node* table = get_table_from_crc32c_class(callee()->holder());
 7684   table = must_be_not_null(table, true);
 7685   Node* table_start = array_element_address(table, intcon(0), T_INT);
 7686 
 7687   // We assume that range check is done by caller.
 7688   // TODO: generate range check (offset+length < src.length) in debug VM.
 7689 
 7690   // Call the stub.
 7691   address stubAddr = StubRoutines::updateBytesCRC32C();
 7692   const char *stubName = "updateBytesCRC32C";
 7693 
 7694   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
 7695                                  stubAddr, stubName, TypePtr::BOTTOM,
 7696                                  crc, src_start, length, table_start);
 7697   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7698   set_result(result);
 7699   return true;
 7700 }
 7701 
 7702 //------------------------------inline_updateDirectByteBufferCRC32C-----------------------
 7703 //
 7704 // Calculate CRC32C for DirectByteBuffer.
 7705 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end)
 7706 //
 7707 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() {
 7708   assert(UseCRC32CIntrinsics, "need CRC32C instruction support");
 7709   assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long");
 7710   assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded");
 7711   // no receiver since it is a static method
 7712   Node* crc     = argument(0); // type: int
 7713   Node* src     = argument(1); // type: long
 7714   Node* offset  = argument(3); // type: int
 7715   Node* end     = argument(4); // type: int
 7716 
 7717   Node* length = _gvn.transform(new SubINode(end, offset));
 7718 
 7719   src = ConvL2X(src);  // adjust Java long to machine word
 7720   Node* base = _gvn.transform(new CastX2PNode(src));
 7721   offset = ConvI2X(offset);
 7722 
 7723   // 'src_start' points to src array + scaled offset
 7724   Node* src_start = off_heap_plus_addr(base, offset);
 7725 
 7726   // static final int[] byteTable in class CRC32C
 7727   Node* table = get_table_from_crc32c_class(callee()->holder());
 7728   table = must_be_not_null(table, true);
 7729   Node* table_start = array_element_address(table, intcon(0), T_INT);
 7730 
 7731   // Call the stub.
 7732   address stubAddr = StubRoutines::updateBytesCRC32C();
 7733   const char *stubName = "updateBytesCRC32C";
 7734 
 7735   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(),
 7736                                  stubAddr, stubName, TypePtr::BOTTOM,
 7737                                  crc, src_start, length, table_start);
 7738   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7739   set_result(result);
 7740   return true;
 7741 }
 7742 
 7743 //------------------------------inline_updateBytesAdler32----------------------
 7744 //
 7745 // Calculate Adler32 checksum for byte[] array.
 7746 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len)
 7747 //
 7748 bool LibraryCallKit::inline_updateBytesAdler32() {
 7749   assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one
 7750   assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters");
 7751   assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded");
 7752   // no receiver since it is static method
 7753   Node* crc     = argument(0); // type: int
 7754   Node* src     = argument(1); // type: oop
 7755   Node* offset  = argument(2); // type: int
 7756   Node* length  = argument(3); // type: int
 7757 
 7758   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 7759   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 7760     // failed array check
 7761     return false;
 7762   }
 7763 
 7764   // Figure out the size and type of the elements we will be copying.
 7765   BasicType src_elem = src_type->elem()->array_element_basic_type();
 7766   if (src_elem != T_BYTE) {
 7767     return false;
 7768   }
 7769 
 7770   // 'src_start' points to src array + scaled offset
 7771   Node* src_start = array_element_address(src, offset, src_elem);
 7772 
 7773   // We assume that range check is done by caller.
 7774   // TODO: generate range check (offset+length < src.length) in debug VM.
 7775 
 7776   // Call the stub.
 7777   address stubAddr = StubRoutines::updateBytesAdler32();
 7778   const char *stubName = "updateBytesAdler32";
 7779 
 7780   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
 7781                                  stubAddr, stubName, TypePtr::BOTTOM,
 7782                                  crc, src_start, length);
 7783   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7784   set_result(result);
 7785   return true;
 7786 }
 7787 
 7788 //------------------------------inline_updateByteBufferAdler32---------------
 7789 //
 7790 // Calculate Adler32 checksum for DirectByteBuffer.
 7791 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len)
 7792 //
 7793 bool LibraryCallKit::inline_updateByteBufferAdler32() {
 7794   assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one
 7795   assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long");
 7796   assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded");
 7797   // no receiver since it is static method
 7798   Node* crc     = argument(0); // type: int
 7799   Node* src     = argument(1); // type: long
 7800   Node* offset  = argument(3); // type: int
 7801   Node* length  = argument(4); // type: int
 7802 
 7803   src = ConvL2X(src);  // adjust Java long to machine word
 7804   Node* base = _gvn.transform(new CastX2PNode(src));
 7805   offset = ConvI2X(offset);
 7806 
 7807   // 'src_start' points to src array + scaled offset
 7808   Node* src_start = off_heap_plus_addr(base, offset);
 7809 
 7810   // Call the stub.
 7811   address stubAddr = StubRoutines::updateBytesAdler32();
 7812   const char *stubName = "updateBytesAdler32";
 7813 
 7814   Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(),
 7815                                  stubAddr, stubName, TypePtr::BOTTOM,
 7816                                  crc, src_start, length);
 7817 
 7818   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 7819   set_result(result);
 7820   return true;
 7821 }
 7822 
 7823 //----------------------------inline_reference_get0----------------------------
 7824 // public T java.lang.ref.Reference.get();
 7825 bool LibraryCallKit::inline_reference_get0() {
 7826   const int referent_offset = java_lang_ref_Reference::referent_offset();
 7827 
 7828   // Get the argument:
 7829   Node* reference_obj = null_check_receiver();
 7830   if (stopped()) return true;
 7831 
 7832   DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF;
 7833   Node* result = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;",
 7834                                         decorators, /*is_static*/ false,
 7835                                         env()->Reference_klass());
 7836   if (result == nullptr) return false;
 7837 
 7838   // Add memory barrier to prevent commoning reads from this field
 7839   // across safepoint since GC can change its value.
 7840   insert_mem_bar(Op_MemBarCPUOrder);
 7841 
 7842   set_result(result);
 7843   return true;
 7844 }
 7845 
 7846 //----------------------------inline_reference_refersTo0----------------------------
 7847 // bool java.lang.ref.Reference.refersTo0();
 7848 // bool java.lang.ref.PhantomReference.refersTo0();
 7849 bool LibraryCallKit::inline_reference_refersTo0(bool is_phantom) {
 7850   // Get arguments:
 7851   Node* reference_obj = null_check_receiver();
 7852   Node* other_obj = argument(1);
 7853   if (stopped()) return true;
 7854 
 7855   DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE;
 7856   decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF);
 7857   Node* referent = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;",
 7858                                           decorators, /*is_static*/ false,
 7859                                           env()->Reference_klass());
 7860   if (referent == nullptr) return false;
 7861 
 7862   // Add memory barrier to prevent commoning reads from this field
 7863   // across safepoint since GC can change its value.
 7864   insert_mem_bar(Op_MemBarCPUOrder);
 7865 
 7866   Node* cmp = _gvn.transform(new CmpPNode(referent, other_obj));
 7867   Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 7868   IfNode* if_node = create_and_map_if(control(), bol, PROB_FAIR, COUNT_UNKNOWN);
 7869 
 7870   RegionNode* region = new RegionNode(3);
 7871   PhiNode* phi = new PhiNode(region, TypeInt::BOOL);
 7872 
 7873   Node* if_true = _gvn.transform(new IfTrueNode(if_node));
 7874   region->init_req(1, if_true);
 7875   phi->init_req(1, intcon(1));
 7876 
 7877   Node* if_false = _gvn.transform(new IfFalseNode(if_node));
 7878   region->init_req(2, if_false);
 7879   phi->init_req(2, intcon(0));
 7880 
 7881   set_control(_gvn.transform(region));
 7882   record_for_igvn(region);
 7883   set_result(_gvn.transform(phi));
 7884   return true;
 7885 }
 7886 
 7887 //----------------------------inline_reference_clear0----------------------------
 7888 // void java.lang.ref.Reference.clear0();
 7889 // void java.lang.ref.PhantomReference.clear0();
 7890 bool LibraryCallKit::inline_reference_clear0(bool is_phantom) {
 7891   // This matches the implementation in JVM_ReferenceClear, see the comments there.
 7892 
 7893   // Get arguments
 7894   Node* reference_obj = null_check_receiver();
 7895   if (stopped()) return true;
 7896 
 7897   // Common access parameters
 7898   DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE;
 7899   decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF);
 7900   Node* referent_field_addr = basic_plus_adr(reference_obj, java_lang_ref_Reference::referent_offset());
 7901   const TypePtr* referent_field_addr_type = _gvn.type(referent_field_addr)->isa_ptr();
 7902   const Type* val_type = TypeOopPtr::make_from_klass(env()->Object_klass());
 7903 
 7904   Node* referent = access_load_at(reference_obj,
 7905                                   referent_field_addr,
 7906                                   referent_field_addr_type,
 7907                                   val_type,
 7908                                   T_OBJECT,
 7909                                   decorators);
 7910 
 7911   IdealKit ideal(this);
 7912 #define __ ideal.
 7913   __ if_then(referent, BoolTest::ne, null());
 7914     sync_kit(ideal);
 7915     access_store_at(reference_obj,
 7916                     referent_field_addr,
 7917                     referent_field_addr_type,
 7918                     null(),
 7919                     val_type,
 7920                     T_OBJECT,
 7921                     decorators);
 7922     __ sync_kit(this);
 7923   __ end_if();
 7924   final_sync(ideal);
 7925 #undef __
 7926 
 7927   return true;
 7928 }
 7929 
 7930 //-----------------------inline_reference_reachabilityFence-----------------
 7931 // bool java.lang.ref.Reference.reachabilityFence();
 7932 bool LibraryCallKit::inline_reference_reachabilityFence() {
 7933   Node* referent = argument(0);
 7934   insert_reachability_fence(referent);
 7935   return true;
 7936 }
 7937 
 7938 Node* LibraryCallKit::load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString,
 7939                                              DecoratorSet decorators, bool is_static,
 7940                                              ciInstanceKlass* fromKls) {
 7941   if (fromKls == nullptr) {
 7942     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
 7943     assert(tinst != nullptr, "obj is null");
 7944     assert(tinst->is_loaded(), "obj is not loaded");
 7945     fromKls = tinst->instance_klass();
 7946   }
 7947   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
 7948                                               ciSymbol::make(fieldTypeString),
 7949                                               is_static);
 7950 
 7951   assert(field != nullptr, "undefined field %s %s %s", fieldTypeString, fromKls->name()->as_utf8(), fieldName);
 7952   if (field == nullptr) return (Node *) nullptr;
 7953 
 7954   if (is_static) {
 7955     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
 7956     fromObj = makecon(tip);
 7957   }
 7958 
 7959   // Next code  copied from Parse::do_get_xxx():
 7960 
 7961   // Compute address and memory type.
 7962   int offset  = field->offset_in_bytes();
 7963   bool is_vol = field->is_volatile();
 7964   ciType* field_klass = field->type();
 7965   assert(field_klass->is_loaded(), "should be loaded");
 7966   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 7967   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
 7968   assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()),
 7969     "slice of address and input slice don't match");
 7970   BasicType bt = field->layout_type();
 7971 
 7972   // Build the resultant type of the load
 7973   const Type *type;
 7974   if (bt == T_OBJECT) {
 7975     type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 7976   } else {
 7977     type = Type::get_const_basic_type(bt);
 7978   }
 7979 
 7980   if (is_vol) {
 7981     decorators |= MO_SEQ_CST;
 7982   }
 7983 
 7984   return access_load_at(fromObj, adr, adr_type, type, bt, decorators);
 7985 }
 7986 
 7987 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString,
 7988                                                  bool is_exact /* true */, bool is_static /* false */,
 7989                                                  ciInstanceKlass * fromKls /* nullptr */) {
 7990   if (fromKls == nullptr) {
 7991     const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr();
 7992     assert(tinst != nullptr, "obj is null");
 7993     assert(tinst->is_loaded(), "obj is not loaded");
 7994     assert(!is_exact || tinst->klass_is_exact(), "klass not exact");
 7995     fromKls = tinst->instance_klass();
 7996   }
 7997   else {
 7998     assert(is_static, "only for static field access");
 7999   }
 8000   ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName),
 8001     ciSymbol::make(fieldTypeString),
 8002     is_static);
 8003 
 8004   assert(field != nullptr, "undefined field");
 8005   assert(!field->is_volatile(), "not defined for volatile fields");
 8006 
 8007   if (is_static) {
 8008     const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror());
 8009     fromObj = makecon(tip);
 8010   }
 8011 
 8012   // Next code  copied from Parse::do_get_xxx():
 8013 
 8014   // Compute address and memory type.
 8015   int offset = field->offset_in_bytes();
 8016   Node *adr = basic_plus_adr(fromObj, fromObj, offset);
 8017 
 8018   return adr;
 8019 }
 8020 
 8021 //------------------------------inline_aescrypt_Block-----------------------
 8022 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) {
 8023   address stubAddr = nullptr;
 8024   const char *stubName;
 8025   bool is_decrypt = false;
 8026   assert(UseAES, "need AES instruction support");
 8027 
 8028   switch(id) {
 8029   case vmIntrinsics::_aescrypt_encryptBlock:
 8030     stubAddr = StubRoutines::aescrypt_encryptBlock();
 8031     stubName = "aescrypt_encryptBlock";
 8032     break;
 8033   case vmIntrinsics::_aescrypt_decryptBlock:
 8034     stubAddr = StubRoutines::aescrypt_decryptBlock();
 8035     stubName = "aescrypt_decryptBlock";
 8036     is_decrypt = true;
 8037     break;
 8038   default:
 8039     break;
 8040   }
 8041   if (stubAddr == nullptr) return false;
 8042 
 8043   Node* aescrypt_object = argument(0);
 8044   Node* src             = argument(1);
 8045   Node* src_offset      = argument(2);
 8046   Node* dest            = argument(3);
 8047   Node* dest_offset     = argument(4);
 8048 
 8049   src = must_be_not_null(src, true);
 8050   dest = must_be_not_null(dest, true);
 8051 
 8052   // (1) src and dest are arrays.
 8053   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8054   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8055   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8056          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8057 
 8058   // for the quick and dirty code we will skip all the checks.
 8059   // we are just trying to get the call to be generated.
 8060   Node* src_start  = src;
 8061   Node* dest_start = dest;
 8062   if (src_offset != nullptr || dest_offset != nullptr) {
 8063     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8064     src_start  = array_element_address(src,  src_offset,  T_BYTE);
 8065     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8066   }
 8067 
 8068   // now need to get the start of its expanded key array
 8069   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8070   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8071   if (k_start == nullptr) return false;
 8072 
 8073   // Call the stub.
 8074   make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(),
 8075                     stubAddr, stubName, TypePtr::BOTTOM,
 8076                     src_start, dest_start, k_start);
 8077 
 8078   return true;
 8079 }
 8080 
 8081 //------------------------------inline_cipherBlockChaining_AESCrypt-----------------------
 8082 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) {
 8083   address stubAddr = nullptr;
 8084   const char *stubName = nullptr;
 8085   bool is_decrypt = false;
 8086   assert(UseAES, "need AES instruction support");
 8087 
 8088   switch(id) {
 8089   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 8090     stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt();
 8091     stubName = "cipherBlockChaining_encryptAESCrypt";
 8092     break;
 8093   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 8094     stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt();
 8095     stubName = "cipherBlockChaining_decryptAESCrypt";
 8096     is_decrypt = true;
 8097     break;
 8098   default:
 8099     break;
 8100   }
 8101   if (stubAddr == nullptr) return false;
 8102 
 8103   Node* cipherBlockChaining_object = argument(0);
 8104   Node* src                        = argument(1);
 8105   Node* src_offset                 = argument(2);
 8106   Node* len                        = argument(3);
 8107   Node* dest                       = argument(4);
 8108   Node* dest_offset                = argument(5);
 8109 
 8110   src = must_be_not_null(src, false);
 8111   dest = must_be_not_null(dest, false);
 8112 
 8113   // (1) src and dest are arrays.
 8114   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8115   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8116   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8117          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8118 
 8119   // checks are the responsibility of the caller
 8120   Node* src_start  = src;
 8121   Node* dest_start = dest;
 8122   if (src_offset != nullptr || dest_offset != nullptr) {
 8123     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8124     src_start  = array_element_address(src,  src_offset,  T_BYTE);
 8125     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8126   }
 8127 
 8128   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8129   // (because of the predicated logic executed earlier).
 8130   // so we cast it here safely.
 8131   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8132 
 8133   Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8134   if (embeddedCipherObj == nullptr) return false;
 8135 
 8136   // cast it to what we know it will be at runtime
 8137   const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
 8138   assert(tinst != nullptr, "CBC obj is null");
 8139   assert(tinst->is_loaded(), "CBC obj is not loaded");
 8140   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8141   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8142 
 8143   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8144   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8145   const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8146   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8147   aescrypt_object = _gvn.transform(aescrypt_object);
 8148 
 8149   // we need to get the start of the aescrypt_object's expanded key array
 8150   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8151   if (k_start == nullptr) return false;
 8152 
 8153   // similarly, get the start address of the r vector
 8154   Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B");
 8155   if (objRvec == nullptr) return false;
 8156   Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE);
 8157 
 8158   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8159   Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8160                                      OptoRuntime::cipherBlockChaining_aescrypt_Type(),
 8161                                      stubAddr, stubName, TypePtr::BOTTOM,
 8162                                      src_start, dest_start, k_start, r_start, len);
 8163 
 8164   // return cipher length (int)
 8165   Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms));
 8166   set_result(retvalue);
 8167   return true;
 8168 }
 8169 
 8170 //------------------------------inline_electronicCodeBook_AESCrypt-----------------------
 8171 bool LibraryCallKit::inline_electronicCodeBook_AESCrypt(vmIntrinsics::ID id) {
 8172   address stubAddr = nullptr;
 8173   const char *stubName = nullptr;
 8174   bool is_decrypt = false;
 8175   assert(UseAES, "need AES instruction support");
 8176 
 8177   switch (id) {
 8178   case vmIntrinsics::_electronicCodeBook_encryptAESCrypt:
 8179     stubAddr = StubRoutines::electronicCodeBook_encryptAESCrypt();
 8180     stubName = "electronicCodeBook_encryptAESCrypt";
 8181     break;
 8182   case vmIntrinsics::_electronicCodeBook_decryptAESCrypt:
 8183     stubAddr = StubRoutines::electronicCodeBook_decryptAESCrypt();
 8184     stubName = "electronicCodeBook_decryptAESCrypt";
 8185     is_decrypt = true;
 8186     break;
 8187   default:
 8188     break;
 8189   }
 8190 
 8191   if (stubAddr == nullptr) return false;
 8192 
 8193   Node* electronicCodeBook_object = argument(0);
 8194   Node* src                       = argument(1);
 8195   Node* src_offset                = argument(2);
 8196   Node* len                       = argument(3);
 8197   Node* dest                      = argument(4);
 8198   Node* dest_offset               = argument(5);
 8199 
 8200   // (1) src and dest are arrays.
 8201   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8202   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8203   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8204          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8205 
 8206   // checks are the responsibility of the caller
 8207   Node* src_start = src;
 8208   Node* dest_start = dest;
 8209   if (src_offset != nullptr || dest_offset != nullptr) {
 8210     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8211     src_start = array_element_address(src, src_offset, T_BYTE);
 8212     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8213   }
 8214 
 8215   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8216   // (because of the predicated logic executed earlier).
 8217   // so we cast it here safely.
 8218   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8219 
 8220   Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8221   if (embeddedCipherObj == nullptr) return false;
 8222 
 8223   // cast it to what we know it will be at runtime
 8224   const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr();
 8225   assert(tinst != nullptr, "ECB obj is null");
 8226   assert(tinst->is_loaded(), "ECB obj is not loaded");
 8227   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8228   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8229 
 8230   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8231   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8232   const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8233   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8234   aescrypt_object = _gvn.transform(aescrypt_object);
 8235 
 8236   // we need to get the start of the aescrypt_object's expanded key array
 8237   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, is_decrypt);
 8238   if (k_start == nullptr) return false;
 8239 
 8240   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8241   Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP,
 8242                                      OptoRuntime::electronicCodeBook_aescrypt_Type(),
 8243                                      stubAddr, stubName, TypePtr::BOTTOM,
 8244                                      src_start, dest_start, k_start, len);
 8245 
 8246   // return cipher length (int)
 8247   Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms));
 8248   set_result(retvalue);
 8249   return true;
 8250 }
 8251 
 8252 //------------------------------inline_counterMode_AESCrypt-----------------------
 8253 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) {
 8254   assert(UseAES, "need AES instruction support");
 8255   if (!UseAESCTRIntrinsics) return false;
 8256 
 8257   address stubAddr = nullptr;
 8258   const char *stubName = nullptr;
 8259   if (id == vmIntrinsics::_counterMode_AESCrypt) {
 8260     stubAddr = StubRoutines::counterMode_AESCrypt();
 8261     stubName = "counterMode_AESCrypt";
 8262   }
 8263   if (stubAddr == nullptr) return false;
 8264 
 8265   Node* counterMode_object = argument(0);
 8266   Node* src = argument(1);
 8267   Node* src_offset = argument(2);
 8268   Node* len = argument(3);
 8269   Node* dest = argument(4);
 8270   Node* dest_offset = argument(5);
 8271 
 8272   // (1) src and dest are arrays.
 8273   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 8274   const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr();
 8275   assert( src_type != nullptr &&  src_type->elem() != Type::BOTTOM &&
 8276          dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange");
 8277 
 8278   // checks are the responsibility of the caller
 8279   Node* src_start = src;
 8280   Node* dest_start = dest;
 8281   if (src_offset != nullptr || dest_offset != nullptr) {
 8282     assert(src_offset != nullptr && dest_offset != nullptr, "");
 8283     src_start = array_element_address(src, src_offset, T_BYTE);
 8284     dest_start = array_element_address(dest, dest_offset, T_BYTE);
 8285   }
 8286 
 8287   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 8288   // (because of the predicated logic executed earlier).
 8289   // so we cast it here safely.
 8290   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 8291   Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8292   if (embeddedCipherObj == nullptr) return false;
 8293   // cast it to what we know it will be at runtime
 8294   const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr();
 8295   assert(tinst != nullptr, "CTR obj is null");
 8296   assert(tinst->is_loaded(), "CTR obj is not loaded");
 8297   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8298   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 8299   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8300   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 8301   const TypeOopPtr* xtype = aklass->as_exact_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 8302   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 8303   aescrypt_object = _gvn.transform(aescrypt_object);
 8304   // we need to get the start of the aescrypt_object's expanded key array
 8305   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
 8306   if (k_start == nullptr) return false;
 8307   // similarly, get the start address of the r vector
 8308   Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B");
 8309   if (obj_counter == nullptr) return false;
 8310   Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE);
 8311 
 8312   Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B");
 8313   if (saved_encCounter == nullptr) return false;
 8314   Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE);
 8315   Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false);
 8316 
 8317   // Call the stub, passing src_start, dest_start, k_start, r_start and src_len
 8318   Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8319                                      OptoRuntime::counterMode_aescrypt_Type(),
 8320                                      stubAddr, stubName, TypePtr::BOTTOM,
 8321                                      src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used);
 8322 
 8323   // return cipher length (int)
 8324   Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms));
 8325   set_result(retvalue);
 8326   return true;
 8327 }
 8328 
 8329 //------------------------------get_key_start_from_aescrypt_object-----------------------
 8330 Node* LibraryCallKit::get_key_start_from_aescrypt_object(Node* aescrypt_object, bool is_decrypt) {
 8331   // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys.
 8332   // Intel's extension is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns.
 8333   // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption.
 8334   // The following platform specific stubs of encryption and decryption use the same round keys.
 8335 #if defined(PPC64) || defined(S390) || defined(RISCV64)
 8336   bool use_decryption_key = false;
 8337 #else
 8338   bool use_decryption_key = is_decrypt;
 8339 #endif
 8340   Node* objAESCryptKey = load_field_from_object(aescrypt_object, use_decryption_key ? "sessionKd" : "sessionKe", "[I");
 8341   assert(objAESCryptKey != nullptr, "wrong version of com.sun.crypto.provider.AES_Crypt");
 8342   if (objAESCryptKey == nullptr) return (Node *) nullptr;
 8343 
 8344   // now have the array, need to get the start address of the selected key array
 8345   Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT);
 8346   return k_start;
 8347 }
 8348 
 8349 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate----------------------------
 8350 // Return node representing slow path of predicate check.
 8351 // the pseudo code we want to emulate with this predicate is:
 8352 // for encryption:
 8353 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8354 // for decryption:
 8355 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8356 //    note cipher==plain is more conservative than the original java code but that's OK
 8357 //
 8358 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) {
 8359   // The receiver was checked for null already.
 8360   Node* objCBC = argument(0);
 8361 
 8362   Node* src = argument(1);
 8363   Node* dest = argument(4);
 8364 
 8365   // Load embeddedCipher field of CipherBlockChaining object.
 8366   Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8367 
 8368   // get AESCrypt klass for instanceOf check
 8369   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8370   // will have same classloader as CipherBlockChaining object
 8371   const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr();
 8372   assert(tinst != nullptr, "CBCobj is null");
 8373   assert(tinst->is_loaded(), "CBCobj is not loaded");
 8374 
 8375   // we want to do an instanceof comparison against the AESCrypt class
 8376   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8377   if (!klass_AESCrypt->is_loaded()) {
 8378     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8379     Node* ctrl = control();
 8380     set_control(top()); // no regular fast path
 8381     return ctrl;
 8382   }
 8383 
 8384   src = must_be_not_null(src, true);
 8385   dest = must_be_not_null(dest, true);
 8386 
 8387   // Resolve oops to stable for CmpP below.
 8388   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8389 
 8390   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8391   Node* cmp_instof  = _gvn.transform(new CmpINode(instof, intcon(1)));
 8392   Node* bool_instof  = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8393 
 8394   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8395 
 8396   // for encryption, we are done
 8397   if (!decrypting)
 8398     return instof_false;  // even if it is null
 8399 
 8400   // for decryption, we need to add a further check to avoid
 8401   // taking the intrinsic path when cipher and plain are the same
 8402   // see the original java code for why.
 8403   RegionNode* region = new RegionNode(3);
 8404   region->init_req(1, instof_false);
 8405 
 8406   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
 8407   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
 8408   Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN);
 8409   region->init_req(2, src_dest_conjoint);
 8410 
 8411   record_for_igvn(region);
 8412   return _gvn.transform(region);
 8413 }
 8414 
 8415 //----------------------------inline_electronicCodeBook_AESCrypt_predicate----------------------------
 8416 // Return node representing slow path of predicate check.
 8417 // the pseudo code we want to emulate with this predicate is:
 8418 // for encryption:
 8419 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8420 // for decryption:
 8421 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8422 //    note cipher==plain is more conservative than the original java code but that's OK
 8423 //
 8424 Node* LibraryCallKit::inline_electronicCodeBook_AESCrypt_predicate(bool decrypting) {
 8425   // The receiver was checked for null already.
 8426   Node* objECB = argument(0);
 8427 
 8428   // Load embeddedCipher field of ElectronicCodeBook object.
 8429   Node* embeddedCipherObj = load_field_from_object(objECB, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8430 
 8431   // get AESCrypt klass for instanceOf check
 8432   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8433   // will have same classloader as ElectronicCodeBook object
 8434   const TypeInstPtr* tinst = _gvn.type(objECB)->isa_instptr();
 8435   assert(tinst != nullptr, "ECBobj is null");
 8436   assert(tinst->is_loaded(), "ECBobj is not loaded");
 8437 
 8438   // we want to do an instanceof comparison against the AESCrypt class
 8439   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8440   if (!klass_AESCrypt->is_loaded()) {
 8441     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8442     Node* ctrl = control();
 8443     set_control(top()); // no regular fast path
 8444     return ctrl;
 8445   }
 8446   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8447 
 8448   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8449   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 8450   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8451 
 8452   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8453 
 8454   // for encryption, we are done
 8455   if (!decrypting)
 8456     return instof_false;  // even if it is null
 8457 
 8458   // for decryption, we need to add a further check to avoid
 8459   // taking the intrinsic path when cipher and plain are the same
 8460   // see the original java code for why.
 8461   RegionNode* region = new RegionNode(3);
 8462   region->init_req(1, instof_false);
 8463   Node* src = argument(1);
 8464   Node* dest = argument(4);
 8465   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
 8466   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
 8467   Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN);
 8468   region->init_req(2, src_dest_conjoint);
 8469 
 8470   record_for_igvn(region);
 8471   return _gvn.transform(region);
 8472 }
 8473 
 8474 //----------------------------inline_counterMode_AESCrypt_predicate----------------------------
 8475 // Return node representing slow path of predicate check.
 8476 // the pseudo code we want to emulate with this predicate is:
 8477 // for encryption:
 8478 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 8479 // for decryption:
 8480 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 8481 //    note cipher==plain is more conservative than the original java code but that's OK
 8482 //
 8483 
 8484 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() {
 8485   // The receiver was checked for null already.
 8486   Node* objCTR = argument(0);
 8487 
 8488   // Load embeddedCipher field of CipherBlockChaining object.
 8489   Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 8490 
 8491   // get AESCrypt klass for instanceOf check
 8492   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 8493   // will have same classloader as CipherBlockChaining object
 8494   const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr();
 8495   assert(tinst != nullptr, "CTRobj is null");
 8496   assert(tinst->is_loaded(), "CTRobj is not loaded");
 8497 
 8498   // we want to do an instanceof comparison against the AESCrypt class
 8499   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 8500   if (!klass_AESCrypt->is_loaded()) {
 8501     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 8502     Node* ctrl = control();
 8503     set_control(top()); // no regular fast path
 8504     return ctrl;
 8505   }
 8506 
 8507   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 8508   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 8509   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 8510   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 8511   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 8512 
 8513   return instof_false; // even if it is null
 8514 }
 8515 
 8516 //------------------------------inline_ghash_processBlocks
 8517 bool LibraryCallKit::inline_ghash_processBlocks() {
 8518   address stubAddr;
 8519   const char *stubName;
 8520   assert(UseGHASHIntrinsics, "need GHASH intrinsics support");
 8521 
 8522   stubAddr = StubRoutines::ghash_processBlocks();
 8523   stubName = "ghash_processBlocks";
 8524 
 8525   Node* data           = argument(0);
 8526   Node* offset         = argument(1);
 8527   Node* len            = argument(2);
 8528   Node* state          = argument(3);
 8529   Node* subkeyH        = argument(4);
 8530 
 8531   state = must_be_not_null(state, true);
 8532   subkeyH = must_be_not_null(subkeyH, true);
 8533   data = must_be_not_null(data, true);
 8534 
 8535   Node* state_start  = array_element_address(state, intcon(0), T_LONG);
 8536   assert(state_start, "state is null");
 8537   Node* subkeyH_start  = array_element_address(subkeyH, intcon(0), T_LONG);
 8538   assert(subkeyH_start, "subkeyH is null");
 8539   Node* data_start  = array_element_address(data, offset, T_BYTE);
 8540   assert(data_start, "data is null");
 8541 
 8542   Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP,
 8543                                   OptoRuntime::ghash_processBlocks_Type(),
 8544                                   stubAddr, stubName, TypePtr::BOTTOM,
 8545                                   state_start, subkeyH_start, data_start, len);
 8546   return true;
 8547 }
 8548 
 8549 //------------------------------inline_chacha20Block
 8550 bool LibraryCallKit::inline_chacha20Block() {
 8551   address stubAddr;
 8552   const char *stubName;
 8553   assert(UseChaCha20Intrinsics, "need ChaCha20 intrinsics support");
 8554 
 8555   stubAddr = StubRoutines::chacha20Block();
 8556   stubName = "chacha20Block";
 8557 
 8558   Node* state          = argument(0);
 8559   Node* result         = argument(1);
 8560 
 8561   state = must_be_not_null(state, true);
 8562   result = must_be_not_null(result, true);
 8563 
 8564   Node* state_start  = array_element_address(state, intcon(0), T_INT);
 8565   assert(state_start, "state is null");
 8566   Node* result_start  = array_element_address(result, intcon(0), T_BYTE);
 8567   assert(result_start, "result is null");
 8568 
 8569   Node* cc20Blk = make_runtime_call(RC_LEAF|RC_NO_FP,
 8570                                   OptoRuntime::chacha20Block_Type(),
 8571                                   stubAddr, stubName, TypePtr::BOTTOM,
 8572                                   state_start, result_start);
 8573   // return key stream length (int)
 8574   Node* retvalue = _gvn.transform(new ProjNode(cc20Blk, TypeFunc::Parms));
 8575   set_result(retvalue);
 8576   return true;
 8577 }
 8578 
 8579 //------------------------------inline_kyberNtt
 8580 bool LibraryCallKit::inline_kyberNtt() {
 8581   address stubAddr;
 8582   const char *stubName;
 8583   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8584   assert(callee()->signature()->size() == 2, "kyberNtt has 2 parameters");
 8585 
 8586   stubAddr = StubRoutines::kyberNtt();
 8587   stubName = "kyberNtt";
 8588   if (!stubAddr) return false;
 8589 
 8590   Node* coeffs          = argument(0);
 8591   Node* ntt_zetas        = argument(1);
 8592 
 8593   coeffs = must_be_not_null(coeffs, true);
 8594   ntt_zetas = must_be_not_null(ntt_zetas, true);
 8595 
 8596   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8597   assert(coeffs_start, "coeffs is null");
 8598   Node* ntt_zetas_start  = array_element_address(ntt_zetas, intcon(0), T_SHORT);
 8599   assert(ntt_zetas_start, "ntt_zetas is null");
 8600   Node* kyberNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8601                                   OptoRuntime::kyberNtt_Type(),
 8602                                   stubAddr, stubName, TypePtr::BOTTOM,
 8603                                   coeffs_start, ntt_zetas_start);
 8604   // return an int
 8605   Node* retvalue = _gvn.transform(new ProjNode(kyberNtt, TypeFunc::Parms));
 8606   set_result(retvalue);
 8607   return true;
 8608 }
 8609 
 8610 //------------------------------inline_kyberInverseNtt
 8611 bool LibraryCallKit::inline_kyberInverseNtt() {
 8612   address stubAddr;
 8613   const char *stubName;
 8614   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8615   assert(callee()->signature()->size() == 2, "kyberInverseNtt has 2 parameters");
 8616 
 8617   stubAddr = StubRoutines::kyberInverseNtt();
 8618   stubName = "kyberInverseNtt";
 8619   if (!stubAddr) return false;
 8620 
 8621   Node* coeffs          = argument(0);
 8622   Node* zetas           = argument(1);
 8623 
 8624   coeffs = must_be_not_null(coeffs, true);
 8625   zetas = must_be_not_null(zetas, true);
 8626 
 8627   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8628   assert(coeffs_start, "coeffs is null");
 8629   Node* zetas_start  = array_element_address(zetas, intcon(0), T_SHORT);
 8630   assert(zetas_start, "inverseNtt_zetas is null");
 8631   Node* kyberInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8632                                   OptoRuntime::kyberInverseNtt_Type(),
 8633                                   stubAddr, stubName, TypePtr::BOTTOM,
 8634                                   coeffs_start, zetas_start);
 8635 
 8636   // return an int
 8637   Node* retvalue = _gvn.transform(new ProjNode(kyberInverseNtt, TypeFunc::Parms));
 8638   set_result(retvalue);
 8639   return true;
 8640 }
 8641 
 8642 //------------------------------inline_kyberNttMult
 8643 bool LibraryCallKit::inline_kyberNttMult() {
 8644   address stubAddr;
 8645   const char *stubName;
 8646   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8647   assert(callee()->signature()->size() == 4, "kyberNttMult has 4 parameters");
 8648 
 8649   stubAddr = StubRoutines::kyberNttMult();
 8650   stubName = "kyberNttMult";
 8651   if (!stubAddr) return false;
 8652 
 8653   Node* result          = argument(0);
 8654   Node* ntta            = argument(1);
 8655   Node* nttb            = argument(2);
 8656   Node* zetas           = argument(3);
 8657 
 8658   result = must_be_not_null(result, true);
 8659   ntta = must_be_not_null(ntta, true);
 8660   nttb = must_be_not_null(nttb, true);
 8661   zetas = must_be_not_null(zetas, true);
 8662 
 8663   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8664   assert(result_start, "result is null");
 8665   Node* ntta_start  = array_element_address(ntta, intcon(0), T_SHORT);
 8666   assert(ntta_start, "ntta is null");
 8667   Node* nttb_start  = array_element_address(nttb, intcon(0), T_SHORT);
 8668   assert(nttb_start, "nttb is null");
 8669   Node* zetas_start  = array_element_address(zetas, intcon(0), T_SHORT);
 8670   assert(zetas_start, "nttMult_zetas is null");
 8671   Node* kyberNttMult = make_runtime_call(RC_LEAF|RC_NO_FP,
 8672                                   OptoRuntime::kyberNttMult_Type(),
 8673                                   stubAddr, stubName, TypePtr::BOTTOM,
 8674                                   result_start, ntta_start, nttb_start,
 8675                                   zetas_start);
 8676 
 8677   // return an int
 8678   Node* retvalue = _gvn.transform(new ProjNode(kyberNttMult, TypeFunc::Parms));
 8679   set_result(retvalue);
 8680 
 8681   return true;
 8682 }
 8683 
 8684 //------------------------------inline_kyberAddPoly_2
 8685 bool LibraryCallKit::inline_kyberAddPoly_2() {
 8686   address stubAddr;
 8687   const char *stubName;
 8688   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8689   assert(callee()->signature()->size() == 3, "kyberAddPoly_2 has 3 parameters");
 8690 
 8691   stubAddr = StubRoutines::kyberAddPoly_2();
 8692   stubName = "kyberAddPoly_2";
 8693   if (!stubAddr) return false;
 8694 
 8695   Node* result          = argument(0);
 8696   Node* a               = argument(1);
 8697   Node* b               = argument(2);
 8698 
 8699   result = must_be_not_null(result, true);
 8700   a = must_be_not_null(a, true);
 8701   b = must_be_not_null(b, true);
 8702 
 8703   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8704   assert(result_start, "result is null");
 8705   Node* a_start  = array_element_address(a, intcon(0), T_SHORT);
 8706   assert(a_start, "a is null");
 8707   Node* b_start  = array_element_address(b, intcon(0), T_SHORT);
 8708   assert(b_start, "b is null");
 8709   Node* kyberAddPoly_2 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8710                                   OptoRuntime::kyberAddPoly_2_Type(),
 8711                                   stubAddr, stubName, TypePtr::BOTTOM,
 8712                                   result_start, a_start, b_start);
 8713   // return an int
 8714   Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_2, TypeFunc::Parms));
 8715   set_result(retvalue);
 8716   return true;
 8717 }
 8718 
 8719 //------------------------------inline_kyberAddPoly_3
 8720 bool LibraryCallKit::inline_kyberAddPoly_3() {
 8721   address stubAddr;
 8722   const char *stubName;
 8723   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8724   assert(callee()->signature()->size() == 4, "kyberAddPoly_3 has 4 parameters");
 8725 
 8726   stubAddr = StubRoutines::kyberAddPoly_3();
 8727   stubName = "kyberAddPoly_3";
 8728   if (!stubAddr) return false;
 8729 
 8730   Node* result          = argument(0);
 8731   Node* a               = argument(1);
 8732   Node* b               = argument(2);
 8733   Node* c               = argument(3);
 8734 
 8735   result = must_be_not_null(result, true);
 8736   a = must_be_not_null(a, true);
 8737   b = must_be_not_null(b, true);
 8738   c = must_be_not_null(c, true);
 8739 
 8740   Node* result_start  = array_element_address(result, intcon(0), T_SHORT);
 8741   assert(result_start, "result is null");
 8742   Node* a_start  = array_element_address(a, intcon(0), T_SHORT);
 8743   assert(a_start, "a is null");
 8744   Node* b_start  = array_element_address(b, intcon(0), T_SHORT);
 8745   assert(b_start, "b is null");
 8746   Node* c_start  = array_element_address(c, intcon(0), T_SHORT);
 8747   assert(c_start, "c is null");
 8748   Node* kyberAddPoly_3 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8749                                   OptoRuntime::kyberAddPoly_3_Type(),
 8750                                   stubAddr, stubName, TypePtr::BOTTOM,
 8751                                   result_start, a_start, b_start, c_start);
 8752   // return an int
 8753   Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_3, TypeFunc::Parms));
 8754   set_result(retvalue);
 8755   return true;
 8756 }
 8757 
 8758 //------------------------------inline_kyber12To16
 8759 bool LibraryCallKit::inline_kyber12To16() {
 8760   address stubAddr;
 8761   const char *stubName;
 8762   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8763   assert(callee()->signature()->size() == 4, "kyber12To16 has 4 parameters");
 8764 
 8765   stubAddr = StubRoutines::kyber12To16();
 8766   stubName = "kyber12To16";
 8767   if (!stubAddr) return false;
 8768 
 8769   Node* condensed       = argument(0);
 8770   Node* condensedOffs   = argument(1);
 8771   Node* parsed          = argument(2);
 8772   Node* parsedLength    = argument(3);
 8773 
 8774   condensed = must_be_not_null(condensed, true);
 8775   parsed = must_be_not_null(parsed, true);
 8776 
 8777   Node* condensed_start  = array_element_address(condensed, intcon(0), T_BYTE);
 8778   assert(condensed_start, "condensed is null");
 8779   Node* parsed_start  = array_element_address(parsed, intcon(0), T_SHORT);
 8780   assert(parsed_start, "parsed is null");
 8781   Node* kyber12To16 = make_runtime_call(RC_LEAF|RC_NO_FP,
 8782                                   OptoRuntime::kyber12To16_Type(),
 8783                                   stubAddr, stubName, TypePtr::BOTTOM,
 8784                                   condensed_start, condensedOffs, parsed_start, parsedLength);
 8785   // return an int
 8786   Node* retvalue = _gvn.transform(new ProjNode(kyber12To16, TypeFunc::Parms));
 8787   set_result(retvalue);
 8788   return true;
 8789 
 8790 }
 8791 
 8792 //------------------------------inline_kyberBarrettReduce
 8793 bool LibraryCallKit::inline_kyberBarrettReduce() {
 8794   address stubAddr;
 8795   const char *stubName;
 8796   assert(UseKyberIntrinsics, "need Kyber intrinsics support");
 8797   assert(callee()->signature()->size() == 1, "kyberBarrettReduce has 1 parameters");
 8798 
 8799   stubAddr = StubRoutines::kyberBarrettReduce();
 8800   stubName = "kyberBarrettReduce";
 8801   if (!stubAddr) return false;
 8802 
 8803   Node* coeffs          = argument(0);
 8804 
 8805   coeffs = must_be_not_null(coeffs, true);
 8806 
 8807   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_SHORT);
 8808   assert(coeffs_start, "coeffs is null");
 8809   Node* kyberBarrettReduce = make_runtime_call(RC_LEAF|RC_NO_FP,
 8810                                   OptoRuntime::kyberBarrettReduce_Type(),
 8811                                   stubAddr, stubName, TypePtr::BOTTOM,
 8812                                   coeffs_start);
 8813   // return an int
 8814   Node* retvalue = _gvn.transform(new ProjNode(kyberBarrettReduce, TypeFunc::Parms));
 8815   set_result(retvalue);
 8816   return true;
 8817 }
 8818 
 8819 //------------------------------inline_dilithiumAlmostNtt
 8820 bool LibraryCallKit::inline_dilithiumAlmostNtt() {
 8821   address stubAddr;
 8822   const char *stubName;
 8823   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8824   assert(callee()->signature()->size() == 2, "dilithiumAlmostNtt has 2 parameters");
 8825 
 8826   stubAddr = StubRoutines::dilithiumAlmostNtt();
 8827   stubName = "dilithiumAlmostNtt";
 8828   if (!stubAddr) return false;
 8829 
 8830   Node* coeffs          = argument(0);
 8831   Node* ntt_zetas        = argument(1);
 8832 
 8833   coeffs = must_be_not_null(coeffs, true);
 8834   ntt_zetas = must_be_not_null(ntt_zetas, true);
 8835 
 8836   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8837   assert(coeffs_start, "coeffs is null");
 8838   Node* ntt_zetas_start  = array_element_address(ntt_zetas, intcon(0), T_INT);
 8839   assert(ntt_zetas_start, "ntt_zetas is null");
 8840   Node* dilithiumAlmostNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8841                                   OptoRuntime::dilithiumAlmostNtt_Type(),
 8842                                   stubAddr, stubName, TypePtr::BOTTOM,
 8843                                   coeffs_start, ntt_zetas_start);
 8844   // return an int
 8845   Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostNtt, TypeFunc::Parms));
 8846   set_result(retvalue);
 8847   return true;
 8848 }
 8849 
 8850 //------------------------------inline_dilithiumAlmostInverseNtt
 8851 bool LibraryCallKit::inline_dilithiumAlmostInverseNtt() {
 8852   address stubAddr;
 8853   const char *stubName;
 8854   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8855   assert(callee()->signature()->size() == 2, "dilithiumAlmostInverseNtt has 2 parameters");
 8856 
 8857   stubAddr = StubRoutines::dilithiumAlmostInverseNtt();
 8858   stubName = "dilithiumAlmostInverseNtt";
 8859   if (!stubAddr) return false;
 8860 
 8861   Node* coeffs          = argument(0);
 8862   Node* zetas           = argument(1);
 8863 
 8864   coeffs = must_be_not_null(coeffs, true);
 8865   zetas = must_be_not_null(zetas, true);
 8866 
 8867   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8868   assert(coeffs_start, "coeffs is null");
 8869   Node* zetas_start  = array_element_address(zetas, intcon(0), T_INT);
 8870   assert(zetas_start, "inverseNtt_zetas is null");
 8871   Node* dilithiumAlmostInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP,
 8872                                   OptoRuntime::dilithiumAlmostInverseNtt_Type(),
 8873                                   stubAddr, stubName, TypePtr::BOTTOM,
 8874                                   coeffs_start, zetas_start);
 8875   // return an int
 8876   Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostInverseNtt, TypeFunc::Parms));
 8877   set_result(retvalue);
 8878   return true;
 8879 }
 8880 
 8881 //------------------------------inline_dilithiumNttMult
 8882 bool LibraryCallKit::inline_dilithiumNttMult() {
 8883   address stubAddr;
 8884   const char *stubName;
 8885   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8886   assert(callee()->signature()->size() == 3, "dilithiumNttMult has 3 parameters");
 8887 
 8888   stubAddr = StubRoutines::dilithiumNttMult();
 8889   stubName = "dilithiumNttMult";
 8890   if (!stubAddr) return false;
 8891 
 8892   Node* result          = argument(0);
 8893   Node* ntta            = argument(1);
 8894   Node* nttb            = argument(2);
 8895   Node* zetas           = argument(3);
 8896 
 8897   result = must_be_not_null(result, true);
 8898   ntta = must_be_not_null(ntta, true);
 8899   nttb = must_be_not_null(nttb, true);
 8900   zetas = must_be_not_null(zetas, true);
 8901 
 8902   Node* result_start  = array_element_address(result, intcon(0), T_INT);
 8903   assert(result_start, "result is null");
 8904   Node* ntta_start  = array_element_address(ntta, intcon(0), T_INT);
 8905   assert(ntta_start, "ntta is null");
 8906   Node* nttb_start  = array_element_address(nttb, intcon(0), T_INT);
 8907   assert(nttb_start, "nttb is null");
 8908   Node* dilithiumNttMult = make_runtime_call(RC_LEAF|RC_NO_FP,
 8909                                   OptoRuntime::dilithiumNttMult_Type(),
 8910                                   stubAddr, stubName, TypePtr::BOTTOM,
 8911                                   result_start, ntta_start, nttb_start);
 8912 
 8913   // return an int
 8914   Node* retvalue = _gvn.transform(new ProjNode(dilithiumNttMult, TypeFunc::Parms));
 8915   set_result(retvalue);
 8916 
 8917   return true;
 8918 }
 8919 
 8920 //------------------------------inline_dilithiumMontMulByConstant
 8921 bool LibraryCallKit::inline_dilithiumMontMulByConstant() {
 8922   address stubAddr;
 8923   const char *stubName;
 8924   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8925   assert(callee()->signature()->size() == 2, "dilithiumMontMulByConstant has 2 parameters");
 8926 
 8927   stubAddr = StubRoutines::dilithiumMontMulByConstant();
 8928   stubName = "dilithiumMontMulByConstant";
 8929   if (!stubAddr) return false;
 8930 
 8931   Node* coeffs          = argument(0);
 8932   Node* constant        = argument(1);
 8933 
 8934   coeffs = must_be_not_null(coeffs, true);
 8935 
 8936   Node* coeffs_start  = array_element_address(coeffs, intcon(0), T_INT);
 8937   assert(coeffs_start, "coeffs is null");
 8938   Node* dilithiumMontMulByConstant = make_runtime_call(RC_LEAF|RC_NO_FP,
 8939                                   OptoRuntime::dilithiumMontMulByConstant_Type(),
 8940                                   stubAddr, stubName, TypePtr::BOTTOM,
 8941                                   coeffs_start, constant);
 8942 
 8943   // return an int
 8944   Node* retvalue = _gvn.transform(new ProjNode(dilithiumMontMulByConstant, TypeFunc::Parms));
 8945   set_result(retvalue);
 8946   return true;
 8947 }
 8948 
 8949 
 8950 //------------------------------inline_dilithiumDecomposePoly
 8951 bool LibraryCallKit::inline_dilithiumDecomposePoly() {
 8952   address stubAddr;
 8953   const char *stubName;
 8954   assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support");
 8955   assert(callee()->signature()->size() == 5, "dilithiumDecomposePoly has 5 parameters");
 8956 
 8957   stubAddr = StubRoutines::dilithiumDecomposePoly();
 8958   stubName = "dilithiumDecomposePoly";
 8959   if (!stubAddr) return false;
 8960 
 8961   Node* input          = argument(0);
 8962   Node* lowPart        = argument(1);
 8963   Node* highPart       = argument(2);
 8964   Node* twoGamma2      = argument(3);
 8965   Node* multiplier     = argument(4);
 8966 
 8967   input = must_be_not_null(input, true);
 8968   lowPart = must_be_not_null(lowPart, true);
 8969   highPart = must_be_not_null(highPart, true);
 8970 
 8971   Node* input_start  = array_element_address(input, intcon(0), T_INT);
 8972   assert(input_start, "input is null");
 8973   Node* lowPart_start  = array_element_address(lowPart, intcon(0), T_INT);
 8974   assert(lowPart_start, "lowPart is null");
 8975   Node* highPart_start  = array_element_address(highPart, intcon(0), T_INT);
 8976   assert(highPart_start, "highPart is null");
 8977 
 8978   Node* dilithiumDecomposePoly = make_runtime_call(RC_LEAF|RC_NO_FP,
 8979                                   OptoRuntime::dilithiumDecomposePoly_Type(),
 8980                                   stubAddr, stubName, TypePtr::BOTTOM,
 8981                                   input_start, lowPart_start, highPart_start,
 8982                                   twoGamma2, multiplier);
 8983 
 8984   // return an int
 8985   Node* retvalue = _gvn.transform(new ProjNode(dilithiumDecomposePoly, TypeFunc::Parms));
 8986   set_result(retvalue);
 8987   return true;
 8988 }
 8989 
 8990 bool LibraryCallKit::inline_base64_encodeBlock() {
 8991   address stubAddr;
 8992   const char *stubName;
 8993   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
 8994   assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters");
 8995   stubAddr = StubRoutines::base64_encodeBlock();
 8996   stubName = "encodeBlock";
 8997 
 8998   if (!stubAddr) return false;
 8999   Node* base64obj = argument(0);
 9000   Node* src = argument(1);
 9001   Node* offset = argument(2);
 9002   Node* len = argument(3);
 9003   Node* dest = argument(4);
 9004   Node* dp = argument(5);
 9005   Node* isURL = argument(6);
 9006 
 9007   src = must_be_not_null(src, true);
 9008   dest = must_be_not_null(dest, true);
 9009 
 9010   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 9011   assert(src_start, "source array is null");
 9012   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
 9013   assert(dest_start, "destination array is null");
 9014 
 9015   Node* base64 = make_runtime_call(RC_LEAF,
 9016                                    OptoRuntime::base64_encodeBlock_Type(),
 9017                                    stubAddr, stubName, TypePtr::BOTTOM,
 9018                                    src_start, offset, len, dest_start, dp, isURL);
 9019   return true;
 9020 }
 9021 
 9022 bool LibraryCallKit::inline_base64_decodeBlock() {
 9023   address stubAddr;
 9024   const char *stubName;
 9025   assert(UseBASE64Intrinsics, "need Base64 intrinsics support");
 9026   assert(callee()->signature()->size() == 7, "base64_decodeBlock has 7 parameters");
 9027   stubAddr = StubRoutines::base64_decodeBlock();
 9028   stubName = "decodeBlock";
 9029 
 9030   if (!stubAddr) return false;
 9031   Node* base64obj = argument(0);
 9032   Node* src = argument(1);
 9033   Node* src_offset = argument(2);
 9034   Node* len = argument(3);
 9035   Node* dest = argument(4);
 9036   Node* dest_offset = argument(5);
 9037   Node* isURL = argument(6);
 9038   Node* isMIME = argument(7);
 9039 
 9040   src = must_be_not_null(src, true);
 9041   dest = must_be_not_null(dest, true);
 9042 
 9043   Node* src_start = array_element_address(src, intcon(0), T_BYTE);
 9044   assert(src_start, "source array is null");
 9045   Node* dest_start = array_element_address(dest, intcon(0), T_BYTE);
 9046   assert(dest_start, "destination array is null");
 9047 
 9048   Node* call = make_runtime_call(RC_LEAF,
 9049                                  OptoRuntime::base64_decodeBlock_Type(),
 9050                                  stubAddr, stubName, TypePtr::BOTTOM,
 9051                                  src_start, src_offset, len, dest_start, dest_offset, isURL, isMIME);
 9052   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 9053   set_result(result);
 9054   return true;
 9055 }
 9056 
 9057 bool LibraryCallKit::inline_poly1305_processBlocks() {
 9058   address stubAddr;
 9059   const char *stubName;
 9060   assert(UsePoly1305Intrinsics, "need Poly intrinsics support");
 9061   assert(callee()->signature()->size() == 5, "poly1305_processBlocks has %d parameters", callee()->signature()->size());
 9062   stubAddr = StubRoutines::poly1305_processBlocks();
 9063   stubName = "poly1305_processBlocks";
 9064 
 9065   if (!stubAddr) return false;
 9066   null_check_receiver();  // null-check receiver
 9067   if (stopped())  return true;
 9068 
 9069   Node* input = argument(1);
 9070   Node* input_offset = argument(2);
 9071   Node* len = argument(3);
 9072   Node* alimbs = argument(4);
 9073   Node* rlimbs = argument(5);
 9074 
 9075   input = must_be_not_null(input, true);
 9076   alimbs = must_be_not_null(alimbs, true);
 9077   rlimbs = must_be_not_null(rlimbs, true);
 9078 
 9079   Node* input_start = array_element_address(input, input_offset, T_BYTE);
 9080   assert(input_start, "input array is null");
 9081   Node* acc_start = array_element_address(alimbs, intcon(0), T_LONG);
 9082   assert(acc_start, "acc array is null");
 9083   Node* r_start = array_element_address(rlimbs, intcon(0), T_LONG);
 9084   assert(r_start, "r array is null");
 9085 
 9086   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9087                                  OptoRuntime::poly1305_processBlocks_Type(),
 9088                                  stubAddr, stubName, TypePtr::BOTTOM,
 9089                                  input_start, len, acc_start, r_start);
 9090   return true;
 9091 }
 9092 
 9093 bool LibraryCallKit::inline_intpoly_montgomeryMult_P256() {
 9094   address stubAddr;
 9095   const char *stubName;
 9096   assert(UseIntPolyIntrinsics, "need intpoly intrinsics support");
 9097   assert(callee()->signature()->size() == 3, "intpoly_montgomeryMult_P256 has %d parameters", callee()->signature()->size());
 9098   stubAddr = StubRoutines::intpoly_montgomeryMult_P256();
 9099   stubName = "intpoly_montgomeryMult_P256";
 9100 
 9101   if (!stubAddr) return false;
 9102   null_check_receiver();  // null-check receiver
 9103   if (stopped())  return true;
 9104 
 9105   Node* a = argument(1);
 9106   Node* b = argument(2);
 9107   Node* r = argument(3);
 9108 
 9109   a = must_be_not_null(a, true);
 9110   b = must_be_not_null(b, true);
 9111   r = must_be_not_null(r, true);
 9112 
 9113   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9114   assert(a_start, "a array is null");
 9115   Node* b_start = array_element_address(b, intcon(0), T_LONG);
 9116   assert(b_start, "b array is null");
 9117   Node* r_start = array_element_address(r, intcon(0), T_LONG);
 9118   assert(r_start, "r array is null");
 9119 
 9120   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9121                                  OptoRuntime::intpoly_montgomeryMult_P256_Type(),
 9122                                  stubAddr, stubName, TypePtr::BOTTOM,
 9123                                  a_start, b_start, r_start);
 9124   return true;
 9125 }
 9126 
 9127 bool LibraryCallKit::inline_intpoly_assign() {
 9128   assert(UseIntPolyIntrinsics, "need intpoly intrinsics support");
 9129   assert(callee()->signature()->size() == 3, "intpoly_assign has %d parameters", callee()->signature()->size());
 9130   const char *stubName = "intpoly_assign";
 9131   address stubAddr = StubRoutines::intpoly_assign();
 9132   if (!stubAddr) return false;
 9133 
 9134   Node* set = argument(0);
 9135   Node* a = argument(1);
 9136   Node* b = argument(2);
 9137   Node* arr_length = load_array_length(a);
 9138 
 9139   a = must_be_not_null(a, true);
 9140   b = must_be_not_null(b, true);
 9141 
 9142   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9143   assert(a_start, "a array is null");
 9144   Node* b_start = array_element_address(b, intcon(0), T_LONG);
 9145   assert(b_start, "b array is null");
 9146 
 9147   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9148                                  OptoRuntime::intpoly_assign_Type(),
 9149                                  stubAddr, stubName, TypePtr::BOTTOM,
 9150                                  set, a_start, b_start, arr_length);
 9151   return true;
 9152 }
 9153 
 9154 bool LibraryCallKit::inline_intpoly_mult_25519() {
 9155   address stubAddr;
 9156   const char *stubName;
 9157   assert(UseIntPoly25519Intrinsics, "need intpoly25519 intrinsics support");
 9158   assert(callee()->signature()->size() == 3, "intpoly_mult_25519 has %d parameters", callee()->signature()->size());
 9159   stubAddr = StubRoutines::intpoly_mult_25519();
 9160   stubName = "intpoly_mult_25519";
 9161 
 9162   if (!stubAddr) return false;
 9163   null_check_receiver();  // null-check receiver
 9164   if (stopped())  return true;
 9165 
 9166   Node* a = argument(1);
 9167   Node* b = argument(2);
 9168   Node* r = argument(3);
 9169 
 9170   a = must_be_not_null(a, true);
 9171   b = must_be_not_null(b, true);
 9172   r = must_be_not_null(r, true);
 9173 
 9174   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9175   assert(a_start, "a array is null");
 9176   Node* b_start = array_element_address(b, intcon(0), T_LONG);
 9177   assert(b_start, "b array is null");
 9178   Node* r_start = array_element_address(r, intcon(0), T_LONG);
 9179   assert(r_start, "r array is null");
 9180 
 9181   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9182                                  OptoRuntime::intpoly_mult_25519_Type(),
 9183                                  stubAddr, stubName, TypePtr::BOTTOM,
 9184                                  a_start, b_start, r_start);
 9185   return true;
 9186 }
 9187 
 9188 bool LibraryCallKit::inline_intpoly_square_25519() {
 9189   address stubAddr;
 9190   const char *stubName;
 9191   assert(UseIntPoly25519Intrinsics, "need intpoly25519 intrinsics support");
 9192   assert(callee()->signature()->size() == 2, "intpoly_mult_25519 has %d parameters", callee()->signature()->size());
 9193   stubAddr = StubRoutines::intpoly_square_25519();
 9194   stubName = "intpoly_square_25519";
 9195 
 9196   if (!stubAddr) return false;
 9197   null_check_receiver();  // null-check receiver
 9198   if (stopped())  return true;
 9199 
 9200   Node* a = argument(1);
 9201   Node* r = argument(2);
 9202 
 9203   a = must_be_not_null(a, true);
 9204   r = must_be_not_null(r, true);
 9205 
 9206   Node* a_start = array_element_address(a, intcon(0), T_LONG);
 9207   assert(a_start, "a array is null");
 9208   Node* r_start = array_element_address(r, intcon(0), T_LONG);
 9209   assert(r_start, "r array is null");
 9210 
 9211   Node* call = make_runtime_call(RC_LEAF | RC_NO_FP,
 9212                                  OptoRuntime::intpoly_square_25519_Type(),
 9213                                  stubAddr, stubName, TypePtr::BOTTOM,
 9214                                  a_start, r_start);
 9215   return true;
 9216 }
 9217 
 9218 //------------------------------inline_digestBase_implCompress-----------------------
 9219 //
 9220 // Calculate MD5 for single-block byte[] array.
 9221 // void com.sun.security.provider.MD5.implCompress(byte[] buf, int ofs)
 9222 //
 9223 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
 9224 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
 9225 //
 9226 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
 9227 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
 9228 //
 9229 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array.
 9230 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs)
 9231 //
 9232 // Calculate SHA3 (i.e., SHA3-224 or SHA3-256 or SHA3-384 or SHA3-512) for single-block byte[] array.
 9233 // void com.sun.security.provider.SHA3.implCompress(byte[] buf, int ofs)
 9234 //
 9235 bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
 9236   assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
 9237 
 9238   Node* digestBase_obj = argument(0);
 9239   Node* src            = argument(1); // type oop
 9240   Node* ofs            = argument(2); // type int
 9241 
 9242   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 9243   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 9244     // failed array check
 9245     return false;
 9246   }
 9247   // Figure out the size and type of the elements we will be copying.
 9248   BasicType src_elem = src_type->elem()->array_element_basic_type();
 9249   if (src_elem != T_BYTE) {
 9250     return false;
 9251   }
 9252   // 'src_start' points to src array + offset
 9253   src = must_be_not_null(src, true);
 9254   Node* src_start = array_element_address(src, ofs, src_elem);
 9255   Node* state = nullptr;
 9256   Node* block_size = nullptr;
 9257   address stubAddr;
 9258   const char *stubName;
 9259 
 9260   switch(id) {
 9261   case vmIntrinsics::_md5_implCompress:
 9262     assert(UseMD5Intrinsics, "need MD5 instruction support");
 9263     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9264     stubAddr = StubRoutines::md5_implCompress();
 9265     stubName = "md5_implCompress";
 9266     break;
 9267   case vmIntrinsics::_sha_implCompress:
 9268     assert(UseSHA1Intrinsics, "need SHA1 instruction support");
 9269     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9270     stubAddr = StubRoutines::sha1_implCompress();
 9271     stubName = "sha1_implCompress";
 9272     break;
 9273   case vmIntrinsics::_sha2_implCompress:
 9274     assert(UseSHA256Intrinsics, "need SHA256 instruction support");
 9275     state = get_state_from_digest_object(digestBase_obj, T_INT);
 9276     stubAddr = StubRoutines::sha256_implCompress();
 9277     stubName = "sha256_implCompress";
 9278     break;
 9279   case vmIntrinsics::_sha5_implCompress:
 9280     assert(UseSHA512Intrinsics, "need SHA512 instruction support");
 9281     state = get_state_from_digest_object(digestBase_obj, T_LONG);
 9282     stubAddr = StubRoutines::sha512_implCompress();
 9283     stubName = "sha512_implCompress";
 9284     break;
 9285   case vmIntrinsics::_sha3_implCompress:
 9286     assert(UseSHA3Intrinsics, "need SHA3 instruction support");
 9287     state = get_state_from_digest_object(digestBase_obj, T_LONG);
 9288     stubAddr = StubRoutines::sha3_implCompress();
 9289     stubName = "sha3_implCompress";
 9290     block_size = get_block_size_from_digest_object(digestBase_obj);
 9291     if (block_size == nullptr) return false;
 9292     break;
 9293   default:
 9294     fatal_unexpected_iid(id);
 9295     return false;
 9296   }
 9297   if (state == nullptr) return false;
 9298 
 9299   assert(stubAddr != nullptr, "Stub %s is not generated", stubName);
 9300   if (stubAddr == nullptr) return false;
 9301 
 9302   // Call the stub.
 9303   Node* call;
 9304   if (block_size == nullptr) {
 9305     call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(false),
 9306                              stubAddr, stubName, TypePtr::BOTTOM,
 9307                              src_start, state);
 9308   } else {
 9309     call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(true),
 9310                              stubAddr, stubName, TypePtr::BOTTOM,
 9311                              src_start, state, block_size);
 9312   }
 9313 
 9314   return true;
 9315 }
 9316 
 9317 //------------------------------inline_keccak
 9318 bool LibraryCallKit::inline_keccak(vmIntrinsics::ID id) {
 9319   address stubAddr = nullptr;
 9320   const char *stubName;
 9321   assert(UseSHA3Intrinsics, "need SHA3 intrinsics support");
 9322   assert((id == vmIntrinsics::_double_keccak && callee()->signature()->size() == 2) ||
 9323          (id == vmIntrinsics::_quad_keccak && callee()->signature()->size() == 4),
 9324           "double_keccak wrong number of parameters");
 9325 
 9326   int parmCnt = 0;
 9327   switch (id) {
 9328     case vmIntrinsics::_double_keccak:
 9329       stubAddr = StubRoutines::double_keccak();
 9330       stubName = "double_keccak";
 9331       parmCnt = 2;
 9332       break;
 9333     case vmIntrinsics::_quad_keccak:
 9334       stubAddr = StubRoutines::quad_keccak();
 9335       stubName = "quad_keccak";
 9336       parmCnt = 4;
 9337       break;
 9338     default:
 9339       ShouldNotReachHere();
 9340   }
 9341 
 9342   if (!stubAddr) return false;
 9343 
 9344   Node* state[4];
 9345   for (int i = 0; i<parmCnt; i++) {
 9346       state[i] = must_be_not_null(argument(i), true);
 9347       state[i] = array_element_address(state[i], intcon(0), T_LONG);
 9348       assert(state[i], "state[%d] is null", i);
 9349   }
 9350 
 9351   Node* keccak;
 9352   switch (id) {
 9353     case vmIntrinsics::_double_keccak:
 9354       keccak = make_runtime_call(RC_LEAF|RC_NO_FP,
 9355                                   OptoRuntime::double_keccak_Type(),
 9356                                   stubAddr, stubName, TypePtr::BOTTOM,
 9357                                   state[0], state[1]);
 9358       break;
 9359     case vmIntrinsics::_quad_keccak:
 9360       keccak = make_runtime_call(RC_LEAF|RC_NO_FP,
 9361                                   OptoRuntime::quad_keccak_Type(),
 9362                                   stubAddr, stubName, TypePtr::BOTTOM,
 9363                                   state[0], state[1], state[2], state[3]);
 9364       break;
 9365     default:
 9366       ShouldNotReachHere();
 9367   }
 9368 
 9369   // return an int
 9370   Node* retvalue = _gvn.transform(new ProjNode(keccak, TypeFunc::Parms));
 9371   set_result(retvalue);
 9372   return true;
 9373 }
 9374 
 9375 
 9376 //------------------------------inline_digestBase_implCompressMB-----------------------
 9377 //
 9378 // Calculate MD5/SHA/SHA2/SHA5/SHA3 for multi-block byte[] array.
 9379 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
 9380 //
 9381 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
 9382   assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics,
 9383          "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support");
 9384   assert((uint)predicate < 5, "sanity");
 9385   assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
 9386 
 9387   Node* digestBase_obj = argument(0); // The receiver was checked for null already.
 9388   Node* src            = argument(1); // byte[] array
 9389   Node* ofs            = argument(2); // type int
 9390   Node* limit          = argument(3); // type int
 9391 
 9392   const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr();
 9393   if (src_type == nullptr || src_type->elem() == Type::BOTTOM) {
 9394     // failed array check
 9395     return false;
 9396   }
 9397   // Figure out the size and type of the elements we will be copying.
 9398   BasicType src_elem = src_type->elem()->array_element_basic_type();
 9399   if (src_elem != T_BYTE) {
 9400     return false;
 9401   }
 9402   // 'src_start' points to src array + offset
 9403   src = must_be_not_null(src, false);
 9404   Node* src_start = array_element_address(src, ofs, src_elem);
 9405 
 9406   const char* klass_digestBase_name = nullptr;
 9407   const char* stub_name = nullptr;
 9408   address     stub_addr = nullptr;
 9409   BasicType elem_type = T_INT;
 9410 
 9411   switch (predicate) {
 9412   case 0:
 9413     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_md5_implCompress)) {
 9414       klass_digestBase_name = "sun/security/provider/MD5";
 9415       stub_name = "md5_implCompressMB";
 9416       stub_addr = StubRoutines::md5_implCompressMB();
 9417     }
 9418     break;
 9419   case 1:
 9420     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha_implCompress)) {
 9421       klass_digestBase_name = "sun/security/provider/SHA";
 9422       stub_name = "sha1_implCompressMB";
 9423       stub_addr = StubRoutines::sha1_implCompressMB();
 9424     }
 9425     break;
 9426   case 2:
 9427     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha2_implCompress)) {
 9428       klass_digestBase_name = "sun/security/provider/SHA2";
 9429       stub_name = "sha256_implCompressMB";
 9430       stub_addr = StubRoutines::sha256_implCompressMB();
 9431     }
 9432     break;
 9433   case 3:
 9434     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha5_implCompress)) {
 9435       klass_digestBase_name = "sun/security/provider/SHA5";
 9436       stub_name = "sha512_implCompressMB";
 9437       stub_addr = StubRoutines::sha512_implCompressMB();
 9438       elem_type = T_LONG;
 9439     }
 9440     break;
 9441   case 4:
 9442     if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha3_implCompress)) {
 9443       klass_digestBase_name = "sun/security/provider/SHA3";
 9444       stub_name = "sha3_implCompressMB";
 9445       stub_addr = StubRoutines::sha3_implCompressMB();
 9446       elem_type = T_LONG;
 9447     }
 9448     break;
 9449   default:
 9450     fatal("unknown DigestBase intrinsic predicate: %d", predicate);
 9451   }
 9452   if (klass_digestBase_name != nullptr) {
 9453     assert(stub_addr != nullptr, "Stub is generated");
 9454     if (stub_addr == nullptr) return false;
 9455 
 9456     // get DigestBase klass to lookup for SHA klass
 9457     const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
 9458     assert(tinst != nullptr, "digestBase_obj is not instance???");
 9459     assert(tinst->is_loaded(), "DigestBase is not loaded");
 9460 
 9461     ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
 9462     assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
 9463     ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
 9464     return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
 9465   }
 9466   return false;
 9467 }
 9468 
 9469 //------------------------------inline_digestBase_implCompressMB-----------------------
 9470 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
 9471                                                       BasicType elem_type, address stubAddr, const char *stubName,
 9472                                                       Node* src_start, Node* ofs, Node* limit) {
 9473   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
 9474   const TypeOopPtr* xtype = aklass->as_subtype_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
 9475   Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
 9476   digest_obj = _gvn.transform(digest_obj);
 9477 
 9478   Node* state = get_state_from_digest_object(digest_obj, elem_type);
 9479   if (state == nullptr) return false;
 9480 
 9481   Node* block_size = nullptr;
 9482   if (strcmp("sha3_implCompressMB", stubName) == 0) {
 9483     block_size = get_block_size_from_digest_object(digest_obj);
 9484     if (block_size == nullptr) return false;
 9485   }
 9486 
 9487   // Call the stub.
 9488   Node* call;
 9489   if (block_size == nullptr) {
 9490     call = make_runtime_call(RC_LEAF|RC_NO_FP,
 9491                              OptoRuntime::digestBase_implCompressMB_Type(false),
 9492                              stubAddr, stubName, TypePtr::BOTTOM,
 9493                              src_start, state, ofs, limit);
 9494   } else {
 9495      call = make_runtime_call(RC_LEAF|RC_NO_FP,
 9496                              OptoRuntime::digestBase_implCompressMB_Type(true),
 9497                              stubAddr, stubName, TypePtr::BOTTOM,
 9498                              src_start, state, block_size, ofs, limit);
 9499   }
 9500 
 9501   // return ofs (int)
 9502   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
 9503   set_result(result);
 9504 
 9505   return true;
 9506 }
 9507 
 9508 //------------------------------inline_galoisCounterMode_AESCrypt-----------------------
 9509 bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() {
 9510   assert(UseAES, "need AES instruction support");
 9511   address stubAddr = nullptr;
 9512   const char *stubName = nullptr;
 9513   stubAddr = StubRoutines::galoisCounterMode_AESCrypt();
 9514   stubName = "galoisCounterMode_AESCrypt";
 9515 
 9516   if (stubAddr == nullptr) return false;
 9517 
 9518   Node* in      = argument(0);
 9519   Node* inOfs   = argument(1);
 9520   Node* len     = argument(2);
 9521   Node* ct      = argument(3);
 9522   Node* ctOfs   = argument(4);
 9523   Node* out     = argument(5);
 9524   Node* outOfs  = argument(6);
 9525   Node* gctr_object = argument(7);
 9526   Node* ghash_object = argument(8);
 9527 
 9528   // (1) in, ct and out are arrays.
 9529   const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr();
 9530   const TypeAryPtr* ct_type = ct->Value(&_gvn)->isa_aryptr();
 9531   const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr();
 9532   assert( in_type != nullptr &&  in_type->elem() != Type::BOTTOM &&
 9533           ct_type != nullptr &&  ct_type->elem() != Type::BOTTOM &&
 9534          out_type != nullptr && out_type->elem() != Type::BOTTOM, "args are strange");
 9535 
 9536   // checks are the responsibility of the caller
 9537   Node* in_start = in;
 9538   Node* ct_start = ct;
 9539   Node* out_start = out;
 9540   if (inOfs != nullptr || ctOfs != nullptr || outOfs != nullptr) {
 9541     assert(inOfs != nullptr && ctOfs != nullptr && outOfs != nullptr, "");
 9542     in_start = array_element_address(in, inOfs, T_BYTE);
 9543     ct_start = array_element_address(ct, ctOfs, T_BYTE);
 9544     out_start = array_element_address(out, outOfs, T_BYTE);
 9545   }
 9546 
 9547   // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
 9548   // (because of the predicated logic executed earlier).
 9549   // so we cast it here safely.
 9550   // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
 9551   Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 9552   Node* counter = load_field_from_object(gctr_object, "counter", "[B");
 9553   Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J");
 9554   Node* state = load_field_from_object(ghash_object, "state", "[J");
 9555 
 9556   if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) {
 9557     return false;
 9558   }
 9559   // cast it to what we know it will be at runtime
 9560   const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr();
 9561   assert(tinst != nullptr, "GCTR obj is null");
 9562   assert(tinst->is_loaded(), "GCTR obj is not loaded");
 9563   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 9564   assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
 9565   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 9566   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
 9567   const TypeOopPtr* xtype = aklass->as_exact_instance_type();
 9568   Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype);
 9569   aescrypt_object = _gvn.transform(aescrypt_object);
 9570   // we need to get the start of the aescrypt_object's expanded key array
 9571   Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object, /* is_decrypt */ false);
 9572   if (k_start == nullptr) return false;
 9573   // similarly, get the start address of the r vector
 9574   Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE);
 9575   Node* state_start = array_element_address(state, intcon(0), T_LONG);
 9576   Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG);
 9577 
 9578 
 9579   // Call the stub, passing params
 9580   Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
 9581                                OptoRuntime::galoisCounterMode_aescrypt_Type(),
 9582                                stubAddr, stubName, TypePtr::BOTTOM,
 9583                                in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start);
 9584 
 9585   // return cipher length (int)
 9586   Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms));
 9587   set_result(retvalue);
 9588 
 9589   return true;
 9590 }
 9591 
 9592 //----------------------------inline_galoisCounterMode_AESCrypt_predicate----------------------------
 9593 // Return node representing slow path of predicate check.
 9594 // the pseudo code we want to emulate with this predicate is:
 9595 // for encryption:
 9596 //    if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
 9597 // for decryption:
 9598 //    if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
 9599 //    note cipher==plain is more conservative than the original java code but that's OK
 9600 //
 9601 
 9602 Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() {
 9603   // The receiver was checked for null already.
 9604   Node* objGCTR = argument(7);
 9605   // Load embeddedCipher field of GCTR object.
 9606   Node* embeddedCipherObj = load_field_from_object(objGCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;");
 9607   assert(embeddedCipherObj != nullptr, "embeddedCipherObj is null");
 9608 
 9609   // get AESCrypt klass for instanceOf check
 9610   // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
 9611   // will have same classloader as CipherBlockChaining object
 9612   const TypeInstPtr* tinst = _gvn.type(objGCTR)->isa_instptr();
 9613   assert(tinst != nullptr, "GCTR obj is null");
 9614   assert(tinst->is_loaded(), "GCTR obj is not loaded");
 9615 
 9616   // we want to do an instanceof comparison against the AESCrypt class
 9617   ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AES_Crypt"));
 9618   if (!klass_AESCrypt->is_loaded()) {
 9619     // if AESCrypt is not even loaded, we never take the intrinsic fast path
 9620     Node* ctrl = control();
 9621     set_control(top()); // no regular fast path
 9622     return ctrl;
 9623   }
 9624 
 9625   ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
 9626   Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt)));
 9627   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 9628   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 9629   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 9630 
 9631   return instof_false; // even if it is null
 9632 }
 9633 
 9634 //------------------------------get_state_from_digest_object-----------------------
 9635 Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) {
 9636   const char* state_type;
 9637   switch (elem_type) {
 9638     case T_BYTE: state_type = "[B"; break;
 9639     case T_INT:  state_type = "[I"; break;
 9640     case T_LONG: state_type = "[J"; break;
 9641     default: ShouldNotReachHere();
 9642   }
 9643   Node* digest_state = load_field_from_object(digest_object, "state", state_type);
 9644   assert (digest_state != nullptr, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3");
 9645   if (digest_state == nullptr) return (Node *) nullptr;
 9646 
 9647   // now have the array, need to get the start address of the state array
 9648   Node* state = array_element_address(digest_state, intcon(0), elem_type);
 9649   return state;
 9650 }
 9651 
 9652 //------------------------------get_block_size_from_sha3_object----------------------------------
 9653 Node * LibraryCallKit::get_block_size_from_digest_object(Node *digest_object) {
 9654   Node* block_size = load_field_from_object(digest_object, "blockSize", "I");
 9655   assert (block_size != nullptr, "sanity");
 9656   return block_size;
 9657 }
 9658 
 9659 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
 9660 // Return node representing slow path of predicate check.
 9661 // the pseudo code we want to emulate with this predicate is:
 9662 //    if (digestBaseObj instanceof MD5/SHA/SHA2/SHA5/SHA3) do_intrinsic, else do_javapath
 9663 //
 9664 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
 9665   assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics,
 9666          "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support");
 9667   assert((uint)predicate < 5, "sanity");
 9668 
 9669   // The receiver was checked for null already.
 9670   Node* digestBaseObj = argument(0);
 9671 
 9672   // get DigestBase klass for instanceOf check
 9673   const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr();
 9674   assert(tinst != nullptr, "digestBaseObj is null");
 9675   assert(tinst->is_loaded(), "DigestBase is not loaded");
 9676 
 9677   const char* klass_name = nullptr;
 9678   switch (predicate) {
 9679   case 0:
 9680     if (UseMD5Intrinsics) {
 9681       // we want to do an instanceof comparison against the MD5 class
 9682       klass_name = "sun/security/provider/MD5";
 9683     }
 9684     break;
 9685   case 1:
 9686     if (UseSHA1Intrinsics) {
 9687       // we want to do an instanceof comparison against the SHA class
 9688       klass_name = "sun/security/provider/SHA";
 9689     }
 9690     break;
 9691   case 2:
 9692     if (UseSHA256Intrinsics) {
 9693       // we want to do an instanceof comparison against the SHA2 class
 9694       klass_name = "sun/security/provider/SHA2";
 9695     }
 9696     break;
 9697   case 3:
 9698     if (UseSHA512Intrinsics) {
 9699       // we want to do an instanceof comparison against the SHA5 class
 9700       klass_name = "sun/security/provider/SHA5";
 9701     }
 9702     break;
 9703   case 4:
 9704     if (UseSHA3Intrinsics) {
 9705       // we want to do an instanceof comparison against the SHA3 class
 9706       klass_name = "sun/security/provider/SHA3";
 9707     }
 9708     break;
 9709   default:
 9710     fatal("unknown SHA intrinsic predicate: %d", predicate);
 9711   }
 9712 
 9713   ciKlass* klass = nullptr;
 9714   if (klass_name != nullptr) {
 9715     klass = tinst->instance_klass()->find_klass(ciSymbol::make(klass_name));
 9716   }
 9717   if ((klass == nullptr) || !klass->is_loaded()) {
 9718     // if none of MD5/SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path
 9719     Node* ctrl = control();
 9720     set_control(top()); // no intrinsic path
 9721     return ctrl;
 9722   }
 9723   ciInstanceKlass* instklass = klass->as_instance_klass();
 9724 
 9725   Node* instof = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass)));
 9726   Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1)));
 9727   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
 9728   Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN);
 9729 
 9730   return instof_false;  // even if it is null
 9731 }
 9732 
 9733 //-------------inline_fma-----------------------------------
 9734 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) {
 9735   Node *a = nullptr;
 9736   Node *b = nullptr;
 9737   Node *c = nullptr;
 9738   Node* result = nullptr;
 9739   switch (id) {
 9740   case vmIntrinsics::_fmaD:
 9741     assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each.");
 9742     // no receiver since it is static method
 9743     a = argument(0);
 9744     b = argument(2);
 9745     c = argument(4);
 9746     result = _gvn.transform(new FmaDNode(a, b, c));
 9747     break;
 9748   case vmIntrinsics::_fmaF:
 9749     assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each.");
 9750     a = argument(0);
 9751     b = argument(1);
 9752     c = argument(2);
 9753     result = _gvn.transform(new FmaFNode(a, b, c));
 9754     break;
 9755   default:
 9756     fatal_unexpected_iid(id);  break;
 9757   }
 9758   set_result(result);
 9759   return true;
 9760 }
 9761 
 9762 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) {
 9763   // argument(0) is receiver
 9764   Node* codePoint = argument(1);
 9765   Node* n = nullptr;
 9766 
 9767   switch (id) {
 9768     case vmIntrinsics::_isDigit :
 9769       n = new DigitNode(control(), codePoint);
 9770       break;
 9771     case vmIntrinsics::_isLowerCase :
 9772       n = new LowerCaseNode(control(), codePoint);
 9773       break;
 9774     case vmIntrinsics::_isUpperCase :
 9775       n = new UpperCaseNode(control(), codePoint);
 9776       break;
 9777     case vmIntrinsics::_isWhitespace :
 9778       n = new WhitespaceNode(control(), codePoint);
 9779       break;
 9780     default:
 9781       fatal_unexpected_iid(id);
 9782   }
 9783 
 9784   set_result(_gvn.transform(n));
 9785   return true;
 9786 }
 9787 
 9788 bool LibraryCallKit::inline_profileBoolean() {
 9789   Node* counts = argument(1);
 9790   const TypeAryPtr* ary = nullptr;
 9791   ciArray* aobj = nullptr;
 9792   if (counts->is_Con()
 9793       && (ary = counts->bottom_type()->isa_aryptr()) != nullptr
 9794       && (aobj = ary->const_oop()->as_array()) != nullptr
 9795       && (aobj->length() == 2)) {
 9796     // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively.
 9797     jint false_cnt = aobj->element_value(0).as_int();
 9798     jint  true_cnt = aobj->element_value(1).as_int();
 9799 
 9800     if (C->log() != nullptr) {
 9801       C->log()->elem("observe source='profileBoolean' false='%d' true='%d'",
 9802                      false_cnt, true_cnt);
 9803     }
 9804 
 9805     if (false_cnt + true_cnt == 0) {
 9806       // According to profile, never executed.
 9807       uncommon_trap_exact(Deoptimization::Reason_intrinsic,
 9808                           Deoptimization::Action_reinterpret);
 9809       return true;
 9810     }
 9811 
 9812     // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt)
 9813     // is a number of each value occurrences.
 9814     Node* result = argument(0);
 9815     if (false_cnt == 0 || true_cnt == 0) {
 9816       // According to profile, one value has been never seen.
 9817       int expected_val = (false_cnt == 0) ? 1 : 0;
 9818 
 9819       Node* cmp  = _gvn.transform(new CmpINode(result, intcon(expected_val)));
 9820       Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
 9821 
 9822       IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN);
 9823       Node* fast_path = _gvn.transform(new IfTrueNode(check));
 9824       Node* slow_path = _gvn.transform(new IfFalseNode(check));
 9825 
 9826       { // Slow path: uncommon trap for never seen value and then reexecute
 9827         // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows
 9828         // the value has been seen at least once.
 9829         PreserveJVMState pjvms(this);
 9830         PreserveReexecuteState preexecs(this);
 9831         jvms()->set_should_reexecute(true);
 9832 
 9833         set_control(slow_path);
 9834         set_i_o(i_o());
 9835 
 9836         uncommon_trap_exact(Deoptimization::Reason_intrinsic,
 9837                             Deoptimization::Action_reinterpret);
 9838       }
 9839       // The guard for never seen value enables sharpening of the result and
 9840       // returning a constant. It allows to eliminate branches on the same value
 9841       // later on.
 9842       set_control(fast_path);
 9843       result = intcon(expected_val);
 9844     }
 9845     // Stop profiling.
 9846     // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode.
 9847     // By replacing method body with profile data (represented as ProfileBooleanNode
 9848     // on IR level) we effectively disable profiling.
 9849     // It enables full speed execution once optimized code is generated.
 9850     Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt));
 9851     C->record_for_igvn(profile);
 9852     set_result(profile);
 9853     return true;
 9854   } else {
 9855     // Continue profiling.
 9856     // Profile data isn't available at the moment. So, execute method's bytecode version.
 9857     // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod
 9858     // is compiled and counters aren't available since corresponding MethodHandle
 9859     // isn't a compile-time constant.
 9860     return false;
 9861   }
 9862 }
 9863 
 9864 bool LibraryCallKit::inline_isCompileConstant() {
 9865   Node* n = argument(0);
 9866   set_result(n->is_Con() ? intcon(1) : intcon(0));
 9867   return true;
 9868 }
 9869 
 9870 //------------------------------- inline_getObjectSize --------------------------------------
 9871 //
 9872 // Calculate the runtime size of the object/array.
 9873 //   native long sun.instrument.InstrumentationImpl.getObjectSize0(long nativeAgent, Object objectToSize);
 9874 //
 9875 bool LibraryCallKit::inline_getObjectSize() {
 9876   Node* obj = argument(3);
 9877   Node* klass_node = load_object_klass(obj);
 9878 
 9879   jint  layout_con = Klass::_lh_neutral_value;
 9880   Node* layout_val = get_layout_helper(klass_node, layout_con);
 9881   int   layout_is_con = (layout_val == nullptr);
 9882 
 9883   if (layout_is_con) {
 9884     // Layout helper is constant, can figure out things at compile time.
 9885 
 9886     if (Klass::layout_helper_is_instance(layout_con)) {
 9887       // Instance case:  layout_con contains the size itself.
 9888       Node *size = longcon(Klass::layout_helper_size_in_bytes(layout_con));
 9889       set_result(size);
 9890     } else {
 9891       // Array case: size is round(header + element_size*arraylength).
 9892       // Since arraylength is different for every array instance, we have to
 9893       // compute the whole thing at runtime.
 9894 
 9895       Node* arr_length = load_array_length(obj);
 9896 
 9897       int round_mask = MinObjAlignmentInBytes - 1;
 9898       int hsize  = Klass::layout_helper_header_size(layout_con);
 9899       int eshift = Klass::layout_helper_log2_element_size(layout_con);
 9900 
 9901       if ((round_mask & ~right_n_bits(eshift)) == 0) {
 9902         round_mask = 0;  // strength-reduce it if it goes away completely
 9903       }
 9904       assert((hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded");
 9905       Node* header_size = intcon(hsize + round_mask);
 9906 
 9907       Node* lengthx = ConvI2X(arr_length);
 9908       Node* headerx = ConvI2X(header_size);
 9909 
 9910       Node* abody = lengthx;
 9911       if (eshift != 0) {
 9912         abody = _gvn.transform(new LShiftXNode(lengthx, intcon(eshift)));
 9913       }
 9914       Node* size = _gvn.transform( new AddXNode(headerx, abody) );
 9915       if (round_mask != 0) {
 9916         size = _gvn.transform( new AndXNode(size, MakeConX(~round_mask)) );
 9917       }
 9918       size = ConvX2L(size);
 9919       set_result(size);
 9920     }
 9921   } else {
 9922     // Layout helper is not constant, need to test for array-ness at runtime.
 9923 
 9924     enum { _instance_path = 1, _array_path, PATH_LIMIT };
 9925     RegionNode* result_reg = new RegionNode(PATH_LIMIT);
 9926     PhiNode* result_val = new PhiNode(result_reg, TypeLong::LONG);
 9927     record_for_igvn(result_reg);
 9928 
 9929     Node* array_ctl = generate_array_guard(klass_node, nullptr, &obj);
 9930     if (array_ctl != nullptr) {
 9931       // Array case: size is round(header + element_size*arraylength).
 9932       // Since arraylength is different for every array instance, we have to
 9933       // compute the whole thing at runtime.
 9934 
 9935       PreserveJVMState pjvms(this);
 9936       set_control(array_ctl);
 9937       Node* arr_length = load_array_length(obj);
 9938 
 9939       int round_mask = MinObjAlignmentInBytes - 1;
 9940       Node* mask = intcon(round_mask);
 9941 
 9942       Node* hss = intcon(Klass::_lh_header_size_shift);
 9943       Node* hsm = intcon(Klass::_lh_header_size_mask);
 9944       Node* header_size = _gvn.transform(new URShiftINode(layout_val, hss));
 9945       header_size = _gvn.transform(new AndINode(header_size, hsm));
 9946       header_size = _gvn.transform(new AddINode(header_size, mask));
 9947 
 9948       // There is no need to mask or shift this value.
 9949       // The semantics of LShiftINode include an implicit mask to 0x1F.
 9950       assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place");
 9951       Node* elem_shift = layout_val;
 9952 
 9953       Node* lengthx = ConvI2X(arr_length);
 9954       Node* headerx = ConvI2X(header_size);
 9955 
 9956       Node* abody = _gvn.transform(new LShiftXNode(lengthx, elem_shift));
 9957       Node* size = _gvn.transform(new AddXNode(headerx, abody));
 9958       if (round_mask != 0) {
 9959         size = _gvn.transform(new AndXNode(size, MakeConX(~round_mask)));
 9960       }
 9961       size = ConvX2L(size);
 9962 
 9963       result_reg->init_req(_array_path, control());
 9964       result_val->init_req(_array_path, size);
 9965     }
 9966 
 9967     if (!stopped()) {
 9968       // Instance case: the layout helper gives us instance size almost directly,
 9969       // but we need to mask out the _lh_instance_slow_path_bit.
 9970       Node* size = ConvI2X(layout_val);
 9971       assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
 9972       Node* mask = MakeConX(~(intptr_t) right_n_bits(LogBytesPerLong));
 9973       size = _gvn.transform(new AndXNode(size, mask));
 9974       size = ConvX2L(size);
 9975 
 9976       result_reg->init_req(_instance_path, control());
 9977       result_val->init_req(_instance_path, size);
 9978     }
 9979 
 9980     set_result(result_reg, result_val);
 9981   }
 9982 
 9983   return true;
 9984 }
 9985 
 9986 //------------------------------- inline_blackhole --------------------------------------
 9987 //
 9988 // Make sure all arguments to this node are alive.
 9989 // This matches methods that were requested to be blackholed through compile commands.
 9990 //
 9991 bool LibraryCallKit::inline_blackhole() {
 9992   assert(callee()->is_static(), "Should have been checked before: only static methods here");
 9993   assert(callee()->is_empty(), "Should have been checked before: only empty methods here");
 9994   assert(callee()->holder()->is_loaded(), "Should have been checked before: only methods for loaded classes here");
 9995 
 9996   // Blackhole node pinches only the control, not memory. This allows
 9997   // the blackhole to be pinned in the loop that computes blackholed
 9998   // values, but have no other side effects, like breaking the optimizations
 9999   // across the blackhole.
10000 
10001   Node* bh = _gvn.transform(new BlackholeNode(control()));
10002   set_control(_gvn.transform(new ProjNode(bh, TypeFunc::Control)));
10003 
10004   // Bind call arguments as blackhole arguments to keep them alive
10005   uint nargs = callee()->arg_size();
10006   for (uint i = 0; i < nargs; i++) {
10007     bh->add_req(argument(i));
10008   }
10009 
10010   return true;
10011 }
10012 
10013 Node* LibraryCallKit::unbox_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* box) {
10014   const TypeInstPtr* box_type = _gvn.type(box)->isa_instptr();
10015   if (box_type == nullptr || box_type->instance_klass() != float16_box_type->instance_klass()) {
10016     return nullptr; // box klass is not Float16
10017   }
10018 
10019   // Null check; get notnull casted pointer
10020   Node* null_ctl = top();
10021   Node* not_null_box = null_check_oop(box, &null_ctl, true);
10022   // If not_null_box is dead, only null-path is taken
10023   if (stopped()) {
10024     set_control(null_ctl);
10025     return nullptr;
10026   }
10027   assert(not_null_box->bottom_type()->is_instptr()->maybe_null() == false, "");
10028   const TypePtr* adr_type = C->alias_type(field)->adr_type();
10029   Node* adr = basic_plus_adr(not_null_box, field->offset_in_bytes());
10030   return access_load_at(not_null_box, adr, adr_type, TypeInt::SHORT, T_SHORT, IN_HEAP);
10031 }
10032 
10033 Node* LibraryCallKit::box_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* value) {
10034   PreserveReexecuteState preexecs(this);
10035   jvms()->set_should_reexecute(true);
10036 
10037   const TypeKlassPtr* klass_type = float16_box_type->as_klass_type();
10038   Node* klass_node = makecon(klass_type);
10039   Node* box = new_instance(klass_node);
10040 
10041   Node* value_field = basic_plus_adr(box, field->offset_in_bytes());
10042   const TypePtr* value_adr_type = value_field->bottom_type()->is_ptr();
10043 
10044   Node* field_store = _gvn.transform(access_store_at(box,
10045                                                      value_field,
10046                                                      value_adr_type,
10047                                                      value,
10048                                                      TypeInt::SHORT,
10049                                                      T_SHORT,
10050                                                      IN_HEAP));
10051   set_memory(field_store, value_adr_type);
10052   return box;
10053 }
10054 
10055 bool LibraryCallKit::inline_fp16_operations(vmIntrinsics::ID id, int num_args) {
10056   if (!Matcher::match_rule_supported(Op_ReinterpretS2HF) ||
10057       !Matcher::match_rule_supported(Op_ReinterpretHF2S)) {
10058     return false;
10059   }
10060 
10061   const TypeInstPtr* box_type = _gvn.type(argument(0))->isa_instptr();
10062   if (box_type == nullptr || box_type->const_oop() == nullptr) {
10063     return false;
10064   }
10065 
10066   ciInstanceKlass* float16_klass = box_type->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
10067   const TypeInstPtr* float16_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, float16_klass);
10068   ciField* field = float16_klass->get_field_by_name(ciSymbols::value_name(),
10069                                                     ciSymbols::short_signature(),
10070                                                     false);
10071   assert(field != nullptr, "");
10072 
10073   // Transformed nodes
10074   Node* fld1 = nullptr;
10075   Node* fld2 = nullptr;
10076   Node* fld3 = nullptr;
10077   switch(num_args) {
10078     case 3:
10079       fld3 = unbox_fp16_value(float16_box_type, field, argument(3));
10080       if (fld3 == nullptr) {
10081         return false;
10082       }
10083       fld3 = _gvn.transform(new ReinterpretS2HFNode(fld3));
10084     // fall-through
10085     case 2:
10086       fld2 = unbox_fp16_value(float16_box_type, field, argument(2));
10087       if (fld2 == nullptr) {
10088         return false;
10089       }
10090       fld2 = _gvn.transform(new ReinterpretS2HFNode(fld2));
10091     // fall-through
10092     case 1:
10093       fld1 = unbox_fp16_value(float16_box_type, field, argument(1));
10094       if (fld1 == nullptr) {
10095         return false;
10096       }
10097       fld1 = _gvn.transform(new ReinterpretS2HFNode(fld1));
10098       break;
10099     default: fatal("Unsupported number of arguments %d", num_args);
10100   }
10101 
10102   Node* result = nullptr;
10103   switch (id) {
10104     // Unary operations
10105     case vmIntrinsics::_sqrt_float16:
10106       result = _gvn.transform(new SqrtHFNode(C, control(), fld1));
10107       break;
10108     // Ternary operations
10109     case vmIntrinsics::_fma_float16:
10110       result = _gvn.transform(new FmaHFNode(fld1, fld2, fld3));
10111       break;
10112     default:
10113       fatal_unexpected_iid(id);
10114       break;
10115   }
10116   result = _gvn.transform(new ReinterpretHF2SNode(result));
10117   set_result(box_fp16_value(float16_box_type, field, result));
10118   return true;
10119 }
10120