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