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/ciArrayKlass.hpp" 27 #include "ci/ciFlatArrayKlass.hpp" 28 #include "ci/ciInstanceKlass.hpp" 29 #include "ci/ciSymbols.hpp" 30 #include "ci/ciUtilities.inline.hpp" 31 #include "classfile/vmIntrinsics.hpp" 32 #include "compiler/compileBroker.hpp" 33 #include "compiler/compileLog.hpp" 34 #include "gc/shared/barrierSet.hpp" 35 #include "gc/shared/c2/barrierSetC2.hpp" 36 #include "jfr/support/jfrIntrinsics.hpp" 37 #include "memory/resourceArea.hpp" 38 #include "oops/accessDecorators.hpp" 39 #include "oops/klass.inline.hpp" 40 #include "oops/layoutKind.hpp" 41 #include "oops/objArrayKlass.hpp" 42 #include "opto/addnode.hpp" 43 #include "opto/arraycopynode.hpp" 44 #include "opto/c2compiler.hpp" 45 #include "opto/castnode.hpp" 46 #include "opto/cfgnode.hpp" 47 #include "opto/convertnode.hpp" 48 #include "opto/countbitsnode.hpp" 49 #include "opto/graphKit.hpp" 50 #include "opto/idealKit.hpp" 51 #include "opto/inlinetypenode.hpp" 52 #include "opto/library_call.hpp" 53 #include "opto/mathexactnode.hpp" 54 #include "opto/mulnode.hpp" 55 #include "opto/narrowptrnode.hpp" 56 #include "opto/opaquenode.hpp" 57 #include "opto/opcodes.hpp" 58 #include "opto/parse.hpp" 59 #include "opto/rootnode.hpp" 60 #include "opto/runtime.hpp" 61 #include "opto/subnode.hpp" 62 #include "opto/type.hpp" 63 #include "opto/vectornode.hpp" 64 #include "prims/jvmtiExport.hpp" 65 #include "prims/jvmtiThreadState.hpp" 66 #include "prims/unsafe.hpp" 67 #include "runtime/jniHandles.inline.hpp" 68 #include "runtime/objectMonitor.hpp" 69 #include "runtime/sharedRuntime.hpp" 70 #include "runtime/stubRoutines.hpp" 71 #include "utilities/globalDefinitions.hpp" 72 #include "utilities/macros.hpp" 73 #include "utilities/powerOfTwo.hpp" 74 75 //---------------------------make_vm_intrinsic---------------------------- 76 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 77 vmIntrinsicID id = m->intrinsic_id(); 78 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 79 80 if (!m->is_loaded()) { 81 // Do not attempt to inline unloaded methods. 82 return nullptr; 83 } 84 85 C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization); 86 bool is_available = false; 87 88 { 89 // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag 90 // the compiler must transition to '_thread_in_vm' state because both 91 // methods access VM-internal data. 92 VM_ENTRY_MARK; 93 methodHandle mh(THREAD, m->get_Method()); 94 is_available = compiler != nullptr && compiler->is_intrinsic_available(mh, C->directive()); 95 if (is_available && is_virtual) { 96 is_available = vmIntrinsics::does_virtual_dispatch(id); 97 } 98 } 99 100 if (is_available) { 101 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility"); 102 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?"); 103 return new LibraryIntrinsic(m, is_virtual, 104 vmIntrinsics::predicates_needed(id), 105 vmIntrinsics::does_virtual_dispatch(id), 106 id); 107 } else { 108 return nullptr; 109 } 110 } 111 112 JVMState* LibraryIntrinsic::generate(JVMState* jvms) { 113 LibraryCallKit kit(jvms, this); 114 Compile* C = kit.C; 115 int nodes = C->unique(); 116 #ifndef PRODUCT 117 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 118 char buf[1000]; 119 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 120 tty->print_cr("Intrinsic %s", str); 121 } 122 #endif 123 ciMethod* callee = kit.callee(); 124 const int bci = kit.bci(); 125 #ifdef ASSERT 126 Node* ctrl = kit.control(); 127 #endif 128 // Try to inline the intrinsic. 129 if (callee->check_intrinsic_candidate() && 130 kit.try_to_inline(_last_predicate)) { 131 const char *inline_msg = is_virtual() ? "(intrinsic, virtual)" 132 : "(intrinsic)"; 133 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::SUCCESS, inline_msg); 134 C->inline_printer()->record(callee, jvms, InliningResult::SUCCESS, inline_msg); 135 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 136 if (C->log()) { 137 C->log()->elem("intrinsic id='%s'%s nodes='%d'", 138 vmIntrinsics::name_at(intrinsic_id()), 139 (is_virtual() ? " virtual='1'" : ""), 140 C->unique() - nodes); 141 } 142 // Push the result from the inlined method onto the stack. 143 kit.push_result(); 144 return kit.transfer_exceptions_into_jvms(); 145 } 146 147 // The intrinsic bailed out 148 assert(ctrl == kit.control(), "Control flow was added although the intrinsic bailed out"); 149 assert(jvms->map() == kit.map(), "Out of sync JVM state"); 150 if (jvms->has_method()) { 151 // Not a root compile. 152 const char* msg; 153 if (callee->intrinsic_candidate()) { 154 msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)"; 155 } else { 156 msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated" 157 : "failed to inline (intrinsic), method not annotated"; 158 } 159 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::FAILURE, msg); 160 C->inline_printer()->record(callee, jvms, InliningResult::FAILURE, msg); 161 } else { 162 // Root compile 163 ResourceMark rm; 164 stringStream msg_stream; 165 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 166 vmIntrinsics::name_at(intrinsic_id()), 167 is_virtual() ? " (virtual)" : "", bci); 168 const char *msg = msg_stream.freeze(); 169 log_debug(jit, inlining)("%s", msg); 170 if (C->print_intrinsics() || C->print_inlining()) { 171 tty->print("%s", msg); 172 } 173 } 174 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 175 176 return nullptr; 177 } 178 179 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) { 180 LibraryCallKit kit(jvms, this); 181 Compile* C = kit.C; 182 int nodes = C->unique(); 183 _last_predicate = predicate; 184 #ifndef PRODUCT 185 assert(is_predicated() && predicate < predicates_count(), "sanity"); 186 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 187 char buf[1000]; 188 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 189 tty->print_cr("Predicate for intrinsic %s", str); 190 } 191 #endif 192 ciMethod* callee = kit.callee(); 193 const int bci = kit.bci(); 194 195 Node* slow_ctl = kit.try_to_predicate(predicate); 196 if (!kit.failing()) { 197 const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)" 198 : "(intrinsic, predicate)"; 199 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::SUCCESS, inline_msg); 200 C->inline_printer()->record(callee, jvms, InliningResult::SUCCESS, inline_msg); 201 202 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 203 if (C->log()) { 204 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 205 vmIntrinsics::name_at(intrinsic_id()), 206 (is_virtual() ? " virtual='1'" : ""), 207 C->unique() - nodes); 208 } 209 return slow_ctl; // Could be null if the check folds. 210 } 211 212 // The intrinsic bailed out 213 if (jvms->has_method()) { 214 // Not a root compile. 215 const char* msg = "failed to generate predicate for intrinsic"; 216 CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, InliningResult::FAILURE, msg); 217 C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg); 218 } else { 219 // Root compile 220 ResourceMark rm; 221 stringStream msg_stream; 222 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 223 vmIntrinsics::name_at(intrinsic_id()), 224 is_virtual() ? " (virtual)" : "", bci); 225 const char *msg = msg_stream.freeze(); 226 log_debug(jit, inlining)("%s", msg); 227 C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg); 228 } 229 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 230 return nullptr; 231 } 232 233 bool LibraryCallKit::try_to_inline(int predicate) { 234 // Handle symbolic names for otherwise undistinguished boolean switches: 235 const bool is_store = true; 236 const bool is_compress = true; 237 const bool is_static = true; 238 const bool is_volatile = true; 239 240 if (!jvms()->has_method()) { 241 // Root JVMState has a null method. 242 assert(map()->memory()->Opcode() == Op_Parm, ""); 243 // Insert the memory aliasing node 244 set_all_memory(reset_memory()); 245 } 246 assert(merged_memory(), ""); 247 248 switch (intrinsic_id()) { 249 case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 250 case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static); 251 case vmIntrinsics::_getClass: return inline_native_getClass(); 252 253 case vmIntrinsics::_ceil: 254 case vmIntrinsics::_floor: 255 case vmIntrinsics::_rint: 256 case vmIntrinsics::_dsin: 257 case vmIntrinsics::_dcos: 258 case vmIntrinsics::_dtan: 259 case vmIntrinsics::_dsinh: 260 case vmIntrinsics::_dtanh: 261 case vmIntrinsics::_dcbrt: 262 case vmIntrinsics::_dabs: 263 case vmIntrinsics::_fabs: 264 case vmIntrinsics::_iabs: 265 case vmIntrinsics::_labs: 266 case vmIntrinsics::_datan2: 267 case vmIntrinsics::_dsqrt: 268 case vmIntrinsics::_dsqrt_strict: 269 case vmIntrinsics::_dexp: 270 case vmIntrinsics::_dlog: 271 case vmIntrinsics::_dlog10: 272 case vmIntrinsics::_dpow: 273 case vmIntrinsics::_dcopySign: 274 case vmIntrinsics::_fcopySign: 275 case vmIntrinsics::_dsignum: 276 case vmIntrinsics::_roundF: 277 case vmIntrinsics::_roundD: 278 case vmIntrinsics::_fsignum: return inline_math_native(intrinsic_id()); 279 280 case vmIntrinsics::_notify: 281 case vmIntrinsics::_notifyAll: 282 return inline_notify(intrinsic_id()); 283 284 case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 285 case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 286 case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 287 case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 288 case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 289 case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 290 case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 291 case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 292 case vmIntrinsics::_multiplyHigh: return inline_math_multiplyHigh(); 293 case vmIntrinsics::_unsignedMultiplyHigh: return inline_math_unsignedMultiplyHigh(); 294 case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 295 case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 296 case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 297 case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 298 299 case vmIntrinsics::_arraycopy: return inline_arraycopy(); 300 301 case vmIntrinsics::_arraySort: return inline_array_sort(); 302 case vmIntrinsics::_arrayPartition: return inline_array_partition(); 303 304 case vmIntrinsics::_compareToL: return inline_string_compareTo(StrIntrinsicNode::LL); 305 case vmIntrinsics::_compareToU: return inline_string_compareTo(StrIntrinsicNode::UU); 306 case vmIntrinsics::_compareToLU: return inline_string_compareTo(StrIntrinsicNode::LU); 307 case vmIntrinsics::_compareToUL: return inline_string_compareTo(StrIntrinsicNode::UL); 308 309 case vmIntrinsics::_indexOfL: return inline_string_indexOf(StrIntrinsicNode::LL); 310 case vmIntrinsics::_indexOfU: return inline_string_indexOf(StrIntrinsicNode::UU); 311 case vmIntrinsics::_indexOfUL: return inline_string_indexOf(StrIntrinsicNode::UL); 312 case vmIntrinsics::_indexOfIL: return inline_string_indexOfI(StrIntrinsicNode::LL); 313 case vmIntrinsics::_indexOfIU: return inline_string_indexOfI(StrIntrinsicNode::UU); 314 case vmIntrinsics::_indexOfIUL: return inline_string_indexOfI(StrIntrinsicNode::UL); 315 case vmIntrinsics::_indexOfU_char: return inline_string_indexOfChar(StrIntrinsicNode::U); 316 case vmIntrinsics::_indexOfL_char: return inline_string_indexOfChar(StrIntrinsicNode::L); 317 318 case vmIntrinsics::_equalsL: return inline_string_equals(StrIntrinsicNode::LL); 319 320 case vmIntrinsics::_vectorizedHashCode: return inline_vectorizedHashCode(); 321 322 case vmIntrinsics::_toBytesStringU: return inline_string_toBytesU(); 323 case vmIntrinsics::_getCharsStringU: return inline_string_getCharsU(); 324 case vmIntrinsics::_getCharStringU: return inline_string_char_access(!is_store); 325 case vmIntrinsics::_putCharStringU: return inline_string_char_access( is_store); 326 327 case vmIntrinsics::_compressStringC: 328 case vmIntrinsics::_compressStringB: return inline_string_copy( is_compress); 329 case vmIntrinsics::_inflateStringC: 330 case vmIntrinsics::_inflateStringB: return inline_string_copy(!is_compress); 331 332 case vmIntrinsics::_makePrivateBuffer: return inline_unsafe_make_private_buffer(); 333 case vmIntrinsics::_finishPrivateBuffer: return inline_unsafe_finish_private_buffer(); 334 case vmIntrinsics::_getReference: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false); 335 case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_store, T_BOOLEAN, Relaxed, false); 336 case vmIntrinsics::_getByte: return inline_unsafe_access(!is_store, T_BYTE, Relaxed, false); 337 case vmIntrinsics::_getShort: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, false); 338 case vmIntrinsics::_getChar: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, false); 339 case vmIntrinsics::_getInt: return inline_unsafe_access(!is_store, T_INT, Relaxed, false); 340 case vmIntrinsics::_getLong: return inline_unsafe_access(!is_store, T_LONG, Relaxed, false); 341 case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_store, T_FLOAT, Relaxed, false); 342 case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_store, T_DOUBLE, Relaxed, false); 343 case vmIntrinsics::_getValue: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false, true); 344 345 case vmIntrinsics::_putReference: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false); 346 case vmIntrinsics::_putBoolean: return inline_unsafe_access( is_store, T_BOOLEAN, Relaxed, false); 347 case vmIntrinsics::_putByte: return inline_unsafe_access( is_store, T_BYTE, Relaxed, false); 348 case vmIntrinsics::_putShort: return inline_unsafe_access( is_store, T_SHORT, Relaxed, false); 349 case vmIntrinsics::_putChar: return inline_unsafe_access( is_store, T_CHAR, Relaxed, false); 350 case vmIntrinsics::_putInt: return inline_unsafe_access( is_store, T_INT, Relaxed, false); 351 case vmIntrinsics::_putLong: return inline_unsafe_access( is_store, T_LONG, Relaxed, false); 352 case vmIntrinsics::_putFloat: return inline_unsafe_access( is_store, T_FLOAT, Relaxed, false); 353 case vmIntrinsics::_putDouble: return inline_unsafe_access( is_store, T_DOUBLE, Relaxed, false); 354 case vmIntrinsics::_putValue: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false, true); 355 356 case vmIntrinsics::_getReferenceVolatile: return inline_unsafe_access(!is_store, T_OBJECT, Volatile, false); 357 case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_store, T_BOOLEAN, Volatile, false); 358 case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_store, T_BYTE, Volatile, false); 359 case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_store, T_SHORT, Volatile, false); 360 case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_store, T_CHAR, Volatile, false); 361 case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_store, T_INT, Volatile, false); 362 case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_store, T_LONG, Volatile, false); 363 case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_store, T_FLOAT, Volatile, false); 364 case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_store, T_DOUBLE, Volatile, false); 365 366 case vmIntrinsics::_putReferenceVolatile: return inline_unsafe_access( is_store, T_OBJECT, Volatile, false); 367 case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access( is_store, T_BOOLEAN, Volatile, false); 368 case vmIntrinsics::_putByteVolatile: return inline_unsafe_access( is_store, T_BYTE, Volatile, false); 369 case vmIntrinsics::_putShortVolatile: return inline_unsafe_access( is_store, T_SHORT, Volatile, false); 370 case vmIntrinsics::_putCharVolatile: return inline_unsafe_access( is_store, T_CHAR, Volatile, false); 371 case vmIntrinsics::_putIntVolatile: return inline_unsafe_access( is_store, T_INT, Volatile, false); 372 case vmIntrinsics::_putLongVolatile: return inline_unsafe_access( is_store, T_LONG, Volatile, false); 373 case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access( is_store, T_FLOAT, Volatile, false); 374 case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access( is_store, T_DOUBLE, Volatile, false); 375 376 case vmIntrinsics::_getShortUnaligned: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, true); 377 case vmIntrinsics::_getCharUnaligned: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, true); 378 case vmIntrinsics::_getIntUnaligned: return inline_unsafe_access(!is_store, T_INT, Relaxed, true); 379 case vmIntrinsics::_getLongUnaligned: return inline_unsafe_access(!is_store, T_LONG, Relaxed, true); 380 381 case vmIntrinsics::_putShortUnaligned: return inline_unsafe_access( is_store, T_SHORT, Relaxed, true); 382 case vmIntrinsics::_putCharUnaligned: return inline_unsafe_access( is_store, T_CHAR, Relaxed, true); 383 case vmIntrinsics::_putIntUnaligned: return inline_unsafe_access( is_store, T_INT, Relaxed, true); 384 case vmIntrinsics::_putLongUnaligned: return inline_unsafe_access( is_store, T_LONG, Relaxed, true); 385 386 case vmIntrinsics::_getReferenceAcquire: return inline_unsafe_access(!is_store, T_OBJECT, Acquire, false); 387 case vmIntrinsics::_getBooleanAcquire: return inline_unsafe_access(!is_store, T_BOOLEAN, Acquire, false); 388 case vmIntrinsics::_getByteAcquire: return inline_unsafe_access(!is_store, T_BYTE, Acquire, false); 389 case vmIntrinsics::_getShortAcquire: return inline_unsafe_access(!is_store, T_SHORT, Acquire, false); 390 case vmIntrinsics::_getCharAcquire: return inline_unsafe_access(!is_store, T_CHAR, Acquire, false); 391 case vmIntrinsics::_getIntAcquire: return inline_unsafe_access(!is_store, T_INT, Acquire, false); 392 case vmIntrinsics::_getLongAcquire: return inline_unsafe_access(!is_store, T_LONG, Acquire, false); 393 case vmIntrinsics::_getFloatAcquire: return inline_unsafe_access(!is_store, T_FLOAT, Acquire, false); 394 case vmIntrinsics::_getDoubleAcquire: return inline_unsafe_access(!is_store, T_DOUBLE, Acquire, false); 395 396 case vmIntrinsics::_putReferenceRelease: return inline_unsafe_access( is_store, T_OBJECT, Release, false); 397 case vmIntrinsics::_putBooleanRelease: return inline_unsafe_access( is_store, T_BOOLEAN, Release, false); 398 case vmIntrinsics::_putByteRelease: return inline_unsafe_access( is_store, T_BYTE, Release, false); 399 case vmIntrinsics::_putShortRelease: return inline_unsafe_access( is_store, T_SHORT, Release, false); 400 case vmIntrinsics::_putCharRelease: return inline_unsafe_access( is_store, T_CHAR, Release, false); 401 case vmIntrinsics::_putIntRelease: return inline_unsafe_access( is_store, T_INT, Release, false); 402 case vmIntrinsics::_putLongRelease: return inline_unsafe_access( is_store, T_LONG, Release, false); 403 case vmIntrinsics::_putFloatRelease: return inline_unsafe_access( is_store, T_FLOAT, Release, false); 404 case vmIntrinsics::_putDoubleRelease: return inline_unsafe_access( is_store, T_DOUBLE, Release, false); 405 406 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false); 407 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false); 408 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false); 409 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false); 410 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false); 411 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false); 412 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false); 413 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false); 414 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false); 415 416 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false); 417 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false); 418 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false); 419 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false); 420 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false); 421 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false); 422 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false); 423 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false); 424 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false); 425 426 case vmIntrinsics::_getFlatValue: return inline_unsafe_flat_access(!is_store, Relaxed); 427 case vmIntrinsics::_putFlatValue: return inline_unsafe_flat_access( is_store, Relaxed); 428 429 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile); 430 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile); 431 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile); 432 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile); 433 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile); 434 435 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed); 436 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire); 437 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release); 438 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile); 439 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed); 440 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire); 441 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release); 442 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile); 443 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed); 444 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire); 445 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release); 446 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile); 447 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed); 448 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire); 449 case vmIntrinsics::_weakCompareAndSetIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Release); 450 case vmIntrinsics::_weakCompareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Volatile); 451 case vmIntrinsics::_weakCompareAndSetLongPlain: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Relaxed); 452 case vmIntrinsics::_weakCompareAndSetLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Acquire); 453 case vmIntrinsics::_weakCompareAndSetLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Release); 454 case vmIntrinsics::_weakCompareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Volatile); 455 456 case vmIntrinsics::_compareAndExchangeReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Volatile); 457 case vmIntrinsics::_compareAndExchangeReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Acquire); 458 case vmIntrinsics::_compareAndExchangeReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Release); 459 case vmIntrinsics::_compareAndExchangeByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Volatile); 460 case vmIntrinsics::_compareAndExchangeByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Acquire); 461 case vmIntrinsics::_compareAndExchangeByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Release); 462 case vmIntrinsics::_compareAndExchangeShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Volatile); 463 case vmIntrinsics::_compareAndExchangeShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Acquire); 464 case vmIntrinsics::_compareAndExchangeShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Release); 465 case vmIntrinsics::_compareAndExchangeInt: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Volatile); 466 case vmIntrinsics::_compareAndExchangeIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Acquire); 467 case vmIntrinsics::_compareAndExchangeIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Release); 468 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile); 469 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire); 470 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release); 471 472 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile); 473 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile); 474 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile); 475 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile); 476 477 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile); 478 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile); 479 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile); 480 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile); 481 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile); 482 483 case vmIntrinsics::_loadFence: 484 case vmIntrinsics::_storeFence: 485 case vmIntrinsics::_storeStoreFence: 486 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id()); 487 488 case vmIntrinsics::_onSpinWait: return inline_onspinwait(); 489 490 case vmIntrinsics::_currentCarrierThread: return inline_native_currentCarrierThread(); 491 case vmIntrinsics::_currentThread: return inline_native_currentThread(); 492 case vmIntrinsics::_setCurrentThread: return inline_native_setCurrentThread(); 493 494 case vmIntrinsics::_scopedValueCache: return inline_native_scopedValueCache(); 495 case vmIntrinsics::_setScopedValueCache: return inline_native_setScopedValueCache(); 496 497 case vmIntrinsics::_Continuation_pin: return inline_native_Continuation_pinning(false); 498 case vmIntrinsics::_Continuation_unpin: return inline_native_Continuation_pinning(true); 499 500 #if INCLUDE_JVMTI 501 case vmIntrinsics::_notifyJvmtiVThreadStart: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_start()), 502 "notifyJvmtiStart", true, false); 503 case vmIntrinsics::_notifyJvmtiVThreadEnd: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_end()), 504 "notifyJvmtiEnd", false, true); 505 case vmIntrinsics::_notifyJvmtiVThreadMount: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_mount()), 506 "notifyJvmtiMount", false, false); 507 case vmIntrinsics::_notifyJvmtiVThreadUnmount: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_unmount()), 508 "notifyJvmtiUnmount", false, false); 509 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend: return inline_native_notify_jvmti_sync(); 510 #endif 511 512 #ifdef JFR_HAVE_INTRINSICS 513 case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JfrTime::time_function()), "counterTime"); 514 case vmIntrinsics::_getEventWriter: return inline_native_getEventWriter(); 515 case vmIntrinsics::_jvm_commit: return inline_native_jvm_commit(); 516 #endif 517 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis"); 518 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime"); 519 case vmIntrinsics::_writeback0: return inline_unsafe_writeback0(); 520 case vmIntrinsics::_writebackPreSync0: return inline_unsafe_writebackSync0(true); 521 case vmIntrinsics::_writebackPostSync0: return inline_unsafe_writebackSync0(false); 522 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate(); 523 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory(); 524 case vmIntrinsics::_setMemory: return inline_unsafe_setMemory(); 525 case vmIntrinsics::_getLength: return inline_native_getLength(); 526 case vmIntrinsics::_copyOf: return inline_array_copyOf(false); 527 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true); 528 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL); 529 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU); 530 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(T_INT); 531 case vmIntrinsics::_Preconditions_checkLongIndex: return inline_preconditions_checkIndex(T_LONG); 532 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual()); 533 534 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true); 535 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false); 536 case vmIntrinsics::_newNullRestrictedNonAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ false); 537 case vmIntrinsics::_newNullRestrictedAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ true); 538 case vmIntrinsics::_newNullableAtomicArray: return inline_newArray(/* null_free */ false, /* atomic */ true); 539 540 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check(); 541 542 case vmIntrinsics::_isInstance: 543 case vmIntrinsics::_isHidden: 544 case vmIntrinsics::_getSuperclass: return inline_native_Class_query(intrinsic_id()); 545 546 case vmIntrinsics::_floatToRawIntBits: 547 case vmIntrinsics::_floatToIntBits: 548 case vmIntrinsics::_intBitsToFloat: 549 case vmIntrinsics::_doubleToRawLongBits: 550 case vmIntrinsics::_doubleToLongBits: 551 case vmIntrinsics::_longBitsToDouble: 552 case vmIntrinsics::_floatToFloat16: 553 case vmIntrinsics::_float16ToFloat: return inline_fp_conversions(intrinsic_id()); 554 case vmIntrinsics::_sqrt_float16: return inline_fp16_operations(intrinsic_id(), 1); 555 case vmIntrinsics::_fma_float16: return inline_fp16_operations(intrinsic_id(), 3); 556 case vmIntrinsics::_floatIsFinite: 557 case vmIntrinsics::_floatIsInfinite: 558 case vmIntrinsics::_doubleIsFinite: 559 case vmIntrinsics::_doubleIsInfinite: return inline_fp_range_check(intrinsic_id()); 560 561 case vmIntrinsics::_numberOfLeadingZeros_i: 562 case vmIntrinsics::_numberOfLeadingZeros_l: 563 case vmIntrinsics::_numberOfTrailingZeros_i: 564 case vmIntrinsics::_numberOfTrailingZeros_l: 565 case vmIntrinsics::_bitCount_i: 566 case vmIntrinsics::_bitCount_l: 567 case vmIntrinsics::_reverse_i: 568 case vmIntrinsics::_reverse_l: 569 case vmIntrinsics::_reverseBytes_i: 570 case vmIntrinsics::_reverseBytes_l: 571 case vmIntrinsics::_reverseBytes_s: 572 case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id()); 573 574 case vmIntrinsics::_compress_i: 575 case vmIntrinsics::_compress_l: 576 case vmIntrinsics::_expand_i: 577 case vmIntrinsics::_expand_l: return inline_bitshuffle_methods(intrinsic_id()); 578 579 case vmIntrinsics::_compareUnsigned_i: 580 case vmIntrinsics::_compareUnsigned_l: return inline_compare_unsigned(intrinsic_id()); 581 582 case vmIntrinsics::_divideUnsigned_i: 583 case vmIntrinsics::_divideUnsigned_l: 584 case vmIntrinsics::_remainderUnsigned_i: 585 case vmIntrinsics::_remainderUnsigned_l: return inline_divmod_methods(intrinsic_id()); 586 587 case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass(); 588 589 case vmIntrinsics::_Reference_get0: return inline_reference_get0(); 590 case vmIntrinsics::_Reference_refersTo0: return inline_reference_refersTo0(false); 591 case vmIntrinsics::_PhantomReference_refersTo0: return inline_reference_refersTo0(true); 592 case vmIntrinsics::_Reference_clear0: return inline_reference_clear0(false); 593 case vmIntrinsics::_PhantomReference_clear0: return inline_reference_clear0(true); 594 595 case vmIntrinsics::_Class_cast: return inline_Class_cast(); 596 597 case vmIntrinsics::_aescrypt_encryptBlock: 598 case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id()); 599 600 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 601 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 602 return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 603 604 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 605 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 606 return inline_electronicCodeBook_AESCrypt(intrinsic_id()); 607 608 case vmIntrinsics::_counterMode_AESCrypt: 609 return inline_counterMode_AESCrypt(intrinsic_id()); 610 611 case vmIntrinsics::_galoisCounterMode_AESCrypt: 612 return inline_galoisCounterMode_AESCrypt(); 613 614 case vmIntrinsics::_md5_implCompress: 615 case vmIntrinsics::_sha_implCompress: 616 case vmIntrinsics::_sha2_implCompress: 617 case vmIntrinsics::_sha5_implCompress: 618 case vmIntrinsics::_sha3_implCompress: 619 return inline_digestBase_implCompress(intrinsic_id()); 620 case vmIntrinsics::_double_keccak: 621 return inline_double_keccak(); 622 623 case vmIntrinsics::_digestBase_implCompressMB: 624 return inline_digestBase_implCompressMB(predicate); 625 626 case vmIntrinsics::_multiplyToLen: 627 return inline_multiplyToLen(); 628 629 case vmIntrinsics::_squareToLen: 630 return inline_squareToLen(); 631 632 case vmIntrinsics::_mulAdd: 633 return inline_mulAdd(); 634 635 case vmIntrinsics::_montgomeryMultiply: 636 return inline_montgomeryMultiply(); 637 case vmIntrinsics::_montgomerySquare: 638 return inline_montgomerySquare(); 639 640 case vmIntrinsics::_bigIntegerRightShiftWorker: 641 return inline_bigIntegerShift(true); 642 case vmIntrinsics::_bigIntegerLeftShiftWorker: 643 return inline_bigIntegerShift(false); 644 645 case vmIntrinsics::_vectorizedMismatch: 646 return inline_vectorizedMismatch(); 647 648 case vmIntrinsics::_ghash_processBlocks: 649 return inline_ghash_processBlocks(); 650 case vmIntrinsics::_chacha20Block: 651 return inline_chacha20Block(); 652 case vmIntrinsics::_kyberNtt: 653 return inline_kyberNtt(); 654 case vmIntrinsics::_kyberInverseNtt: 655 return inline_kyberInverseNtt(); 656 case vmIntrinsics::_kyberNttMult: 657 return inline_kyberNttMult(); 658 case vmIntrinsics::_kyberAddPoly_2: 659 return inline_kyberAddPoly_2(); 660 case vmIntrinsics::_kyberAddPoly_3: 661 return inline_kyberAddPoly_3(); 662 case vmIntrinsics::_kyber12To16: 663 return inline_kyber12To16(); 664 case vmIntrinsics::_kyberBarrettReduce: 665 return inline_kyberBarrettReduce(); 666 case vmIntrinsics::_dilithiumAlmostNtt: 667 return inline_dilithiumAlmostNtt(); 668 case vmIntrinsics::_dilithiumAlmostInverseNtt: 669 return inline_dilithiumAlmostInverseNtt(); 670 case vmIntrinsics::_dilithiumNttMult: 671 return inline_dilithiumNttMult(); 672 case vmIntrinsics::_dilithiumMontMulByConstant: 673 return inline_dilithiumMontMulByConstant(); 674 case vmIntrinsics::_dilithiumDecomposePoly: 675 return inline_dilithiumDecomposePoly(); 676 case vmIntrinsics::_base64_encodeBlock: 677 return inline_base64_encodeBlock(); 678 case vmIntrinsics::_base64_decodeBlock: 679 return inline_base64_decodeBlock(); 680 case vmIntrinsics::_poly1305_processBlocks: 681 return inline_poly1305_processBlocks(); 682 case vmIntrinsics::_intpoly_montgomeryMult_P256: 683 return inline_intpoly_montgomeryMult_P256(); 684 case vmIntrinsics::_intpoly_assign: 685 return inline_intpoly_assign(); 686 case vmIntrinsics::_encodeISOArray: 687 case vmIntrinsics::_encodeByteISOArray: 688 return inline_encodeISOArray(false); 689 case vmIntrinsics::_encodeAsciiArray: 690 return inline_encodeISOArray(true); 691 692 case vmIntrinsics::_updateCRC32: 693 return inline_updateCRC32(); 694 case vmIntrinsics::_updateBytesCRC32: 695 return inline_updateBytesCRC32(); 696 case vmIntrinsics::_updateByteBufferCRC32: 697 return inline_updateByteBufferCRC32(); 698 699 case vmIntrinsics::_updateBytesCRC32C: 700 return inline_updateBytesCRC32C(); 701 case vmIntrinsics::_updateDirectByteBufferCRC32C: 702 return inline_updateDirectByteBufferCRC32C(); 703 704 case vmIntrinsics::_updateBytesAdler32: 705 return inline_updateBytesAdler32(); 706 case vmIntrinsics::_updateByteBufferAdler32: 707 return inline_updateByteBufferAdler32(); 708 709 case vmIntrinsics::_profileBoolean: 710 return inline_profileBoolean(); 711 case vmIntrinsics::_isCompileConstant: 712 return inline_isCompileConstant(); 713 714 case vmIntrinsics::_countPositives: 715 return inline_countPositives(); 716 717 case vmIntrinsics::_fmaD: 718 case vmIntrinsics::_fmaF: 719 return inline_fma(intrinsic_id()); 720 721 case vmIntrinsics::_isDigit: 722 case vmIntrinsics::_isLowerCase: 723 case vmIntrinsics::_isUpperCase: 724 case vmIntrinsics::_isWhitespace: 725 return inline_character_compare(intrinsic_id()); 726 727 case vmIntrinsics::_min: 728 case vmIntrinsics::_max: 729 case vmIntrinsics::_min_strict: 730 case vmIntrinsics::_max_strict: 731 case vmIntrinsics::_minL: 732 case vmIntrinsics::_maxL: 733 case vmIntrinsics::_minF: 734 case vmIntrinsics::_maxF: 735 case vmIntrinsics::_minD: 736 case vmIntrinsics::_maxD: 737 case vmIntrinsics::_minF_strict: 738 case vmIntrinsics::_maxF_strict: 739 case vmIntrinsics::_minD_strict: 740 case vmIntrinsics::_maxD_strict: 741 return inline_min_max(intrinsic_id()); 742 743 case vmIntrinsics::_VectorUnaryOp: 744 return inline_vector_nary_operation(1); 745 case vmIntrinsics::_VectorBinaryOp: 746 return inline_vector_nary_operation(2); 747 case vmIntrinsics::_VectorUnaryLibOp: 748 return inline_vector_call(1); 749 case vmIntrinsics::_VectorBinaryLibOp: 750 return inline_vector_call(2); 751 case vmIntrinsics::_VectorTernaryOp: 752 return inline_vector_nary_operation(3); 753 case vmIntrinsics::_VectorFromBitsCoerced: 754 return inline_vector_frombits_coerced(); 755 case vmIntrinsics::_VectorMaskOp: 756 return inline_vector_mask_operation(); 757 case vmIntrinsics::_VectorLoadOp: 758 return inline_vector_mem_operation(/*is_store=*/false); 759 case vmIntrinsics::_VectorLoadMaskedOp: 760 return inline_vector_mem_masked_operation(/*is_store*/false); 761 case vmIntrinsics::_VectorStoreOp: 762 return inline_vector_mem_operation(/*is_store=*/true); 763 case vmIntrinsics::_VectorStoreMaskedOp: 764 return inline_vector_mem_masked_operation(/*is_store=*/true); 765 case vmIntrinsics::_VectorGatherOp: 766 return inline_vector_gather_scatter(/*is_scatter*/ false); 767 case vmIntrinsics::_VectorScatterOp: 768 return inline_vector_gather_scatter(/*is_scatter*/ true); 769 case vmIntrinsics::_VectorReductionCoerced: 770 return inline_vector_reduction(); 771 case vmIntrinsics::_VectorTest: 772 return inline_vector_test(); 773 case vmIntrinsics::_VectorBlend: 774 return inline_vector_blend(); 775 case vmIntrinsics::_VectorRearrange: 776 return inline_vector_rearrange(); 777 case vmIntrinsics::_VectorSelectFrom: 778 return inline_vector_select_from(); 779 case vmIntrinsics::_VectorCompare: 780 return inline_vector_compare(); 781 case vmIntrinsics::_VectorBroadcastInt: 782 return inline_vector_broadcast_int(); 783 case vmIntrinsics::_VectorConvert: 784 return inline_vector_convert(); 785 case vmIntrinsics::_VectorInsert: 786 return inline_vector_insert(); 787 case vmIntrinsics::_VectorExtract: 788 return inline_vector_extract(); 789 case vmIntrinsics::_VectorCompressExpand: 790 return inline_vector_compress_expand(); 791 case vmIntrinsics::_VectorSelectFromTwoVectorOp: 792 return inline_vector_select_from_two_vectors(); 793 case vmIntrinsics::_IndexVector: 794 return inline_index_vector(); 795 case vmIntrinsics::_IndexPartiallyInUpperRange: 796 return inline_index_partially_in_upper_range(); 797 798 case vmIntrinsics::_getObjectSize: 799 return inline_getObjectSize(); 800 801 case vmIntrinsics::_blackhole: 802 return inline_blackhole(); 803 804 default: 805 // If you get here, it may be that someone has added a new intrinsic 806 // to the list in vmIntrinsics.hpp without implementing it here. 807 #ifndef PRODUCT 808 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 809 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 810 vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id())); 811 } 812 #endif 813 return false; 814 } 815 } 816 817 Node* LibraryCallKit::try_to_predicate(int predicate) { 818 if (!jvms()->has_method()) { 819 // Root JVMState has a null method. 820 assert(map()->memory()->Opcode() == Op_Parm, ""); 821 // Insert the memory aliasing node 822 set_all_memory(reset_memory()); 823 } 824 assert(merged_memory(), ""); 825 826 switch (intrinsic_id()) { 827 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 828 return inline_cipherBlockChaining_AESCrypt_predicate(false); 829 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 830 return inline_cipherBlockChaining_AESCrypt_predicate(true); 831 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 832 return inline_electronicCodeBook_AESCrypt_predicate(false); 833 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 834 return inline_electronicCodeBook_AESCrypt_predicate(true); 835 case vmIntrinsics::_counterMode_AESCrypt: 836 return inline_counterMode_AESCrypt_predicate(); 837 case vmIntrinsics::_digestBase_implCompressMB: 838 return inline_digestBase_implCompressMB_predicate(predicate); 839 case vmIntrinsics::_galoisCounterMode_AESCrypt: 840 return inline_galoisCounterMode_AESCrypt_predicate(); 841 842 default: 843 // If you get here, it may be that someone has added a new intrinsic 844 // to the list in vmIntrinsics.hpp without implementing it here. 845 #ifndef PRODUCT 846 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 847 tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)", 848 vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id())); 849 } 850 #endif 851 Node* slow_ctl = control(); 852 set_control(top()); // No fast path intrinsic 853 return slow_ctl; 854 } 855 } 856 857 //------------------------------set_result------------------------------- 858 // Helper function for finishing intrinsics. 859 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) { 860 record_for_igvn(region); 861 set_control(_gvn.transform(region)); 862 set_result( _gvn.transform(value)); 863 assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity"); 864 } 865 866 //------------------------------generate_guard--------------------------- 867 // Helper function for generating guarded fast-slow graph structures. 868 // The given 'test', if true, guards a slow path. If the test fails 869 // then a fast path can be taken. (We generally hope it fails.) 870 // In all cases, GraphKit::control() is updated to the fast path. 871 // The returned value represents the control for the slow path. 872 // The return value is never 'top'; it is either a valid control 873 // or null if it is obvious that the slow path can never be taken. 874 // Also, if region and the slow control are not null, the slow edge 875 // is appended to the region. 876 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 877 if (stopped()) { 878 // Already short circuited. 879 return nullptr; 880 } 881 882 // Build an if node and its projections. 883 // If test is true we take the slow path, which we assume is uncommon. 884 if (_gvn.type(test) == TypeInt::ZERO) { 885 // The slow branch is never taken. No need to build this guard. 886 return nullptr; 887 } 888 889 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 890 891 Node* if_slow = _gvn.transform(new IfTrueNode(iff)); 892 if (if_slow == top()) { 893 // The slow branch is never taken. No need to build this guard. 894 return nullptr; 895 } 896 897 if (region != nullptr) 898 region->add_req(if_slow); 899 900 Node* if_fast = _gvn.transform(new IfFalseNode(iff)); 901 set_control(if_fast); 902 903 return if_slow; 904 } 905 906 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 907 return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 908 } 909 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 910 return generate_guard(test, region, PROB_FAIR); 911 } 912 913 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 914 Node* *pos_index) { 915 if (stopped()) 916 return nullptr; // already stopped 917 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 918 return nullptr; // index is already adequately typed 919 Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0))); 920 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 921 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 922 if (is_neg != nullptr && pos_index != nullptr) { 923 // Emulate effect of Parse::adjust_map_after_if. 924 Node* ccast = new CastIINode(control(), index, TypeInt::POS); 925 (*pos_index) = _gvn.transform(ccast); 926 } 927 return is_neg; 928 } 929 930 // Make sure that 'position' is a valid limit index, in [0..length]. 931 // There are two equivalent plans for checking this: 932 // A. (offset + copyLength) unsigned<= arrayLength 933 // B. offset <= (arrayLength - copyLength) 934 // We require that all of the values above, except for the sum and 935 // difference, are already known to be non-negative. 936 // Plan A is robust in the face of overflow, if offset and copyLength 937 // are both hugely positive. 938 // 939 // Plan B is less direct and intuitive, but it does not overflow at 940 // all, since the difference of two non-negatives is always 941 // representable. Whenever Java methods must perform the equivalent 942 // check they generally use Plan B instead of Plan A. 943 // For the moment we use Plan A. 944 inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 945 Node* subseq_length, 946 Node* array_length, 947 RegionNode* region) { 948 if (stopped()) 949 return nullptr; // already stopped 950 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 951 if (zero_offset && subseq_length->eqv_uncast(array_length)) 952 return nullptr; // common case of whole-array copy 953 Node* last = subseq_length; 954 if (!zero_offset) // last += offset 955 last = _gvn.transform(new AddINode(last, offset)); 956 Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last)); 957 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 958 Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 959 return is_over; 960 } 961 962 // Emit range checks for the given String.value byte array 963 void LibraryCallKit::generate_string_range_check(Node* array, 964 Node* offset, 965 Node* count, 966 bool char_count, 967 bool halt_on_oob) { 968 if (stopped()) { 969 return; // already stopped 970 } 971 RegionNode* bailout = new RegionNode(1); 972 record_for_igvn(bailout); 973 if (char_count) { 974 // Convert char count to byte count 975 count = _gvn.transform(new LShiftINode(count, intcon(1))); 976 } 977 978 // Offset and count must not be negative 979 generate_negative_guard(offset, bailout); 980 generate_negative_guard(count, bailout); 981 // Offset + count must not exceed length of array 982 generate_limit_guard(offset, count, load_array_length(array), bailout); 983 984 if (bailout->req() > 1) { 985 if (halt_on_oob) { 986 bailout = _gvn.transform(bailout)->as_Region(); 987 Node* frame = _gvn.transform(new ParmNode(C->start(), TypeFunc::FramePtr)); 988 Node* halt = _gvn.transform(new HaltNode(bailout, frame, "unexpected guard failure in intrinsic")); 989 C->root()->add_req(halt); 990 } else { 991 PreserveJVMState pjvms(this); 992 set_control(_gvn.transform(bailout)); 993 uncommon_trap(Deoptimization::Reason_intrinsic, 994 Deoptimization::Action_maybe_recompile); 995 } 996 } 997 } 998 999 Node* LibraryCallKit::current_thread_helper(Node*& tls_output, ByteSize handle_offset, 1000 bool is_immutable) { 1001 ciKlass* thread_klass = env()->Thread_klass(); 1002 const Type* thread_type 1003 = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 1004 1005 Node* thread = _gvn.transform(new ThreadLocalNode()); 1006 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(handle_offset)); 1007 tls_output = thread; 1008 1009 Node* thread_obj_handle 1010 = (is_immutable 1011 ? LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(), 1012 TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered) 1013 : make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered)); 1014 thread_obj_handle = _gvn.transform(thread_obj_handle); 1015 1016 DecoratorSet decorators = IN_NATIVE; 1017 if (is_immutable) { 1018 decorators |= C2_IMMUTABLE_MEMORY; 1019 } 1020 return access_load(thread_obj_handle, thread_type, T_OBJECT, decorators); 1021 } 1022 1023 //--------------------------generate_current_thread-------------------- 1024 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1025 return current_thread_helper(tls_output, JavaThread::threadObj_offset(), 1026 /*is_immutable*/false); 1027 } 1028 1029 //--------------------------generate_virtual_thread-------------------- 1030 Node* LibraryCallKit::generate_virtual_thread(Node* tls_output) { 1031 return current_thread_helper(tls_output, JavaThread::vthread_offset(), 1032 !C->method()->changes_current_thread()); 1033 } 1034 1035 //------------------------------make_string_method_node------------------------ 1036 // Helper method for String intrinsic functions. This version is called with 1037 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded 1038 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes 1039 // containing the lengths of str1 and str2. 1040 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) { 1041 Node* result = nullptr; 1042 switch (opcode) { 1043 case Op_StrIndexOf: 1044 result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES), 1045 str1_start, cnt1, str2_start, cnt2, ae); 1046 break; 1047 case Op_StrComp: 1048 result = new StrCompNode(control(), memory(TypeAryPtr::BYTES), 1049 str1_start, cnt1, str2_start, cnt2, ae); 1050 break; 1051 case Op_StrEquals: 1052 // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals'). 1053 // Use the constant length if there is one because optimized match rule may exist. 1054 result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES), 1055 str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae); 1056 break; 1057 default: 1058 ShouldNotReachHere(); 1059 return nullptr; 1060 } 1061 1062 // All these intrinsics have checks. 1063 C->set_has_split_ifs(true); // Has chance for split-if optimization 1064 clear_upper_avx(); 1065 1066 return _gvn.transform(result); 1067 } 1068 1069 //------------------------------inline_string_compareTo------------------------ 1070 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) { 1071 Node* arg1 = argument(0); 1072 Node* arg2 = argument(1); 1073 1074 arg1 = must_be_not_null(arg1, true); 1075 arg2 = must_be_not_null(arg2, true); 1076 1077 // Get start addr and length of first argument 1078 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1079 Node* arg1_cnt = load_array_length(arg1); 1080 1081 // Get start addr and length of second argument 1082 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1083 Node* arg2_cnt = load_array_length(arg2); 1084 1085 Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1086 set_result(result); 1087 return true; 1088 } 1089 1090 //------------------------------inline_string_equals------------------------ 1091 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) { 1092 Node* arg1 = argument(0); 1093 Node* arg2 = argument(1); 1094 1095 // paths (plus control) merge 1096 RegionNode* region = new RegionNode(3); 1097 Node* phi = new PhiNode(region, TypeInt::BOOL); 1098 1099 if (!stopped()) { 1100 1101 arg1 = must_be_not_null(arg1, true); 1102 arg2 = must_be_not_null(arg2, true); 1103 1104 // Get start addr and length of first argument 1105 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1106 Node* arg1_cnt = load_array_length(arg1); 1107 1108 // Get start addr and length of second argument 1109 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1110 Node* arg2_cnt = load_array_length(arg2); 1111 1112 // Check for arg1_cnt != arg2_cnt 1113 Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt)); 1114 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 1115 Node* if_ne = generate_slow_guard(bol, nullptr); 1116 if (if_ne != nullptr) { 1117 phi->init_req(2, intcon(0)); 1118 region->init_req(2, if_ne); 1119 } 1120 1121 // Check for count == 0 is done by assembler code for StrEquals. 1122 1123 if (!stopped()) { 1124 Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1125 phi->init_req(1, equals); 1126 region->init_req(1, control()); 1127 } 1128 } 1129 1130 // post merge 1131 set_control(_gvn.transform(region)); 1132 record_for_igvn(region); 1133 1134 set_result(_gvn.transform(phi)); 1135 return true; 1136 } 1137 1138 //------------------------------inline_array_equals---------------------------- 1139 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) { 1140 assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types"); 1141 Node* arg1 = argument(0); 1142 Node* arg2 = argument(1); 1143 1144 const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES; 1145 set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae))); 1146 clear_upper_avx(); 1147 1148 return true; 1149 } 1150 1151 1152 //------------------------------inline_countPositives------------------------------ 1153 // int java.lang.StringCoding#countPositives0(byte[] ba, int off, int len) 1154 bool LibraryCallKit::inline_countPositives() { 1155 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1156 return false; 1157 } 1158 1159 assert(callee()->signature()->size() == 3, "countPositives has 3 parameters"); 1160 // no receiver since it is static method 1161 Node* ba = argument(0); 1162 Node* offset = argument(1); 1163 Node* len = argument(2); 1164 1165 if (VerifyIntrinsicChecks) { 1166 ba = must_be_not_null(ba, true); 1167 generate_string_range_check(ba, offset, len, false, true); 1168 if (stopped()) { 1169 return true; 1170 } 1171 } 1172 1173 Node* ba_start = array_element_address(ba, offset, T_BYTE); 1174 Node* result = new CountPositivesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len); 1175 set_result(_gvn.transform(result)); 1176 clear_upper_avx(); 1177 return true; 1178 } 1179 1180 bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) { 1181 Node* index = argument(0); 1182 Node* length = bt == T_INT ? argument(1) : argument(2); 1183 if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) { 1184 return false; 1185 } 1186 1187 // check that length is positive 1188 Node* len_pos_cmp = _gvn.transform(CmpNode::make(length, integercon(0, bt), bt)); 1189 Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge)); 1190 1191 { 1192 BuildCutout unless(this, len_pos_bol, PROB_MAX); 1193 uncommon_trap(Deoptimization::Reason_intrinsic, 1194 Deoptimization::Action_make_not_entrant); 1195 } 1196 1197 if (stopped()) { 1198 // Length is known to be always negative during compilation and the IR graph so far constructed is good so return success 1199 return true; 1200 } 1201 1202 // length is now known positive, add a cast node to make this explicit 1203 jlong upper_bound = _gvn.type(length)->is_integer(bt)->hi_as_long(); 1204 Node* casted_length = ConstraintCastNode::make_cast_for_basic_type( 1205 control(), length, TypeInteger::make(0, upper_bound, Type::WidenMax, bt), 1206 ConstraintCastNode::RegularDependency, bt); 1207 casted_length = _gvn.transform(casted_length); 1208 replace_in_map(length, casted_length); 1209 length = casted_length; 1210 1211 // Use an unsigned comparison for the range check itself 1212 Node* rc_cmp = _gvn.transform(CmpNode::make(index, length, bt, true)); 1213 BoolTest::mask btest = BoolTest::lt; 1214 Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest)); 1215 RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN); 1216 _gvn.set_type(rc, rc->Value(&_gvn)); 1217 if (!rc_bool->is_Con()) { 1218 record_for_igvn(rc); 1219 } 1220 set_control(_gvn.transform(new IfTrueNode(rc))); 1221 { 1222 PreserveJVMState pjvms(this); 1223 set_control(_gvn.transform(new IfFalseNode(rc))); 1224 uncommon_trap(Deoptimization::Reason_range_check, 1225 Deoptimization::Action_make_not_entrant); 1226 } 1227 1228 if (stopped()) { 1229 // Range check is known to always fail during compilation and the IR graph so far constructed is good so return success 1230 return true; 1231 } 1232 1233 // index is now known to be >= 0 and < length, cast it 1234 Node* result = ConstraintCastNode::make_cast_for_basic_type( 1235 control(), index, TypeInteger::make(0, upper_bound, Type::WidenMax, bt), 1236 ConstraintCastNode::RegularDependency, bt); 1237 result = _gvn.transform(result); 1238 set_result(result); 1239 replace_in_map(index, result); 1240 return true; 1241 } 1242 1243 //------------------------------inline_string_indexOf------------------------ 1244 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) { 1245 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1246 return false; 1247 } 1248 Node* src = argument(0); 1249 Node* tgt = argument(1); 1250 1251 // Make the merge point 1252 RegionNode* result_rgn = new RegionNode(4); 1253 Node* result_phi = new PhiNode(result_rgn, TypeInt::INT); 1254 1255 src = must_be_not_null(src, true); 1256 tgt = must_be_not_null(tgt, true); 1257 1258 // Get start addr and length of source string 1259 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 1260 Node* src_count = load_array_length(src); 1261 1262 // Get start addr and length of substring 1263 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1264 Node* tgt_count = load_array_length(tgt); 1265 1266 Node* result = nullptr; 1267 bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr); 1268 1269 if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) { 1270 // Divide src size by 2 if String is UTF16 encoded 1271 src_count = _gvn.transform(new RShiftINode(src_count, intcon(1))); 1272 } 1273 if (ae == StrIntrinsicNode::UU) { 1274 // Divide substring size by 2 if String is UTF16 encoded 1275 tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1))); 1276 } 1277 1278 if (call_opt_stub) { 1279 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(), 1280 StubRoutines::_string_indexof_array[ae], 1281 "stringIndexOf", TypePtr::BOTTOM, src_start, 1282 src_count, tgt_start, tgt_count); 1283 result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 1284 } else { 1285 result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, 1286 result_rgn, result_phi, ae); 1287 } 1288 if (result != nullptr) { 1289 result_phi->init_req(3, result); 1290 result_rgn->init_req(3, control()); 1291 } 1292 set_control(_gvn.transform(result_rgn)); 1293 record_for_igvn(result_rgn); 1294 set_result(_gvn.transform(result_phi)); 1295 1296 return true; 1297 } 1298 1299 //-----------------------------inline_string_indexOfI----------------------- 1300 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) { 1301 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1302 return false; 1303 } 1304 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1305 return false; 1306 } 1307 1308 assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments"); 1309 Node* src = argument(0); // byte[] 1310 Node* src_count = argument(1); // char count 1311 Node* tgt = argument(2); // byte[] 1312 Node* tgt_count = argument(3); // char count 1313 Node* from_index = argument(4); // char index 1314 1315 src = must_be_not_null(src, true); 1316 tgt = must_be_not_null(tgt, true); 1317 1318 // Multiply byte array index by 2 if String is UTF16 encoded 1319 Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1))); 1320 src_count = _gvn.transform(new SubINode(src_count, from_index)); 1321 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1322 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1323 1324 // Range checks 1325 generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL); 1326 generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU); 1327 if (stopped()) { 1328 return true; 1329 } 1330 1331 RegionNode* region = new RegionNode(5); 1332 Node* phi = new PhiNode(region, TypeInt::INT); 1333 Node* result = nullptr; 1334 1335 bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr); 1336 1337 if (call_opt_stub) { 1338 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(), 1339 StubRoutines::_string_indexof_array[ae], 1340 "stringIndexOf", TypePtr::BOTTOM, src_start, 1341 src_count, tgt_start, tgt_count); 1342 result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 1343 } else { 1344 result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, 1345 region, phi, ae); 1346 } 1347 if (result != nullptr) { 1348 // The result is index relative to from_index if substring was found, -1 otherwise. 1349 // Generate code which will fold into cmove. 1350 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1351 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1352 1353 Node* if_lt = generate_slow_guard(bol, nullptr); 1354 if (if_lt != nullptr) { 1355 // result == -1 1356 phi->init_req(3, result); 1357 region->init_req(3, if_lt); 1358 } 1359 if (!stopped()) { 1360 result = _gvn.transform(new AddINode(result, from_index)); 1361 phi->init_req(4, result); 1362 region->init_req(4, control()); 1363 } 1364 } 1365 1366 set_control(_gvn.transform(region)); 1367 record_for_igvn(region); 1368 set_result(_gvn.transform(phi)); 1369 clear_upper_avx(); 1370 1371 return true; 1372 } 1373 1374 // Create StrIndexOfNode with fast path checks 1375 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count, 1376 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) { 1377 // Check for substr count > string count 1378 Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count)); 1379 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt)); 1380 Node* if_gt = generate_slow_guard(bol, nullptr); 1381 if (if_gt != nullptr) { 1382 phi->init_req(1, intcon(-1)); 1383 region->init_req(1, if_gt); 1384 } 1385 if (!stopped()) { 1386 // Check for substr count == 0 1387 cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0))); 1388 bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 1389 Node* if_zero = generate_slow_guard(bol, nullptr); 1390 if (if_zero != nullptr) { 1391 phi->init_req(2, intcon(0)); 1392 region->init_req(2, if_zero); 1393 } 1394 } 1395 if (!stopped()) { 1396 return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae); 1397 } 1398 return nullptr; 1399 } 1400 1401 //-----------------------------inline_string_indexOfChar----------------------- 1402 bool LibraryCallKit::inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae) { 1403 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1404 return false; 1405 } 1406 if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) { 1407 return false; 1408 } 1409 assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments"); 1410 Node* src = argument(0); // byte[] 1411 Node* int_ch = argument(1); 1412 Node* from_index = argument(2); 1413 Node* max = argument(3); 1414 1415 src = must_be_not_null(src, true); 1416 1417 Node* src_offset = ae == StrIntrinsicNode::L ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1))); 1418 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1419 Node* src_count = _gvn.transform(new SubINode(max, from_index)); 1420 1421 // Range checks 1422 generate_string_range_check(src, src_offset, src_count, ae == StrIntrinsicNode::U); 1423 1424 // Check for int_ch >= 0 1425 Node* int_ch_cmp = _gvn.transform(new CmpINode(int_ch, intcon(0))); 1426 Node* int_ch_bol = _gvn.transform(new BoolNode(int_ch_cmp, BoolTest::ge)); 1427 { 1428 BuildCutout unless(this, int_ch_bol, PROB_MAX); 1429 uncommon_trap(Deoptimization::Reason_intrinsic, 1430 Deoptimization::Action_maybe_recompile); 1431 } 1432 if (stopped()) { 1433 return true; 1434 } 1435 1436 RegionNode* region = new RegionNode(3); 1437 Node* phi = new PhiNode(region, TypeInt::INT); 1438 1439 Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, int_ch, ae); 1440 C->set_has_split_ifs(true); // Has chance for split-if optimization 1441 _gvn.transform(result); 1442 1443 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1444 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1445 1446 Node* if_lt = generate_slow_guard(bol, nullptr); 1447 if (if_lt != nullptr) { 1448 // result == -1 1449 phi->init_req(2, result); 1450 region->init_req(2, if_lt); 1451 } 1452 if (!stopped()) { 1453 result = _gvn.transform(new AddINode(result, from_index)); 1454 phi->init_req(1, result); 1455 region->init_req(1, control()); 1456 } 1457 set_control(_gvn.transform(region)); 1458 record_for_igvn(region); 1459 set_result(_gvn.transform(phi)); 1460 clear_upper_avx(); 1461 1462 return true; 1463 } 1464 //---------------------------inline_string_copy--------------------- 1465 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[]) 1466 // int StringUTF16.compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) 1467 // int StringUTF16.compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1468 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[]) 1469 // void StringLatin1.inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) 1470 // void StringLatin1.inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1471 bool LibraryCallKit::inline_string_copy(bool compress) { 1472 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1473 return false; 1474 } 1475 int nargs = 5; // 2 oops, 3 ints 1476 assert(callee()->signature()->size() == nargs, "string copy has 5 arguments"); 1477 1478 Node* src = argument(0); 1479 Node* src_offset = argument(1); 1480 Node* dst = argument(2); 1481 Node* dst_offset = argument(3); 1482 Node* length = argument(4); 1483 1484 // Check for allocation before we add nodes that would confuse 1485 // tightly_coupled_allocation() 1486 AllocateArrayNode* alloc = tightly_coupled_allocation(dst); 1487 1488 // Figure out the size and type of the elements we will be copying. 1489 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 1490 const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr(); 1491 if (src_type == nullptr || dst_type == nullptr) { 1492 return false; 1493 } 1494 BasicType src_elem = src_type->elem()->array_element_basic_type(); 1495 BasicType dst_elem = dst_type->elem()->array_element_basic_type(); 1496 assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) || 1497 (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)), 1498 "Unsupported array types for inline_string_copy"); 1499 1500 src = must_be_not_null(src, true); 1501 dst = must_be_not_null(dst, true); 1502 1503 // Convert char[] offsets to byte[] offsets 1504 bool convert_src = (compress && src_elem == T_BYTE); 1505 bool convert_dst = (!compress && dst_elem == T_BYTE); 1506 if (convert_src) { 1507 src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1))); 1508 } else if (convert_dst) { 1509 dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1))); 1510 } 1511 1512 // Range checks 1513 generate_string_range_check(src, src_offset, length, convert_src); 1514 generate_string_range_check(dst, dst_offset, length, convert_dst); 1515 if (stopped()) { 1516 return true; 1517 } 1518 1519 Node* src_start = array_element_address(src, src_offset, src_elem); 1520 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 1521 // 'src_start' points to src array + scaled offset 1522 // 'dst_start' points to dst array + scaled offset 1523 Node* count = nullptr; 1524 if (compress) { 1525 count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length); 1526 } else { 1527 inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length); 1528 } 1529 1530 if (alloc != nullptr) { 1531 if (alloc->maybe_set_complete(&_gvn)) { 1532 // "You break it, you buy it." 1533 InitializeNode* init = alloc->initialization(); 1534 assert(init->is_complete(), "we just did this"); 1535 init->set_complete_with_arraycopy(); 1536 assert(dst->is_CheckCastPP(), "sanity"); 1537 assert(dst->in(0)->in(0) == init, "dest pinned"); 1538 } 1539 // Do not let stores that initialize this object be reordered with 1540 // a subsequent store that would make this object accessible by 1541 // other threads. 1542 // Record what AllocateNode this StoreStore protects so that 1543 // escape analysis can go from the MemBarStoreStoreNode to the 1544 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1545 // based on the escape status of the AllocateNode. 1546 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1547 } 1548 if (compress) { 1549 set_result(_gvn.transform(count)); 1550 } 1551 clear_upper_avx(); 1552 1553 return true; 1554 } 1555 1556 #ifdef _LP64 1557 #define XTOP ,top() /*additional argument*/ 1558 #else //_LP64 1559 #define XTOP /*no additional argument*/ 1560 #endif //_LP64 1561 1562 //------------------------inline_string_toBytesU-------------------------- 1563 // public static byte[] StringUTF16.toBytes(char[] value, int off, int len) 1564 bool LibraryCallKit::inline_string_toBytesU() { 1565 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1566 return false; 1567 } 1568 // Get the arguments. 1569 Node* value = argument(0); 1570 Node* offset = argument(1); 1571 Node* length = argument(2); 1572 1573 Node* newcopy = nullptr; 1574 1575 // Set the original stack and the reexecute bit for the interpreter to reexecute 1576 // the bytecode that invokes StringUTF16.toBytes() if deoptimization happens. 1577 { PreserveReexecuteState preexecs(this); 1578 jvms()->set_should_reexecute(true); 1579 1580 // Check if a null path was taken unconditionally. 1581 value = null_check(value); 1582 1583 RegionNode* bailout = new RegionNode(1); 1584 record_for_igvn(bailout); 1585 1586 // Range checks 1587 generate_negative_guard(offset, bailout); 1588 generate_negative_guard(length, bailout); 1589 generate_limit_guard(offset, length, load_array_length(value), bailout); 1590 // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE 1591 generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout); 1592 1593 if (bailout->req() > 1) { 1594 PreserveJVMState pjvms(this); 1595 set_control(_gvn.transform(bailout)); 1596 uncommon_trap(Deoptimization::Reason_intrinsic, 1597 Deoptimization::Action_maybe_recompile); 1598 } 1599 if (stopped()) { 1600 return true; 1601 } 1602 1603 Node* size = _gvn.transform(new LShiftINode(length, intcon(1))); 1604 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE))); 1605 newcopy = new_array(klass_node, size, 0); // no arguments to push 1606 AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy); 1607 guarantee(alloc != nullptr, "created above"); 1608 1609 // Calculate starting addresses. 1610 Node* src_start = array_element_address(value, offset, T_CHAR); 1611 Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE)); 1612 1613 // Check if dst array address is aligned to HeapWordSize 1614 bool aligned = (arrayOopDesc::base_offset_in_bytes(T_BYTE) % HeapWordSize == 0); 1615 // If true, then check if src array address is aligned to HeapWordSize 1616 if (aligned) { 1617 const TypeInt* toffset = gvn().type(offset)->is_int(); 1618 aligned = toffset->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) + 1619 toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1620 } 1621 1622 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1623 const char* copyfunc_name = "arraycopy"; 1624 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1625 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1626 OptoRuntime::fast_arraycopy_Type(), 1627 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1628 src_start, dst_start, ConvI2X(length) XTOP); 1629 // Do not let reads from the cloned object float above the arraycopy. 1630 if (alloc->maybe_set_complete(&_gvn)) { 1631 // "You break it, you buy it." 1632 InitializeNode* init = alloc->initialization(); 1633 assert(init->is_complete(), "we just did this"); 1634 init->set_complete_with_arraycopy(); 1635 assert(newcopy->is_CheckCastPP(), "sanity"); 1636 assert(newcopy->in(0)->in(0) == init, "dest pinned"); 1637 } 1638 // Do not let stores that initialize this object be reordered with 1639 // a subsequent store that would make this object accessible by 1640 // other threads. 1641 // Record what AllocateNode this StoreStore protects so that 1642 // escape analysis can go from the MemBarStoreStoreNode to the 1643 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1644 // based on the escape status of the AllocateNode. 1645 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1646 } // original reexecute is set back here 1647 1648 C->set_has_split_ifs(true); // Has chance for split-if optimization 1649 if (!stopped()) { 1650 set_result(newcopy); 1651 } 1652 clear_upper_avx(); 1653 1654 return true; 1655 } 1656 1657 //------------------------inline_string_getCharsU-------------------------- 1658 // public void StringUTF16.getChars(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin) 1659 bool LibraryCallKit::inline_string_getCharsU() { 1660 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1661 return false; 1662 } 1663 1664 // Get the arguments. 1665 Node* src = argument(0); 1666 Node* src_begin = argument(1); 1667 Node* src_end = argument(2); // exclusive offset (i < src_end) 1668 Node* dst = argument(3); 1669 Node* dst_begin = argument(4); 1670 1671 // Check for allocation before we add nodes that would confuse 1672 // tightly_coupled_allocation() 1673 AllocateArrayNode* alloc = tightly_coupled_allocation(dst); 1674 1675 // Check if a null path was taken unconditionally. 1676 src = null_check(src); 1677 dst = null_check(dst); 1678 if (stopped()) { 1679 return true; 1680 } 1681 1682 // Get length and convert char[] offset to byte[] offset 1683 Node* length = _gvn.transform(new SubINode(src_end, src_begin)); 1684 src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1))); 1685 1686 // Range checks 1687 generate_string_range_check(src, src_begin, length, true); 1688 generate_string_range_check(dst, dst_begin, length, false); 1689 if (stopped()) { 1690 return true; 1691 } 1692 1693 if (!stopped()) { 1694 // Calculate starting addresses. 1695 Node* src_start = array_element_address(src, src_begin, T_BYTE); 1696 Node* dst_start = array_element_address(dst, dst_begin, T_CHAR); 1697 1698 // Check if array addresses are aligned to HeapWordSize 1699 const TypeInt* tsrc = gvn().type(src_begin)->is_int(); 1700 const TypeInt* tdst = gvn().type(dst_begin)->is_int(); 1701 bool aligned = tsrc->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_BYTE) + tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) && 1702 tdst->is_con() && ((arrayOopDesc::base_offset_in_bytes(T_CHAR) + tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1703 1704 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1705 const char* copyfunc_name = "arraycopy"; 1706 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1707 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1708 OptoRuntime::fast_arraycopy_Type(), 1709 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1710 src_start, dst_start, ConvI2X(length) XTOP); 1711 // Do not let reads from the cloned object float above the arraycopy. 1712 if (alloc != nullptr) { 1713 if (alloc->maybe_set_complete(&_gvn)) { 1714 // "You break it, you buy it." 1715 InitializeNode* init = alloc->initialization(); 1716 assert(init->is_complete(), "we just did this"); 1717 init->set_complete_with_arraycopy(); 1718 assert(dst->is_CheckCastPP(), "sanity"); 1719 assert(dst->in(0)->in(0) == init, "dest pinned"); 1720 } 1721 // Do not let stores that initialize this object be reordered with 1722 // a subsequent store that would make this object accessible by 1723 // other threads. 1724 // Record what AllocateNode this StoreStore protects so that 1725 // escape analysis can go from the MemBarStoreStoreNode to the 1726 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1727 // based on the escape status of the AllocateNode. 1728 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1729 } else { 1730 insert_mem_bar(Op_MemBarCPUOrder); 1731 } 1732 } 1733 1734 C->set_has_split_ifs(true); // Has chance for split-if optimization 1735 return true; 1736 } 1737 1738 //----------------------inline_string_char_access---------------------------- 1739 // Store/Load char to/from byte[] array. 1740 // static void StringUTF16.putChar(byte[] val, int index, int c) 1741 // static char StringUTF16.getChar(byte[] val, int index) 1742 bool LibraryCallKit::inline_string_char_access(bool is_store) { 1743 Node* value = argument(0); 1744 Node* index = argument(1); 1745 Node* ch = is_store ? argument(2) : nullptr; 1746 1747 // This intrinsic accesses byte[] array as char[] array. Computing the offsets 1748 // correctly requires matched array shapes. 1749 assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE), 1750 "sanity: byte[] and char[] bases agree"); 1751 assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2, 1752 "sanity: byte[] and char[] scales agree"); 1753 1754 // Bail when getChar over constants is requested: constant folding would 1755 // reject folding mismatched char access over byte[]. A normal inlining for getChar 1756 // Java method would constant fold nicely instead. 1757 if (!is_store && value->is_Con() && index->is_Con()) { 1758 return false; 1759 } 1760 1761 // Save state and restore on bailout 1762 SavedState old_state(this); 1763 1764 value = must_be_not_null(value, true); 1765 1766 Node* adr = array_element_address(value, index, T_CHAR); 1767 if (adr->is_top()) { 1768 return false; 1769 } 1770 old_state.discard(); 1771 if (is_store) { 1772 access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED); 1773 } else { 1774 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); 1775 set_result(ch); 1776 } 1777 return true; 1778 } 1779 1780 1781 //------------------------------inline_math----------------------------------- 1782 // public static double Math.abs(double) 1783 // public static double Math.sqrt(double) 1784 // public static double Math.log(double) 1785 // public static double Math.log10(double) 1786 // public static double Math.round(double) 1787 bool LibraryCallKit::inline_double_math(vmIntrinsics::ID id) { 1788 Node* arg = argument(0); 1789 Node* n = nullptr; 1790 switch (id) { 1791 case vmIntrinsics::_dabs: n = new AbsDNode( arg); break; 1792 case vmIntrinsics::_dsqrt: 1793 case vmIntrinsics::_dsqrt_strict: 1794 n = new SqrtDNode(C, control(), arg); break; 1795 case vmIntrinsics::_ceil: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_ceil); break; 1796 case vmIntrinsics::_floor: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_floor); break; 1797 case vmIntrinsics::_rint: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_rint); break; 1798 case vmIntrinsics::_roundD: n = new RoundDNode(arg); break; 1799 case vmIntrinsics::_dcopySign: n = CopySignDNode::make(_gvn, arg, argument(2)); break; 1800 case vmIntrinsics::_dsignum: n = SignumDNode::make(_gvn, arg); break; 1801 default: fatal_unexpected_iid(id); break; 1802 } 1803 set_result(_gvn.transform(n)); 1804 return true; 1805 } 1806 1807 //------------------------------inline_math----------------------------------- 1808 // public static float Math.abs(float) 1809 // public static int Math.abs(int) 1810 // public static long Math.abs(long) 1811 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) { 1812 Node* arg = argument(0); 1813 Node* n = nullptr; 1814 switch (id) { 1815 case vmIntrinsics::_fabs: n = new AbsFNode( arg); break; 1816 case vmIntrinsics::_iabs: n = new AbsINode( arg); break; 1817 case vmIntrinsics::_labs: n = new AbsLNode( arg); break; 1818 case vmIntrinsics::_fcopySign: n = new CopySignFNode(arg, argument(1)); break; 1819 case vmIntrinsics::_fsignum: n = SignumFNode::make(_gvn, arg); break; 1820 case vmIntrinsics::_roundF: n = new RoundFNode(arg); break; 1821 default: fatal_unexpected_iid(id); break; 1822 } 1823 set_result(_gvn.transform(n)); 1824 return true; 1825 } 1826 1827 //------------------------------runtime_math----------------------------- 1828 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1829 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1830 "must be (DD)D or (D)D type"); 1831 1832 // Inputs 1833 Node* a = argument(0); 1834 Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? argument(2) : nullptr; 1835 1836 const TypePtr* no_memory_effects = nullptr; 1837 Node* trig = make_runtime_call(RC_LEAF | RC_PURE, call_type, funcAddr, funcName, 1838 no_memory_effects, 1839 a, top(), b, b ? top() : nullptr); 1840 Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0)); 1841 #ifdef ASSERT 1842 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1)); 1843 assert(value_top == top(), "second value must be top"); 1844 #endif 1845 1846 set_result(value); 1847 return true; 1848 } 1849 1850 //------------------------------inline_math_pow----------------------------- 1851 bool LibraryCallKit::inline_math_pow() { 1852 Node* exp = argument(2); 1853 const TypeD* d = _gvn.type(exp)->isa_double_constant(); 1854 if (d != nullptr) { 1855 if (d->getd() == 2.0) { 1856 // Special case: pow(x, 2.0) => x * x 1857 Node* base = argument(0); 1858 set_result(_gvn.transform(new MulDNode(base, base))); 1859 return true; 1860 } else if (d->getd() == 0.5 && Matcher::match_rule_supported(Op_SqrtD)) { 1861 // Special case: pow(x, 0.5) => sqrt(x) 1862 Node* base = argument(0); 1863 Node* zero = _gvn.zerocon(T_DOUBLE); 1864 1865 RegionNode* region = new RegionNode(3); 1866 Node* phi = new PhiNode(region, Type::DOUBLE); 1867 1868 Node* cmp = _gvn.transform(new CmpDNode(base, zero)); 1869 // According to the API specs, pow(-0.0, 0.5) = 0.0 and sqrt(-0.0) = -0.0. 1870 // So pow(-0.0, 0.5) shouldn't be replaced with sqrt(-0.0). 1871 // -0.0/+0.0 are both excluded since floating-point comparison doesn't distinguish -0.0 from +0.0. 1872 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::le)); 1873 1874 Node* if_pow = generate_slow_guard(test, nullptr); 1875 Node* value_sqrt = _gvn.transform(new SqrtDNode(C, control(), base)); 1876 phi->init_req(1, value_sqrt); 1877 region->init_req(1, control()); 1878 1879 if (if_pow != nullptr) { 1880 set_control(if_pow); 1881 address target = StubRoutines::dpow() != nullptr ? StubRoutines::dpow() : 1882 CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 1883 const TypePtr* no_memory_effects = nullptr; 1884 Node* trig = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), target, "POW", 1885 no_memory_effects, base, top(), exp, top()); 1886 Node* value_pow = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0)); 1887 #ifdef ASSERT 1888 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1)); 1889 assert(value_top == top(), "second value must be top"); 1890 #endif 1891 phi->init_req(2, value_pow); 1892 region->init_req(2, _gvn.transform(new ProjNode(trig, TypeFunc::Control))); 1893 } 1894 1895 C->set_has_split_ifs(true); // Has chance for split-if optimization 1896 set_control(_gvn.transform(region)); 1897 record_for_igvn(region); 1898 set_result(_gvn.transform(phi)); 1899 1900 return true; 1901 } 1902 } 1903 1904 return StubRoutines::dpow() != nullptr ? 1905 runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") : 1906 runtime_math(OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW"); 1907 } 1908 1909 //------------------------------inline_math_native----------------------------- 1910 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1911 switch (id) { 1912 case vmIntrinsics::_dsin: 1913 return StubRoutines::dsin() != nullptr ? 1914 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") : 1915 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin), "SIN"); 1916 case vmIntrinsics::_dcos: 1917 return StubRoutines::dcos() != nullptr ? 1918 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") : 1919 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos), "COS"); 1920 case vmIntrinsics::_dtan: 1921 return StubRoutines::dtan() != nullptr ? 1922 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") : 1923 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN"); 1924 case vmIntrinsics::_dsinh: 1925 return StubRoutines::dsinh() != nullptr ? 1926 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsinh(), "dsinh") : false; 1927 case vmIntrinsics::_dtanh: 1928 return StubRoutines::dtanh() != nullptr ? 1929 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtanh(), "dtanh") : false; 1930 case vmIntrinsics::_dcbrt: 1931 return StubRoutines::dcbrt() != nullptr ? 1932 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcbrt(), "dcbrt") : false; 1933 case vmIntrinsics::_dexp: 1934 return StubRoutines::dexp() != nullptr ? 1935 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") : 1936 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP"); 1937 case vmIntrinsics::_dlog: 1938 return StubRoutines::dlog() != nullptr ? 1939 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") : 1940 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog), "LOG"); 1941 case vmIntrinsics::_dlog10: 1942 return StubRoutines::dlog10() != nullptr ? 1943 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") : 1944 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10"); 1945 1946 case vmIntrinsics::_roundD: return Matcher::match_rule_supported(Op_RoundD) ? inline_double_math(id) : false; 1947 case vmIntrinsics::_ceil: 1948 case vmIntrinsics::_floor: 1949 case vmIntrinsics::_rint: return Matcher::match_rule_supported(Op_RoundDoubleMode) ? inline_double_math(id) : false; 1950 1951 case vmIntrinsics::_dsqrt: 1952 case vmIntrinsics::_dsqrt_strict: 1953 return Matcher::match_rule_supported(Op_SqrtD) ? inline_double_math(id) : false; 1954 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_double_math(id) : false; 1955 case vmIntrinsics::_fabs: return Matcher::match_rule_supported(Op_AbsF) ? inline_math(id) : false; 1956 case vmIntrinsics::_iabs: return Matcher::match_rule_supported(Op_AbsI) ? inline_math(id) : false; 1957 case vmIntrinsics::_labs: return Matcher::match_rule_supported(Op_AbsL) ? inline_math(id) : false; 1958 1959 case vmIntrinsics::_dpow: return inline_math_pow(); 1960 case vmIntrinsics::_dcopySign: return inline_double_math(id); 1961 case vmIntrinsics::_fcopySign: return inline_math(id); 1962 case vmIntrinsics::_dsignum: return Matcher::match_rule_supported(Op_SignumD) ? inline_double_math(id) : false; 1963 case vmIntrinsics::_fsignum: return Matcher::match_rule_supported(Op_SignumF) ? inline_math(id) : false; 1964 case vmIntrinsics::_roundF: return Matcher::match_rule_supported(Op_RoundF) ? inline_math(id) : false; 1965 1966 // These intrinsics are not yet correctly implemented 1967 case vmIntrinsics::_datan2: 1968 return false; 1969 1970 default: 1971 fatal_unexpected_iid(id); 1972 return false; 1973 } 1974 } 1975 1976 //----------------------------inline_notify-----------------------------------* 1977 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) { 1978 const TypeFunc* ftype = OptoRuntime::monitor_notify_Type(); 1979 address func; 1980 if (id == vmIntrinsics::_notify) { 1981 func = OptoRuntime::monitor_notify_Java(); 1982 } else { 1983 func = OptoRuntime::monitor_notifyAll_Java(); 1984 } 1985 Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, nullptr, TypeRawPtr::BOTTOM, argument(0)); 1986 make_slow_call_ex(call, env()->Throwable_klass(), false); 1987 return true; 1988 } 1989 1990 1991 //----------------------------inline_min_max----------------------------------- 1992 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 1993 Node* a = nullptr; 1994 Node* b = nullptr; 1995 Node* n = nullptr; 1996 switch (id) { 1997 case vmIntrinsics::_min: 1998 case vmIntrinsics::_max: 1999 case vmIntrinsics::_minF: 2000 case vmIntrinsics::_maxF: 2001 case vmIntrinsics::_minF_strict: 2002 case vmIntrinsics::_maxF_strict: 2003 case vmIntrinsics::_min_strict: 2004 case vmIntrinsics::_max_strict: 2005 assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each."); 2006 a = argument(0); 2007 b = argument(1); 2008 break; 2009 case vmIntrinsics::_minD: 2010 case vmIntrinsics::_maxD: 2011 case vmIntrinsics::_minD_strict: 2012 case vmIntrinsics::_maxD_strict: 2013 assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each."); 2014 a = argument(0); 2015 b = argument(2); 2016 break; 2017 case vmIntrinsics::_minL: 2018 case vmIntrinsics::_maxL: 2019 assert(callee()->signature()->size() == 4, "minL/maxL has 2 parameters of size 2 each."); 2020 a = argument(0); 2021 b = argument(2); 2022 break; 2023 default: 2024 fatal_unexpected_iid(id); 2025 break; 2026 } 2027 2028 switch (id) { 2029 case vmIntrinsics::_min: 2030 case vmIntrinsics::_min_strict: 2031 n = new MinINode(a, b); 2032 break; 2033 case vmIntrinsics::_max: 2034 case vmIntrinsics::_max_strict: 2035 n = new MaxINode(a, b); 2036 break; 2037 case vmIntrinsics::_minF: 2038 case vmIntrinsics::_minF_strict: 2039 n = new MinFNode(a, b); 2040 break; 2041 case vmIntrinsics::_maxF: 2042 case vmIntrinsics::_maxF_strict: 2043 n = new MaxFNode(a, b); 2044 break; 2045 case vmIntrinsics::_minD: 2046 case vmIntrinsics::_minD_strict: 2047 n = new MinDNode(a, b); 2048 break; 2049 case vmIntrinsics::_maxD: 2050 case vmIntrinsics::_maxD_strict: 2051 n = new MaxDNode(a, b); 2052 break; 2053 case vmIntrinsics::_minL: 2054 n = new MinLNode(_gvn.C, a, b); 2055 break; 2056 case vmIntrinsics::_maxL: 2057 n = new MaxLNode(_gvn.C, a, b); 2058 break; 2059 default: 2060 fatal_unexpected_iid(id); 2061 break; 2062 } 2063 2064 set_result(_gvn.transform(n)); 2065 return true; 2066 } 2067 2068 bool LibraryCallKit::inline_math_mathExact(Node* math, Node* test) { 2069 if (builtin_throw_too_many_traps(Deoptimization::Reason_intrinsic, 2070 env()->ArithmeticException_instance())) { 2071 // It has been already too many times, but we cannot use builtin_throw (e.g. we care about backtraces), 2072 // so let's bail out intrinsic rather than risking deopting again. 2073 return false; 2074 } 2075 2076 Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) ); 2077 IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 2078 Node* fast_path = _gvn.transform( new IfFalseNode(check)); 2079 Node* slow_path = _gvn.transform( new IfTrueNode(check) ); 2080 2081 { 2082 PreserveJVMState pjvms(this); 2083 PreserveReexecuteState preexecs(this); 2084 jvms()->set_should_reexecute(true); 2085 2086 set_control(slow_path); 2087 set_i_o(i_o()); 2088 2089 builtin_throw(Deoptimization::Reason_intrinsic, 2090 env()->ArithmeticException_instance(), 2091 /*allow_too_many_traps*/ false); 2092 } 2093 2094 set_control(fast_path); 2095 set_result(math); 2096 return true; 2097 } 2098 2099 template <typename OverflowOp> 2100 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) { 2101 typedef typename OverflowOp::MathOp MathOp; 2102 2103 MathOp* mathOp = new MathOp(arg1, arg2); 2104 Node* operation = _gvn.transform( mathOp ); 2105 Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) ); 2106 return inline_math_mathExact(operation, ofcheck); 2107 } 2108 2109 bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 2110 return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1)); 2111 } 2112 2113 bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 2114 return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2)); 2115 } 2116 2117 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 2118 return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1)); 2119 } 2120 2121 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 2122 return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2)); 2123 } 2124 2125 bool LibraryCallKit::inline_math_negateExactI() { 2126 return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0)); 2127 } 2128 2129 bool LibraryCallKit::inline_math_negateExactL() { 2130 return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0)); 2131 } 2132 2133 bool LibraryCallKit::inline_math_multiplyExactI() { 2134 return inline_math_overflow<OverflowMulINode>(argument(0), argument(1)); 2135 } 2136 2137 bool LibraryCallKit::inline_math_multiplyExactL() { 2138 return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2)); 2139 } 2140 2141 bool LibraryCallKit::inline_math_multiplyHigh() { 2142 set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2)))); 2143 return true; 2144 } 2145 2146 bool LibraryCallKit::inline_math_unsignedMultiplyHigh() { 2147 set_result(_gvn.transform(new UMulHiLNode(argument(0), argument(2)))); 2148 return true; 2149 } 2150 2151 inline int 2152 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) { 2153 const TypePtr* base_type = TypePtr::NULL_PTR; 2154 if (base != nullptr) base_type = _gvn.type(base)->isa_ptr(); 2155 if (base_type == nullptr) { 2156 // Unknown type. 2157 return Type::AnyPtr; 2158 } else if (_gvn.type(base->uncast()) == TypePtr::NULL_PTR) { 2159 // Since this is a null+long form, we have to switch to a rawptr. 2160 base = _gvn.transform(new CastX2PNode(offset)); 2161 offset = MakeConX(0); 2162 return Type::RawPtr; 2163 } else if (base_type->base() == Type::RawPtr) { 2164 return Type::RawPtr; 2165 } else if (base_type->isa_oopptr()) { 2166 // Base is never null => always a heap address. 2167 if (!TypePtr::NULL_PTR->higher_equal(base_type)) { 2168 return Type::OopPtr; 2169 } 2170 // Offset is small => always a heap address. 2171 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 2172 if (offset_type != nullptr && 2173 base_type->offset() == 0 && // (should always be?) 2174 offset_type->_lo >= 0 && 2175 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 2176 return Type::OopPtr; 2177 } else if (type == T_OBJECT) { 2178 // off heap access to an oop doesn't make any sense. Has to be on 2179 // heap. 2180 return Type::OopPtr; 2181 } 2182 // Otherwise, it might either be oop+off or null+addr. 2183 return Type::AnyPtr; 2184 } else { 2185 // No information: 2186 return Type::AnyPtr; 2187 } 2188 } 2189 2190 Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, BasicType type, bool can_cast) { 2191 Node* uncasted_base = base; 2192 int kind = classify_unsafe_addr(uncasted_base, offset, type); 2193 if (kind == Type::RawPtr) { 2194 return basic_plus_adr(top(), uncasted_base, offset); 2195 } else if (kind == Type::AnyPtr) { 2196 assert(base == uncasted_base, "unexpected base change"); 2197 if (can_cast) { 2198 if (!_gvn.type(base)->speculative_maybe_null() && 2199 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2200 // According to profiling, this access is always on 2201 // heap. Casting the base to not null and thus avoiding membars 2202 // around the access should allow better optimizations 2203 Node* null_ctl = top(); 2204 base = null_check_oop(base, &null_ctl, true, true, true); 2205 assert(null_ctl->is_top(), "no null control here"); 2206 return basic_plus_adr(base, offset); 2207 } else if (_gvn.type(base)->speculative_always_null() && 2208 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) { 2209 // According to profiling, this access is always off 2210 // heap. 2211 base = null_assert(base); 2212 Node* raw_base = _gvn.transform(new CastX2PNode(offset)); 2213 offset = MakeConX(0); 2214 return basic_plus_adr(top(), raw_base, offset); 2215 } 2216 } 2217 // We don't know if it's an on heap or off heap access. Fall back 2218 // to raw memory access. 2219 Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM)); 2220 return basic_plus_adr(top(), raw, offset); 2221 } else { 2222 assert(base == uncasted_base, "unexpected base change"); 2223 // We know it's an on heap access so base can't be null 2224 if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) { 2225 base = must_be_not_null(base, true); 2226 } 2227 return basic_plus_adr(base, offset); 2228 } 2229 } 2230 2231 //--------------------------inline_number_methods----------------------------- 2232 // inline int Integer.numberOfLeadingZeros(int) 2233 // inline int Long.numberOfLeadingZeros(long) 2234 // 2235 // inline int Integer.numberOfTrailingZeros(int) 2236 // inline int Long.numberOfTrailingZeros(long) 2237 // 2238 // inline int Integer.bitCount(int) 2239 // inline int Long.bitCount(long) 2240 // 2241 // inline char Character.reverseBytes(char) 2242 // inline short Short.reverseBytes(short) 2243 // inline int Integer.reverseBytes(int) 2244 // inline long Long.reverseBytes(long) 2245 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 2246 Node* arg = argument(0); 2247 Node* n = nullptr; 2248 switch (id) { 2249 case vmIntrinsics::_numberOfLeadingZeros_i: n = new CountLeadingZerosINode( arg); break; 2250 case vmIntrinsics::_numberOfLeadingZeros_l: n = new CountLeadingZerosLNode( arg); break; 2251 case vmIntrinsics::_numberOfTrailingZeros_i: n = new CountTrailingZerosINode(arg); break; 2252 case vmIntrinsics::_numberOfTrailingZeros_l: n = new CountTrailingZerosLNode(arg); break; 2253 case vmIntrinsics::_bitCount_i: n = new PopCountINode( arg); break; 2254 case vmIntrinsics::_bitCount_l: n = new PopCountLNode( arg); break; 2255 case vmIntrinsics::_reverseBytes_c: n = new ReverseBytesUSNode( arg); break; 2256 case vmIntrinsics::_reverseBytes_s: n = new ReverseBytesSNode( arg); break; 2257 case vmIntrinsics::_reverseBytes_i: n = new ReverseBytesINode( arg); break; 2258 case vmIntrinsics::_reverseBytes_l: n = new ReverseBytesLNode( arg); break; 2259 case vmIntrinsics::_reverse_i: n = new ReverseINode( arg); break; 2260 case vmIntrinsics::_reverse_l: n = new ReverseLNode( arg); break; 2261 default: fatal_unexpected_iid(id); break; 2262 } 2263 set_result(_gvn.transform(n)); 2264 return true; 2265 } 2266 2267 //--------------------------inline_bitshuffle_methods----------------------------- 2268 // inline int Integer.compress(int, int) 2269 // inline int Integer.expand(int, int) 2270 // inline long Long.compress(long, long) 2271 // inline long Long.expand(long, long) 2272 bool LibraryCallKit::inline_bitshuffle_methods(vmIntrinsics::ID id) { 2273 Node* n = nullptr; 2274 switch (id) { 2275 case vmIntrinsics::_compress_i: n = new CompressBitsNode(argument(0), argument(1), TypeInt::INT); break; 2276 case vmIntrinsics::_expand_i: n = new ExpandBitsNode(argument(0), argument(1), TypeInt::INT); break; 2277 case vmIntrinsics::_compress_l: n = new CompressBitsNode(argument(0), argument(2), TypeLong::LONG); break; 2278 case vmIntrinsics::_expand_l: n = new ExpandBitsNode(argument(0), argument(2), TypeLong::LONG); break; 2279 default: fatal_unexpected_iid(id); break; 2280 } 2281 set_result(_gvn.transform(n)); 2282 return true; 2283 } 2284 2285 //--------------------------inline_number_methods----------------------------- 2286 // inline int Integer.compareUnsigned(int, int) 2287 // inline int Long.compareUnsigned(long, long) 2288 bool LibraryCallKit::inline_compare_unsigned(vmIntrinsics::ID id) { 2289 Node* arg1 = argument(0); 2290 Node* arg2 = (id == vmIntrinsics::_compareUnsigned_l) ? argument(2) : argument(1); 2291 Node* n = nullptr; 2292 switch (id) { 2293 case vmIntrinsics::_compareUnsigned_i: n = new CmpU3Node(arg1, arg2); break; 2294 case vmIntrinsics::_compareUnsigned_l: n = new CmpUL3Node(arg1, arg2); break; 2295 default: fatal_unexpected_iid(id); break; 2296 } 2297 set_result(_gvn.transform(n)); 2298 return true; 2299 } 2300 2301 //--------------------------inline_unsigned_divmod_methods----------------------------- 2302 // inline int Integer.divideUnsigned(int, int) 2303 // inline int Integer.remainderUnsigned(int, int) 2304 // inline long Long.divideUnsigned(long, long) 2305 // inline long Long.remainderUnsigned(long, long) 2306 bool LibraryCallKit::inline_divmod_methods(vmIntrinsics::ID id) { 2307 Node* n = nullptr; 2308 switch (id) { 2309 case vmIntrinsics::_divideUnsigned_i: { 2310 zero_check_int(argument(1)); 2311 // Compile-time detect of null-exception 2312 if (stopped()) { 2313 return true; // keep the graph constructed so far 2314 } 2315 n = new UDivINode(control(), argument(0), argument(1)); 2316 break; 2317 } 2318 case vmIntrinsics::_divideUnsigned_l: { 2319 zero_check_long(argument(2)); 2320 // Compile-time detect of null-exception 2321 if (stopped()) { 2322 return true; // keep the graph constructed so far 2323 } 2324 n = new UDivLNode(control(), argument(0), argument(2)); 2325 break; 2326 } 2327 case vmIntrinsics::_remainderUnsigned_i: { 2328 zero_check_int(argument(1)); 2329 // Compile-time detect of null-exception 2330 if (stopped()) { 2331 return true; // keep the graph constructed so far 2332 } 2333 n = new UModINode(control(), argument(0), argument(1)); 2334 break; 2335 } 2336 case vmIntrinsics::_remainderUnsigned_l: { 2337 zero_check_long(argument(2)); 2338 // Compile-time detect of null-exception 2339 if (stopped()) { 2340 return true; // keep the graph constructed so far 2341 } 2342 n = new UModLNode(control(), argument(0), argument(2)); 2343 break; 2344 } 2345 default: fatal_unexpected_iid(id); break; 2346 } 2347 set_result(_gvn.transform(n)); 2348 return true; 2349 } 2350 2351 //----------------------------inline_unsafe_access---------------------------- 2352 2353 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { 2354 // Attempt to infer a sharper value type from the offset and base type. 2355 ciKlass* sharpened_klass = nullptr; 2356 bool null_free = false; 2357 2358 // See if it is an instance field, with an object type. 2359 if (alias_type->field() != nullptr) { 2360 if (alias_type->field()->type()->is_klass()) { 2361 sharpened_klass = alias_type->field()->type()->as_klass(); 2362 null_free = alias_type->field()->is_null_free(); 2363 } 2364 } 2365 2366 const TypeOopPtr* result = nullptr; 2367 // See if it is a narrow oop array. 2368 if (adr_type->isa_aryptr()) { 2369 if (adr_type->offset() >= refArrayOopDesc::base_offset_in_bytes()) { 2370 const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr(); 2371 null_free = adr_type->is_aryptr()->is_null_free(); 2372 if (elem_type != nullptr && elem_type->is_loaded()) { 2373 // Sharpen the value type. 2374 result = elem_type; 2375 } 2376 } 2377 } 2378 2379 // The sharpened class might be unloaded if there is no class loader 2380 // contraint in place. 2381 if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) { 2382 // Sharpen the value type. 2383 result = TypeOopPtr::make_from_klass(sharpened_klass); 2384 if (null_free) { 2385 result = result->join_speculative(TypePtr::NOTNULL)->is_oopptr(); 2386 } 2387 } 2388 if (result != nullptr) { 2389 #ifndef PRODUCT 2390 if (C->print_intrinsics() || C->print_inlining()) { 2391 tty->print(" from base type: "); adr_type->dump(); tty->cr(); 2392 tty->print(" sharpened value: "); result->dump(); tty->cr(); 2393 } 2394 #endif 2395 } 2396 return result; 2397 } 2398 2399 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) { 2400 switch (kind) { 2401 case Relaxed: 2402 return MO_UNORDERED; 2403 case Opaque: 2404 return MO_RELAXED; 2405 case Acquire: 2406 return MO_ACQUIRE; 2407 case Release: 2408 return MO_RELEASE; 2409 case Volatile: 2410 return MO_SEQ_CST; 2411 default: 2412 ShouldNotReachHere(); 2413 return 0; 2414 } 2415 } 2416 2417 LibraryCallKit::SavedState::SavedState(LibraryCallKit* kit) : 2418 _kit(kit), 2419 _sp(kit->sp()), 2420 _jvms(kit->jvms()), 2421 _map(kit->clone_map()), 2422 _discarded(false) 2423 { 2424 for (DUIterator_Fast imax, i = kit->control()->fast_outs(imax); i < imax; i++) { 2425 Node* out = kit->control()->fast_out(i); 2426 if (out->is_CFG()) { 2427 _ctrl_succ.push(out); 2428 } 2429 } 2430 } 2431 2432 LibraryCallKit::SavedState::~SavedState() { 2433 if (_discarded) { 2434 _kit->destruct_map_clone(_map); 2435 return; 2436 } 2437 _kit->jvms()->set_map(_map); 2438 _kit->jvms()->set_sp(_sp); 2439 _map->set_jvms(_kit->jvms()); 2440 _kit->set_map(_map); 2441 _kit->set_sp(_sp); 2442 for (DUIterator_Fast imax, i = _kit->control()->fast_outs(imax); i < imax; i++) { 2443 Node* out = _kit->control()->fast_out(i); 2444 if (out->is_CFG() && out->in(0) == _kit->control() && out != _kit->map() && !_ctrl_succ.member(out)) { 2445 _kit->_gvn.hash_delete(out); 2446 out->set_req(0, _kit->C->top()); 2447 _kit->C->record_for_igvn(out); 2448 --i; --imax; 2449 _kit->_gvn.hash_find_insert(out); 2450 } 2451 } 2452 } 2453 2454 void LibraryCallKit::SavedState::discard() { 2455 _discarded = true; 2456 } 2457 2458 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned, const bool is_flat) { 2459 if (callee()->is_static()) return false; // caller must have the capability! 2460 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2461 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); 2462 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); 2463 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); 2464 2465 if (is_reference_type(type)) { 2466 decorators |= ON_UNKNOWN_OOP_REF; 2467 } 2468 2469 if (unaligned) { 2470 decorators |= C2_UNALIGNED; 2471 } 2472 2473 #ifndef PRODUCT 2474 { 2475 ResourceMark rm; 2476 // Check the signatures. 2477 ciSignature* sig = callee()->signature(); 2478 #ifdef ASSERT 2479 if (!is_store) { 2480 // Object getReference(Object base, int/long offset), etc. 2481 BasicType rtype = sig->return_type()->basic_type(); 2482 assert(rtype == type, "getter must return the expected value"); 2483 assert(sig->count() == 2 || (is_flat && sig->count() == 3), "oop getter has 2 or 3 arguments"); 2484 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 2485 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 2486 } else { 2487 // void putReference(Object base, int/long offset, Object x), etc. 2488 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 2489 assert(sig->count() == 3 || (is_flat && sig->count() == 4), "oop putter has 3 arguments"); 2490 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 2491 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 2492 BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 2493 assert(vtype == type, "putter must accept the expected value"); 2494 } 2495 #endif // ASSERT 2496 } 2497 #endif //PRODUCT 2498 2499 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2500 2501 Node* receiver = argument(0); // type: oop 2502 2503 // Build address expression. 2504 Node* heap_base_oop = top(); 2505 2506 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2507 Node* base = argument(1); // type: oop 2508 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2509 Node* offset = argument(2); // type: long 2510 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2511 // to be plain byte offsets, which are also the same as those accepted 2512 // by oopDesc::field_addr. 2513 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2514 "fieldOffset must be byte-scaled"); 2515 2516 ciInlineKlass* inline_klass = nullptr; 2517 if (is_flat) { 2518 const TypeInstPtr* cls = _gvn.type(argument(4))->isa_instptr(); 2519 if (cls == nullptr || cls->const_oop() == nullptr) { 2520 return false; 2521 } 2522 ciType* mirror_type = cls->const_oop()->as_instance()->java_mirror_type(); 2523 if (!mirror_type->is_inlinetype()) { 2524 return false; 2525 } 2526 inline_klass = mirror_type->as_inline_klass(); 2527 } 2528 2529 if (base->is_InlineType()) { 2530 assert(!is_store, "InlineTypeNodes are non-larval value objects"); 2531 InlineTypeNode* vt = base->as_InlineType(); 2532 if (offset->is_Con()) { 2533 long off = find_long_con(offset, 0); 2534 ciInlineKlass* vk = vt->type()->inline_klass(); 2535 if ((long)(int)off != off || !vk->contains_field_offset(off)) { 2536 return false; 2537 } 2538 2539 ciField* field = vk->get_non_flat_field_by_offset(off); 2540 if (field != nullptr) { 2541 BasicType bt = type2field[field->type()->basic_type()]; 2542 if (bt == T_ARRAY || bt == T_NARROWOOP) { 2543 bt = T_OBJECT; 2544 } 2545 if (bt == type && (!field->is_flat() || field->type() == inline_klass)) { 2546 Node* value = vt->field_value_by_offset(off, false); 2547 if (value->is_InlineType()) { 2548 value = value->as_InlineType()->adjust_scalarization_depth(this); 2549 } 2550 set_result(value); 2551 return true; 2552 } 2553 } 2554 } 2555 { 2556 // Re-execute the unsafe access if allocation triggers deoptimization. 2557 PreserveReexecuteState preexecs(this); 2558 jvms()->set_should_reexecute(true); 2559 vt = vt->buffer(this); 2560 } 2561 base = vt->get_oop(); 2562 } 2563 2564 // 32-bit machines ignore the high half! 2565 offset = ConvL2X(offset); 2566 2567 // Save state and restore on bailout 2568 SavedState old_state(this); 2569 2570 Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed); 2571 assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly"); 2572 2573 if (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR) { 2574 if (type != T_OBJECT && (inline_klass == nullptr || !inline_klass->has_object_fields())) { 2575 decorators |= IN_NATIVE; // off-heap primitive access 2576 } else { 2577 return false; // off-heap oop accesses are not supported 2578 } 2579 } else { 2580 heap_base_oop = base; // on-heap or mixed access 2581 } 2582 2583 // Can base be null? Otherwise, always on-heap access. 2584 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base)); 2585 2586 if (!can_access_non_heap) { 2587 decorators |= IN_HEAP; 2588 } 2589 2590 Node* val = is_store ? argument(4 + (is_flat ? 1 : 0)) : nullptr; 2591 2592 const TypePtr* adr_type = _gvn.type(adr)->isa_ptr(); 2593 if (adr_type == TypePtr::NULL_PTR) { 2594 return false; // off-heap access with zero address 2595 } 2596 2597 // Try to categorize the address. 2598 Compile::AliasType* alias_type = C->alias_type(adr_type); 2599 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2600 2601 if (alias_type->adr_type() == TypeInstPtr::KLASS || 2602 alias_type->adr_type() == TypeAryPtr::RANGE) { 2603 return false; // not supported 2604 } 2605 2606 bool mismatched = false; 2607 BasicType bt = T_ILLEGAL; 2608 ciField* field = nullptr; 2609 if (adr_type->isa_instptr()) { 2610 const TypeInstPtr* instptr = adr_type->is_instptr(); 2611 ciInstanceKlass* k = instptr->instance_klass(); 2612 int off = instptr->offset(); 2613 if (instptr->const_oop() != nullptr && 2614 k == ciEnv::current()->Class_klass() && 2615 instptr->offset() >= (k->size_helper() * wordSize)) { 2616 k = instptr->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); 2617 field = k->get_field_by_offset(off, true); 2618 } else { 2619 field = k->get_non_flat_field_by_offset(off); 2620 } 2621 if (field != nullptr) { 2622 bt = type2field[field->type()->basic_type()]; 2623 } 2624 if (bt != alias_type->basic_type()) { 2625 // Type mismatch. Is it an access to a nested flat field? 2626 field = k->get_field_by_offset(off, false); 2627 if (field != nullptr) { 2628 bt = type2field[field->type()->basic_type()]; 2629 } 2630 } 2631 assert(bt == alias_type->basic_type() || is_flat, "should match"); 2632 } else { 2633 bt = alias_type->basic_type(); 2634 } 2635 2636 if (bt != T_ILLEGAL) { 2637 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access"); 2638 if (bt == T_BYTE && adr_type->isa_aryptr()) { 2639 // Alias type doesn't differentiate between byte[] and boolean[]). 2640 // Use address type to get the element type. 2641 bt = adr_type->is_aryptr()->elem()->array_element_basic_type(); 2642 } 2643 if (is_reference_type(bt, true)) { 2644 // accessing an array field with getReference is not a mismatch 2645 bt = T_OBJECT; 2646 } 2647 if ((bt == T_OBJECT) != (type == T_OBJECT)) { 2648 // Don't intrinsify mismatched object accesses 2649 return false; 2650 } 2651 mismatched = (bt != type); 2652 } else if (alias_type->adr_type()->isa_oopptr()) { 2653 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched 2654 } 2655 2656 if (is_flat) { 2657 if (adr_type->isa_instptr()) { 2658 if (field == nullptr || field->type() != inline_klass) { 2659 mismatched = true; 2660 } 2661 } else if (adr_type->isa_aryptr()) { 2662 const Type* elem = adr_type->is_aryptr()->elem(); 2663 if (!adr_type->is_flat() || elem->inline_klass() != inline_klass) { 2664 mismatched = true; 2665 } 2666 } else { 2667 mismatched = true; 2668 } 2669 if (is_store) { 2670 const Type* val_t = _gvn.type(val); 2671 if (!val_t->is_inlinetypeptr() || val_t->inline_klass() != inline_klass) { 2672 return false; 2673 } 2674 } 2675 } 2676 2677 old_state.discard(); 2678 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); 2679 2680 if (mismatched) { 2681 decorators |= C2_MISMATCHED; 2682 } 2683 2684 // First guess at the value type. 2685 const Type *value_type = Type::get_const_basic_type(type); 2686 2687 // Figure out the memory ordering. 2688 decorators |= mo_decorator_for_access_kind(kind); 2689 2690 if (!is_store) { 2691 if (type == T_OBJECT && !is_flat) { 2692 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2693 if (tjp != nullptr) { 2694 value_type = tjp; 2695 } 2696 } 2697 } 2698 2699 receiver = null_check(receiver); 2700 if (stopped()) { 2701 return true; 2702 } 2703 // Heap pointers get a null-check from the interpreter, 2704 // as a courtesy. However, this is not guaranteed by Unsafe, 2705 // and it is not possible to fully distinguish unintended nulls 2706 // from intended ones in this API. 2707 2708 if (!is_store) { 2709 Node* p = nullptr; 2710 // Try to constant fold a load from a constant field 2711 2712 if (heap_base_oop != top() && field != nullptr && field->is_constant() && !field->is_flat() && !mismatched) { 2713 // final or stable field 2714 p = make_constant_from_field(field, heap_base_oop); 2715 } 2716 2717 if (p == nullptr) { // Could not constant fold the load 2718 if (is_flat) { 2719 p = InlineTypeNode::make_from_flat(this, inline_klass, base, adr, adr_type, false, false, true); 2720 } else { 2721 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators); 2722 const TypeOopPtr* ptr = value_type->make_oopptr(); 2723 if (ptr != nullptr && ptr->is_inlinetypeptr()) { 2724 // Load a non-flattened inline type from memory 2725 p = InlineTypeNode::make_from_oop(this, p, ptr->inline_klass()); 2726 } 2727 } 2728 // Normalize the value returned by getBoolean in the following cases 2729 if (type == T_BOOLEAN && 2730 (mismatched || 2731 heap_base_oop == top() || // - heap_base_oop is null or 2732 (can_access_non_heap && field == nullptr)) // - heap_base_oop is potentially null 2733 // and the unsafe access is made to large offset 2734 // (i.e., larger than the maximum offset necessary for any 2735 // field access) 2736 ) { 2737 IdealKit ideal = IdealKit(this); 2738 #define __ ideal. 2739 IdealVariable normalized_result(ideal); 2740 __ declarations_done(); 2741 __ set(normalized_result, p); 2742 __ if_then(p, BoolTest::ne, ideal.ConI(0)); 2743 __ set(normalized_result, ideal.ConI(1)); 2744 ideal.end_if(); 2745 final_sync(ideal); 2746 p = __ value(normalized_result); 2747 #undef __ 2748 } 2749 } 2750 if (type == T_ADDRESS) { 2751 p = gvn().transform(new CastP2XNode(nullptr, p)); 2752 p = ConvX2UL(p); 2753 } 2754 // The load node has the control of the preceding MemBarCPUOrder. All 2755 // following nodes will have the control of the MemBarCPUOrder inserted at 2756 // the end of this method. So, pushing the load onto the stack at a later 2757 // point is fine. 2758 set_result(p); 2759 } else { 2760 if (bt == T_ADDRESS) { 2761 // Repackage the long as a pointer. 2762 val = ConvL2X(val); 2763 val = gvn().transform(new CastX2PNode(val)); 2764 } 2765 if (is_flat) { 2766 val->as_InlineType()->store_flat(this, base, adr, false, false, true, decorators); 2767 } else { 2768 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators); 2769 } 2770 } 2771 2772 return true; 2773 } 2774 2775 bool LibraryCallKit::inline_unsafe_flat_access(bool is_store, AccessKind kind) { 2776 #ifdef ASSERT 2777 { 2778 ResourceMark rm; 2779 // Check the signatures. 2780 ciSignature* sig = callee()->signature(); 2781 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base should be object, but is %s", type2name(sig->type_at(0)->basic_type())); 2782 assert(sig->type_at(1)->basic_type() == T_LONG, "offset should be long, but is %s", type2name(sig->type_at(1)->basic_type())); 2783 assert(sig->type_at(2)->basic_type() == T_INT, "layout kind should be int, but is %s", type2name(sig->type_at(3)->basic_type())); 2784 assert(sig->type_at(3)->basic_type() == T_OBJECT, "value klass should be object, but is %s", type2name(sig->type_at(4)->basic_type())); 2785 if (is_store) { 2786 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value, but returns %s", type2name(sig->return_type()->basic_type())); 2787 assert(sig->count() == 5, "flat putter should have 5 arguments, but has %d", sig->count()); 2788 assert(sig->type_at(4)->basic_type() == T_OBJECT, "put value should be object, but is %s", type2name(sig->type_at(5)->basic_type())); 2789 } else { 2790 assert(sig->return_type()->basic_type() == T_OBJECT, "getter must return an object, but returns %s", type2name(sig->return_type()->basic_type())); 2791 assert(sig->count() == 4, "flat getter should have 4 arguments, but has %d", sig->count()); 2792 } 2793 } 2794 #endif // ASSERT 2795 2796 assert(kind == Relaxed, "Only plain accesses for now"); 2797 if (callee()->is_static()) { 2798 // caller must have the capability! 2799 return false; 2800 } 2801 C->set_has_unsafe_access(true); 2802 2803 const TypeInstPtr* value_klass_node = _gvn.type(argument(5))->isa_instptr(); 2804 if (value_klass_node == nullptr || value_klass_node->const_oop() == nullptr) { 2805 // parameter valueType is not a constant 2806 return false; 2807 } 2808 ciType* mirror_type = value_klass_node->const_oop()->as_instance()->java_mirror_type(); 2809 if (!mirror_type->is_inlinetype()) { 2810 // Dead code 2811 return false; 2812 } 2813 ciInlineKlass* value_klass = mirror_type->as_inline_klass(); 2814 2815 const TypeInt* layout_type = _gvn.type(argument(4))->isa_int(); 2816 if (layout_type == nullptr || !layout_type->is_con()) { 2817 // parameter layoutKind is not a constant 2818 return false; 2819 } 2820 assert(layout_type->get_con() >= static_cast<int>(LayoutKind::REFERENCE) && 2821 layout_type->get_con() <= static_cast<int>(LayoutKind::UNKNOWN), 2822 "invalid layoutKind %d", layout_type->get_con()); 2823 LayoutKind layout = static_cast<LayoutKind>(layout_type->get_con()); 2824 assert(layout == LayoutKind::REFERENCE || layout == LayoutKind::NON_ATOMIC_FLAT || 2825 layout == LayoutKind::ATOMIC_FLAT || layout == LayoutKind::NULLABLE_ATOMIC_FLAT, 2826 "unexpected layoutKind %d", layout_type->get_con()); 2827 2828 null_check(argument(0)); 2829 if (stopped()) { 2830 return true; 2831 } 2832 2833 Node* base = must_be_not_null(argument(1), true); 2834 Node* offset = argument(2); 2835 const Type* base_type = _gvn.type(base); 2836 2837 Node* ptr; 2838 bool immutable_memory = false; 2839 DecoratorSet decorators = C2_UNSAFE_ACCESS | IN_HEAP | MO_UNORDERED; 2840 if (base_type->isa_instptr()) { 2841 const TypeLong* offset_type = _gvn.type(offset)->isa_long(); 2842 if (offset_type == nullptr || !offset_type->is_con()) { 2843 // Offset into a non-array should be a constant 2844 decorators |= C2_MISMATCHED; 2845 } else { 2846 int offset_con = checked_cast<int>(offset_type->get_con()); 2847 ciInstanceKlass* base_klass = base_type->is_instptr()->instance_klass(); 2848 ciField* field = base_klass->get_non_flat_field_by_offset(offset_con); 2849 if (field == nullptr) { 2850 assert(!base_klass->is_final(), "non-existence field at offset %d of class %s", offset_con, base_klass->name()->as_utf8()); 2851 decorators |= C2_MISMATCHED; 2852 } else { 2853 assert(field->type() == value_klass, "field at offset %d of %s is of type %s, but valueType is %s", 2854 offset_con, base_klass->name()->as_utf8(), field->type()->name(), value_klass->name()->as_utf8()); 2855 immutable_memory = field->is_strict() && field->is_final(); 2856 2857 if (base->is_InlineType()) { 2858 assert(!is_store, "Cannot store into a non-larval value object"); 2859 set_result(base->as_InlineType()->field_value_by_offset(offset_con, false)); 2860 return true; 2861 } 2862 } 2863 } 2864 2865 if (base->is_InlineType()) { 2866 assert(!is_store, "Cannot store into a non-larval value object"); 2867 base = base->as_InlineType()->buffer(this, true); 2868 } 2869 ptr = basic_plus_adr(base, ConvL2X(offset)); 2870 } else if (base_type->isa_aryptr()) { 2871 decorators |= IS_ARRAY; 2872 if (layout == LayoutKind::REFERENCE) { 2873 if (!base_type->is_aryptr()->is_not_flat()) { 2874 const TypeAryPtr* array_type = base_type->is_aryptr()->cast_to_not_flat(); 2875 Node* new_base = _gvn.transform(new CastPPNode(control(), base, array_type, ConstraintCastNode::StrongDependency)); 2876 replace_in_map(base, new_base); 2877 base = new_base; 2878 } 2879 ptr = basic_plus_adr(base, ConvL2X(offset)); 2880 } else { 2881 if (UseArrayFlattening) { 2882 // Flat array must have an exact type 2883 bool is_null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2884 bool is_atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2885 Node* new_base = cast_to_flat_array(base, value_klass, is_null_free, !is_null_free, is_atomic); 2886 replace_in_map(base, new_base); 2887 base = new_base; 2888 ptr = basic_plus_adr(base, ConvL2X(offset)); 2889 const TypeAryPtr* ptr_type = _gvn.type(ptr)->is_aryptr(); 2890 if (ptr_type->field_offset().get() != 0) { 2891 ptr = _gvn.transform(new CastPPNode(control(), ptr, ptr_type->with_field_offset(0), ConstraintCastNode::StrongDependency)); 2892 } 2893 } else { 2894 uncommon_trap(Deoptimization::Reason_intrinsic, 2895 Deoptimization::Action_none); 2896 return true; 2897 } 2898 } 2899 } else { 2900 decorators |= C2_MISMATCHED; 2901 ptr = basic_plus_adr(base, ConvL2X(offset)); 2902 } 2903 2904 if (is_store) { 2905 Node* value = argument(6); 2906 const Type* value_type = _gvn.type(value); 2907 if (!value_type->is_inlinetypeptr()) { 2908 value_type = Type::get_const_type(value_klass)->filter_speculative(value_type); 2909 Node* new_value = _gvn.transform(new CastPPNode(control(), value, value_type, ConstraintCastNode::StrongDependency)); 2910 new_value = InlineTypeNode::make_from_oop(this, new_value, value_klass); 2911 replace_in_map(value, new_value); 2912 value = new_value; 2913 } 2914 2915 assert(value_type->inline_klass() == value_klass, "value is of type %s while valueType is %s", value_type->inline_klass()->name()->as_utf8(), value_klass->name()->as_utf8()); 2916 if (layout == LayoutKind::REFERENCE) { 2917 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr(); 2918 access_store_at(base, ptr, ptr_type, value, value_type, T_OBJECT, decorators); 2919 } else { 2920 bool atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2921 bool null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2922 value->as_InlineType()->store_flat(this, base, ptr, atomic, immutable_memory, null_free, decorators); 2923 } 2924 2925 return true; 2926 } else { 2927 decorators |= (C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD); 2928 InlineTypeNode* result; 2929 if (layout == LayoutKind::REFERENCE) { 2930 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr(); 2931 Node* oop = access_load_at(base, ptr, ptr_type, Type::get_const_type(value_klass), T_OBJECT, decorators); 2932 result = InlineTypeNode::make_from_oop(this, oop, value_klass); 2933 } else { 2934 bool atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2935 bool null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2936 result = InlineTypeNode::make_from_flat(this, value_klass, base, ptr, atomic, immutable_memory, null_free, decorators); 2937 } 2938 2939 set_result(result); 2940 return true; 2941 } 2942 } 2943 2944 bool LibraryCallKit::inline_unsafe_make_private_buffer() { 2945 Node* receiver = argument(0); 2946 Node* value = argument(1); 2947 2948 const Type* type = gvn().type(value); 2949 if (!type->is_inlinetypeptr()) { 2950 C->record_method_not_compilable("value passed to Unsafe::makePrivateBuffer is not of a constant value type"); 2951 return false; 2952 } 2953 2954 null_check(receiver); 2955 if (stopped()) { 2956 return true; 2957 } 2958 2959 value = null_check(value); 2960 if (stopped()) { 2961 return true; 2962 } 2963 2964 ciInlineKlass* vk = type->inline_klass(); 2965 Node* klass = makecon(TypeKlassPtr::make(vk)); 2966 Node* obj = new_instance(klass); 2967 AllocateNode::Ideal_allocation(obj)->_larval = true; 2968 2969 assert(value->is_InlineType(), "must be an InlineTypeNode"); 2970 Node* payload_ptr = basic_plus_adr(obj, vk->payload_offset()); 2971 value->as_InlineType()->store_flat(this, obj, payload_ptr, false, true, true, IN_HEAP | MO_UNORDERED); 2972 2973 set_result(obj); 2974 return true; 2975 } 2976 2977 bool LibraryCallKit::inline_unsafe_finish_private_buffer() { 2978 Node* receiver = argument(0); 2979 Node* buffer = argument(1); 2980 2981 const Type* type = gvn().type(buffer); 2982 if (!type->is_inlinetypeptr()) { 2983 C->record_method_not_compilable("value passed to Unsafe::finishPrivateBuffer is not of a constant value type"); 2984 return false; 2985 } 2986 2987 AllocateNode* alloc = AllocateNode::Ideal_allocation(buffer); 2988 if (alloc == nullptr) { 2989 C->record_method_not_compilable("value passed to Unsafe::finishPrivateBuffer must be allocated by Unsafe::makePrivateBuffer"); 2990 return false; 2991 } 2992 2993 null_check(receiver); 2994 if (stopped()) { 2995 return true; 2996 } 2997 2998 // Unset the larval bit in the object header 2999 Node* old_header = make_load(control(), buffer, TypeX_X, TypeX_X->basic_type(), MemNode::unordered, LoadNode::Pinned); 3000 Node* new_header = gvn().transform(new AndXNode(old_header, MakeConX(~markWord::larval_bit_in_place))); 3001 access_store_at(buffer, buffer, type->is_ptr(), new_header, TypeX_X, TypeX_X->basic_type(), MO_UNORDERED | IN_HEAP); 3002 3003 // We must ensure that the buffer is properly published 3004 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 3005 assert(!type->maybe_null(), "result of an allocation should not be null"); 3006 set_result(InlineTypeNode::make_from_oop(this, buffer, type->inline_klass())); 3007 return true; 3008 } 3009 3010 //----------------------------inline_unsafe_load_store---------------------------- 3011 // This method serves a couple of different customers (depending on LoadStoreKind): 3012 // 3013 // LS_cmp_swap: 3014 // 3015 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x); 3016 // boolean compareAndSetInt( Object o, long offset, int expected, int x); 3017 // boolean compareAndSetLong( Object o, long offset, long expected, long x); 3018 // 3019 // LS_cmp_swap_weak: 3020 // 3021 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x); 3022 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x); 3023 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x); 3024 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x); 3025 // 3026 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x); 3027 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x); 3028 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x); 3029 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x); 3030 // 3031 // boolean weakCompareAndSetLong( Object o, long offset, long expected, long x); 3032 // boolean weakCompareAndSetLongPlain( Object o, long offset, long expected, long x); 3033 // boolean weakCompareAndSetLongAcquire( Object o, long offset, long expected, long x); 3034 // boolean weakCompareAndSetLongRelease( Object o, long offset, long expected, long x); 3035 // 3036 // LS_cmp_exchange: 3037 // 3038 // Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x); 3039 // Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x); 3040 // Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x); 3041 // 3042 // Object compareAndExchangeIntVolatile( Object o, long offset, Object expected, Object x); 3043 // Object compareAndExchangeIntAcquire( Object o, long offset, Object expected, Object x); 3044 // Object compareAndExchangeIntRelease( Object o, long offset, Object expected, Object x); 3045 // 3046 // Object compareAndExchangeLongVolatile( Object o, long offset, Object expected, Object x); 3047 // Object compareAndExchangeLongAcquire( Object o, long offset, Object expected, Object x); 3048 // Object compareAndExchangeLongRelease( Object o, long offset, Object expected, Object x); 3049 // 3050 // LS_get_add: 3051 // 3052 // int getAndAddInt( Object o, long offset, int delta) 3053 // long getAndAddLong(Object o, long offset, long delta) 3054 // 3055 // LS_get_set: 3056 // 3057 // int getAndSet(Object o, long offset, int newValue) 3058 // long getAndSet(Object o, long offset, long newValue) 3059 // Object getAndSet(Object o, long offset, Object newValue) 3060 // 3061 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) { 3062 // This basic scheme here is the same as inline_unsafe_access, but 3063 // differs in enough details that combining them would make the code 3064 // overly confusing. (This is a true fact! I originally combined 3065 // them, but even I was confused by it!) As much code/comments as 3066 // possible are retained from inline_unsafe_access though to make 3067 // the correspondences clearer. - dl 3068 3069 if (callee()->is_static()) return false; // caller must have the capability! 3070 3071 DecoratorSet decorators = C2_UNSAFE_ACCESS; 3072 decorators |= mo_decorator_for_access_kind(access_kind); 3073 3074 #ifndef PRODUCT 3075 BasicType rtype; 3076 { 3077 ResourceMark rm; 3078 // Check the signatures. 3079 ciSignature* sig = callee()->signature(); 3080 rtype = sig->return_type()->basic_type(); 3081 switch(kind) { 3082 case LS_get_add: 3083 case LS_get_set: { 3084 // Check the signatures. 3085 #ifdef ASSERT 3086 assert(rtype == type, "get and set must return the expected type"); 3087 assert(sig->count() == 3, "get and set has 3 arguments"); 3088 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 3089 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 3090 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 3091 assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation"); 3092 #endif // ASSERT 3093 break; 3094 } 3095 case LS_cmp_swap: 3096 case LS_cmp_swap_weak: { 3097 // Check the signatures. 3098 #ifdef ASSERT 3099 assert(rtype == T_BOOLEAN, "CAS must return boolean"); 3100 assert(sig->count() == 4, "CAS has 4 arguments"); 3101 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 3102 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 3103 #endif // ASSERT 3104 break; 3105 } 3106 case LS_cmp_exchange: { 3107 // Check the signatures. 3108 #ifdef ASSERT 3109 assert(rtype == type, "CAS must return the expected type"); 3110 assert(sig->count() == 4, "CAS has 4 arguments"); 3111 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 3112 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 3113 #endif // ASSERT 3114 break; 3115 } 3116 default: 3117 ShouldNotReachHere(); 3118 } 3119 } 3120 #endif //PRODUCT 3121 3122 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 3123 3124 // Get arguments: 3125 Node* receiver = nullptr; 3126 Node* base = nullptr; 3127 Node* offset = nullptr; 3128 Node* oldval = nullptr; 3129 Node* newval = nullptr; 3130 switch(kind) { 3131 case LS_cmp_swap: 3132 case LS_cmp_swap_weak: 3133 case LS_cmp_exchange: { 3134 const bool two_slot_type = type2size[type] == 2; 3135 receiver = argument(0); // type: oop 3136 base = argument(1); // type: oop 3137 offset = argument(2); // type: long 3138 oldval = argument(4); // type: oop, int, or long 3139 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 3140 break; 3141 } 3142 case LS_get_add: 3143 case LS_get_set: { 3144 receiver = argument(0); // type: oop 3145 base = argument(1); // type: oop 3146 offset = argument(2); // type: long 3147 oldval = nullptr; 3148 newval = argument(4); // type: oop, int, or long 3149 break; 3150 } 3151 default: 3152 ShouldNotReachHere(); 3153 } 3154 3155 // Build field offset expression. 3156 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 3157 // to be plain byte offsets, which are also the same as those accepted 3158 // by oopDesc::field_addr. 3159 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 3160 // 32-bit machines ignore the high half of long offsets 3161 offset = ConvL2X(offset); 3162 // Save state and restore on bailout 3163 SavedState old_state(this); 3164 Node* adr = make_unsafe_address(base, offset,type, false); 3165 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 3166 3167 Compile::AliasType* alias_type = C->alias_type(adr_type); 3168 BasicType bt = alias_type->basic_type(); 3169 if (bt != T_ILLEGAL && 3170 (is_reference_type(bt) != (type == T_OBJECT))) { 3171 // Don't intrinsify mismatched object accesses. 3172 return false; 3173 } 3174 3175 old_state.discard(); 3176 3177 // For CAS, unlike inline_unsafe_access, there seems no point in 3178 // trying to refine types. Just use the coarse types here. 3179 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 3180 const Type *value_type = Type::get_const_basic_type(type); 3181 3182 switch (kind) { 3183 case LS_get_set: 3184 case LS_cmp_exchange: { 3185 if (type == T_OBJECT) { 3186 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 3187 if (tjp != nullptr) { 3188 value_type = tjp; 3189 } 3190 } 3191 break; 3192 } 3193 case LS_cmp_swap: 3194 case LS_cmp_swap_weak: 3195 case LS_get_add: 3196 break; 3197 default: 3198 ShouldNotReachHere(); 3199 } 3200 3201 // Null check receiver. 3202 receiver = null_check(receiver); 3203 if (stopped()) { 3204 return true; 3205 } 3206 3207 int alias_idx = C->get_alias_index(adr_type); 3208 3209 if (is_reference_type(type)) { 3210 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF; 3211 3212 if (oldval != nullptr && oldval->is_InlineType()) { 3213 // Re-execute the unsafe access if allocation triggers deoptimization. 3214 PreserveReexecuteState preexecs(this); 3215 jvms()->set_should_reexecute(true); 3216 oldval = oldval->as_InlineType()->buffer(this)->get_oop(); 3217 } 3218 if (newval != nullptr && newval->is_InlineType()) { 3219 // Re-execute the unsafe access if allocation triggers deoptimization. 3220 PreserveReexecuteState preexecs(this); 3221 jvms()->set_should_reexecute(true); 3222 newval = newval->as_InlineType()->buffer(this)->get_oop(); 3223 } 3224 3225 // Transformation of a value which could be null pointer (CastPP #null) 3226 // could be delayed during Parse (for example, in adjust_map_after_if()). 3227 // Execute transformation here to avoid barrier generation in such case. 3228 if (_gvn.type(newval) == TypePtr::NULL_PTR) 3229 newval = _gvn.makecon(TypePtr::NULL_PTR); 3230 3231 if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) { 3232 // Refine the value to a null constant, when it is known to be null 3233 oldval = _gvn.makecon(TypePtr::NULL_PTR); 3234 } 3235 } 3236 3237 Node* result = nullptr; 3238 switch (kind) { 3239 case LS_cmp_exchange: { 3240 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx, 3241 oldval, newval, value_type, type, decorators); 3242 break; 3243 } 3244 case LS_cmp_swap_weak: 3245 decorators |= C2_WEAK_CMPXCHG; 3246 case LS_cmp_swap: { 3247 result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx, 3248 oldval, newval, value_type, type, decorators); 3249 break; 3250 } 3251 case LS_get_set: { 3252 result = access_atomic_xchg_at(base, adr, adr_type, alias_idx, 3253 newval, value_type, type, decorators); 3254 break; 3255 } 3256 case LS_get_add: { 3257 result = access_atomic_add_at(base, adr, adr_type, alias_idx, 3258 newval, value_type, type, decorators); 3259 break; 3260 } 3261 default: 3262 ShouldNotReachHere(); 3263 } 3264 3265 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 3266 set_result(result); 3267 return true; 3268 } 3269 3270 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 3271 // Regardless of form, don't allow previous ld/st to move down, 3272 // then issue acquire, release, or volatile mem_bar. 3273 insert_mem_bar(Op_MemBarCPUOrder); 3274 switch(id) { 3275 case vmIntrinsics::_loadFence: 3276 insert_mem_bar(Op_LoadFence); 3277 return true; 3278 case vmIntrinsics::_storeFence: 3279 insert_mem_bar(Op_StoreFence); 3280 return true; 3281 case vmIntrinsics::_storeStoreFence: 3282 insert_mem_bar(Op_StoreStoreFence); 3283 return true; 3284 case vmIntrinsics::_fullFence: 3285 insert_mem_bar(Op_MemBarVolatile); 3286 return true; 3287 default: 3288 fatal_unexpected_iid(id); 3289 return false; 3290 } 3291 } 3292 3293 bool LibraryCallKit::inline_onspinwait() { 3294 insert_mem_bar(Op_OnSpinWait); 3295 return true; 3296 } 3297 3298 bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 3299 if (!kls->is_Con()) { 3300 return true; 3301 } 3302 const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr(); 3303 if (klsptr == nullptr) { 3304 return true; 3305 } 3306 ciInstanceKlass* ik = klsptr->instance_klass(); 3307 // don't need a guard for a klass that is already initialized 3308 return !ik->is_initialized(); 3309 } 3310 3311 //----------------------------inline_unsafe_writeback0------------------------- 3312 // public native void Unsafe.writeback0(long address) 3313 bool LibraryCallKit::inline_unsafe_writeback0() { 3314 if (!Matcher::has_match_rule(Op_CacheWB)) { 3315 return false; 3316 } 3317 #ifndef PRODUCT 3318 assert(Matcher::has_match_rule(Op_CacheWBPreSync), "found match rule for CacheWB but not CacheWBPreSync"); 3319 assert(Matcher::has_match_rule(Op_CacheWBPostSync), "found match rule for CacheWB but not CacheWBPostSync"); 3320 ciSignature* sig = callee()->signature(); 3321 assert(sig->type_at(0)->basic_type() == T_LONG, "Unsafe_writeback0 address is long!"); 3322 #endif 3323 null_check_receiver(); // null-check, then ignore 3324 Node *addr = argument(1); 3325 addr = new CastX2PNode(addr); 3326 addr = _gvn.transform(addr); 3327 Node *flush = new CacheWBNode(control(), memory(TypeRawPtr::BOTTOM), addr); 3328 flush = _gvn.transform(flush); 3329 set_memory(flush, TypeRawPtr::BOTTOM); 3330 return true; 3331 } 3332 3333 //----------------------------inline_unsafe_writeback0------------------------- 3334 // public native void Unsafe.writeback0(long address) 3335 bool LibraryCallKit::inline_unsafe_writebackSync0(bool is_pre) { 3336 if (is_pre && !Matcher::has_match_rule(Op_CacheWBPreSync)) { 3337 return false; 3338 } 3339 if (!is_pre && !Matcher::has_match_rule(Op_CacheWBPostSync)) { 3340 return false; 3341 } 3342 #ifndef PRODUCT 3343 assert(Matcher::has_match_rule(Op_CacheWB), 3344 (is_pre ? "found match rule for CacheWBPreSync but not CacheWB" 3345 : "found match rule for CacheWBPostSync but not CacheWB")); 3346 3347 #endif 3348 null_check_receiver(); // null-check, then ignore 3349 Node *sync; 3350 if (is_pre) { 3351 sync = new CacheWBPreSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 3352 } else { 3353 sync = new CacheWBPostSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 3354 } 3355 sync = _gvn.transform(sync); 3356 set_memory(sync, TypeRawPtr::BOTTOM); 3357 return true; 3358 } 3359 3360 //----------------------------inline_unsafe_allocate--------------------------- 3361 // public native Object Unsafe.allocateInstance(Class<?> cls); 3362 bool LibraryCallKit::inline_unsafe_allocate() { 3363 3364 #if INCLUDE_JVMTI 3365 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 3366 return false; 3367 } 3368 #endif //INCLUDE_JVMTI 3369 3370 if (callee()->is_static()) return false; // caller must have the capability! 3371 3372 null_check_receiver(); // null-check, then ignore 3373 Node* cls = null_check(argument(1)); 3374 if (stopped()) return true; 3375 3376 Node* kls = load_klass_from_mirror(cls, false, nullptr, 0); 3377 kls = null_check(kls); 3378 if (stopped()) return true; // argument was like int.class 3379 3380 #if INCLUDE_JVMTI 3381 // Don't try to access new allocated obj in the intrinsic. 3382 // It causes perfomance issues even when jvmti event VmObjectAlloc is disabled. 3383 // Deoptimize and allocate in interpreter instead. 3384 Node* addr = makecon(TypeRawPtr::make((address) &JvmtiExport::_should_notify_object_alloc)); 3385 Node* should_post_vm_object_alloc = make_load(this->control(), addr, TypeInt::INT, T_INT, MemNode::unordered); 3386 Node* chk = _gvn.transform(new CmpINode(should_post_vm_object_alloc, intcon(0))); 3387 Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq)); 3388 { 3389 BuildCutout unless(this, tst, PROB_MAX); 3390 uncommon_trap(Deoptimization::Reason_intrinsic, 3391 Deoptimization::Action_make_not_entrant); 3392 } 3393 if (stopped()) { 3394 return true; 3395 } 3396 #endif //INCLUDE_JVMTI 3397 3398 Node* test = nullptr; 3399 if (LibraryCallKit::klass_needs_init_guard(kls)) { 3400 // Note: The argument might still be an illegal value like 3401 // Serializable.class or Object[].class. The runtime will handle it. 3402 // But we must make an explicit check for initialization. 3403 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 3404 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 3405 // can generate code to load it as unsigned byte. 3406 Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire); 3407 Node* bits = intcon(InstanceKlass::fully_initialized); 3408 test = _gvn.transform(new SubINode(inst, bits)); 3409 // The 'test' is non-zero if we need to take a slow path. 3410 } 3411 Node* obj = nullptr; 3412 const TypeInstKlassPtr* tkls = _gvn.type(kls)->isa_instklassptr(); 3413 if (tkls != nullptr && tkls->instance_klass()->is_inlinetype()) { 3414 obj = InlineTypeNode::make_all_zero(_gvn, tkls->instance_klass()->as_inline_klass())->buffer(this); 3415 } else { 3416 obj = new_instance(kls, test); 3417 } 3418 set_result(obj); 3419 return true; 3420 } 3421 3422 //------------------------inline_native_time_funcs-------------- 3423 // inline code for System.currentTimeMillis() and System.nanoTime() 3424 // these have the same type and signature 3425 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 3426 const TypeFunc* tf = OptoRuntime::void_long_Type(); 3427 const TypePtr* no_memory_effects = nullptr; 3428 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 3429 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0)); 3430 #ifdef ASSERT 3431 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1)); 3432 assert(value_top == top(), "second value must be top"); 3433 #endif 3434 set_result(value); 3435 return true; 3436 } 3437 3438 3439 #if INCLUDE_JVMTI 3440 3441 // When notifications are disabled then just update the VTMS transition bit and return. 3442 // Otherwise, the bit is updated in the given function call implementing JVMTI notification protocol. 3443 bool LibraryCallKit::inline_native_notify_jvmti_funcs(address funcAddr, const char* funcName, bool is_start, bool is_end) { 3444 if (!DoJVMTIVirtualThreadTransitions) { 3445 return true; 3446 } 3447 Node* vt_oop = _gvn.transform(must_be_not_null(argument(0), true)); // VirtualThread this argument 3448 IdealKit ideal(this); 3449 3450 Node* ONE = ideal.ConI(1); 3451 Node* hide = is_start ? ideal.ConI(0) : (is_end ? ideal.ConI(1) : _gvn.transform(argument(1))); 3452 Node* addr = makecon(TypeRawPtr::make((address)&JvmtiVTMSTransitionDisabler::_VTMS_notify_jvmti_events)); 3453 Node* notify_jvmti_enabled = ideal.load(ideal.ctrl(), addr, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw); 3454 3455 ideal.if_then(notify_jvmti_enabled, BoolTest::eq, ONE); { 3456 sync_kit(ideal); 3457 // if notifyJvmti enabled then make a call to the given SharedRuntime function 3458 const TypeFunc* tf = OptoRuntime::notify_jvmti_vthread_Type(); 3459 make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, hide); 3460 ideal.sync_kit(this); 3461 } ideal.else_(); { 3462 // set hide value to the VTMS transition bit in current JavaThread and VirtualThread object 3463 Node* thread = ideal.thread(); 3464 Node* jt_addr = basic_plus_adr(thread, in_bytes(JavaThread::is_in_VTMS_transition_offset())); 3465 Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_VTMS_transition_offset()); 3466 3467 sync_kit(ideal); 3468 access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3469 access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3470 3471 ideal.sync_kit(this); 3472 } ideal.end_if(); 3473 final_sync(ideal); 3474 3475 return true; 3476 } 3477 3478 // Always update the is_disable_suspend bit. 3479 bool LibraryCallKit::inline_native_notify_jvmti_sync() { 3480 if (!DoJVMTIVirtualThreadTransitions) { 3481 return true; 3482 } 3483 IdealKit ideal(this); 3484 3485 { 3486 // unconditionally update the is_disable_suspend bit in current JavaThread 3487 Node* thread = ideal.thread(); 3488 Node* arg = _gvn.transform(argument(0)); // argument for notification 3489 Node* addr = basic_plus_adr(thread, in_bytes(JavaThread::is_disable_suspend_offset())); 3490 const TypePtr *addr_type = _gvn.type(addr)->isa_ptr(); 3491 3492 sync_kit(ideal); 3493 access_store_at(nullptr, addr, addr_type, arg, _gvn.type(arg), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3494 ideal.sync_kit(this); 3495 } 3496 final_sync(ideal); 3497 3498 return true; 3499 } 3500 3501 #endif // INCLUDE_JVMTI 3502 3503 #ifdef JFR_HAVE_INTRINSICS 3504 3505 /** 3506 * if oop->klass != null 3507 * // normal class 3508 * epoch = _epoch_state ? 2 : 1 3509 * if oop->klass->trace_id & ((epoch << META_SHIFT) | epoch)) != epoch { 3510 * ... // enter slow path when the klass is first recorded or the epoch of JFR shifts 3511 * } 3512 * id = oop->klass->trace_id >> TRACE_ID_SHIFT // normal class path 3513 * else 3514 * // primitive class 3515 * if oop->array_klass != null 3516 * id = (oop->array_klass->trace_id >> TRACE_ID_SHIFT) + 1 // primitive class path 3517 * else 3518 * id = LAST_TYPE_ID + 1 // void class path 3519 * if (!signaled) 3520 * signaled = true 3521 */ 3522 bool LibraryCallKit::inline_native_classID() { 3523 Node* cls = argument(0); 3524 3525 IdealKit ideal(this); 3526 #define __ ideal. 3527 IdealVariable result(ideal); __ declarations_done(); 3528 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), 3529 basic_plus_adr(cls, java_lang_Class::klass_offset()), 3530 TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 3531 3532 3533 __ if_then(kls, BoolTest::ne, null()); { 3534 Node* kls_trace_id_addr = basic_plus_adr(kls, in_bytes(KLASS_TRACE_ID_OFFSET)); 3535 Node* kls_trace_id_raw = ideal.load(ideal.ctrl(), kls_trace_id_addr,TypeLong::LONG, T_LONG, Compile::AliasIdxRaw); 3536 3537 Node* epoch_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_address())); 3538 Node* epoch = ideal.load(ideal.ctrl(), epoch_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw); 3539 epoch = _gvn.transform(new LShiftLNode(longcon(1), epoch)); 3540 Node* mask = _gvn.transform(new LShiftLNode(epoch, intcon(META_SHIFT))); 3541 mask = _gvn.transform(new OrLNode(mask, epoch)); 3542 Node* kls_trace_id_raw_and_mask = _gvn.transform(new AndLNode(kls_trace_id_raw, mask)); 3543 3544 float unlikely = PROB_UNLIKELY(0.999); 3545 __ if_then(kls_trace_id_raw_and_mask, BoolTest::ne, epoch, unlikely); { 3546 sync_kit(ideal); 3547 make_runtime_call(RC_LEAF, 3548 OptoRuntime::class_id_load_barrier_Type(), 3549 CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::load_barrier), 3550 "class id load barrier", 3551 TypePtr::BOTTOM, 3552 kls); 3553 ideal.sync_kit(this); 3554 } __ end_if(); 3555 3556 ideal.set(result, _gvn.transform(new URShiftLNode(kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT)))); 3557 } __ else_(); { 3558 Node* array_kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), 3559 basic_plus_adr(cls, java_lang_Class::array_klass_offset()), 3560 TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 3561 __ if_then(array_kls, BoolTest::ne, null()); { 3562 Node* array_kls_trace_id_addr = basic_plus_adr(array_kls, in_bytes(KLASS_TRACE_ID_OFFSET)); 3563 Node* array_kls_trace_id_raw = ideal.load(ideal.ctrl(), array_kls_trace_id_addr, TypeLong::LONG, T_LONG, Compile::AliasIdxRaw); 3564 Node* array_kls_trace_id = _gvn.transform(new URShiftLNode(array_kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT))); 3565 ideal.set(result, _gvn.transform(new AddLNode(array_kls_trace_id, longcon(1)))); 3566 } __ else_(); { 3567 // void class case 3568 ideal.set(result, _gvn.transform(longcon(LAST_TYPE_ID + 1))); 3569 } __ end_if(); 3570 3571 Node* signaled_flag_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::signal_address())); 3572 Node* signaled = ideal.load(ideal.ctrl(), signaled_flag_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw, true, MemNode::acquire); 3573 __ if_then(signaled, BoolTest::ne, ideal.ConI(1)); { 3574 ideal.store(ideal.ctrl(), signaled_flag_address, ideal.ConI(1), T_BOOLEAN, Compile::AliasIdxRaw, MemNode::release, true); 3575 } __ end_if(); 3576 } __ end_if(); 3577 3578 final_sync(ideal); 3579 set_result(ideal.value(result)); 3580 #undef __ 3581 return true; 3582 } 3583 3584 //------------------------inline_native_jvm_commit------------------ 3585 bool LibraryCallKit::inline_native_jvm_commit() { 3586 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 3587 3588 // Save input memory and i_o state. 3589 Node* input_memory_state = reset_memory(); 3590 set_all_memory(input_memory_state); 3591 Node* input_io_state = i_o(); 3592 3593 // TLS. 3594 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 3595 // Jfr java buffer. 3596 Node* java_buffer_offset = _gvn.transform(new AddPNode(top(), tls_ptr, _gvn.transform(MakeConX(in_bytes(JAVA_BUFFER_OFFSET_JFR))))); 3597 Node* java_buffer = _gvn.transform(new LoadPNode(control(), input_memory_state, java_buffer_offset, TypePtr::BOTTOM, TypeRawPtr::NOTNULL, MemNode::unordered)); 3598 Node* java_buffer_pos_offset = _gvn.transform(new AddPNode(top(), java_buffer, _gvn.transform(MakeConX(in_bytes(JFR_BUFFER_POS_OFFSET))))); 3599 3600 // Load the current value of the notified field in the JfrThreadLocal. 3601 Node* notified_offset = basic_plus_adr(top(), tls_ptr, in_bytes(NOTIFY_OFFSET_JFR)); 3602 Node* notified = make_load(control(), notified_offset, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered); 3603 3604 // Test for notification. 3605 Node* notified_cmp = _gvn.transform(new CmpINode(notified, _gvn.intcon(1))); 3606 Node* test_notified = _gvn.transform(new BoolNode(notified_cmp, BoolTest::eq)); 3607 IfNode* iff_notified = create_and_map_if(control(), test_notified, PROB_MIN, COUNT_UNKNOWN); 3608 3609 // True branch, is notified. 3610 Node* is_notified = _gvn.transform(new IfTrueNode(iff_notified)); 3611 set_control(is_notified); 3612 3613 // Reset notified state. 3614 store_to_memory(control(), notified_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::unordered); 3615 Node* notified_reset_memory = reset_memory(); 3616 3617 // 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. 3618 Node* current_pos_X = _gvn.transform(new LoadXNode(control(), input_memory_state, java_buffer_pos_offset, TypeRawPtr::NOTNULL, TypeX_X, MemNode::unordered)); 3619 // Convert the machine-word to a long. 3620 Node* current_pos = _gvn.transform(ConvX2L(current_pos_X)); 3621 3622 // False branch, not notified. 3623 Node* not_notified = _gvn.transform(new IfFalseNode(iff_notified)); 3624 set_control(not_notified); 3625 set_all_memory(input_memory_state); 3626 3627 // Arg is the next position as a long. 3628 Node* arg = argument(0); 3629 // Convert long to machine-word. 3630 Node* next_pos_X = _gvn.transform(ConvL2X(arg)); 3631 3632 // Store the next_position to the underlying jfr java buffer. 3633 store_to_memory(control(), java_buffer_pos_offset, next_pos_X, LP64_ONLY(T_LONG) NOT_LP64(T_INT), MemNode::release); 3634 3635 Node* commit_memory = reset_memory(); 3636 set_all_memory(commit_memory); 3637 3638 // 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. 3639 Node* java_buffer_flags_offset = _gvn.transform(new AddPNode(top(), java_buffer, _gvn.transform(MakeConX(in_bytes(JFR_BUFFER_FLAGS_OFFSET))))); 3640 Node* flags = make_load(control(), java_buffer_flags_offset, TypeInt::UBYTE, T_BYTE, MemNode::unordered); 3641 Node* lease_constant = _gvn.transform(_gvn.intcon(4)); 3642 3643 // And flags with lease constant. 3644 Node* lease = _gvn.transform(new AndINode(flags, lease_constant)); 3645 3646 // Branch on lease to conditionalize returning the leased java buffer. 3647 Node* lease_cmp = _gvn.transform(new CmpINode(lease, lease_constant)); 3648 Node* test_lease = _gvn.transform(new BoolNode(lease_cmp, BoolTest::eq)); 3649 IfNode* iff_lease = create_and_map_if(control(), test_lease, PROB_MIN, COUNT_UNKNOWN); 3650 3651 // False branch, not a lease. 3652 Node* not_lease = _gvn.transform(new IfFalseNode(iff_lease)); 3653 3654 // True branch, is lease. 3655 Node* is_lease = _gvn.transform(new IfTrueNode(iff_lease)); 3656 set_control(is_lease); 3657 3658 // Make a runtime call, which can safepoint, to return the leased buffer. This updates both the JfrThreadLocal and the Java event writer oop. 3659 Node* call_return_lease = make_runtime_call(RC_NO_LEAF, 3660 OptoRuntime::void_void_Type(), 3661 SharedRuntime::jfr_return_lease(), 3662 "return_lease", TypePtr::BOTTOM); 3663 Node* call_return_lease_control = _gvn.transform(new ProjNode(call_return_lease, TypeFunc::Control)); 3664 3665 RegionNode* lease_compare_rgn = new RegionNode(PATH_LIMIT); 3666 record_for_igvn(lease_compare_rgn); 3667 PhiNode* lease_compare_mem = new PhiNode(lease_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3668 record_for_igvn(lease_compare_mem); 3669 PhiNode* lease_compare_io = new PhiNode(lease_compare_rgn, Type::ABIO); 3670 record_for_igvn(lease_compare_io); 3671 PhiNode* lease_result_value = new PhiNode(lease_compare_rgn, TypeLong::LONG); 3672 record_for_igvn(lease_result_value); 3673 3674 // Update control and phi nodes. 3675 lease_compare_rgn->init_req(_true_path, call_return_lease_control); 3676 lease_compare_rgn->init_req(_false_path, not_lease); 3677 3678 lease_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3679 lease_compare_mem->init_req(_false_path, commit_memory); 3680 3681 lease_compare_io->init_req(_true_path, i_o()); 3682 lease_compare_io->init_req(_false_path, input_io_state); 3683 3684 lease_result_value->init_req(_true_path, _gvn.longcon(0)); // if the lease was returned, return 0L. 3685 lease_result_value->init_req(_false_path, arg); // if not lease, return new updated position. 3686 3687 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 3688 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 3689 PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO); 3690 PhiNode* result_value = new PhiNode(result_rgn, TypeLong::LONG); 3691 3692 // Update control and phi nodes. 3693 result_rgn->init_req(_true_path, is_notified); 3694 result_rgn->init_req(_false_path, _gvn.transform(lease_compare_rgn)); 3695 3696 result_mem->init_req(_true_path, notified_reset_memory); 3697 result_mem->init_req(_false_path, _gvn.transform(lease_compare_mem)); 3698 3699 result_io->init_req(_true_path, input_io_state); 3700 result_io->init_req(_false_path, _gvn.transform(lease_compare_io)); 3701 3702 result_value->init_req(_true_path, current_pos); 3703 result_value->init_req(_false_path, _gvn.transform(lease_result_value)); 3704 3705 // Set output state. 3706 set_control(_gvn.transform(result_rgn)); 3707 set_all_memory(_gvn.transform(result_mem)); 3708 set_i_o(_gvn.transform(result_io)); 3709 set_result(result_rgn, result_value); 3710 return true; 3711 } 3712 3713 /* 3714 * The intrinsic is a model of this pseudo-code: 3715 * 3716 * JfrThreadLocal* const tl = Thread::jfr_thread_local() 3717 * jobject h_event_writer = tl->java_event_writer(); 3718 * if (h_event_writer == nullptr) { 3719 * return nullptr; 3720 * } 3721 * oop threadObj = Thread::threadObj(); 3722 * oop vthread = java_lang_Thread::vthread(threadObj); 3723 * traceid tid; 3724 * bool pinVirtualThread; 3725 * bool excluded; 3726 * if (vthread != threadObj) { // i.e. current thread is virtual 3727 * tid = java_lang_Thread::tid(vthread); 3728 * u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(vthread); 3729 * pinVirtualThread = VMContinuations; 3730 * excluded = vthread_epoch_raw & excluded_mask; 3731 * if (!excluded) { 3732 * traceid current_epoch = JfrTraceIdEpoch::current_generation(); 3733 * u2 vthread_epoch = vthread_epoch_raw & epoch_mask; 3734 * if (vthread_epoch != current_epoch) { 3735 * write_checkpoint(); 3736 * } 3737 * } 3738 * } else { 3739 * tid = java_lang_Thread::tid(threadObj); 3740 * u2 thread_epoch_raw = java_lang_Thread::jfr_epoch(threadObj); 3741 * pinVirtualThread = false; 3742 * excluded = thread_epoch_raw & excluded_mask; 3743 * } 3744 * oop event_writer = JNIHandles::resolve_non_null(h_event_writer); 3745 * traceid tid_in_event_writer = getField(event_writer, "threadID"); 3746 * if (tid_in_event_writer != tid) { 3747 * setField(event_writer, "pinVirtualThread", pinVirtualThread); 3748 * setField(event_writer, "excluded", excluded); 3749 * setField(event_writer, "threadID", tid); 3750 * } 3751 * return event_writer 3752 */ 3753 bool LibraryCallKit::inline_native_getEventWriter() { 3754 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 3755 3756 // Save input memory and i_o state. 3757 Node* input_memory_state = reset_memory(); 3758 set_all_memory(input_memory_state); 3759 Node* input_io_state = i_o(); 3760 3761 // The most significant bit of the u2 is used to denote thread exclusion 3762 Node* excluded_shift = _gvn.intcon(15); 3763 Node* excluded_mask = _gvn.intcon(1 << 15); 3764 // The epoch generation is the range [1-32767] 3765 Node* epoch_mask = _gvn.intcon(32767); 3766 3767 // TLS 3768 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 3769 3770 // Load the address of java event writer jobject handle from the jfr_thread_local structure. 3771 Node* jobj_ptr = basic_plus_adr(top(), tls_ptr, in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR)); 3772 3773 // Load the eventwriter jobject handle. 3774 Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); 3775 3776 // Null check the jobject handle. 3777 Node* jobj_cmp_null = _gvn.transform(new CmpPNode(jobj, null())); 3778 Node* test_jobj_not_equal_null = _gvn.transform(new BoolNode(jobj_cmp_null, BoolTest::ne)); 3779 IfNode* iff_jobj_not_equal_null = create_and_map_if(control(), test_jobj_not_equal_null, PROB_MAX, COUNT_UNKNOWN); 3780 3781 // False path, jobj is null. 3782 Node* jobj_is_null = _gvn.transform(new IfFalseNode(iff_jobj_not_equal_null)); 3783 3784 // True path, jobj is not null. 3785 Node* jobj_is_not_null = _gvn.transform(new IfTrueNode(iff_jobj_not_equal_null)); 3786 3787 set_control(jobj_is_not_null); 3788 3789 // Load the threadObj for the CarrierThread. 3790 Node* threadObj = generate_current_thread(tls_ptr); 3791 3792 // Load the vthread. 3793 Node* vthread = generate_virtual_thread(tls_ptr); 3794 3795 // If vthread != threadObj, this is a virtual thread. 3796 Node* vthread_cmp_threadObj = _gvn.transform(new CmpPNode(vthread, threadObj)); 3797 Node* test_vthread_not_equal_threadObj = _gvn.transform(new BoolNode(vthread_cmp_threadObj, BoolTest::ne)); 3798 IfNode* iff_vthread_not_equal_threadObj = 3799 create_and_map_if(jobj_is_not_null, test_vthread_not_equal_threadObj, PROB_FAIR, COUNT_UNKNOWN); 3800 3801 // False branch, fallback to threadObj. 3802 Node* vthread_equal_threadObj = _gvn.transform(new IfFalseNode(iff_vthread_not_equal_threadObj)); 3803 set_control(vthread_equal_threadObj); 3804 3805 // Load the tid field from the vthread object. 3806 Node* thread_obj_tid = load_field_from_object(threadObj, "tid", "J"); 3807 3808 // Load the raw epoch value from the threadObj. 3809 Node* threadObj_epoch_offset = basic_plus_adr(threadObj, java_lang_Thread::jfr_epoch_offset()); 3810 Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset, 3811 _gvn.type(threadObj_epoch_offset)->isa_ptr(), 3812 TypeInt::CHAR, T_CHAR, 3813 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 3814 3815 // Mask off the excluded information from the epoch. 3816 Node * threadObj_is_excluded = _gvn.transform(new AndINode(threadObj_epoch_raw, excluded_mask)); 3817 3818 // True branch, this is a virtual thread. 3819 Node* vthread_not_equal_threadObj = _gvn.transform(new IfTrueNode(iff_vthread_not_equal_threadObj)); 3820 set_control(vthread_not_equal_threadObj); 3821 3822 // Load the tid field from the vthread object. 3823 Node* vthread_tid = load_field_from_object(vthread, "tid", "J"); 3824 3825 // Continuation support determines if a virtual thread should be pinned. 3826 Node* global_addr = makecon(TypeRawPtr::make((address)&VMContinuations)); 3827 Node* continuation_support = make_load(control(), global_addr, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered); 3828 3829 // Load the raw epoch value from the vthread. 3830 Node* vthread_epoch_offset = basic_plus_adr(vthread, java_lang_Thread::jfr_epoch_offset()); 3831 Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, _gvn.type(vthread_epoch_offset)->is_ptr(), 3832 TypeInt::CHAR, T_CHAR, 3833 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 3834 3835 // Mask off the excluded information from the epoch. 3836 Node * vthread_is_excluded = _gvn.transform(new AndINode(vthread_epoch_raw, _gvn.transform(excluded_mask))); 3837 3838 // Branch on excluded to conditionalize updating the epoch for the virtual thread. 3839 Node* is_excluded_cmp = _gvn.transform(new CmpINode(vthread_is_excluded, _gvn.transform(excluded_mask))); 3840 Node* test_not_excluded = _gvn.transform(new BoolNode(is_excluded_cmp, BoolTest::ne)); 3841 IfNode* iff_not_excluded = create_and_map_if(control(), test_not_excluded, PROB_MAX, COUNT_UNKNOWN); 3842 3843 // False branch, vthread is excluded, no need to write epoch info. 3844 Node* excluded = _gvn.transform(new IfFalseNode(iff_not_excluded)); 3845 3846 // True branch, vthread is included, update epoch info. 3847 Node* included = _gvn.transform(new IfTrueNode(iff_not_excluded)); 3848 set_control(included); 3849 3850 // Get epoch value. 3851 Node* epoch = _gvn.transform(new AndINode(vthread_epoch_raw, _gvn.transform(epoch_mask))); 3852 3853 // Load the current epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR. 3854 Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address())); 3855 Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered); 3856 3857 // Compare the epoch in the vthread to the current epoch generation. 3858 Node* const epoch_cmp = _gvn.transform(new CmpUNode(current_epoch_generation, epoch)); 3859 Node* test_epoch_not_equal = _gvn.transform(new BoolNode(epoch_cmp, BoolTest::ne)); 3860 IfNode* iff_epoch_not_equal = create_and_map_if(control(), test_epoch_not_equal, PROB_FAIR, COUNT_UNKNOWN); 3861 3862 // False path, epoch is equal, checkpoint information is valid. 3863 Node* epoch_is_equal = _gvn.transform(new IfFalseNode(iff_epoch_not_equal)); 3864 3865 // True path, epoch is not equal, write a checkpoint for the vthread. 3866 Node* epoch_is_not_equal = _gvn.transform(new IfTrueNode(iff_epoch_not_equal)); 3867 3868 set_control(epoch_is_not_equal); 3869 3870 // Make a runtime call, which can safepoint, to write a checkpoint for the vthread for this epoch. 3871 // The call also updates the native thread local thread id and the vthread with the current epoch. 3872 Node* call_write_checkpoint = make_runtime_call(RC_NO_LEAF, 3873 OptoRuntime::jfr_write_checkpoint_Type(), 3874 SharedRuntime::jfr_write_checkpoint(), 3875 "write_checkpoint", TypePtr::BOTTOM); 3876 Node* call_write_checkpoint_control = _gvn.transform(new ProjNode(call_write_checkpoint, TypeFunc::Control)); 3877 3878 // vthread epoch != current epoch 3879 RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT); 3880 record_for_igvn(epoch_compare_rgn); 3881 PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3882 record_for_igvn(epoch_compare_mem); 3883 PhiNode* epoch_compare_io = new PhiNode(epoch_compare_rgn, Type::ABIO); 3884 record_for_igvn(epoch_compare_io); 3885 3886 // Update control and phi nodes. 3887 epoch_compare_rgn->init_req(_true_path, call_write_checkpoint_control); 3888 epoch_compare_rgn->init_req(_false_path, epoch_is_equal); 3889 epoch_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3890 epoch_compare_mem->init_req(_false_path, input_memory_state); 3891 epoch_compare_io->init_req(_true_path, i_o()); 3892 epoch_compare_io->init_req(_false_path, input_io_state); 3893 3894 // excluded != true 3895 RegionNode* exclude_compare_rgn = new RegionNode(PATH_LIMIT); 3896 record_for_igvn(exclude_compare_rgn); 3897 PhiNode* exclude_compare_mem = new PhiNode(exclude_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3898 record_for_igvn(exclude_compare_mem); 3899 PhiNode* exclude_compare_io = new PhiNode(exclude_compare_rgn, Type::ABIO); 3900 record_for_igvn(exclude_compare_io); 3901 3902 // Update control and phi nodes. 3903 exclude_compare_rgn->init_req(_true_path, _gvn.transform(epoch_compare_rgn)); 3904 exclude_compare_rgn->init_req(_false_path, excluded); 3905 exclude_compare_mem->init_req(_true_path, _gvn.transform(epoch_compare_mem)); 3906 exclude_compare_mem->init_req(_false_path, input_memory_state); 3907 exclude_compare_io->init_req(_true_path, _gvn.transform(epoch_compare_io)); 3908 exclude_compare_io->init_req(_false_path, input_io_state); 3909 3910 // vthread != threadObj 3911 RegionNode* vthread_compare_rgn = new RegionNode(PATH_LIMIT); 3912 record_for_igvn(vthread_compare_rgn); 3913 PhiNode* vthread_compare_mem = new PhiNode(vthread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3914 PhiNode* vthread_compare_io = new PhiNode(vthread_compare_rgn, Type::ABIO); 3915 record_for_igvn(vthread_compare_io); 3916 PhiNode* tid = new PhiNode(vthread_compare_rgn, TypeLong::LONG); 3917 record_for_igvn(tid); 3918 PhiNode* exclusion = new PhiNode(vthread_compare_rgn, TypeInt::CHAR); 3919 record_for_igvn(exclusion); 3920 PhiNode* pinVirtualThread = new PhiNode(vthread_compare_rgn, TypeInt::BOOL); 3921 record_for_igvn(pinVirtualThread); 3922 3923 // Update control and phi nodes. 3924 vthread_compare_rgn->init_req(_true_path, _gvn.transform(exclude_compare_rgn)); 3925 vthread_compare_rgn->init_req(_false_path, vthread_equal_threadObj); 3926 vthread_compare_mem->init_req(_true_path, _gvn.transform(exclude_compare_mem)); 3927 vthread_compare_mem->init_req(_false_path, input_memory_state); 3928 vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io)); 3929 vthread_compare_io->init_req(_false_path, input_io_state); 3930 tid->init_req(_true_path, _gvn.transform(vthread_tid)); 3931 tid->init_req(_false_path, _gvn.transform(thread_obj_tid)); 3932 exclusion->init_req(_true_path, _gvn.transform(vthread_is_excluded)); 3933 exclusion->init_req(_false_path, _gvn.transform(threadObj_is_excluded)); 3934 pinVirtualThread->init_req(_true_path, _gvn.transform(continuation_support)); 3935 pinVirtualThread->init_req(_false_path, _gvn.intcon(0)); 3936 3937 // Update branch state. 3938 set_control(_gvn.transform(vthread_compare_rgn)); 3939 set_all_memory(_gvn.transform(vthread_compare_mem)); 3940 set_i_o(_gvn.transform(vthread_compare_io)); 3941 3942 // Load the event writer oop by dereferencing the jobject handle. 3943 ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter")); 3944 assert(klass_EventWriter->is_loaded(), "invariant"); 3945 ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass(); 3946 const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter); 3947 const TypeOopPtr* const xtype = aklass->as_instance_type(); 3948 Node* jobj_untagged = _gvn.transform(new AddPNode(top(), jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global))); 3949 Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD); 3950 3951 // Load the current thread id from the event writer object. 3952 Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J"); 3953 // Get the field offset to, conditionally, store an updated tid value later. 3954 Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false); 3955 // Get the field offset to, conditionally, store an updated exclusion value later. 3956 Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false); 3957 // Get the field offset to, conditionally, store an updated pinVirtualThread value later. 3958 Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false); 3959 3960 RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT); 3961 record_for_igvn(event_writer_tid_compare_rgn); 3962 PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3963 record_for_igvn(event_writer_tid_compare_mem); 3964 PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO); 3965 record_for_igvn(event_writer_tid_compare_io); 3966 3967 // Compare the current tid from the thread object to what is currently stored in the event writer object. 3968 Node* const tid_cmp = _gvn.transform(new CmpLNode(event_writer_tid, _gvn.transform(tid))); 3969 Node* test_tid_not_equal = _gvn.transform(new BoolNode(tid_cmp, BoolTest::ne)); 3970 IfNode* iff_tid_not_equal = create_and_map_if(_gvn.transform(vthread_compare_rgn), test_tid_not_equal, PROB_FAIR, COUNT_UNKNOWN); 3971 3972 // False path, tids are the same. 3973 Node* tid_is_equal = _gvn.transform(new IfFalseNode(iff_tid_not_equal)); 3974 3975 // True path, tid is not equal, need to update the tid in the event writer. 3976 Node* tid_is_not_equal = _gvn.transform(new IfTrueNode(iff_tid_not_equal)); 3977 record_for_igvn(tid_is_not_equal); 3978 3979 // Store the pin state to the event writer. 3980 store_to_memory(tid_is_not_equal, event_writer_pin_field, _gvn.transform(pinVirtualThread), T_BOOLEAN, MemNode::unordered); 3981 3982 // Store the exclusion state to the event writer. 3983 Node* excluded_bool = _gvn.transform(new URShiftINode(_gvn.transform(exclusion), excluded_shift)); 3984 store_to_memory(tid_is_not_equal, event_writer_excluded_field, excluded_bool, T_BOOLEAN, MemNode::unordered); 3985 3986 // Store the tid to the event writer. 3987 store_to_memory(tid_is_not_equal, event_writer_tid_field, tid, T_LONG, MemNode::unordered); 3988 3989 // Update control and phi nodes. 3990 event_writer_tid_compare_rgn->init_req(_true_path, tid_is_not_equal); 3991 event_writer_tid_compare_rgn->init_req(_false_path, tid_is_equal); 3992 event_writer_tid_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3993 event_writer_tid_compare_mem->init_req(_false_path, _gvn.transform(vthread_compare_mem)); 3994 event_writer_tid_compare_io->init_req(_true_path, _gvn.transform(i_o())); 3995 event_writer_tid_compare_io->init_req(_false_path, _gvn.transform(vthread_compare_io)); 3996 3997 // Result of top level CFG, Memory, IO and Value. 3998 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 3999 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 4000 PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO); 4001 PhiNode* result_value = new PhiNode(result_rgn, TypeInstPtr::BOTTOM); 4002 4003 // Result control. 4004 result_rgn->init_req(_true_path, _gvn.transform(event_writer_tid_compare_rgn)); 4005 result_rgn->init_req(_false_path, jobj_is_null); 4006 4007 // Result memory. 4008 result_mem->init_req(_true_path, _gvn.transform(event_writer_tid_compare_mem)); 4009 result_mem->init_req(_false_path, _gvn.transform(input_memory_state)); 4010 4011 // Result IO. 4012 result_io->init_req(_true_path, _gvn.transform(event_writer_tid_compare_io)); 4013 result_io->init_req(_false_path, _gvn.transform(input_io_state)); 4014 4015 // Result value. 4016 result_value->init_req(_true_path, _gvn.transform(event_writer)); // return event writer oop 4017 result_value->init_req(_false_path, null()); // return null 4018 4019 // Set output state. 4020 set_control(_gvn.transform(result_rgn)); 4021 set_all_memory(_gvn.transform(result_mem)); 4022 set_i_o(_gvn.transform(result_io)); 4023 set_result(result_rgn, result_value); 4024 return true; 4025 } 4026 4027 /* 4028 * The intrinsic is a model of this pseudo-code: 4029 * 4030 * JfrThreadLocal* const tl = thread->jfr_thread_local(); 4031 * if (carrierThread != thread) { // is virtual thread 4032 * const u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(thread); 4033 * bool excluded = vthread_epoch_raw & excluded_mask; 4034 * Atomic::store(&tl->_contextual_tid, java_lang_Thread::tid(thread)); 4035 * Atomic::store(&tl->_contextual_thread_excluded, is_excluded); 4036 * if (!excluded) { 4037 * const u2 vthread_epoch = vthread_epoch_raw & epoch_mask; 4038 * Atomic::store(&tl->_vthread_epoch, vthread_epoch); 4039 * } 4040 * Atomic::release_store(&tl->_vthread, true); 4041 * return; 4042 * } 4043 * Atomic::release_store(&tl->_vthread, false); 4044 */ 4045 void LibraryCallKit::extend_setCurrentThread(Node* jt, Node* thread) { 4046 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 4047 4048 Node* input_memory_state = reset_memory(); 4049 set_all_memory(input_memory_state); 4050 4051 // The most significant bit of the u2 is used to denote thread exclusion 4052 Node* excluded_mask = _gvn.intcon(1 << 15); 4053 // The epoch generation is the range [1-32767] 4054 Node* epoch_mask = _gvn.intcon(32767); 4055 4056 Node* const carrierThread = generate_current_thread(jt); 4057 // If thread != carrierThread, this is a virtual thread. 4058 Node* thread_cmp_carrierThread = _gvn.transform(new CmpPNode(thread, carrierThread)); 4059 Node* test_thread_not_equal_carrierThread = _gvn.transform(new BoolNode(thread_cmp_carrierThread, BoolTest::ne)); 4060 IfNode* iff_thread_not_equal_carrierThread = 4061 create_and_map_if(control(), test_thread_not_equal_carrierThread, PROB_FAIR, COUNT_UNKNOWN); 4062 4063 Node* vthread_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_OFFSET_JFR)); 4064 4065 // False branch, is carrierThread. 4066 Node* thread_equal_carrierThread = _gvn.transform(new IfFalseNode(iff_thread_not_equal_carrierThread)); 4067 // Store release 4068 Node* vthread_false_memory = store_to_memory(thread_equal_carrierThread, vthread_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::release, true); 4069 4070 set_all_memory(input_memory_state); 4071 4072 // True branch, is virtual thread. 4073 Node* thread_not_equal_carrierThread = _gvn.transform(new IfTrueNode(iff_thread_not_equal_carrierThread)); 4074 set_control(thread_not_equal_carrierThread); 4075 4076 // Load the raw epoch value from the vthread. 4077 Node* epoch_offset = basic_plus_adr(thread, java_lang_Thread::jfr_epoch_offset()); 4078 Node* epoch_raw = access_load_at(thread, epoch_offset, _gvn.type(epoch_offset)->is_ptr(), TypeInt::CHAR, T_CHAR, 4079 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 4080 4081 // Mask off the excluded information from the epoch. 4082 Node * const is_excluded = _gvn.transform(new AndINode(epoch_raw, _gvn.transform(excluded_mask))); 4083 4084 // Load the tid field from the thread. 4085 Node* tid = load_field_from_object(thread, "tid", "J"); 4086 4087 // Store the vthread tid to the jfr thread local. 4088 Node* thread_id_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_ID_OFFSET_JFR)); 4089 Node* tid_memory = store_to_memory(control(), thread_id_offset, tid, T_LONG, MemNode::unordered, true); 4090 4091 // Branch is_excluded to conditionalize updating the epoch . 4092 Node* excluded_cmp = _gvn.transform(new CmpINode(is_excluded, _gvn.transform(excluded_mask))); 4093 Node* test_excluded = _gvn.transform(new BoolNode(excluded_cmp, BoolTest::eq)); 4094 IfNode* iff_excluded = create_and_map_if(control(), test_excluded, PROB_MIN, COUNT_UNKNOWN); 4095 4096 // True branch, vthread is excluded, no need to write epoch info. 4097 Node* excluded = _gvn.transform(new IfTrueNode(iff_excluded)); 4098 set_control(excluded); 4099 Node* vthread_is_excluded = _gvn.intcon(1); 4100 4101 // False branch, vthread is included, update epoch info. 4102 Node* included = _gvn.transform(new IfFalseNode(iff_excluded)); 4103 set_control(included); 4104 Node* vthread_is_included = _gvn.intcon(0); 4105 4106 // Get epoch value. 4107 Node* epoch = _gvn.transform(new AndINode(epoch_raw, _gvn.transform(epoch_mask))); 4108 4109 // Store the vthread epoch to the jfr thread local. 4110 Node* vthread_epoch_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EPOCH_OFFSET_JFR)); 4111 Node* included_memory = store_to_memory(control(), vthread_epoch_offset, epoch, T_CHAR, MemNode::unordered, true); 4112 4113 RegionNode* excluded_rgn = new RegionNode(PATH_LIMIT); 4114 record_for_igvn(excluded_rgn); 4115 PhiNode* excluded_mem = new PhiNode(excluded_rgn, Type::MEMORY, TypePtr::BOTTOM); 4116 record_for_igvn(excluded_mem); 4117 PhiNode* exclusion = new PhiNode(excluded_rgn, TypeInt::BOOL); 4118 record_for_igvn(exclusion); 4119 4120 // Merge the excluded control and memory. 4121 excluded_rgn->init_req(_true_path, excluded); 4122 excluded_rgn->init_req(_false_path, included); 4123 excluded_mem->init_req(_true_path, tid_memory); 4124 excluded_mem->init_req(_false_path, included_memory); 4125 exclusion->init_req(_true_path, _gvn.transform(vthread_is_excluded)); 4126 exclusion->init_req(_false_path, _gvn.transform(vthread_is_included)); 4127 4128 // Set intermediate state. 4129 set_control(_gvn.transform(excluded_rgn)); 4130 set_all_memory(excluded_mem); 4131 4132 // Store the vthread exclusion state to the jfr thread local. 4133 Node* thread_local_excluded_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EXCLUDED_OFFSET_JFR)); 4134 store_to_memory(control(), thread_local_excluded_offset, _gvn.transform(exclusion), T_BOOLEAN, MemNode::unordered, true); 4135 4136 // Store release 4137 Node * vthread_true_memory = store_to_memory(control(), vthread_offset, _gvn.intcon(1), T_BOOLEAN, MemNode::release, true); 4138 4139 RegionNode* thread_compare_rgn = new RegionNode(PATH_LIMIT); 4140 record_for_igvn(thread_compare_rgn); 4141 PhiNode* thread_compare_mem = new PhiNode(thread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 4142 record_for_igvn(thread_compare_mem); 4143 PhiNode* vthread = new PhiNode(thread_compare_rgn, TypeInt::BOOL); 4144 record_for_igvn(vthread); 4145 4146 // Merge the thread_compare control and memory. 4147 thread_compare_rgn->init_req(_true_path, control()); 4148 thread_compare_rgn->init_req(_false_path, thread_equal_carrierThread); 4149 thread_compare_mem->init_req(_true_path, vthread_true_memory); 4150 thread_compare_mem->init_req(_false_path, vthread_false_memory); 4151 4152 // Set output state. 4153 set_control(_gvn.transform(thread_compare_rgn)); 4154 set_all_memory(_gvn.transform(thread_compare_mem)); 4155 } 4156 4157 #endif // JFR_HAVE_INTRINSICS 4158 4159 //------------------------inline_native_currentCarrierThread------------------ 4160 bool LibraryCallKit::inline_native_currentCarrierThread() { 4161 Node* junk = nullptr; 4162 set_result(generate_current_thread(junk)); 4163 return true; 4164 } 4165 4166 //------------------------inline_native_currentThread------------------ 4167 bool LibraryCallKit::inline_native_currentThread() { 4168 Node* junk = nullptr; 4169 set_result(generate_virtual_thread(junk)); 4170 return true; 4171 } 4172 4173 //------------------------inline_native_setVthread------------------ 4174 bool LibraryCallKit::inline_native_setCurrentThread() { 4175 assert(C->method()->changes_current_thread(), 4176 "method changes current Thread but is not annotated ChangesCurrentThread"); 4177 Node* arr = argument(1); 4178 Node* thread = _gvn.transform(new ThreadLocalNode()); 4179 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::vthread_offset())); 4180 Node* thread_obj_handle 4181 = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered); 4182 thread_obj_handle = _gvn.transform(thread_obj_handle); 4183 const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr(); 4184 access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED); 4185 4186 // Change the _monitor_owner_id of the JavaThread 4187 Node* tid = load_field_from_object(arr, "tid", "J"); 4188 Node* monitor_owner_id_offset = basic_plus_adr(thread, in_bytes(JavaThread::monitor_owner_id_offset())); 4189 store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true); 4190 4191 JFR_ONLY(extend_setCurrentThread(thread, arr);) 4192 return true; 4193 } 4194 4195 const Type* LibraryCallKit::scopedValueCache_type() { 4196 ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass()); 4197 const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass()); 4198 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true); 4199 4200 // Because we create the scopedValue cache lazily we have to make the 4201 // type of the result BotPTR. 4202 bool xk = etype->klass_is_exact(); 4203 const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, TypeAryPtr::Offset(0)); 4204 return objects_type; 4205 } 4206 4207 Node* LibraryCallKit::scopedValueCache_helper() { 4208 Node* thread = _gvn.transform(new ThreadLocalNode()); 4209 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::scopedValueCache_offset())); 4210 // We cannot use immutable_memory() because we might flip onto a 4211 // different carrier thread, at which point we'll need to use that 4212 // carrier thread's cache. 4213 // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(), 4214 // TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered)); 4215 return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered); 4216 } 4217 4218 //------------------------inline_native_scopedValueCache------------------ 4219 bool LibraryCallKit::inline_native_scopedValueCache() { 4220 Node* cache_obj_handle = scopedValueCache_helper(); 4221 const Type* objects_type = scopedValueCache_type(); 4222 set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE)); 4223 4224 return true; 4225 } 4226 4227 //------------------------inline_native_setScopedValueCache------------------ 4228 bool LibraryCallKit::inline_native_setScopedValueCache() { 4229 Node* arr = argument(0); 4230 Node* cache_obj_handle = scopedValueCache_helper(); 4231 const Type* objects_type = scopedValueCache_type(); 4232 4233 const TypePtr *adr_type = _gvn.type(cache_obj_handle)->isa_ptr(); 4234 access_store_at(nullptr, cache_obj_handle, adr_type, arr, objects_type, T_OBJECT, IN_NATIVE | MO_UNORDERED); 4235 4236 return true; 4237 } 4238 4239 //------------------------inline_native_Continuation_pin and unpin----------- 4240 4241 // Shared implementation routine for both pin and unpin. 4242 bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) { 4243 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 4244 4245 // Save input memory. 4246 Node* input_memory_state = reset_memory(); 4247 set_all_memory(input_memory_state); 4248 4249 // TLS 4250 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 4251 Node* last_continuation_offset = basic_plus_adr(top(), tls_ptr, in_bytes(JavaThread::cont_entry_offset())); 4252 Node* last_continuation = make_load(control(), last_continuation_offset, last_continuation_offset->get_ptr_type(), T_ADDRESS, MemNode::unordered); 4253 4254 // Null check the last continuation object. 4255 Node* continuation_cmp_null = _gvn.transform(new CmpPNode(last_continuation, null())); 4256 Node* test_continuation_not_equal_null = _gvn.transform(new BoolNode(continuation_cmp_null, BoolTest::ne)); 4257 IfNode* iff_continuation_not_equal_null = create_and_map_if(control(), test_continuation_not_equal_null, PROB_MAX, COUNT_UNKNOWN); 4258 4259 // False path, last continuation is null. 4260 Node* continuation_is_null = _gvn.transform(new IfFalseNode(iff_continuation_not_equal_null)); 4261 4262 // True path, last continuation is not null. 4263 Node* continuation_is_not_null = _gvn.transform(new IfTrueNode(iff_continuation_not_equal_null)); 4264 4265 set_control(continuation_is_not_null); 4266 4267 // Load the pin count from the last continuation. 4268 Node* pin_count_offset = basic_plus_adr(top(), last_continuation, in_bytes(ContinuationEntry::pin_count_offset())); 4269 Node* pin_count = make_load(control(), pin_count_offset, TypeInt::INT, T_INT, MemNode::unordered); 4270 4271 // The loaded pin count is compared against a context specific rhs for over/underflow detection. 4272 Node* pin_count_rhs; 4273 if (unpin) { 4274 pin_count_rhs = _gvn.intcon(0); 4275 } else { 4276 pin_count_rhs = _gvn.intcon(UINT32_MAX); 4277 } 4278 Node* pin_count_cmp = _gvn.transform(new CmpUNode(_gvn.transform(pin_count), pin_count_rhs)); 4279 Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq)); 4280 IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN); 4281 4282 // True branch, pin count over/underflow. 4283 Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow)); 4284 { 4285 // Trap (but not deoptimize (Action_none)) and continue in the interpreter 4286 // which will throw IllegalStateException for pin count over/underflow. 4287 // No memory changed so far - we can use memory create by reset_memory() 4288 // at the beginning of this intrinsic. No need to call reset_memory() again. 4289 PreserveJVMState pjvms(this); 4290 set_control(pin_count_over_underflow); 4291 uncommon_trap(Deoptimization::Reason_intrinsic, 4292 Deoptimization::Action_none); 4293 assert(stopped(), "invariant"); 4294 } 4295 4296 // False branch, no pin count over/underflow. Increment or decrement pin count and store back. 4297 Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow)); 4298 set_control(valid_pin_count); 4299 4300 Node* next_pin_count; 4301 if (unpin) { 4302 next_pin_count = _gvn.transform(new SubINode(pin_count, _gvn.intcon(1))); 4303 } else { 4304 next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1))); 4305 } 4306 4307 store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered); 4308 4309 // Result of top level CFG and Memory. 4310 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 4311 record_for_igvn(result_rgn); 4312 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 4313 record_for_igvn(result_mem); 4314 4315 result_rgn->init_req(_true_path, _gvn.transform(valid_pin_count)); 4316 result_rgn->init_req(_false_path, _gvn.transform(continuation_is_null)); 4317 result_mem->init_req(_true_path, _gvn.transform(reset_memory())); 4318 result_mem->init_req(_false_path, _gvn.transform(input_memory_state)); 4319 4320 // Set output state. 4321 set_control(_gvn.transform(result_rgn)); 4322 set_all_memory(_gvn.transform(result_mem)); 4323 4324 return true; 4325 } 4326 4327 //-----------------------load_klass_from_mirror_common------------------------- 4328 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 4329 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 4330 // and branch to the given path on the region. 4331 // If never_see_null, take an uncommon trap on null, so we can optimistically 4332 // compile for the non-null case. 4333 // If the region is null, force never_see_null = true. 4334 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 4335 bool never_see_null, 4336 RegionNode* region, 4337 int null_path, 4338 int offset) { 4339 if (region == nullptr) never_see_null = true; 4340 Node* p = basic_plus_adr(mirror, offset); 4341 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL; 4342 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 4343 Node* null_ctl = top(); 4344 kls = null_check_oop(kls, &null_ctl, never_see_null); 4345 if (region != nullptr) { 4346 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 4347 region->init_req(null_path, null_ctl); 4348 } else { 4349 assert(null_ctl == top(), "no loose ends"); 4350 } 4351 return kls; 4352 } 4353 4354 //--------------------(inline_native_Class_query helpers)--------------------- 4355 // Use this for JVM_ACC_INTERFACE. 4356 // Fall through if (mods & mask) == bits, take the guard otherwise. 4357 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region, 4358 ByteSize offset, const Type* type, BasicType bt) { 4359 // Branch around if the given klass has the given modifier bit set. 4360 // Like generate_guard, adds a new path onto the region. 4361 Node* modp = basic_plus_adr(kls, in_bytes(offset)); 4362 Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered); 4363 Node* mask = intcon(modifier_mask); 4364 Node* bits = intcon(modifier_bits); 4365 Node* mbit = _gvn.transform(new AndINode(mods, mask)); 4366 Node* cmp = _gvn.transform(new CmpINode(mbit, bits)); 4367 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 4368 return generate_fair_guard(bol, region); 4369 } 4370 4371 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 4372 return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region, 4373 Klass::access_flags_offset(), TypeInt::CHAR, T_CHAR); 4374 } 4375 4376 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast. 4377 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 4378 return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region, 4379 Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN); 4380 } 4381 4382 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) { 4383 return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region); 4384 } 4385 4386 //-------------------------inline_native_Class_query------------------- 4387 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 4388 const Type* return_type = TypeInt::BOOL; 4389 Node* prim_return_value = top(); // what happens if it's a primitive class? 4390 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4391 bool expect_prim = false; // most of these guys expect to work on refs 4392 4393 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 4394 4395 Node* mirror = argument(0); 4396 Node* obj = top(); 4397 4398 switch (id) { 4399 case vmIntrinsics::_isInstance: 4400 // nothing is an instance of a primitive type 4401 prim_return_value = intcon(0); 4402 obj = argument(1); 4403 break; 4404 case vmIntrinsics::_isHidden: 4405 prim_return_value = intcon(0); 4406 break; 4407 case vmIntrinsics::_getSuperclass: 4408 prim_return_value = null(); 4409 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 4410 break; 4411 default: 4412 fatal_unexpected_iid(id); 4413 break; 4414 } 4415 4416 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 4417 if (mirror_con == nullptr) return false; // cannot happen? 4418 4419 #ifndef PRODUCT 4420 if (C->print_intrinsics() || C->print_inlining()) { 4421 ciType* k = mirror_con->java_mirror_type(); 4422 if (k) { 4423 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 4424 k->print_name(); 4425 tty->cr(); 4426 } 4427 } 4428 #endif 4429 4430 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 4431 RegionNode* region = new RegionNode(PATH_LIMIT); 4432 record_for_igvn(region); 4433 PhiNode* phi = new PhiNode(region, return_type); 4434 4435 // The mirror will never be null of Reflection.getClassAccessFlags, however 4436 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 4437 // if it is. See bug 4774291. 4438 4439 // For Reflection.getClassAccessFlags(), the null check occurs in 4440 // the wrong place; see inline_unsafe_access(), above, for a similar 4441 // situation. 4442 mirror = null_check(mirror); 4443 // If mirror or obj is dead, only null-path is taken. 4444 if (stopped()) return true; 4445 4446 if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 4447 4448 // Now load the mirror's klass metaobject, and null-check it. 4449 // Side-effects region with the control path if the klass is null. 4450 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 4451 // If kls is null, we have a primitive mirror. 4452 phi->init_req(_prim_path, prim_return_value); 4453 if (stopped()) { set_result(region, phi); return true; } 4454 bool safe_for_replace = (region->in(_prim_path) == top()); 4455 4456 Node* p; // handy temp 4457 Node* null_ctl; 4458 4459 // Now that we have the non-null klass, we can perform the real query. 4460 // For constant classes, the query will constant-fold in LoadNode::Value. 4461 Node* query_value = top(); 4462 switch (id) { 4463 case vmIntrinsics::_isInstance: 4464 // nothing is an instance of a primitive type 4465 query_value = gen_instanceof(obj, kls, safe_for_replace); 4466 break; 4467 4468 case vmIntrinsics::_isHidden: 4469 // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.) 4470 if (generate_hidden_class_guard(kls, region) != nullptr) 4471 // A guard was added. If the guard is taken, it was an hidden class. 4472 phi->add_req(intcon(1)); 4473 // If we fall through, it's a plain class. 4474 query_value = intcon(0); 4475 break; 4476 4477 4478 case vmIntrinsics::_getSuperclass: 4479 // The rules here are somewhat unfortunate, but we can still do better 4480 // with random logic than with a JNI call. 4481 // Interfaces store null or Object as _super, but must report null. 4482 // Arrays store an intermediate super as _super, but must report Object. 4483 // Other types can report the actual _super. 4484 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 4485 if (generate_interface_guard(kls, region) != nullptr) 4486 // A guard was added. If the guard is taken, it was an interface. 4487 phi->add_req(null()); 4488 if (generate_array_guard(kls, region) != nullptr) 4489 // A guard was added. If the guard is taken, it was an array. 4490 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 4491 // If we fall through, it's a plain class. Get its _super. 4492 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 4493 kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 4494 null_ctl = top(); 4495 kls = null_check_oop(kls, &null_ctl); 4496 if (null_ctl != top()) { 4497 // If the guard is taken, Object.superClass is null (both klass and mirror). 4498 region->add_req(null_ctl); 4499 phi ->add_req(null()); 4500 } 4501 if (!stopped()) { 4502 query_value = load_mirror_from_klass(kls); 4503 } 4504 break; 4505 4506 default: 4507 fatal_unexpected_iid(id); 4508 break; 4509 } 4510 4511 // Fall-through is the normal case of a query to a real class. 4512 phi->init_req(1, query_value); 4513 region->init_req(1, control()); 4514 4515 C->set_has_split_ifs(true); // Has chance for split-if optimization 4516 set_result(region, phi); 4517 return true; 4518 } 4519 4520 4521 //-------------------------inline_Class_cast------------------- 4522 bool LibraryCallKit::inline_Class_cast() { 4523 Node* mirror = argument(0); // Class 4524 Node* obj = argument(1); 4525 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 4526 if (mirror_con == nullptr) { 4527 return false; // dead path (mirror->is_top()). 4528 } 4529 if (obj == nullptr || obj->is_top()) { 4530 return false; // dead path 4531 } 4532 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr(); 4533 4534 // First, see if Class.cast() can be folded statically. 4535 // java_mirror_type() returns non-null for compile-time Class constants. 4536 ciType* tm = mirror_con->java_mirror_type(); 4537 if (tm != nullptr && tm->is_klass() && 4538 tp != nullptr) { 4539 if (!tp->is_loaded()) { 4540 // Don't use intrinsic when class is not loaded. 4541 return false; 4542 } else { 4543 const TypeKlassPtr* tklass = TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces); 4544 int static_res = C->static_subtype_check(tklass, tp->as_klass_type()); 4545 if (static_res == Compile::SSC_always_true) { 4546 // isInstance() is true - fold the code. 4547 set_result(obj); 4548 return true; 4549 } else if (static_res == Compile::SSC_always_false) { 4550 // Don't use intrinsic, have to throw ClassCastException. 4551 // If the reference is null, the non-intrinsic bytecode will 4552 // be optimized appropriately. 4553 return false; 4554 } 4555 } 4556 } 4557 4558 // Bailout intrinsic and do normal inlining if exception path is frequent. 4559 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 4560 return false; 4561 } 4562 4563 // Generate dynamic checks. 4564 // Class.cast() is java implementation of _checkcast bytecode. 4565 // Do checkcast (Parse::do_checkcast()) optimizations here. 4566 4567 mirror = null_check(mirror); 4568 // If mirror is dead, only null-path is taken. 4569 if (stopped()) { 4570 return true; 4571 } 4572 4573 // Not-subtype or the mirror's klass ptr is nullptr (in case it is a primitive). 4574 enum { _bad_type_path = 1, _prim_path = 2, _npe_path = 3, PATH_LIMIT }; 4575 RegionNode* region = new RegionNode(PATH_LIMIT); 4576 record_for_igvn(region); 4577 4578 // Now load the mirror's klass metaobject, and null-check it. 4579 // If kls is null, we have a primitive mirror and 4580 // nothing is an instance of a primitive type. 4581 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path); 4582 4583 Node* res = top(); 4584 Node* io = i_o(); 4585 Node* mem = merged_memory(); 4586 if (!stopped()) { 4587 4588 Node* bad_type_ctrl = top(); 4589 // Do checkcast optimizations. 4590 res = gen_checkcast(obj, kls, &bad_type_ctrl); 4591 region->init_req(_bad_type_path, bad_type_ctrl); 4592 } 4593 if (region->in(_prim_path) != top() || 4594 region->in(_bad_type_path) != top() || 4595 region->in(_npe_path) != top()) { 4596 // Let Interpreter throw ClassCastException. 4597 PreserveJVMState pjvms(this); 4598 set_control(_gvn.transform(region)); 4599 // Set IO and memory because gen_checkcast may override them when buffering inline types 4600 set_i_o(io); 4601 set_all_memory(mem); 4602 uncommon_trap(Deoptimization::Reason_intrinsic, 4603 Deoptimization::Action_maybe_recompile); 4604 } 4605 if (!stopped()) { 4606 set_result(res); 4607 } 4608 return true; 4609 } 4610 4611 4612 //--------------------------inline_native_subtype_check------------------------ 4613 // This intrinsic takes the JNI calls out of the heart of 4614 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 4615 bool LibraryCallKit::inline_native_subtype_check() { 4616 // Pull both arguments off the stack. 4617 Node* args[2]; // two java.lang.Class mirrors: superc, subc 4618 args[0] = argument(0); 4619 args[1] = argument(1); 4620 Node* klasses[2]; // corresponding Klasses: superk, subk 4621 klasses[0] = klasses[1] = top(); 4622 4623 enum { 4624 // A full decision tree on {superc is prim, subc is prim}: 4625 _prim_0_path = 1, // {P,N} => false 4626 // {P,P} & superc!=subc => false 4627 _prim_same_path, // {P,P} & superc==subc => true 4628 _prim_1_path, // {N,P} => false 4629 _ref_subtype_path, // {N,N} & subtype check wins => true 4630 _both_ref_path, // {N,N} & subtype check loses => false 4631 PATH_LIMIT 4632 }; 4633 4634 RegionNode* region = new RegionNode(PATH_LIMIT); 4635 RegionNode* prim_region = new RegionNode(2); 4636 Node* phi = new PhiNode(region, TypeInt::BOOL); 4637 record_for_igvn(region); 4638 record_for_igvn(prim_region); 4639 4640 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 4641 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL; 4642 int class_klass_offset = java_lang_Class::klass_offset(); 4643 4644 // First null-check both mirrors and load each mirror's klass metaobject. 4645 int which_arg; 4646 for (which_arg = 0; which_arg <= 1; which_arg++) { 4647 Node* arg = args[which_arg]; 4648 arg = null_check(arg); 4649 if (stopped()) break; 4650 args[which_arg] = arg; 4651 4652 Node* p = basic_plus_adr(arg, class_klass_offset); 4653 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type); 4654 klasses[which_arg] = _gvn.transform(kls); 4655 } 4656 4657 // Having loaded both klasses, test each for null. 4658 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4659 for (which_arg = 0; which_arg <= 1; which_arg++) { 4660 Node* kls = klasses[which_arg]; 4661 Node* null_ctl = top(); 4662 kls = null_check_oop(kls, &null_ctl, never_see_null); 4663 if (which_arg == 0) { 4664 prim_region->init_req(1, null_ctl); 4665 } else { 4666 region->init_req(_prim_1_path, null_ctl); 4667 } 4668 if (stopped()) break; 4669 klasses[which_arg] = kls; 4670 } 4671 4672 if (!stopped()) { 4673 // now we have two reference types, in klasses[0..1] 4674 Node* subk = klasses[1]; // the argument to isAssignableFrom 4675 Node* superk = klasses[0]; // the receiver 4676 region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 4677 region->set_req(_ref_subtype_path, control()); 4678 } 4679 4680 // If both operands are primitive (both klasses null), then 4681 // we must return true when they are identical primitives. 4682 // It is convenient to test this after the first null klass check. 4683 // This path is also used if superc is a value mirror. 4684 set_control(_gvn.transform(prim_region)); 4685 if (!stopped()) { 4686 // Since superc is primitive, make a guard for the superc==subc case. 4687 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1])); 4688 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq)); 4689 generate_fair_guard(bol_eq, region); 4690 if (region->req() == PATH_LIMIT+1) { 4691 // A guard was added. If the added guard is taken, superc==subc. 4692 region->swap_edges(PATH_LIMIT, _prim_same_path); 4693 region->del_req(PATH_LIMIT); 4694 } 4695 region->set_req(_prim_0_path, control()); // Not equal after all. 4696 } 4697 4698 // these are the only paths that produce 'true': 4699 phi->set_req(_prim_same_path, intcon(1)); 4700 phi->set_req(_ref_subtype_path, intcon(1)); 4701 4702 // pull together the cases: 4703 assert(region->req() == PATH_LIMIT, "sane region"); 4704 for (uint i = 1; i < region->req(); i++) { 4705 Node* ctl = region->in(i); 4706 if (ctl == nullptr || ctl == top()) { 4707 region->set_req(i, top()); 4708 phi ->set_req(i, top()); 4709 } else if (phi->in(i) == nullptr) { 4710 phi->set_req(i, intcon(0)); // all other paths produce 'false' 4711 } 4712 } 4713 4714 set_control(_gvn.transform(region)); 4715 set_result(_gvn.transform(phi)); 4716 return true; 4717 } 4718 4719 //---------------------generate_array_guard_common------------------------ 4720 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind, Node** obj) { 4721 4722 if (stopped()) { 4723 return nullptr; 4724 } 4725 4726 // Like generate_guard, adds a new path onto the region. 4727 jint layout_con = 0; 4728 Node* layout_val = get_layout_helper(kls, layout_con); 4729 if (layout_val == nullptr) { 4730 bool query = 0; 4731 switch(kind) { 4732 case RefArray: query = Klass::layout_helper_is_refArray(layout_con); break; 4733 case NonRefArray: query = !Klass::layout_helper_is_refArray(layout_con); break; 4734 case TypeArray: query = Klass::layout_helper_is_typeArray(layout_con); break; 4735 case AnyArray: query = Klass::layout_helper_is_array(layout_con); break; 4736 case NonArray: query = !Klass::layout_helper_is_array(layout_con); break; 4737 default: 4738 ShouldNotReachHere(); 4739 } 4740 if (!query) { 4741 return nullptr; // never a branch 4742 } else { // always a branch 4743 Node* always_branch = control(); 4744 if (region != nullptr) 4745 region->add_req(always_branch); 4746 set_control(top()); 4747 return always_branch; 4748 } 4749 } 4750 unsigned int value = 0; 4751 BoolTest::mask btest = BoolTest::illegal; 4752 switch(kind) { 4753 case RefArray: 4754 case NonRefArray: { 4755 value = Klass::_lh_array_tag_ref_value; 4756 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift))); 4757 btest = (kind == RefArray) ? BoolTest::eq : BoolTest::ne; 4758 break; 4759 } 4760 case TypeArray: { 4761 value = Klass::_lh_array_tag_type_value; 4762 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift))); 4763 btest = BoolTest::eq; 4764 break; 4765 } 4766 case AnyArray: value = Klass::_lh_neutral_value; btest = BoolTest::lt; break; 4767 case NonArray: value = Klass::_lh_neutral_value; btest = BoolTest::gt; break; 4768 default: 4769 ShouldNotReachHere(); 4770 } 4771 // Now test the correct condition. 4772 jint nval = (jint)value; 4773 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval))); 4774 Node* bol = _gvn.transform(new BoolNode(cmp, btest)); 4775 Node* ctrl = generate_fair_guard(bol, region); 4776 Node* is_array_ctrl = kind == NonArray ? control() : ctrl; 4777 if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) { 4778 // Keep track of the fact that 'obj' is an array to prevent 4779 // array specific accesses from floating above the guard. 4780 *obj = _gvn.transform(new CastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM)); 4781 } 4782 return ctrl; 4783 } 4784 4785 // public static native Object[] newNullRestrictedAtomicArray(Class<?> componentType, int length, Object initVal); 4786 // public static native Object[] newNullRestrictedNonAtomicArray(Class<?> componentType, int length, Object initVal); 4787 // public static native Object[] newNullableAtomicArray(Class<?> componentType, int length); 4788 bool LibraryCallKit::inline_newArray(bool null_free, bool atomic) { 4789 assert(null_free || atomic, "nullable implies atomic"); 4790 Node* componentType = argument(0); 4791 Node* length = argument(1); 4792 Node* init_val = null_free ? argument(2) : nullptr; 4793 4794 const TypeInstPtr* tp = _gvn.type(componentType)->isa_instptr(); 4795 if (tp != nullptr) { 4796 ciInstanceKlass* ik = tp->instance_klass(); 4797 if (ik == C->env()->Class_klass()) { 4798 ciType* t = tp->java_mirror_type(); 4799 if (t != nullptr && t->is_inlinetype()) { 4800 4801 ciArrayKlass* array_klass = ciArrayKlass::make(t, null_free, atomic, true); 4802 assert(array_klass->is_elem_null_free() == null_free, "inconsistency"); 4803 assert(array_klass->is_elem_atomic() == atomic, "inconsistency"); 4804 4805 // TOOD 8350865 ZGC needs card marks on initializing oop stores 4806 if (UseZGC && null_free && !array_klass->is_flat_array_klass()) { 4807 return false; 4808 } 4809 4810 if (array_klass->is_loaded() && array_klass->element_klass()->as_inline_klass()->is_initialized()) { 4811 const TypeAryKlassPtr* array_klass_type = TypeAryKlassPtr::make(array_klass, Type::trust_interfaces, true); 4812 if (null_free) { 4813 if (init_val->is_InlineType()) { 4814 if (array_klass_type->is_flat() && init_val->as_InlineType()->is_all_zero(&gvn(), /* flat */ true)) { 4815 // Zeroing is enough because the init value is the all-zero value 4816 init_val = nullptr; 4817 } else { 4818 init_val = init_val->as_InlineType()->buffer(this); 4819 } 4820 } 4821 // TODO 8350865 Should we add a check of the init_val type (maybe in debug only + halt)? 4822 } 4823 Node* obj = new_array(makecon(array_klass_type), length, 0, nullptr, false, init_val); 4824 const TypeAryPtr* arytype = gvn().type(obj)->is_aryptr(); 4825 assert(arytype->is_null_free() == null_free, "inconsistency"); 4826 assert(arytype->is_not_null_free() == !null_free, "inconsistency"); 4827 assert(arytype->is_atomic() == atomic, "inconsistency"); 4828 set_result(obj); 4829 return true; 4830 } 4831 } 4832 } 4833 } 4834 return false; 4835 } 4836 4837 Node* LibraryCallKit::load_default_array_klass(Node* klass_node) { 4838 // TODO 8366668 4839 // - Fred suggested that we could just have the first entry in the refined list point to the array with ArrayKlass::ArrayProperties::DEFAULT property 4840 // For now, we just load from ObjArrayKlass::_next_refined_array_klass, which would always be the refKlass for non-values, and deopt if it's not 4841 // - Convert this to an IGVN optimization, so it's also folded after parsing 4842 // - The generate_typeArray_guard is not needed by all callers, double-check that it's folded 4843 4844 const Type* klass_t = _gvn.type(klass_node); 4845 const TypeAryKlassPtr* ary_klass_t = klass_t->isa_aryklassptr(); 4846 if (ary_klass_t && ary_klass_t->klass_is_exact()) { 4847 if (ary_klass_t->exact_klass()->is_obj_array_klass()) { 4848 ary_klass_t = ary_klass_t->get_vm_type(false); 4849 return makecon(ary_klass_t); 4850 } else { 4851 return klass_node; 4852 } 4853 } 4854 4855 // Load next refined array klass if klass is an ObjArrayKlass 4856 RegionNode* refined_region = new RegionNode(2); 4857 Node* refined_phi = new PhiNode(refined_region, klass_t); 4858 4859 generate_typeArray_guard(klass_node, refined_region); 4860 if (refined_region->req() == 3) { 4861 refined_phi->add_req(klass_node); 4862 } 4863 4864 Node* adr_refined_klass = basic_plus_adr(klass_node, in_bytes(ObjArrayKlass::next_refined_array_klass_offset())); 4865 Node* refined_klass = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), adr_refined_klass, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 4866 4867 RegionNode* refined_region2 = new RegionNode(3); 4868 Node* refined_phi2 = new PhiNode(refined_region2, klass_t); 4869 4870 Node* null_ctl = top(); 4871 Node* null_free_klass = null_check_common(refined_klass, T_OBJECT, false, &null_ctl); 4872 refined_region2->init_req(1, null_ctl); 4873 refined_phi2->init_req(1, klass_node); 4874 4875 refined_region2->init_req(2, control()); 4876 refined_phi2->init_req(2, null_free_klass); 4877 4878 set_control(_gvn.transform(refined_region2)); 4879 refined_klass = _gvn.transform(refined_phi2); 4880 4881 Node* adr_properties = basic_plus_adr(refined_klass, in_bytes(ObjArrayKlass::properties_offset())); 4882 4883 Node* properties = _gvn.transform(LoadNode::make(_gvn, control(), immutable_memory(), adr_properties, TypeRawPtr::BOTTOM, TypeInt::INT, T_INT, MemNode::unordered)); 4884 Node* default_val = makecon(TypeInt::make(ArrayKlass::ArrayProperties::DEFAULT)); 4885 Node* chk = _gvn.transform(new CmpINode(properties, default_val)); 4886 Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq)); 4887 4888 { // Deoptimize if not the default property 4889 BuildCutout unless(this, tst, PROB_MAX); 4890 uncommon_trap_exact(Deoptimization::Reason_class_check, Deoptimization::Action_none); 4891 } 4892 4893 refined_region->init_req(1, control()); 4894 refined_phi->init_req(1, refined_klass); 4895 4896 set_control(_gvn.transform(refined_region)); 4897 klass_node = _gvn.transform(refined_phi); 4898 4899 return klass_node; 4900 } 4901 4902 //-----------------------inline_native_newArray-------------------------- 4903 // private static native Object java.lang.reflect.Array.newArray(Class<?> componentType, int length); 4904 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size); 4905 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) { 4906 Node* mirror; 4907 Node* count_val; 4908 if (uninitialized) { 4909 null_check_receiver(); 4910 mirror = argument(1); 4911 count_val = argument(2); 4912 } else { 4913 mirror = argument(0); 4914 count_val = argument(1); 4915 } 4916 4917 mirror = null_check(mirror); 4918 // If mirror or obj is dead, only null-path is taken. 4919 if (stopped()) return true; 4920 4921 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 4922 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 4923 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 4924 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 4925 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 4926 4927 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4928 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 4929 result_reg, _slow_path); 4930 Node* normal_ctl = control(); 4931 Node* no_array_ctl = result_reg->in(_slow_path); 4932 4933 // Generate code for the slow case. We make a call to newArray(). 4934 set_control(no_array_ctl); 4935 if (!stopped()) { 4936 // Either the input type is void.class, or else the 4937 // array klass has not yet been cached. Either the 4938 // ensuing call will throw an exception, or else it 4939 // will cache the array klass for next time. 4940 PreserveJVMState pjvms(this); 4941 CallJavaNode* slow_call = nullptr; 4942 if (uninitialized) { 4943 // Generate optimized virtual call (holder class 'Unsafe' is final) 4944 slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true); 4945 } else { 4946 slow_call = generate_method_call_static(vmIntrinsics::_newArray, true); 4947 } 4948 Node* slow_result = set_results_for_java_call(slow_call); 4949 // this->control() comes from set_results_for_java_call 4950 result_reg->set_req(_slow_path, control()); 4951 result_val->set_req(_slow_path, slow_result); 4952 result_io ->set_req(_slow_path, i_o()); 4953 result_mem->set_req(_slow_path, reset_memory()); 4954 } 4955 4956 set_control(normal_ctl); 4957 if (!stopped()) { 4958 // Normal case: The array type has been cached in the java.lang.Class. 4959 // The following call works fine even if the array type is polymorphic. 4960 // It could be a dynamic mix of int[], boolean[], Object[], etc. 4961 4962 klass_node = load_default_array_klass(klass_node); 4963 4964 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 4965 result_reg->init_req(_normal_path, control()); 4966 result_val->init_req(_normal_path, obj); 4967 result_io ->init_req(_normal_path, i_o()); 4968 result_mem->init_req(_normal_path, reset_memory()); 4969 4970 if (uninitialized) { 4971 // Mark the allocation so that zeroing is skipped 4972 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj); 4973 alloc->maybe_set_complete(&_gvn); 4974 } 4975 } 4976 4977 // Return the combined state. 4978 set_i_o( _gvn.transform(result_io) ); 4979 set_all_memory( _gvn.transform(result_mem)); 4980 4981 C->set_has_split_ifs(true); // Has chance for split-if optimization 4982 set_result(result_reg, result_val); 4983 return true; 4984 } 4985 4986 //----------------------inline_native_getLength-------------------------- 4987 // public static native int java.lang.reflect.Array.getLength(Object array); 4988 bool LibraryCallKit::inline_native_getLength() { 4989 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 4990 4991 Node* array = null_check(argument(0)); 4992 // If array is dead, only null-path is taken. 4993 if (stopped()) return true; 4994 4995 // Deoptimize if it is a non-array. 4996 Node* non_array = generate_non_array_guard(load_object_klass(array), nullptr, &array); 4997 4998 if (non_array != nullptr) { 4999 PreserveJVMState pjvms(this); 5000 set_control(non_array); 5001 uncommon_trap(Deoptimization::Reason_intrinsic, 5002 Deoptimization::Action_maybe_recompile); 5003 } 5004 5005 // If control is dead, only non-array-path is taken. 5006 if (stopped()) return true; 5007 5008 // The works fine even if the array type is polymorphic. 5009 // It could be a dynamic mix of int[], boolean[], Object[], etc. 5010 Node* result = load_array_length(array); 5011 5012 C->set_has_split_ifs(true); // Has chance for split-if optimization 5013 set_result(result); 5014 return true; 5015 } 5016 5017 //------------------------inline_array_copyOf---------------------------- 5018 // public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 5019 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 5020 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 5021 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 5022 5023 // Get the arguments. 5024 Node* original = argument(0); 5025 Node* start = is_copyOfRange? argument(1): intcon(0); 5026 Node* end = is_copyOfRange? argument(2): argument(1); 5027 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 5028 5029 Node* newcopy = nullptr; 5030 5031 // Set the original stack and the reexecute bit for the interpreter to reexecute 5032 // the bytecode that invokes Arrays.copyOf if deoptimization happens. 5033 { PreserveReexecuteState preexecs(this); 5034 jvms()->set_should_reexecute(true); 5035 5036 array_type_mirror = null_check(array_type_mirror); 5037 original = null_check(original); 5038 5039 // Check if a null path was taken unconditionally. 5040 if (stopped()) return true; 5041 5042 Node* orig_length = load_array_length(original); 5043 5044 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, nullptr, 0); 5045 klass_node = null_check(klass_node); 5046 5047 RegionNode* bailout = new RegionNode(1); 5048 record_for_igvn(bailout); 5049 5050 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 5051 // Bail out if that is so. 5052 // Inline type array may have object field that would require a 5053 // write barrier. Conservatively, go to slow path. 5054 // TODO 8251971: Optimize for the case when flat src/dst are later found 5055 // to not contain oops (i.e., move this check to the macro expansion phase). 5056 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 5057 const TypeAryPtr* orig_t = _gvn.type(original)->isa_aryptr(); 5058 const TypeKlassPtr* tklass = _gvn.type(klass_node)->is_klassptr(); 5059 bool exclude_flat = UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, false, false, BarrierSetC2::Parsing) && 5060 // Can src array be flat and contain oops? 5061 (orig_t == nullptr || (!orig_t->is_not_flat() && (!orig_t->is_flat() || orig_t->elem()->inline_klass()->contains_oops()))) && 5062 // Can dest array be flat and contain oops? 5063 tklass->can_be_inline_array() && (!tklass->is_flat() || tklass->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->as_inline_klass()->contains_oops()); 5064 // TODO 8366668 generate_non_refArray_guard also passed for ref arrays?? 5065 Node* not_objArray = exclude_flat ? generate_non_refArray_guard(klass_node, bailout) : generate_typeArray_guard(klass_node, bailout); 5066 5067 klass_node = load_default_array_klass(klass_node); 5068 5069 if (not_objArray != nullptr) { 5070 // Improve the klass node's type from the new optimistic assumption: 5071 ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 5072 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 5073 Node* cast = new CastPPNode(control(), klass_node, akls); 5074 klass_node = _gvn.transform(cast); 5075 } 5076 5077 // Bail out if either start or end is negative. 5078 generate_negative_guard(start, bailout, &start); 5079 generate_negative_guard(end, bailout, &end); 5080 5081 Node* length = end; 5082 if (_gvn.type(start) != TypeInt::ZERO) { 5083 length = _gvn.transform(new SubINode(end, start)); 5084 } 5085 5086 // Bail out if length is negative (i.e., if start > end). 5087 // Without this the new_array would throw 5088 // NegativeArraySizeException but IllegalArgumentException is what 5089 // should be thrown 5090 generate_negative_guard(length, bailout, &length); 5091 5092 // Handle inline type arrays 5093 bool can_validate = !too_many_traps(Deoptimization::Reason_class_check); 5094 if (!stopped()) { 5095 // TODO JDK-8329224 5096 if (!orig_t->is_null_free()) { 5097 // Not statically known to be null free, add a check 5098 generate_fair_guard(null_free_array_test(original), bailout); 5099 } 5100 orig_t = _gvn.type(original)->isa_aryptr(); 5101 if (orig_t != nullptr && orig_t->is_flat()) { 5102 // Src is flat, check that dest is flat as well 5103 if (exclude_flat) { 5104 // Dest can't be flat, bail out 5105 bailout->add_req(control()); 5106 set_control(top()); 5107 } else { 5108 generate_fair_guard(flat_array_test(klass_node, /* flat = */ false), bailout); 5109 } 5110 // TODO 8350865 This is not correct anymore. Write tests and fix logic similar to arraycopy. 5111 } else if (UseArrayFlattening && (orig_t == nullptr || !orig_t->is_not_flat()) && 5112 // If dest is flat, src must be flat as well (guaranteed by src <: dest check if validated). 5113 ((!tklass->is_flat() && tklass->can_be_inline_array()) || !can_validate)) { 5114 // Src might be flat and dest might not be flat. Go to the slow path if src is flat. 5115 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat. 5116 generate_fair_guard(flat_array_test(load_object_klass(original)), bailout); 5117 if (orig_t != nullptr) { 5118 orig_t = orig_t->cast_to_not_flat(); 5119 original = _gvn.transform(new CheckCastPPNode(control(), original, orig_t)); 5120 } 5121 } 5122 if (!can_validate) { 5123 // No validation. The subtype check emitted at macro expansion time will not go to the slow 5124 // path but call checkcast_arraycopy which can not handle flat/null-free inline type arrays. 5125 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat/null-free. 5126 generate_fair_guard(flat_array_test(klass_node), bailout); 5127 generate_fair_guard(null_free_array_test(original), bailout); 5128 } 5129 } 5130 5131 // Bail out if start is larger than the original length 5132 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start)); 5133 generate_negative_guard(orig_tail, bailout, &orig_tail); 5134 5135 if (bailout->req() > 1) { 5136 PreserveJVMState pjvms(this); 5137 set_control(_gvn.transform(bailout)); 5138 uncommon_trap(Deoptimization::Reason_intrinsic, 5139 Deoptimization::Action_maybe_recompile); 5140 } 5141 5142 if (!stopped()) { 5143 // How many elements will we copy from the original? 5144 // The answer is MinI(orig_tail, length). 5145 Node* moved = _gvn.transform(new MinINode(orig_tail, length)); 5146 5147 // Generate a direct call to the right arraycopy function(s). 5148 // We know the copy is disjoint but we might not know if the 5149 // oop stores need checking. 5150 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 5151 // This will fail a store-check if x contains any non-nulls. 5152 5153 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to 5154 // loads/stores but it is legal only if we're sure the 5155 // Arrays.copyOf would succeed. So we need all input arguments 5156 // to the copyOf to be validated, including that the copy to the 5157 // new array won't trigger an ArrayStoreException. That subtype 5158 // check can be optimized if we know something on the type of 5159 // the input array from type speculation. 5160 if (_gvn.type(klass_node)->singleton()) { 5161 const TypeKlassPtr* subk = _gvn.type(load_object_klass(original))->is_klassptr(); 5162 const TypeKlassPtr* superk = _gvn.type(klass_node)->is_klassptr(); 5163 5164 int test = C->static_subtype_check(superk, subk); 5165 if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) { 5166 const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr(); 5167 if (t_original->speculative_type() != nullptr) { 5168 original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true); 5169 } 5170 } 5171 } 5172 5173 bool validated = false; 5174 // Reason_class_check rather than Reason_intrinsic because we 5175 // want to intrinsify even if this traps. 5176 if (can_validate) { 5177 Node* not_subtype_ctrl = gen_subtype_check(original, klass_node); 5178 5179 if (not_subtype_ctrl != top()) { 5180 PreserveJVMState pjvms(this); 5181 set_control(not_subtype_ctrl); 5182 uncommon_trap(Deoptimization::Reason_class_check, 5183 Deoptimization::Action_make_not_entrant); 5184 assert(stopped(), "Should be stopped"); 5185 } 5186 validated = true; 5187 } 5188 5189 if (!stopped()) { 5190 newcopy = new_array(klass_node, length, 0); // no arguments to push 5191 5192 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true, 5193 load_object_klass(original), klass_node); 5194 if (!is_copyOfRange) { 5195 ac->set_copyof(validated); 5196 } else { 5197 ac->set_copyofrange(validated); 5198 } 5199 Node* n = _gvn.transform(ac); 5200 if (n == ac) { 5201 ac->connect_outputs(this); 5202 } else { 5203 assert(validated, "shouldn't transform if all arguments not validated"); 5204 set_all_memory(n); 5205 } 5206 } 5207 } 5208 } // original reexecute is set back here 5209 5210 C->set_has_split_ifs(true); // Has chance for split-if optimization 5211 if (!stopped()) { 5212 set_result(newcopy); 5213 } 5214 return true; 5215 } 5216 5217 5218 //----------------------generate_virtual_guard--------------------------- 5219 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 5220 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 5221 RegionNode* slow_region) { 5222 ciMethod* method = callee(); 5223 int vtable_index = method->vtable_index(); 5224 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 5225 "bad index %d", vtable_index); 5226 // Get the Method* out of the appropriate vtable entry. 5227 int entry_offset = in_bytes(Klass::vtable_start_offset()) + 5228 vtable_index*vtableEntry::size_in_bytes() + 5229 in_bytes(vtableEntry::method_offset()); 5230 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 5231 Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 5232 5233 // Compare the target method with the expected method (e.g., Object.hashCode). 5234 const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 5235 5236 Node* native_call = makecon(native_call_addr); 5237 Node* chk_native = _gvn.transform(new CmpPNode(target_call, native_call)); 5238 Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne)); 5239 5240 return generate_slow_guard(test_native, slow_region); 5241 } 5242 5243 //-----------------------generate_method_call---------------------------- 5244 // Use generate_method_call to make a slow-call to the real 5245 // method if the fast path fails. An alternative would be to 5246 // use a stub like OptoRuntime::slow_arraycopy_Java. 5247 // This only works for expanding the current library call, 5248 // not another intrinsic. (E.g., don't use this for making an 5249 // arraycopy call inside of the copyOf intrinsic.) 5250 CallJavaNode* 5251 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) { 5252 // When compiling the intrinsic method itself, do not use this technique. 5253 guarantee(callee() != C->method(), "cannot make slow-call to self"); 5254 5255 ciMethod* method = callee(); 5256 // ensure the JVMS we have will be correct for this call 5257 guarantee(method_id == method->intrinsic_id(), "must match"); 5258 5259 const TypeFunc* tf = TypeFunc::make(method); 5260 if (res_not_null) { 5261 assert(tf->return_type() == T_OBJECT, ""); 5262 const TypeTuple* range = tf->range_cc(); 5263 const Type** fields = TypeTuple::fields(range->cnt()); 5264 fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL); 5265 const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields); 5266 tf = TypeFunc::make(tf->domain_cc(), new_range); 5267 } 5268 CallJavaNode* slow_call; 5269 if (is_static) { 5270 assert(!is_virtual, ""); 5271 slow_call = new CallStaticJavaNode(C, tf, 5272 SharedRuntime::get_resolve_static_call_stub(), method); 5273 } else if (is_virtual) { 5274 assert(!gvn().type(argument(0))->maybe_null(), "should not be null"); 5275 int vtable_index = Method::invalid_vtable_index; 5276 if (UseInlineCaches) { 5277 // Suppress the vtable call 5278 } else { 5279 // hashCode and clone are not a miranda methods, 5280 // so the vtable index is fixed. 5281 // No need to use the linkResolver to get it. 5282 vtable_index = method->vtable_index(); 5283 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 5284 "bad index %d", vtable_index); 5285 } 5286 slow_call = new CallDynamicJavaNode(tf, 5287 SharedRuntime::get_resolve_virtual_call_stub(), 5288 method, vtable_index); 5289 } else { // neither virtual nor static: opt_virtual 5290 assert(!gvn().type(argument(0))->maybe_null(), "should not be null"); 5291 slow_call = new CallStaticJavaNode(C, tf, 5292 SharedRuntime::get_resolve_opt_virtual_call_stub(), method); 5293 slow_call->set_optimized_virtual(true); 5294 } 5295 if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) { 5296 // To be able to issue a direct call (optimized virtual or virtual) 5297 // and skip a call to MH.linkTo*/invokeBasic adapter, additional information 5298 // about the method being invoked should be attached to the call site to 5299 // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C). 5300 slow_call->set_override_symbolic_info(true); 5301 } 5302 set_arguments_for_java_call(slow_call); 5303 set_edges_for_java_call(slow_call); 5304 return slow_call; 5305 } 5306 5307 5308 /** 5309 * Build special case code for calls to hashCode on an object. This call may 5310 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate 5311 * slightly different code. 5312 */ 5313 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 5314 assert(is_static == callee()->is_static(), "correct intrinsic selection"); 5315 assert(!(is_virtual && is_static), "either virtual, special, or static"); 5316 5317 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 5318 5319 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 5320 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT); 5321 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 5322 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 5323 Node* obj = argument(0); 5324 5325 // Don't intrinsify hashcode on inline types for now. 5326 // The "is locked" runtime check below also serves as inline type check and goes to the slow path. 5327 if (gvn().type(obj)->is_inlinetypeptr()) { 5328 return false; 5329 } 5330 5331 if (!is_static) { 5332 // Check for hashing null object 5333 obj = null_check_receiver(); 5334 if (stopped()) return true; // unconditionally null 5335 result_reg->init_req(_null_path, top()); 5336 result_val->init_req(_null_path, top()); 5337 } else { 5338 // Do a null check, and return zero if null. 5339 // System.identityHashCode(null) == 0 5340 Node* null_ctl = top(); 5341 obj = null_check_oop(obj, &null_ctl); 5342 result_reg->init_req(_null_path, null_ctl); 5343 result_val->init_req(_null_path, _gvn.intcon(0)); 5344 } 5345 5346 // Unconditionally null? Then return right away. 5347 if (stopped()) { 5348 set_control( result_reg->in(_null_path)); 5349 if (!stopped()) 5350 set_result(result_val->in(_null_path)); 5351 return true; 5352 } 5353 5354 // We only go to the fast case code if we pass a number of guards. The 5355 // paths which do not pass are accumulated in the slow_region. 5356 RegionNode* slow_region = new RegionNode(1); 5357 record_for_igvn(slow_region); 5358 5359 // If this is a virtual call, we generate a funny guard. We pull out 5360 // the vtable entry corresponding to hashCode() from the target object. 5361 // If the target method which we are calling happens to be the native 5362 // Object hashCode() method, we pass the guard. We do not need this 5363 // guard for non-virtual calls -- the caller is known to be the native 5364 // Object hashCode(). 5365 if (is_virtual) { 5366 // After null check, get the object's klass. 5367 Node* obj_klass = load_object_klass(obj); 5368 generate_virtual_guard(obj_klass, slow_region); 5369 } 5370 5371 // Get the header out of the object, use LoadMarkNode when available 5372 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 5373 // The control of the load must be null. Otherwise, the load can move before 5374 // the null check after castPP removal. 5375 Node* no_ctrl = nullptr; 5376 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 5377 5378 if (!UseObjectMonitorTable) { 5379 // Test the header to see if it is safe to read w.r.t. locking. 5380 // This also serves as guard against inline types 5381 Node *lock_mask = _gvn.MakeConX(markWord::inline_type_mask_in_place); 5382 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask)); 5383 if (LockingMode == LM_LIGHTWEIGHT) { 5384 Node *monitor_val = _gvn.MakeConX(markWord::monitor_value); 5385 Node *chk_monitor = _gvn.transform(new CmpXNode(lmasked_header, monitor_val)); 5386 Node *test_monitor = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq)); 5387 5388 generate_slow_guard(test_monitor, slow_region); 5389 } else { 5390 Node *unlocked_val = _gvn.MakeConX(markWord::unlocked_value); 5391 Node *chk_unlocked = _gvn.transform(new CmpXNode(lmasked_header, unlocked_val)); 5392 Node *test_not_unlocked = _gvn.transform(new BoolNode(chk_unlocked, BoolTest::ne)); 5393 5394 generate_slow_guard(test_not_unlocked, slow_region); 5395 } 5396 } 5397 5398 // Get the hash value and check to see that it has been properly assigned. 5399 // We depend on hash_mask being at most 32 bits and avoid the use of 5400 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 5401 // vm: see markWord.hpp. 5402 Node *hash_mask = _gvn.intcon(markWord::hash_mask); 5403 Node *hash_shift = _gvn.intcon(markWord::hash_shift); 5404 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift)); 5405 // This hack lets the hash bits live anywhere in the mark object now, as long 5406 // as the shift drops the relevant bits into the low 32 bits. Note that 5407 // Java spec says that HashCode is an int so there's no point in capturing 5408 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 5409 hshifted_header = ConvX2I(hshifted_header); 5410 Node *hash_val = _gvn.transform(new AndINode(hshifted_header, hash_mask)); 5411 5412 Node *no_hash_val = _gvn.intcon(markWord::no_hash); 5413 Node *chk_assigned = _gvn.transform(new CmpINode( hash_val, no_hash_val)); 5414 Node *test_assigned = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq)); 5415 5416 generate_slow_guard(test_assigned, slow_region); 5417 5418 Node* init_mem = reset_memory(); 5419 // fill in the rest of the null path: 5420 result_io ->init_req(_null_path, i_o()); 5421 result_mem->init_req(_null_path, init_mem); 5422 5423 result_val->init_req(_fast_path, hash_val); 5424 result_reg->init_req(_fast_path, control()); 5425 result_io ->init_req(_fast_path, i_o()); 5426 result_mem->init_req(_fast_path, init_mem); 5427 5428 // Generate code for the slow case. We make a call to hashCode(). 5429 set_control(_gvn.transform(slow_region)); 5430 if (!stopped()) { 5431 // No need for PreserveJVMState, because we're using up the present state. 5432 set_all_memory(init_mem); 5433 vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 5434 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false); 5435 Node* slow_result = set_results_for_java_call(slow_call); 5436 // this->control() comes from set_results_for_java_call 5437 result_reg->init_req(_slow_path, control()); 5438 result_val->init_req(_slow_path, slow_result); 5439 result_io ->set_req(_slow_path, i_o()); 5440 result_mem ->set_req(_slow_path, reset_memory()); 5441 } 5442 5443 // Return the combined state. 5444 set_i_o( _gvn.transform(result_io) ); 5445 set_all_memory( _gvn.transform(result_mem)); 5446 5447 set_result(result_reg, result_val); 5448 return true; 5449 } 5450 5451 //---------------------------inline_native_getClass---------------------------- 5452 // public final native Class<?> java.lang.Object.getClass(); 5453 // 5454 // Build special case code for calls to getClass on an object. 5455 bool LibraryCallKit::inline_native_getClass() { 5456 Node* obj = argument(0); 5457 if (obj->is_InlineType()) { 5458 const Type* t = _gvn.type(obj); 5459 if (t->maybe_null()) { 5460 null_check(obj); 5461 } 5462 set_result(makecon(TypeInstPtr::make(t->inline_klass()->java_mirror()))); 5463 return true; 5464 } 5465 obj = null_check_receiver(); 5466 if (stopped()) return true; 5467 set_result(load_mirror_from_klass(load_object_klass(obj))); 5468 return true; 5469 } 5470 5471 //-----------------inline_native_Reflection_getCallerClass--------------------- 5472 // public static native Class<?> sun.reflect.Reflection.getCallerClass(); 5473 // 5474 // In the presence of deep enough inlining, getCallerClass() becomes a no-op. 5475 // 5476 // NOTE: This code must perform the same logic as JVM_GetCallerClass 5477 // in that it must skip particular security frames and checks for 5478 // caller sensitive methods. 5479 bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 5480 #ifndef PRODUCT 5481 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5482 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 5483 } 5484 #endif 5485 5486 if (!jvms()->has_method()) { 5487 #ifndef PRODUCT 5488 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5489 tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 5490 } 5491 #endif 5492 return false; 5493 } 5494 5495 // Walk back up the JVM state to find the caller at the required 5496 // depth. 5497 JVMState* caller_jvms = jvms(); 5498 5499 // Cf. JVM_GetCallerClass 5500 // NOTE: Start the loop at depth 1 because the current JVM state does 5501 // not include the Reflection.getCallerClass() frame. 5502 for (int n = 1; caller_jvms != nullptr; caller_jvms = caller_jvms->caller(), n++) { 5503 ciMethod* m = caller_jvms->method(); 5504 switch (n) { 5505 case 0: 5506 fatal("current JVM state does not include the Reflection.getCallerClass frame"); 5507 break; 5508 case 1: 5509 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 5510 if (!m->caller_sensitive()) { 5511 #ifndef PRODUCT 5512 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5513 tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 5514 } 5515 #endif 5516 return false; // bail-out; let JVM_GetCallerClass do the work 5517 } 5518 break; 5519 default: 5520 if (!m->is_ignored_by_security_stack_walk()) { 5521 // We have reached the desired frame; return the holder class. 5522 // Acquire method holder as java.lang.Class and push as constant. 5523 ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 5524 ciInstance* caller_mirror = caller_klass->java_mirror(); 5525 set_result(makecon(TypeInstPtr::make(caller_mirror))); 5526 5527 #ifndef PRODUCT 5528 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5529 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()); 5530 tty->print_cr(" JVM state at this point:"); 5531 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 5532 ciMethod* m = jvms()->of_depth(i)->method(); 5533 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 5534 } 5535 } 5536 #endif 5537 return true; 5538 } 5539 break; 5540 } 5541 } 5542 5543 #ifndef PRODUCT 5544 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5545 tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 5546 tty->print_cr(" JVM state at this point:"); 5547 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 5548 ciMethod* m = jvms()->of_depth(i)->method(); 5549 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 5550 } 5551 } 5552 #endif 5553 5554 return false; // bail-out; let JVM_GetCallerClass do the work 5555 } 5556 5557 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 5558 Node* arg = argument(0); 5559 Node* result = nullptr; 5560 5561 switch (id) { 5562 case vmIntrinsics::_floatToRawIntBits: result = new MoveF2INode(arg); break; 5563 case vmIntrinsics::_intBitsToFloat: result = new MoveI2FNode(arg); break; 5564 case vmIntrinsics::_doubleToRawLongBits: result = new MoveD2LNode(arg); break; 5565 case vmIntrinsics::_longBitsToDouble: result = new MoveL2DNode(arg); break; 5566 case vmIntrinsics::_floatToFloat16: result = new ConvF2HFNode(arg); break; 5567 case vmIntrinsics::_float16ToFloat: result = new ConvHF2FNode(arg); break; 5568 5569 case vmIntrinsics::_doubleToLongBits: { 5570 // two paths (plus control) merge in a wood 5571 RegionNode *r = new RegionNode(3); 5572 Node *phi = new PhiNode(r, TypeLong::LONG); 5573 5574 Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg)); 5575 // Build the boolean node 5576 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 5577 5578 // Branch either way. 5579 // NaN case is less traveled, which makes all the difference. 5580 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 5581 Node *opt_isnan = _gvn.transform(ifisnan); 5582 assert( opt_isnan->is_If(), "Expect an IfNode"); 5583 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 5584 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 5585 5586 set_control(iftrue); 5587 5588 static const jlong nan_bits = CONST64(0x7ff8000000000000); 5589 Node *slow_result = longcon(nan_bits); // return NaN 5590 phi->init_req(1, _gvn.transform( slow_result )); 5591 r->init_req(1, iftrue); 5592 5593 // Else fall through 5594 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 5595 set_control(iffalse); 5596 5597 phi->init_req(2, _gvn.transform(new MoveD2LNode(arg))); 5598 r->init_req(2, iffalse); 5599 5600 // Post merge 5601 set_control(_gvn.transform(r)); 5602 record_for_igvn(r); 5603 5604 C->set_has_split_ifs(true); // Has chance for split-if optimization 5605 result = phi; 5606 assert(result->bottom_type()->isa_long(), "must be"); 5607 break; 5608 } 5609 5610 case vmIntrinsics::_floatToIntBits: { 5611 // two paths (plus control) merge in a wood 5612 RegionNode *r = new RegionNode(3); 5613 Node *phi = new PhiNode(r, TypeInt::INT); 5614 5615 Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg)); 5616 // Build the boolean node 5617 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 5618 5619 // Branch either way. 5620 // NaN case is less traveled, which makes all the difference. 5621 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 5622 Node *opt_isnan = _gvn.transform(ifisnan); 5623 assert( opt_isnan->is_If(), "Expect an IfNode"); 5624 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 5625 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 5626 5627 set_control(iftrue); 5628 5629 static const jint nan_bits = 0x7fc00000; 5630 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 5631 phi->init_req(1, _gvn.transform( slow_result )); 5632 r->init_req(1, iftrue); 5633 5634 // Else fall through 5635 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 5636 set_control(iffalse); 5637 5638 phi->init_req(2, _gvn.transform(new MoveF2INode(arg))); 5639 r->init_req(2, iffalse); 5640 5641 // Post merge 5642 set_control(_gvn.transform(r)); 5643 record_for_igvn(r); 5644 5645 C->set_has_split_ifs(true); // Has chance for split-if optimization 5646 result = phi; 5647 assert(result->bottom_type()->isa_int(), "must be"); 5648 break; 5649 } 5650 5651 default: 5652 fatal_unexpected_iid(id); 5653 break; 5654 } 5655 set_result(_gvn.transform(result)); 5656 return true; 5657 } 5658 5659 bool LibraryCallKit::inline_fp_range_check(vmIntrinsics::ID id) { 5660 Node* arg = argument(0); 5661 Node* result = nullptr; 5662 5663 switch (id) { 5664 case vmIntrinsics::_floatIsInfinite: 5665 result = new IsInfiniteFNode(arg); 5666 break; 5667 case vmIntrinsics::_floatIsFinite: 5668 result = new IsFiniteFNode(arg); 5669 break; 5670 case vmIntrinsics::_doubleIsInfinite: 5671 result = new IsInfiniteDNode(arg); 5672 break; 5673 case vmIntrinsics::_doubleIsFinite: 5674 result = new IsFiniteDNode(arg); 5675 break; 5676 default: 5677 fatal_unexpected_iid(id); 5678 break; 5679 } 5680 set_result(_gvn.transform(result)); 5681 return true; 5682 } 5683 5684 //----------------------inline_unsafe_copyMemory------------------------- 5685 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 5686 5687 static bool has_wide_mem(PhaseGVN& gvn, Node* addr, Node* base) { 5688 const TypeAryPtr* addr_t = gvn.type(addr)->isa_aryptr(); 5689 const Type* base_t = gvn.type(base); 5690 5691 bool in_native = (base_t == TypePtr::NULL_PTR); 5692 bool in_heap = !TypePtr::NULL_PTR->higher_equal(base_t); 5693 bool is_mixed = !in_heap && !in_native; 5694 5695 if (is_mixed) { 5696 return true; // mixed accesses can touch both on-heap and off-heap memory 5697 } 5698 if (in_heap) { 5699 bool is_prim_array = (addr_t != nullptr) && (addr_t->elem() != Type::BOTTOM); 5700 if (!is_prim_array) { 5701 // Though Unsafe.copyMemory() ensures at runtime for on-heap accesses that base is a primitive array, 5702 // there's not enough type information available to determine proper memory slice for it. 5703 return true; 5704 } 5705 } 5706 return false; 5707 } 5708 5709 bool LibraryCallKit::inline_unsafe_copyMemory() { 5710 if (callee()->is_static()) return false; // caller must have the capability! 5711 null_check_receiver(); // null-check receiver 5712 if (stopped()) return true; 5713 5714 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 5715 5716 Node* src_base = argument(1); // type: oop 5717 Node* src_off = ConvL2X(argument(2)); // type: long 5718 Node* dst_base = argument(4); // type: oop 5719 Node* dst_off = ConvL2X(argument(5)); // type: long 5720 Node* size = ConvL2X(argument(7)); // type: long 5721 5722 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 5723 "fieldOffset must be byte-scaled"); 5724 5725 Node* src_addr = make_unsafe_address(src_base, src_off); 5726 Node* dst_addr = make_unsafe_address(dst_base, dst_off); 5727 5728 Node* thread = _gvn.transform(new ThreadLocalNode()); 5729 Node* doing_unsafe_access_addr = basic_plus_adr(top(), thread, in_bytes(JavaThread::doing_unsafe_access_offset())); 5730 BasicType doing_unsafe_access_bt = T_BYTE; 5731 assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented"); 5732 5733 // update volatile field 5734 store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered); 5735 5736 int flags = RC_LEAF | RC_NO_FP; 5737 5738 const TypePtr* dst_type = TypePtr::BOTTOM; 5739 5740 // Adjust memory effects of the runtime call based on input values. 5741 if (!has_wide_mem(_gvn, src_addr, src_base) && 5742 !has_wide_mem(_gvn, dst_addr, dst_base)) { 5743 dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory 5744 5745 const TypePtr* src_type = _gvn.type(src_addr)->is_ptr(); 5746 if (C->get_alias_index(src_type) == C->get_alias_index(dst_type)) { 5747 flags |= RC_NARROW_MEM; // narrow in memory 5748 } 5749 } 5750 5751 // Call it. Note that the length argument is not scaled. 5752 make_runtime_call(flags, 5753 OptoRuntime::fast_arraycopy_Type(), 5754 StubRoutines::unsafe_arraycopy(), 5755 "unsafe_arraycopy", 5756 dst_type, 5757 src_addr, dst_addr, size XTOP); 5758 5759 store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered); 5760 5761 return true; 5762 } 5763 5764 // unsafe_setmemory(void *base, ulong offset, size_t length, char fill_value); 5765 // Fill 'length' bytes starting from 'base[offset]' with 'fill_value' 5766 bool LibraryCallKit::inline_unsafe_setMemory() { 5767 if (callee()->is_static()) return false; // caller must have the capability! 5768 null_check_receiver(); // null-check receiver 5769 if (stopped()) return true; 5770 5771 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 5772 5773 Node* dst_base = argument(1); // type: oop 5774 Node* dst_off = ConvL2X(argument(2)); // type: long 5775 Node* size = ConvL2X(argument(4)); // type: long 5776 Node* byte = argument(6); // type: byte 5777 5778 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 5779 "fieldOffset must be byte-scaled"); 5780 5781 Node* dst_addr = make_unsafe_address(dst_base, dst_off); 5782 5783 Node* thread = _gvn.transform(new ThreadLocalNode()); 5784 Node* doing_unsafe_access_addr = basic_plus_adr(top(), thread, in_bytes(JavaThread::doing_unsafe_access_offset())); 5785 BasicType doing_unsafe_access_bt = T_BYTE; 5786 assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented"); 5787 5788 // update volatile field 5789 store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered); 5790 5791 int flags = RC_LEAF | RC_NO_FP; 5792 5793 const TypePtr* dst_type = TypePtr::BOTTOM; 5794 5795 // Adjust memory effects of the runtime call based on input values. 5796 if (!has_wide_mem(_gvn, dst_addr, dst_base)) { 5797 dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory 5798 5799 flags |= RC_NARROW_MEM; // narrow in memory 5800 } 5801 5802 // Call it. Note that the length argument is not scaled. 5803 make_runtime_call(flags, 5804 OptoRuntime::unsafe_setmemory_Type(), 5805 StubRoutines::unsafe_setmemory(), 5806 "unsafe_setmemory", 5807 dst_type, 5808 dst_addr, size XTOP, byte); 5809 5810 store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered); 5811 5812 return true; 5813 } 5814 5815 #undef XTOP 5816 5817 //------------------------clone_coping----------------------------------- 5818 // Helper function for inline_native_clone. 5819 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) { 5820 assert(obj_size != nullptr, ""); 5821 Node* raw_obj = alloc_obj->in(1); 5822 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 5823 5824 AllocateNode* alloc = nullptr; 5825 if (ReduceBulkZeroing && 5826 // If we are implementing an array clone without knowing its source type 5827 // (can happen when compiling the array-guarded branch of a reflective 5828 // Object.clone() invocation), initialize the array within the allocation. 5829 // This is needed because some GCs (e.g. ZGC) might fall back in this case 5830 // to a runtime clone call that assumes fully initialized source arrays. 5831 (!is_array || obj->get_ptr_type()->isa_aryptr() != nullptr)) { 5832 // We will be completely responsible for initializing this object - 5833 // mark Initialize node as complete. 5834 alloc = AllocateNode::Ideal_allocation(alloc_obj); 5835 // The object was just allocated - there should be no any stores! 5836 guarantee(alloc != nullptr && alloc->maybe_set_complete(&_gvn), ""); 5837 // Mark as complete_with_arraycopy so that on AllocateNode 5838 // expansion, we know this AllocateNode is initialized by an array 5839 // copy and a StoreStore barrier exists after the array copy. 5840 alloc->initialization()->set_complete_with_arraycopy(); 5841 } 5842 5843 Node* size = _gvn.transform(obj_size); 5844 access_clone(obj, alloc_obj, size, is_array); 5845 5846 // Do not let reads from the cloned object float above the arraycopy. 5847 if (alloc != nullptr) { 5848 // Do not let stores that initialize this object be reordered with 5849 // a subsequent store that would make this object accessible by 5850 // other threads. 5851 // Record what AllocateNode this StoreStore protects so that 5852 // escape analysis can go from the MemBarStoreStoreNode to the 5853 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 5854 // based on the escape status of the AllocateNode. 5855 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 5856 } else { 5857 insert_mem_bar(Op_MemBarCPUOrder); 5858 } 5859 } 5860 5861 //------------------------inline_native_clone---------------------------- 5862 // protected native Object java.lang.Object.clone(); 5863 // 5864 // Here are the simple edge cases: 5865 // null receiver => normal trap 5866 // virtual and clone was overridden => slow path to out-of-line clone 5867 // not cloneable or finalizer => slow path to out-of-line Object.clone 5868 // 5869 // The general case has two steps, allocation and copying. 5870 // Allocation has two cases, and uses GraphKit::new_instance or new_array. 5871 // 5872 // Copying also has two cases, oop arrays and everything else. 5873 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 5874 // Everything else uses the tight inline loop supplied by CopyArrayNode. 5875 // 5876 // These steps fold up nicely if and when the cloned object's klass 5877 // can be sharply typed as an object array, a type array, or an instance. 5878 // 5879 bool LibraryCallKit::inline_native_clone(bool is_virtual) { 5880 PhiNode* result_val; 5881 5882 // Set the reexecute bit for the interpreter to reexecute 5883 // the bytecode that invokes Object.clone if deoptimization happens. 5884 { PreserveReexecuteState preexecs(this); 5885 jvms()->set_should_reexecute(true); 5886 5887 Node* obj = argument(0); 5888 obj = null_check_receiver(); 5889 if (stopped()) return true; 5890 5891 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 5892 if (obj_type->is_inlinetypeptr()) { 5893 // If the object to clone is an inline type, we can simply return it (i.e. a nop) since inline types have 5894 // no identity. 5895 set_result(obj); 5896 return true; 5897 } 5898 5899 // If we are going to clone an instance, we need its exact type to 5900 // know the number and types of fields to convert the clone to 5901 // loads/stores. Maybe a speculative type can help us. 5902 if (!obj_type->klass_is_exact() && 5903 obj_type->speculative_type() != nullptr && 5904 obj_type->speculative_type()->is_instance_klass() && 5905 !obj_type->speculative_type()->is_inlinetype()) { 5906 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass(); 5907 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem && 5908 !spec_ik->has_injected_fields()) { 5909 if (!obj_type->isa_instptr() || 5910 obj_type->is_instptr()->instance_klass()->has_subklass()) { 5911 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false); 5912 } 5913 } 5914 } 5915 5916 // Conservatively insert a memory barrier on all memory slices. 5917 // Do not let writes into the original float below the clone. 5918 insert_mem_bar(Op_MemBarCPUOrder); 5919 5920 // paths into result_reg: 5921 enum { 5922 _slow_path = 1, // out-of-line call to clone method (virtual or not) 5923 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 5924 _array_path, // plain array allocation, plus arrayof_long_arraycopy 5925 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 5926 PATH_LIMIT 5927 }; 5928 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 5929 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 5930 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); 5931 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 5932 record_for_igvn(result_reg); 5933 5934 Node* obj_klass = load_object_klass(obj); 5935 // We only go to the fast case code if we pass a number of guards. 5936 // The paths which do not pass are accumulated in the slow_region. 5937 RegionNode* slow_region = new RegionNode(1); 5938 record_for_igvn(slow_region); 5939 5940 Node* array_obj = obj; 5941 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj); 5942 if (array_ctl != nullptr) { 5943 // It's an array. 5944 PreserveJVMState pjvms(this); 5945 set_control(array_ctl); 5946 5947 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 5948 const TypeAryPtr* ary_ptr = obj_type->isa_aryptr(); 5949 if (UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Expansion) && 5950 obj_type->can_be_inline_array() && 5951 (ary_ptr == nullptr || (!ary_ptr->is_not_flat() && (!ary_ptr->is_flat() || ary_ptr->elem()->inline_klass()->contains_oops())))) { 5952 // Flat inline type array may have object field that would require a 5953 // write barrier. Conservatively, go to slow path. 5954 generate_fair_guard(flat_array_test(obj_klass), slow_region); 5955 } 5956 5957 if (!stopped()) { 5958 Node* obj_length = load_array_length(array_obj); 5959 Node* array_size = nullptr; // Size of the array without object alignment padding. 5960 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true); 5961 5962 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 5963 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) { 5964 // If it is an oop array, it requires very special treatment, 5965 // because gc barriers are required when accessing the array. 5966 Node* is_obja = generate_refArray_guard(obj_klass, (RegionNode*)nullptr); 5967 if (is_obja != nullptr) { 5968 PreserveJVMState pjvms2(this); 5969 set_control(is_obja); 5970 // Generate a direct call to the right arraycopy function(s). 5971 // Clones are always tightly coupled. 5972 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false); 5973 ac->set_clone_oop_array(); 5974 Node* n = _gvn.transform(ac); 5975 assert(n == ac, "cannot disappear"); 5976 ac->connect_outputs(this, /*deoptimize_on_exception=*/true); 5977 5978 result_reg->init_req(_objArray_path, control()); 5979 result_val->init_req(_objArray_path, alloc_obj); 5980 result_i_o ->set_req(_objArray_path, i_o()); 5981 result_mem ->set_req(_objArray_path, reset_memory()); 5982 } 5983 } 5984 // Otherwise, there are no barriers to worry about. 5985 // (We can dispense with card marks if we know the allocation 5986 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 5987 // causes the non-eden paths to take compensating steps to 5988 // simulate a fresh allocation, so that no further 5989 // card marks are required in compiled code to initialize 5990 // the object.) 5991 5992 if (!stopped()) { 5993 copy_to_clone(obj, alloc_obj, array_size, true); 5994 5995 // Present the results of the copy. 5996 result_reg->init_req(_array_path, control()); 5997 result_val->init_req(_array_path, alloc_obj); 5998 result_i_o ->set_req(_array_path, i_o()); 5999 result_mem ->set_req(_array_path, reset_memory()); 6000 } 6001 } 6002 } 6003 6004 if (!stopped()) { 6005 // It's an instance (we did array above). Make the slow-path tests. 6006 // If this is a virtual call, we generate a funny guard. We grab 6007 // the vtable entry corresponding to clone() from the target object. 6008 // If the target method which we are calling happens to be the 6009 // Object clone() method, we pass the guard. We do not need this 6010 // guard for non-virtual calls; the caller is known to be the native 6011 // Object clone(). 6012 if (is_virtual) { 6013 generate_virtual_guard(obj_klass, slow_region); 6014 } 6015 6016 // The object must be easily cloneable and must not have a finalizer. 6017 // Both of these conditions may be checked in a single test. 6018 // We could optimize the test further, but we don't care. 6019 generate_misc_flags_guard(obj_klass, 6020 // Test both conditions: 6021 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer, 6022 // Must be cloneable but not finalizer: 6023 KlassFlags::_misc_is_cloneable_fast, 6024 slow_region); 6025 } 6026 6027 if (!stopped()) { 6028 // It's an instance, and it passed the slow-path tests. 6029 PreserveJVMState pjvms(this); 6030 Node* obj_size = nullptr; // Total object size, including object alignment padding. 6031 // Need to deoptimize on exception from allocation since Object.clone intrinsic 6032 // is reexecuted if deoptimization occurs and there could be problems when merging 6033 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). 6034 Node* alloc_obj = new_instance(obj_klass, nullptr, &obj_size, /*deoptimize_on_exception=*/true); 6035 6036 copy_to_clone(obj, alloc_obj, obj_size, false); 6037 6038 // Present the results of the slow call. 6039 result_reg->init_req(_instance_path, control()); 6040 result_val->init_req(_instance_path, alloc_obj); 6041 result_i_o ->set_req(_instance_path, i_o()); 6042 result_mem ->set_req(_instance_path, reset_memory()); 6043 } 6044 6045 // Generate code for the slow case. We make a call to clone(). 6046 set_control(_gvn.transform(slow_region)); 6047 if (!stopped()) { 6048 PreserveJVMState pjvms(this); 6049 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual, false, true); 6050 // We need to deoptimize on exception (see comment above) 6051 Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true); 6052 // this->control() comes from set_results_for_java_call 6053 result_reg->init_req(_slow_path, control()); 6054 result_val->init_req(_slow_path, slow_result); 6055 result_i_o ->set_req(_slow_path, i_o()); 6056 result_mem ->set_req(_slow_path, reset_memory()); 6057 } 6058 6059 // Return the combined state. 6060 set_control( _gvn.transform(result_reg)); 6061 set_i_o( _gvn.transform(result_i_o)); 6062 set_all_memory( _gvn.transform(result_mem)); 6063 } // original reexecute is set back here 6064 6065 set_result(_gvn.transform(result_val)); 6066 return true; 6067 } 6068 6069 // If we have a tightly coupled allocation, the arraycopy may take care 6070 // of the array initialization. If one of the guards we insert between 6071 // the allocation and the arraycopy causes a deoptimization, an 6072 // uninitialized array will escape the compiled method. To prevent that 6073 // we set the JVM state for uncommon traps between the allocation and 6074 // the arraycopy to the state before the allocation so, in case of 6075 // deoptimization, we'll reexecute the allocation and the 6076 // initialization. 6077 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) { 6078 if (alloc != nullptr) { 6079 ciMethod* trap_method = alloc->jvms()->method(); 6080 int trap_bci = alloc->jvms()->bci(); 6081 6082 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 6083 !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) { 6084 // Make sure there's no store between the allocation and the 6085 // arraycopy otherwise visible side effects could be rexecuted 6086 // in case of deoptimization and cause incorrect execution. 6087 bool no_interfering_store = true; 6088 Node* mem = alloc->in(TypeFunc::Memory); 6089 if (mem->is_MergeMem()) { 6090 for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) { 6091 Node* n = mms.memory(); 6092 if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 6093 assert(n->is_Store(), "what else?"); 6094 no_interfering_store = false; 6095 break; 6096 } 6097 } 6098 } else { 6099 for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { 6100 Node* n = mms.memory(); 6101 if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 6102 assert(n->is_Store(), "what else?"); 6103 no_interfering_store = false; 6104 break; 6105 } 6106 } 6107 } 6108 6109 if (no_interfering_store) { 6110 SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc); 6111 6112 JVMState* saved_jvms = jvms(); 6113 saved_reexecute_sp = _reexecute_sp; 6114 6115 set_jvms(sfpt->jvms()); 6116 _reexecute_sp = jvms()->sp(); 6117 6118 return saved_jvms; 6119 } 6120 } 6121 } 6122 return nullptr; 6123 } 6124 6125 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack 6126 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter. 6127 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const { 6128 JVMState* old_jvms = alloc->jvms()->clone_shallow(C); 6129 uint size = alloc->req(); 6130 SafePointNode* sfpt = new SafePointNode(size, old_jvms); 6131 old_jvms->set_map(sfpt); 6132 for (uint i = 0; i < size; i++) { 6133 sfpt->init_req(i, alloc->in(i)); 6134 } 6135 int adjustment = 1; 6136 const TypeAryKlassPtr* ary_klass_ptr = alloc->in(AllocateNode::KlassNode)->bottom_type()->is_aryklassptr(); 6137 if (ary_klass_ptr->is_null_free()) { 6138 // A null-free, tightly coupled array allocation can only come from LibraryCallKit::inline_newArray which 6139 // also requires the componentType and initVal on stack for re-execution. 6140 // Re-create and push the componentType. 6141 ciArrayKlass* klass = ary_klass_ptr->exact_klass()->as_array_klass(); 6142 ciInstance* instance = klass->component_mirror_instance(); 6143 const TypeInstPtr* t_instance = TypeInstPtr::make(instance); 6144 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), makecon(t_instance)); 6145 adjustment++; 6146 } 6147 // re-push array length for deoptimization 6148 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment - 1, alloc->in(AllocateNode::ALength)); 6149 if (ary_klass_ptr->is_null_free()) { 6150 // Re-create and push the initVal. 6151 Node* init_val = alloc->in(AllocateNode::InitValue); 6152 if (init_val == nullptr) { 6153 init_val = InlineTypeNode::make_all_zero(_gvn, ary_klass_ptr->elem()->is_instklassptr()->instance_klass()->as_inline_klass()); 6154 } else if (UseCompressedOops) { 6155 init_val = _gvn.transform(new DecodeNNode(init_val, init_val->bottom_type()->make_ptr())); 6156 } 6157 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment, init_val); 6158 adjustment++; 6159 } 6160 old_jvms->set_sp(old_jvms->sp() + adjustment); 6161 old_jvms->set_monoff(old_jvms->monoff() + adjustment); 6162 old_jvms->set_scloff(old_jvms->scloff() + adjustment); 6163 old_jvms->set_endoff(old_jvms->endoff() + adjustment); 6164 old_jvms->set_should_reexecute(true); 6165 6166 sfpt->set_i_o(map()->i_o()); 6167 sfpt->set_memory(map()->memory()); 6168 sfpt->set_control(map()->control()); 6169 return sfpt; 6170 } 6171 6172 // In case of a deoptimization, we restart execution at the 6173 // allocation, allocating a new array. We would leave an uninitialized 6174 // array in the heap that GCs wouldn't expect. Move the allocation 6175 // after the traps so we don't allocate the array if we 6176 // deoptimize. This is possible because tightly_coupled_allocation() 6177 // guarantees there's no observer of the allocated array at this point 6178 // and the control flow is simple enough. 6179 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards, 6180 int saved_reexecute_sp, uint new_idx) { 6181 if (saved_jvms_before_guards != nullptr && !stopped()) { 6182 replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards); 6183 6184 assert(alloc != nullptr, "only with a tightly coupled allocation"); 6185 // restore JVM state to the state at the arraycopy 6186 saved_jvms_before_guards->map()->set_control(map()->control()); 6187 assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?"); 6188 assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?"); 6189 // If we've improved the types of some nodes (null check) while 6190 // emitting the guards, propagate them to the current state 6191 map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx); 6192 set_jvms(saved_jvms_before_guards); 6193 _reexecute_sp = saved_reexecute_sp; 6194 6195 // Remove the allocation from above the guards 6196 CallProjections* callprojs = alloc->extract_projections(true); 6197 InitializeNode* init = alloc->initialization(); 6198 Node* alloc_mem = alloc->in(TypeFunc::Memory); 6199 C->gvn_replace_by(callprojs->fallthrough_ioproj, alloc->in(TypeFunc::I_O)); 6200 C->gvn_replace_by(init->proj_out(TypeFunc::Memory), alloc_mem); 6201 6202 // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below 6203 // the allocation (i.e. is only valid if the allocation succeeds): 6204 // 1) replace CastIINode with AllocateArrayNode's length here 6205 // 2) Create CastIINode again once allocation has moved (see below) at the end of this method 6206 // 6207 // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate 6208 // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy) 6209 Node* init_control = init->proj_out(TypeFunc::Control); 6210 Node* alloc_length = alloc->Ideal_length(); 6211 #ifdef ASSERT 6212 Node* prev_cast = nullptr; 6213 #endif 6214 for (uint i = 0; i < init_control->outcnt(); i++) { 6215 Node* init_out = init_control->raw_out(i); 6216 if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) { 6217 #ifdef ASSERT 6218 if (prev_cast == nullptr) { 6219 prev_cast = init_out; 6220 } else { 6221 if (prev_cast->cmp(*init_out) == false) { 6222 prev_cast->dump(); 6223 init_out->dump(); 6224 assert(false, "not equal CastIINode"); 6225 } 6226 } 6227 #endif 6228 C->gvn_replace_by(init_out, alloc_length); 6229 } 6230 } 6231 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0)); 6232 6233 // move the allocation here (after the guards) 6234 _gvn.hash_delete(alloc); 6235 alloc->set_req(TypeFunc::Control, control()); 6236 alloc->set_req(TypeFunc::I_O, i_o()); 6237 Node *mem = reset_memory(); 6238 set_all_memory(mem); 6239 alloc->set_req(TypeFunc::Memory, mem); 6240 set_control(init->proj_out_or_null(TypeFunc::Control)); 6241 set_i_o(callprojs->fallthrough_ioproj); 6242 6243 // Update memory as done in GraphKit::set_output_for_allocation() 6244 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength)); 6245 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type(); 6246 if (ary_type->isa_aryptr() && length_type != nullptr) { 6247 ary_type = ary_type->is_aryptr()->cast_to_size(length_type); 6248 } 6249 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot); 6250 int elemidx = C->get_alias_index(telemref); 6251 set_memory(init->proj_out_or_null(TypeFunc::Memory), Compile::AliasIdxRaw); 6252 set_memory(init->proj_out_or_null(TypeFunc::Memory), elemidx); 6253 6254 Node* allocx = _gvn.transform(alloc); 6255 assert(allocx == alloc, "where has the allocation gone?"); 6256 assert(dest->is_CheckCastPP(), "not an allocation result?"); 6257 6258 _gvn.hash_delete(dest); 6259 dest->set_req(0, control()); 6260 Node* destx = _gvn.transform(dest); 6261 assert(destx == dest, "where has the allocation result gone?"); 6262 6263 array_ideal_length(alloc, ary_type, true); 6264 } 6265 } 6266 6267 // Unrelated UCTs between the array allocation and the array copy, which are considered safe by tightly_coupled_allocation(), 6268 // need to be replaced by an UCT with a state before the array allocation (including the array length). This is necessary 6269 // because we could hit one of these UCTs (which are executed before the emitted array copy guards and the actual array 6270 // allocation which is moved down in arraycopy_move_allocation_here()). When later resuming execution in the interpreter, 6271 // we would have wrongly skipped the array allocation. To prevent this, we resume execution at the array allocation in 6272 // the interpreter similar to what we are doing for the newly emitted guards for the array copy. 6273 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc, 6274 JVMState* saved_jvms_before_guards) { 6275 if (saved_jvms_before_guards->map()->control()->is_IfProj()) { 6276 // There is at least one unrelated uncommon trap which needs to be replaced. 6277 SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc); 6278 6279 JVMState* saved_jvms = jvms(); 6280 const int saved_reexecute_sp = _reexecute_sp; 6281 set_jvms(sfpt->jvms()); 6282 _reexecute_sp = jvms()->sp(); 6283 6284 replace_unrelated_uncommon_traps_with_alloc_state(saved_jvms_before_guards); 6285 6286 // Restore state 6287 set_jvms(saved_jvms); 6288 _reexecute_sp = saved_reexecute_sp; 6289 } 6290 } 6291 6292 // Replace the unrelated uncommon traps with new uncommon trap nodes by reusing the action and reason. The new uncommon 6293 // traps will have the state of the array allocation. Let the old uncommon trap nodes die. 6294 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards) { 6295 Node* if_proj = saved_jvms_before_guards->map()->control(); // Start the search right before the newly emitted guards 6296 while (if_proj->is_IfProj()) { 6297 CallStaticJavaNode* uncommon_trap = get_uncommon_trap_from_success_proj(if_proj); 6298 if (uncommon_trap != nullptr) { 6299 create_new_uncommon_trap(uncommon_trap); 6300 } 6301 assert(if_proj->in(0)->is_If(), "must be If"); 6302 if_proj = if_proj->in(0)->in(0); 6303 } 6304 assert(if_proj->is_Proj() && if_proj->in(0)->is_Initialize(), 6305 "must have reached control projection of init node"); 6306 } 6307 6308 void LibraryCallKit::create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call) { 6309 const int trap_request = uncommon_trap_call->uncommon_trap_request(); 6310 assert(trap_request != 0, "no valid UCT trap request"); 6311 PreserveJVMState pjvms(this); 6312 set_control(uncommon_trap_call->in(0)); 6313 uncommon_trap(Deoptimization::trap_request_reason(trap_request), 6314 Deoptimization::trap_request_action(trap_request)); 6315 assert(stopped(), "Should be stopped"); 6316 _gvn.hash_delete(uncommon_trap_call); 6317 uncommon_trap_call->set_req(0, top()); // not used anymore, kill it 6318 } 6319 6320 // Common checks for array sorting intrinsics arguments. 6321 // Returns `true` if checks passed. 6322 bool LibraryCallKit::check_array_sort_arguments(Node* elementType, Node* obj, BasicType& bt) { 6323 // check address of the class 6324 if (elementType == nullptr || elementType->is_top()) { 6325 return false; // dead path 6326 } 6327 const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr(); 6328 if (elem_klass == nullptr) { 6329 return false; // dead path 6330 } 6331 // java_mirror_type() returns non-null for compile-time Class constants only 6332 ciType* elem_type = elem_klass->java_mirror_type(); 6333 if (elem_type == nullptr) { 6334 return false; 6335 } 6336 bt = elem_type->basic_type(); 6337 // Disable the intrinsic if the CPU does not support SIMD sort 6338 if (!Matcher::supports_simd_sort(bt)) { 6339 return false; 6340 } 6341 // check address of the array 6342 if (obj == nullptr || obj->is_top()) { 6343 return false; // dead path 6344 } 6345 const TypeAryPtr* obj_t = _gvn.type(obj)->isa_aryptr(); 6346 if (obj_t == nullptr || obj_t->elem() == Type::BOTTOM) { 6347 return false; // failed input validation 6348 } 6349 return true; 6350 } 6351 6352 //------------------------------inline_array_partition----------------------- 6353 bool LibraryCallKit::inline_array_partition() { 6354 address stubAddr = StubRoutines::select_array_partition_function(); 6355 if (stubAddr == nullptr) { 6356 return false; // Intrinsic's stub is not implemented on this platform 6357 } 6358 assert(callee()->signature()->size() == 9, "arrayPartition has 8 parameters (one long)"); 6359 6360 // no receiver because it is a static method 6361 Node* elementType = argument(0); 6362 Node* obj = argument(1); 6363 Node* offset = argument(2); // long 6364 Node* fromIndex = argument(4); 6365 Node* toIndex = argument(5); 6366 Node* indexPivot1 = argument(6); 6367 Node* indexPivot2 = argument(7); 6368 // PartitionOperation: argument(8) is ignored 6369 6370 Node* pivotIndices = nullptr; 6371 BasicType bt = T_ILLEGAL; 6372 6373 if (!check_array_sort_arguments(elementType, obj, bt)) { 6374 return false; 6375 } 6376 null_check(obj); 6377 // If obj is dead, only null-path is taken. 6378 if (stopped()) { 6379 return true; 6380 } 6381 // Set the original stack and the reexecute bit for the interpreter to reexecute 6382 // the bytecode that invokes DualPivotQuicksort.partition() if deoptimization happens. 6383 { PreserveReexecuteState preexecs(this); 6384 jvms()->set_should_reexecute(true); 6385 6386 Node* obj_adr = make_unsafe_address(obj, offset); 6387 6388 // create the pivotIndices array of type int and size = 2 6389 Node* size = intcon(2); 6390 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_INT))); 6391 pivotIndices = new_array(klass_node, size, 0); // no arguments to push 6392 AllocateArrayNode* alloc = tightly_coupled_allocation(pivotIndices); 6393 guarantee(alloc != nullptr, "created above"); 6394 Node* pivotIndices_adr = basic_plus_adr(pivotIndices, arrayOopDesc::base_offset_in_bytes(T_INT)); 6395 6396 // pass the basic type enum to the stub 6397 Node* elemType = intcon(bt); 6398 6399 // Call the stub 6400 const char *stubName = "array_partition_stub"; 6401 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_partition_Type(), 6402 stubAddr, stubName, TypePtr::BOTTOM, 6403 obj_adr, elemType, fromIndex, toIndex, pivotIndices_adr, 6404 indexPivot1, indexPivot2); 6405 6406 } // original reexecute is set back here 6407 6408 if (!stopped()) { 6409 set_result(pivotIndices); 6410 } 6411 6412 return true; 6413 } 6414 6415 6416 //------------------------------inline_array_sort----------------------- 6417 bool LibraryCallKit::inline_array_sort() { 6418 address stubAddr = StubRoutines::select_arraysort_function(); 6419 if (stubAddr == nullptr) { 6420 return false; // Intrinsic's stub is not implemented on this platform 6421 } 6422 assert(callee()->signature()->size() == 7, "arraySort has 6 parameters (one long)"); 6423 6424 // no receiver because it is a static method 6425 Node* elementType = argument(0); 6426 Node* obj = argument(1); 6427 Node* offset = argument(2); // long 6428 Node* fromIndex = argument(4); 6429 Node* toIndex = argument(5); 6430 // SortOperation: argument(6) is ignored 6431 6432 BasicType bt = T_ILLEGAL; 6433 6434 if (!check_array_sort_arguments(elementType, obj, bt)) { 6435 return false; 6436 } 6437 null_check(obj); 6438 // If obj is dead, only null-path is taken. 6439 if (stopped()) { 6440 return true; 6441 } 6442 Node* obj_adr = make_unsafe_address(obj, offset); 6443 6444 // pass the basic type enum to the stub 6445 Node* elemType = intcon(bt); 6446 6447 // Call the stub. 6448 const char *stubName = "arraysort_stub"; 6449 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_sort_Type(), 6450 stubAddr, stubName, TypePtr::BOTTOM, 6451 obj_adr, elemType, fromIndex, toIndex); 6452 6453 return true; 6454 } 6455 6456 6457 //------------------------------inline_arraycopy----------------------- 6458 // public static native void java.lang.System.arraycopy(Object src, int srcPos, 6459 // Object dest, int destPos, 6460 // int length); 6461 bool LibraryCallKit::inline_arraycopy() { 6462 // Get the arguments. 6463 Node* src = argument(0); // type: oop 6464 Node* src_offset = argument(1); // type: int 6465 Node* dest = argument(2); // type: oop 6466 Node* dest_offset = argument(3); // type: int 6467 Node* length = argument(4); // type: int 6468 6469 uint new_idx = C->unique(); 6470 6471 // Check for allocation before we add nodes that would confuse 6472 // tightly_coupled_allocation() 6473 AllocateArrayNode* alloc = tightly_coupled_allocation(dest); 6474 6475 int saved_reexecute_sp = -1; 6476 JVMState* saved_jvms_before_guards = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp); 6477 // See arraycopy_restore_alloc_state() comment 6478 // if alloc == null we don't have to worry about a tightly coupled allocation so we can emit all needed guards 6479 // if saved_jvms_before_guards is not null (then alloc is not null) then we can handle guards and a tightly coupled allocation 6480 // if saved_jvms_before_guards is null and alloc is not null, we can't emit any guards 6481 bool can_emit_guards = (alloc == nullptr || saved_jvms_before_guards != nullptr); 6482 6483 // The following tests must be performed 6484 // (1) src and dest are arrays. 6485 // (2) src and dest arrays must have elements of the same BasicType 6486 // (3) src and dest must not be null. 6487 // (4) src_offset must not be negative. 6488 // (5) dest_offset must not be negative. 6489 // (6) length must not be negative. 6490 // (7) src_offset + length must not exceed length of src. 6491 // (8) dest_offset + length must not exceed length of dest. 6492 // (9) each element of an oop array must be assignable 6493 6494 // (3) src and dest must not be null. 6495 // always do this here because we need the JVM state for uncommon traps 6496 Node* null_ctl = top(); 6497 src = saved_jvms_before_guards != nullptr ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY); 6498 assert(null_ctl->is_top(), "no null control here"); 6499 dest = null_check(dest, T_ARRAY); 6500 6501 if (!can_emit_guards) { 6502 // if saved_jvms_before_guards is null and alloc is not null, we don't emit any 6503 // guards but the arraycopy node could still take advantage of a 6504 // tightly allocated allocation. tightly_coupled_allocation() is 6505 // called again to make sure it takes the null check above into 6506 // account: the null check is mandatory and if it caused an 6507 // uncommon trap to be emitted then the allocation can't be 6508 // considered tightly coupled in this context. 6509 alloc = tightly_coupled_allocation(dest); 6510 } 6511 6512 bool validated = false; 6513 6514 const Type* src_type = _gvn.type(src); 6515 const Type* dest_type = _gvn.type(dest); 6516 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6517 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 6518 6519 // Do we have the type of src? 6520 bool has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM); 6521 // Do we have the type of dest? 6522 bool has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM); 6523 // Is the type for src from speculation? 6524 bool src_spec = false; 6525 // Is the type for dest from speculation? 6526 bool dest_spec = false; 6527 6528 if ((!has_src || !has_dest) && can_emit_guards) { 6529 // We don't have sufficient type information, let's see if 6530 // speculative types can help. We need to have types for both src 6531 // and dest so that it pays off. 6532 6533 // Do we already have or could we have type information for src 6534 bool could_have_src = has_src; 6535 // Do we already have or could we have type information for dest 6536 bool could_have_dest = has_dest; 6537 6538 ciKlass* src_k = nullptr; 6539 if (!has_src) { 6540 src_k = src_type->speculative_type_not_null(); 6541 if (src_k != nullptr && src_k->is_array_klass()) { 6542 could_have_src = true; 6543 } 6544 } 6545 6546 ciKlass* dest_k = nullptr; 6547 if (!has_dest) { 6548 dest_k = dest_type->speculative_type_not_null(); 6549 if (dest_k != nullptr && dest_k->is_array_klass()) { 6550 could_have_dest = true; 6551 } 6552 } 6553 6554 if (could_have_src && could_have_dest) { 6555 // This is going to pay off so emit the required guards 6556 if (!has_src) { 6557 src = maybe_cast_profiled_obj(src, src_k, true); 6558 src_type = _gvn.type(src); 6559 top_src = src_type->isa_aryptr(); 6560 has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM); 6561 src_spec = true; 6562 } 6563 if (!has_dest) { 6564 dest = maybe_cast_profiled_obj(dest, dest_k, true); 6565 dest_type = _gvn.type(dest); 6566 top_dest = dest_type->isa_aryptr(); 6567 has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM); 6568 dest_spec = true; 6569 } 6570 } 6571 } 6572 6573 if (has_src && has_dest && can_emit_guards) { 6574 BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type(); 6575 BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type(); 6576 if (is_reference_type(src_elem, true)) src_elem = T_OBJECT; 6577 if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT; 6578 6579 if (src_elem == dest_elem && top_src->is_flat() == top_dest->is_flat() && src_elem == T_OBJECT) { 6580 // If both arrays are object arrays then having the exact types 6581 // for both will remove the need for a subtype check at runtime 6582 // before the call and may make it possible to pick a faster copy 6583 // routine (without a subtype check on every element) 6584 // Do we have the exact type of src? 6585 bool could_have_src = src_spec; 6586 // Do we have the exact type of dest? 6587 bool could_have_dest = dest_spec; 6588 ciKlass* src_k = nullptr; 6589 ciKlass* dest_k = nullptr; 6590 if (!src_spec) { 6591 src_k = src_type->speculative_type_not_null(); 6592 if (src_k != nullptr && src_k->is_array_klass()) { 6593 could_have_src = true; 6594 } 6595 } 6596 if (!dest_spec) { 6597 dest_k = dest_type->speculative_type_not_null(); 6598 if (dest_k != nullptr && dest_k->is_array_klass()) { 6599 could_have_dest = true; 6600 } 6601 } 6602 if (could_have_src && could_have_dest) { 6603 // If we can have both exact types, emit the missing guards 6604 if (could_have_src && !src_spec) { 6605 src = maybe_cast_profiled_obj(src, src_k, true); 6606 src_type = _gvn.type(src); 6607 top_src = src_type->isa_aryptr(); 6608 } 6609 if (could_have_dest && !dest_spec) { 6610 dest = maybe_cast_profiled_obj(dest, dest_k, true); 6611 dest_type = _gvn.type(dest); 6612 top_dest = dest_type->isa_aryptr(); 6613 } 6614 } 6615 } 6616 } 6617 6618 ciMethod* trap_method = method(); 6619 int trap_bci = bci(); 6620 if (saved_jvms_before_guards != nullptr) { 6621 trap_method = alloc->jvms()->method(); 6622 trap_bci = alloc->jvms()->bci(); 6623 } 6624 6625 bool negative_length_guard_generated = false; 6626 6627 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 6628 can_emit_guards && !src->is_top() && !dest->is_top()) { 6629 // validate arguments: enables transformation the ArrayCopyNode 6630 validated = true; 6631 6632 RegionNode* slow_region = new RegionNode(1); 6633 record_for_igvn(slow_region); 6634 6635 // (1) src and dest are arrays. 6636 generate_non_array_guard(load_object_klass(src), slow_region, &src); 6637 generate_non_array_guard(load_object_klass(dest), slow_region, &dest); 6638 6639 // (2) src and dest arrays must have elements of the same BasicType 6640 // done at macro expansion or at Ideal transformation time 6641 6642 // (4) src_offset must not be negative. 6643 generate_negative_guard(src_offset, slow_region); 6644 6645 // (5) dest_offset must not be negative. 6646 generate_negative_guard(dest_offset, slow_region); 6647 6648 // (7) src_offset + length must not exceed length of src. 6649 generate_limit_guard(src_offset, length, 6650 load_array_length(src), 6651 slow_region); 6652 6653 // (8) dest_offset + length must not exceed length of dest. 6654 generate_limit_guard(dest_offset, length, 6655 load_array_length(dest), 6656 slow_region); 6657 6658 // (6) length must not be negative. 6659 // This is also checked in generate_arraycopy() during macro expansion, but 6660 // we also have to check it here for the case where the ArrayCopyNode will 6661 // be eliminated by Escape Analysis. 6662 if (EliminateAllocations) { 6663 generate_negative_guard(length, slow_region); 6664 negative_length_guard_generated = true; 6665 } 6666 6667 // (9) each element of an oop array must be assignable 6668 Node* dest_klass = load_object_klass(dest); 6669 if (src != dest) { 6670 Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass); 6671 slow_region->add_req(not_subtype_ctrl); 6672 } 6673 6674 // TODO 8350865 Fix below logic. Also handle atomicity. 6675 generate_fair_guard(flat_array_test(src), slow_region); 6676 generate_fair_guard(flat_array_test(dest), slow_region); 6677 6678 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr(); 6679 const Type* toop = dest_klass_t->cast_to_exactness(false)->as_instance_type(); 6680 src = _gvn.transform(new CheckCastPPNode(control(), src, toop)); 6681 src_type = _gvn.type(src); 6682 top_src = src_type->isa_aryptr(); 6683 6684 // Handle flat inline type arrays (null-free arrays are handled by the subtype check above) 6685 if (!stopped() && UseArrayFlattening) { 6686 // If dest is flat, src must be flat as well (guaranteed by src <: dest check). Handle flat src here. 6687 assert(top_dest == nullptr || !top_dest->is_flat() || top_src->is_flat(), "src array must be flat"); 6688 if (top_src != nullptr && top_src->is_flat()) { 6689 // Src is flat, check that dest is flat as well 6690 if (top_dest != nullptr && !top_dest->is_flat()) { 6691 generate_fair_guard(flat_array_test(dest_klass, /* flat = */ false), slow_region); 6692 // Since dest is flat and src <: dest, dest must have the same type as src. 6693 top_dest = top_src->cast_to_exactness(false); 6694 assert(top_dest->is_flat(), "dest must be flat"); 6695 dest = _gvn.transform(new CheckCastPPNode(control(), dest, top_dest)); 6696 } 6697 } else if (top_src == nullptr || !top_src->is_not_flat()) { 6698 // Src might be flat and dest might not be flat. Go to the slow path if src is flat. 6699 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat. 6700 assert(top_dest == nullptr || !top_dest->is_flat(), "dest array must not be flat"); 6701 generate_fair_guard(flat_array_test(src), slow_region); 6702 if (top_src != nullptr) { 6703 top_src = top_src->cast_to_not_flat(); 6704 src = _gvn.transform(new CheckCastPPNode(control(), src, top_src)); 6705 } 6706 } 6707 } 6708 6709 { 6710 PreserveJVMState pjvms(this); 6711 set_control(_gvn.transform(slow_region)); 6712 uncommon_trap(Deoptimization::Reason_intrinsic, 6713 Deoptimization::Action_make_not_entrant); 6714 assert(stopped(), "Should be stopped"); 6715 } 6716 arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx); 6717 } 6718 6719 if (stopped()) { 6720 return true; 6721 } 6722 6723 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated, 6724 // Create LoadRange and LoadKlass nodes for use during macro expansion here 6725 // so the compiler has a chance to eliminate them: during macro expansion, 6726 // we have to set their control (CastPP nodes are eliminated). 6727 load_object_klass(src), load_object_klass(dest), 6728 load_array_length(src), load_array_length(dest)); 6729 6730 ac->set_arraycopy(validated); 6731 6732 Node* n = _gvn.transform(ac); 6733 if (n == ac) { 6734 ac->connect_outputs(this); 6735 } else { 6736 assert(validated, "shouldn't transform if all arguments not validated"); 6737 set_all_memory(n); 6738 } 6739 clear_upper_avx(); 6740 6741 6742 return true; 6743 } 6744 6745 6746 // Helper function which determines if an arraycopy immediately follows 6747 // an allocation, with no intervening tests or other escapes for the object. 6748 AllocateArrayNode* 6749 LibraryCallKit::tightly_coupled_allocation(Node* ptr) { 6750 if (stopped()) return nullptr; // no fast path 6751 if (!C->do_aliasing()) return nullptr; // no MergeMems around 6752 6753 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr); 6754 if (alloc == nullptr) return nullptr; 6755 6756 Node* rawmem = memory(Compile::AliasIdxRaw); 6757 // Is the allocation's memory state untouched? 6758 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 6759 // Bail out if there have been raw-memory effects since the allocation. 6760 // (Example: There might have been a call or safepoint.) 6761 return nullptr; 6762 } 6763 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 6764 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 6765 return nullptr; 6766 } 6767 6768 // There must be no unexpected observers of this allocation. 6769 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 6770 Node* obs = ptr->fast_out(i); 6771 if (obs != this->map()) { 6772 return nullptr; 6773 } 6774 } 6775 6776 // This arraycopy must unconditionally follow the allocation of the ptr. 6777 Node* alloc_ctl = ptr->in(0); 6778 Node* ctl = control(); 6779 while (ctl != alloc_ctl) { 6780 // There may be guards which feed into the slow_region. 6781 // Any other control flow means that we might not get a chance 6782 // to finish initializing the allocated object. 6783 // Various low-level checks bottom out in uncommon traps. These 6784 // are considered safe since we've already checked above that 6785 // there is no unexpected observer of this allocation. 6786 if (get_uncommon_trap_from_success_proj(ctl) != nullptr) { 6787 assert(ctl->in(0)->is_If(), "must be If"); 6788 ctl = ctl->in(0)->in(0); 6789 } else { 6790 return nullptr; 6791 } 6792 } 6793 6794 // If we get this far, we have an allocation which immediately 6795 // precedes the arraycopy, and we can take over zeroing the new object. 6796 // The arraycopy will finish the initialization, and provide 6797 // a new control state to which we will anchor the destination pointer. 6798 6799 return alloc; 6800 } 6801 6802 CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* node) { 6803 if (node->is_IfProj()) { 6804 Node* other_proj = node->as_IfProj()->other_if_proj(); 6805 for (DUIterator_Fast jmax, j = other_proj->fast_outs(jmax); j < jmax; j++) { 6806 Node* obs = other_proj->fast_out(j); 6807 if (obs->in(0) == other_proj && obs->is_CallStaticJava() && 6808 (obs->as_CallStaticJava()->entry_point() == OptoRuntime::uncommon_trap_blob()->entry_point())) { 6809 return obs->as_CallStaticJava(); 6810 } 6811 } 6812 } 6813 return nullptr; 6814 } 6815 6816 //-------------inline_encodeISOArray----------------------------------- 6817 // int sun.nio.cs.ISO_8859_1.Encoder#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len) 6818 // int java.lang.StringCoding#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len) 6819 // int java.lang.StringCoding#encodeAsciiArray0(char[] sa, int sp, byte[] da, int dp, int len) 6820 // encode char[] to byte[] in ISO_8859_1 or ASCII 6821 bool LibraryCallKit::inline_encodeISOArray(bool ascii) { 6822 assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 6823 // no receiver since it is static method 6824 Node *src = argument(0); 6825 Node *src_offset = argument(1); 6826 Node *dst = argument(2); 6827 Node *dst_offset = argument(3); 6828 Node *length = argument(4); 6829 6830 // Cast source & target arrays to not-null 6831 if (VerifyIntrinsicChecks) { 6832 src = must_be_not_null(src, true); 6833 dst = must_be_not_null(dst, true); 6834 if (stopped()) { 6835 return true; 6836 } 6837 } 6838 6839 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 6840 const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr(); 6841 if (src_type == nullptr || src_type->elem() == Type::BOTTOM || 6842 dst_type == nullptr || dst_type->elem() == Type::BOTTOM) { 6843 // failed array check 6844 return false; 6845 } 6846 6847 // Figure out the size and type of the elements we will be copying. 6848 BasicType src_elem = src_type->elem()->array_element_basic_type(); 6849 BasicType dst_elem = dst_type->elem()->array_element_basic_type(); 6850 if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) { 6851 return false; 6852 } 6853 6854 // Check source & target bounds 6855 if (VerifyIntrinsicChecks) { 6856 generate_string_range_check(src, src_offset, length, src_elem == T_BYTE, true); 6857 generate_string_range_check(dst, dst_offset, length, false, true); 6858 if (stopped()) { 6859 return true; 6860 } 6861 } 6862 6863 Node* src_start = array_element_address(src, src_offset, T_CHAR); 6864 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 6865 // 'src_start' points to src array + scaled offset 6866 // 'dst_start' points to dst array + scaled offset 6867 6868 const TypeAryPtr* mtype = TypeAryPtr::BYTES; 6869 Node* enc = new EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length, ascii); 6870 enc = _gvn.transform(enc); 6871 Node* res_mem = _gvn.transform(new SCMemProjNode(enc)); 6872 set_memory(res_mem, mtype); 6873 set_result(enc); 6874 clear_upper_avx(); 6875 6876 return true; 6877 } 6878 6879 //-------------inline_multiplyToLen----------------------------------- 6880 bool LibraryCallKit::inline_multiplyToLen() { 6881 assert(UseMultiplyToLenIntrinsic, "not implemented on this platform"); 6882 6883 address stubAddr = StubRoutines::multiplyToLen(); 6884 if (stubAddr == nullptr) { 6885 return false; // Intrinsic's stub is not implemented on this platform 6886 } 6887 const char* stubName = "multiplyToLen"; 6888 6889 assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters"); 6890 6891 // no receiver because it is a static method 6892 Node* x = argument(0); 6893 Node* xlen = argument(1); 6894 Node* y = argument(2); 6895 Node* ylen = argument(3); 6896 Node* z = argument(4); 6897 6898 x = must_be_not_null(x, true); 6899 y = must_be_not_null(y, true); 6900 6901 const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr(); 6902 const TypeAryPtr* y_type = y->Value(&_gvn)->isa_aryptr(); 6903 if (x_type == nullptr || x_type->elem() == Type::BOTTOM || 6904 y_type == nullptr || y_type->elem() == Type::BOTTOM) { 6905 // failed array check 6906 return false; 6907 } 6908 6909 BasicType x_elem = x_type->elem()->array_element_basic_type(); 6910 BasicType y_elem = y_type->elem()->array_element_basic_type(); 6911 if (x_elem != T_INT || y_elem != T_INT) { 6912 return false; 6913 } 6914 6915 Node* x_start = array_element_address(x, intcon(0), x_elem); 6916 Node* y_start = array_element_address(y, intcon(0), y_elem); 6917 // 'x_start' points to x array + scaled xlen 6918 // 'y_start' points to y array + scaled ylen 6919 6920 Node* z_start = array_element_address(z, intcon(0), T_INT); 6921 6922 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6923 OptoRuntime::multiplyToLen_Type(), 6924 stubAddr, stubName, TypePtr::BOTTOM, 6925 x_start, xlen, y_start, ylen, z_start); 6926 6927 C->set_has_split_ifs(true); // Has chance for split-if optimization 6928 set_result(z); 6929 return true; 6930 } 6931 6932 //-------------inline_squareToLen------------------------------------ 6933 bool LibraryCallKit::inline_squareToLen() { 6934 assert(UseSquareToLenIntrinsic, "not implemented on this platform"); 6935 6936 address stubAddr = StubRoutines::squareToLen(); 6937 if (stubAddr == nullptr) { 6938 return false; // Intrinsic's stub is not implemented on this platform 6939 } 6940 const char* stubName = "squareToLen"; 6941 6942 assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters"); 6943 6944 Node* x = argument(0); 6945 Node* len = argument(1); 6946 Node* z = argument(2); 6947 Node* zlen = argument(3); 6948 6949 x = must_be_not_null(x, true); 6950 z = must_be_not_null(z, true); 6951 6952 const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr(); 6953 const TypeAryPtr* z_type = z->Value(&_gvn)->isa_aryptr(); 6954 if (x_type == nullptr || x_type->elem() == Type::BOTTOM || 6955 z_type == nullptr || z_type->elem() == Type::BOTTOM) { 6956 // failed array check 6957 return false; 6958 } 6959 6960 BasicType x_elem = x_type->elem()->array_element_basic_type(); 6961 BasicType z_elem = z_type->elem()->array_element_basic_type(); 6962 if (x_elem != T_INT || z_elem != T_INT) { 6963 return false; 6964 } 6965 6966 6967 Node* x_start = array_element_address(x, intcon(0), x_elem); 6968 Node* z_start = array_element_address(z, intcon(0), z_elem); 6969 6970 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6971 OptoRuntime::squareToLen_Type(), 6972 stubAddr, stubName, TypePtr::BOTTOM, 6973 x_start, len, z_start, zlen); 6974 6975 set_result(z); 6976 return true; 6977 } 6978 6979 //-------------inline_mulAdd------------------------------------------ 6980 bool LibraryCallKit::inline_mulAdd() { 6981 assert(UseMulAddIntrinsic, "not implemented on this platform"); 6982 6983 address stubAddr = StubRoutines::mulAdd(); 6984 if (stubAddr == nullptr) { 6985 return false; // Intrinsic's stub is not implemented on this platform 6986 } 6987 const char* stubName = "mulAdd"; 6988 6989 assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters"); 6990 6991 Node* out = argument(0); 6992 Node* in = argument(1); 6993 Node* offset = argument(2); 6994 Node* len = argument(3); 6995 Node* k = argument(4); 6996 6997 in = must_be_not_null(in, true); 6998 out = must_be_not_null(out, true); 6999 7000 const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr(); 7001 const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr(); 7002 if (out_type == nullptr || out_type->elem() == Type::BOTTOM || 7003 in_type == nullptr || in_type->elem() == Type::BOTTOM) { 7004 // failed array check 7005 return false; 7006 } 7007 7008 BasicType out_elem = out_type->elem()->array_element_basic_type(); 7009 BasicType in_elem = in_type->elem()->array_element_basic_type(); 7010 if (out_elem != T_INT || in_elem != T_INT) { 7011 return false; 7012 } 7013 7014 Node* outlen = load_array_length(out); 7015 Node* new_offset = _gvn.transform(new SubINode(outlen, offset)); 7016 Node* out_start = array_element_address(out, intcon(0), out_elem); 7017 Node* in_start = array_element_address(in, intcon(0), in_elem); 7018 7019 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 7020 OptoRuntime::mulAdd_Type(), 7021 stubAddr, stubName, TypePtr::BOTTOM, 7022 out_start,in_start, new_offset, len, k); 7023 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7024 set_result(result); 7025 return true; 7026 } 7027 7028 //-------------inline_montgomeryMultiply----------------------------------- 7029 bool LibraryCallKit::inline_montgomeryMultiply() { 7030 address stubAddr = StubRoutines::montgomeryMultiply(); 7031 if (stubAddr == nullptr) { 7032 return false; // Intrinsic's stub is not implemented on this platform 7033 } 7034 7035 assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform"); 7036 const char* stubName = "montgomery_multiply"; 7037 7038 assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters"); 7039 7040 Node* a = argument(0); 7041 Node* b = argument(1); 7042 Node* n = argument(2); 7043 Node* len = argument(3); 7044 Node* inv = argument(4); 7045 Node* m = argument(6); 7046 7047 const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr(); 7048 const TypeAryPtr* b_type = b->Value(&_gvn)->isa_aryptr(); 7049 const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr(); 7050 const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr(); 7051 if (a_type == nullptr || a_type->elem() == Type::BOTTOM || 7052 b_type == nullptr || b_type->elem() == Type::BOTTOM || 7053 n_type == nullptr || n_type->elem() == Type::BOTTOM || 7054 m_type == nullptr || m_type->elem() == Type::BOTTOM) { 7055 // failed array check 7056 return false; 7057 } 7058 7059 BasicType a_elem = a_type->elem()->array_element_basic_type(); 7060 BasicType b_elem = b_type->elem()->array_element_basic_type(); 7061 BasicType n_elem = n_type->elem()->array_element_basic_type(); 7062 BasicType m_elem = m_type->elem()->array_element_basic_type(); 7063 if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 7064 return false; 7065 } 7066 7067 // Make the call 7068 { 7069 Node* a_start = array_element_address(a, intcon(0), a_elem); 7070 Node* b_start = array_element_address(b, intcon(0), b_elem); 7071 Node* n_start = array_element_address(n, intcon(0), n_elem); 7072 Node* m_start = array_element_address(m, intcon(0), m_elem); 7073 7074 Node* call = make_runtime_call(RC_LEAF, 7075 OptoRuntime::montgomeryMultiply_Type(), 7076 stubAddr, stubName, TypePtr::BOTTOM, 7077 a_start, b_start, n_start, len, inv, top(), 7078 m_start); 7079 set_result(m); 7080 } 7081 7082 return true; 7083 } 7084 7085 bool LibraryCallKit::inline_montgomerySquare() { 7086 address stubAddr = StubRoutines::montgomerySquare(); 7087 if (stubAddr == nullptr) { 7088 return false; // Intrinsic's stub is not implemented on this platform 7089 } 7090 7091 assert(UseMontgomerySquareIntrinsic, "not implemented on this platform"); 7092 const char* stubName = "montgomery_square"; 7093 7094 assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters"); 7095 7096 Node* a = argument(0); 7097 Node* n = argument(1); 7098 Node* len = argument(2); 7099 Node* inv = argument(3); 7100 Node* m = argument(5); 7101 7102 const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr(); 7103 const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr(); 7104 const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr(); 7105 if (a_type == nullptr || a_type->elem() == Type::BOTTOM || 7106 n_type == nullptr || n_type->elem() == Type::BOTTOM || 7107 m_type == nullptr || m_type->elem() == Type::BOTTOM) { 7108 // failed array check 7109 return false; 7110 } 7111 7112 BasicType a_elem = a_type->elem()->array_element_basic_type(); 7113 BasicType n_elem = n_type->elem()->array_element_basic_type(); 7114 BasicType m_elem = m_type->elem()->array_element_basic_type(); 7115 if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 7116 return false; 7117 } 7118 7119 // Make the call 7120 { 7121 Node* a_start = array_element_address(a, intcon(0), a_elem); 7122 Node* n_start = array_element_address(n, intcon(0), n_elem); 7123 Node* m_start = array_element_address(m, intcon(0), m_elem); 7124 7125 Node* call = make_runtime_call(RC_LEAF, 7126 OptoRuntime::montgomerySquare_Type(), 7127 stubAddr, stubName, TypePtr::BOTTOM, 7128 a_start, n_start, len, inv, top(), 7129 m_start); 7130 set_result(m); 7131 } 7132 7133 return true; 7134 } 7135 7136 bool LibraryCallKit::inline_bigIntegerShift(bool isRightShift) { 7137 address stubAddr = nullptr; 7138 const char* stubName = nullptr; 7139 7140 stubAddr = isRightShift? StubRoutines::bigIntegerRightShift(): StubRoutines::bigIntegerLeftShift(); 7141 if (stubAddr == nullptr) { 7142 return false; // Intrinsic's stub is not implemented on this platform 7143 } 7144 7145 stubName = isRightShift? "bigIntegerRightShiftWorker" : "bigIntegerLeftShiftWorker"; 7146 7147 assert(callee()->signature()->size() == 5, "expected 5 arguments"); 7148 7149 Node* newArr = argument(0); 7150 Node* oldArr = argument(1); 7151 Node* newIdx = argument(2); 7152 Node* shiftCount = argument(3); 7153 Node* numIter = argument(4); 7154 7155 const TypeAryPtr* newArr_type = newArr->Value(&_gvn)->isa_aryptr(); 7156 const TypeAryPtr* oldArr_type = oldArr->Value(&_gvn)->isa_aryptr(); 7157 if (newArr_type == nullptr || newArr_type->elem() == Type::BOTTOM || 7158 oldArr_type == nullptr || oldArr_type->elem() == Type::BOTTOM) { 7159 return false; 7160 } 7161 7162 BasicType newArr_elem = newArr_type->elem()->array_element_basic_type(); 7163 BasicType oldArr_elem = oldArr_type->elem()->array_element_basic_type(); 7164 if (newArr_elem != T_INT || oldArr_elem != T_INT) { 7165 return false; 7166 } 7167 7168 // Make the call 7169 { 7170 Node* newArr_start = array_element_address(newArr, intcon(0), newArr_elem); 7171 Node* oldArr_start = array_element_address(oldArr, intcon(0), oldArr_elem); 7172 7173 Node* call = make_runtime_call(RC_LEAF, 7174 OptoRuntime::bigIntegerShift_Type(), 7175 stubAddr, 7176 stubName, 7177 TypePtr::BOTTOM, 7178 newArr_start, 7179 oldArr_start, 7180 newIdx, 7181 shiftCount, 7182 numIter); 7183 } 7184 7185 return true; 7186 } 7187 7188 //-------------inline_vectorizedMismatch------------------------------ 7189 bool LibraryCallKit::inline_vectorizedMismatch() { 7190 assert(UseVectorizedMismatchIntrinsic, "not implemented on this platform"); 7191 7192 assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters"); 7193 Node* obja = argument(0); // Object 7194 Node* aoffset = argument(1); // long 7195 Node* objb = argument(3); // Object 7196 Node* boffset = argument(4); // long 7197 Node* length = argument(6); // int 7198 Node* scale = argument(7); // int 7199 7200 const TypeAryPtr* obja_t = _gvn.type(obja)->isa_aryptr(); 7201 const TypeAryPtr* objb_t = _gvn.type(objb)->isa_aryptr(); 7202 if (obja_t == nullptr || obja_t->elem() == Type::BOTTOM || 7203 objb_t == nullptr || objb_t->elem() == Type::BOTTOM || 7204 scale == top()) { 7205 return false; // failed input validation 7206 } 7207 7208 Node* obja_adr = make_unsafe_address(obja, aoffset); 7209 Node* objb_adr = make_unsafe_address(objb, boffset); 7210 7211 // Partial inlining handling for inputs smaller than ArrayOperationPartialInlineSize bytes in size. 7212 // 7213 // inline_limit = ArrayOperationPartialInlineSize / element_size; 7214 // if (length <= inline_limit) { 7215 // inline_path: 7216 // vmask = VectorMaskGen length 7217 // vload1 = LoadVectorMasked obja, vmask 7218 // vload2 = LoadVectorMasked objb, vmask 7219 // result1 = VectorCmpMasked vload1, vload2, vmask 7220 // } else { 7221 // call_stub_path: 7222 // result2 = call vectorizedMismatch_stub(obja, objb, length, scale) 7223 // } 7224 // exit_block: 7225 // return Phi(result1, result2); 7226 // 7227 enum { inline_path = 1, // input is small enough to process it all at once 7228 stub_path = 2, // input is too large; call into the VM 7229 PATH_LIMIT = 3 7230 }; 7231 7232 Node* exit_block = new RegionNode(PATH_LIMIT); 7233 Node* result_phi = new PhiNode(exit_block, TypeInt::INT); 7234 Node* memory_phi = new PhiNode(exit_block, Type::MEMORY, TypePtr::BOTTOM); 7235 7236 Node* call_stub_path = control(); 7237 7238 BasicType elem_bt = T_ILLEGAL; 7239 7240 const TypeInt* scale_t = _gvn.type(scale)->is_int(); 7241 if (scale_t->is_con()) { 7242 switch (scale_t->get_con()) { 7243 case 0: elem_bt = T_BYTE; break; 7244 case 1: elem_bt = T_SHORT; break; 7245 case 2: elem_bt = T_INT; break; 7246 case 3: elem_bt = T_LONG; break; 7247 7248 default: elem_bt = T_ILLEGAL; break; // not supported 7249 } 7250 } 7251 7252 int inline_limit = 0; 7253 bool do_partial_inline = false; 7254 7255 if (elem_bt != T_ILLEGAL && ArrayOperationPartialInlineSize > 0) { 7256 inline_limit = ArrayOperationPartialInlineSize / type2aelembytes(elem_bt); 7257 do_partial_inline = inline_limit >= 16; 7258 } 7259 7260 if (do_partial_inline) { 7261 assert(elem_bt != T_ILLEGAL, "sanity"); 7262 7263 if (Matcher::match_rule_supported_vector(Op_VectorMaskGen, inline_limit, elem_bt) && 7264 Matcher::match_rule_supported_vector(Op_LoadVectorMasked, inline_limit, elem_bt) && 7265 Matcher::match_rule_supported_vector(Op_VectorCmpMasked, inline_limit, elem_bt)) { 7266 7267 const TypeVect* vt = TypeVect::make(elem_bt, inline_limit); 7268 Node* cmp_length = _gvn.transform(new CmpINode(length, intcon(inline_limit))); 7269 Node* bol_gt = _gvn.transform(new BoolNode(cmp_length, BoolTest::gt)); 7270 7271 call_stub_path = generate_guard(bol_gt, nullptr, PROB_MIN); 7272 7273 if (!stopped()) { 7274 Node* casted_length = _gvn.transform(new CastIINode(control(), length, TypeInt::make(0, inline_limit, Type::WidenMin))); 7275 7276 const TypePtr* obja_adr_t = _gvn.type(obja_adr)->isa_ptr(); 7277 const TypePtr* objb_adr_t = _gvn.type(objb_adr)->isa_ptr(); 7278 Node* obja_adr_mem = memory(C->get_alias_index(obja_adr_t)); 7279 Node* objb_adr_mem = memory(C->get_alias_index(objb_adr_t)); 7280 7281 Node* vmask = _gvn.transform(VectorMaskGenNode::make(ConvI2X(casted_length), elem_bt)); 7282 Node* vload_obja = _gvn.transform(new LoadVectorMaskedNode(control(), obja_adr_mem, obja_adr, obja_adr_t, vt, vmask)); 7283 Node* vload_objb = _gvn.transform(new LoadVectorMaskedNode(control(), objb_adr_mem, objb_adr, objb_adr_t, vt, vmask)); 7284 Node* result = _gvn.transform(new VectorCmpMaskedNode(vload_obja, vload_objb, vmask, TypeInt::INT)); 7285 7286 exit_block->init_req(inline_path, control()); 7287 memory_phi->init_req(inline_path, map()->memory()); 7288 result_phi->init_req(inline_path, result); 7289 7290 C->set_max_vector_size(MAX2((uint)ArrayOperationPartialInlineSize, C->max_vector_size())); 7291 clear_upper_avx(); 7292 } 7293 } 7294 } 7295 7296 if (call_stub_path != nullptr) { 7297 set_control(call_stub_path); 7298 7299 Node* call = make_runtime_call(RC_LEAF, 7300 OptoRuntime::vectorizedMismatch_Type(), 7301 StubRoutines::vectorizedMismatch(), "vectorizedMismatch", TypePtr::BOTTOM, 7302 obja_adr, objb_adr, length, scale); 7303 7304 exit_block->init_req(stub_path, control()); 7305 memory_phi->init_req(stub_path, map()->memory()); 7306 result_phi->init_req(stub_path, _gvn.transform(new ProjNode(call, TypeFunc::Parms))); 7307 } 7308 7309 exit_block = _gvn.transform(exit_block); 7310 memory_phi = _gvn.transform(memory_phi); 7311 result_phi = _gvn.transform(result_phi); 7312 7313 record_for_igvn(exit_block); 7314 record_for_igvn(memory_phi); 7315 record_for_igvn(result_phi); 7316 7317 set_control(exit_block); 7318 set_all_memory(memory_phi); 7319 set_result(result_phi); 7320 7321 return true; 7322 } 7323 7324 //------------------------------inline_vectorizedHashcode---------------------------- 7325 bool LibraryCallKit::inline_vectorizedHashCode() { 7326 assert(UseVectorizedHashCodeIntrinsic, "not implemented on this platform"); 7327 7328 assert(callee()->signature()->size() == 5, "vectorizedHashCode has 5 parameters"); 7329 Node* array = argument(0); 7330 Node* offset = argument(1); 7331 Node* length = argument(2); 7332 Node* initialValue = argument(3); 7333 Node* basic_type = argument(4); 7334 7335 if (basic_type == top()) { 7336 return false; // failed input validation 7337 } 7338 7339 const TypeInt* basic_type_t = _gvn.type(basic_type)->is_int(); 7340 if (!basic_type_t->is_con()) { 7341 return false; // Only intrinsify if mode argument is constant 7342 } 7343 7344 array = must_be_not_null(array, true); 7345 7346 BasicType bt = (BasicType)basic_type_t->get_con(); 7347 7348 // Resolve address of first element 7349 Node* array_start = array_element_address(array, offset, bt); 7350 7351 set_result(_gvn.transform(new VectorizedHashCodeNode(control(), memory(TypeAryPtr::get_array_body_type(bt)), 7352 array_start, length, initialValue, basic_type))); 7353 clear_upper_avx(); 7354 7355 return true; 7356 } 7357 7358 /** 7359 * Calculate CRC32 for byte. 7360 * int java.util.zip.CRC32.update(int crc, int b) 7361 */ 7362 bool LibraryCallKit::inline_updateCRC32() { 7363 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7364 assert(callee()->signature()->size() == 2, "update has 2 parameters"); 7365 // no receiver since it is static method 7366 Node* crc = argument(0); // type: int 7367 Node* b = argument(1); // type: int 7368 7369 /* 7370 * int c = ~ crc; 7371 * b = timesXtoThe32[(b ^ c) & 0xFF]; 7372 * b = b ^ (c >>> 8); 7373 * crc = ~b; 7374 */ 7375 7376 Node* M1 = intcon(-1); 7377 crc = _gvn.transform(new XorINode(crc, M1)); 7378 Node* result = _gvn.transform(new XorINode(crc, b)); 7379 result = _gvn.transform(new AndINode(result, intcon(0xFF))); 7380 7381 Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 7382 Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2))); 7383 Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 7384 result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 7385 7386 crc = _gvn.transform(new URShiftINode(crc, intcon(8))); 7387 result = _gvn.transform(new XorINode(crc, result)); 7388 result = _gvn.transform(new XorINode(result, M1)); 7389 set_result(result); 7390 return true; 7391 } 7392 7393 /** 7394 * Calculate CRC32 for byte[] array. 7395 * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 7396 */ 7397 bool LibraryCallKit::inline_updateBytesCRC32() { 7398 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7399 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7400 // no receiver since it is static method 7401 Node* crc = argument(0); // type: int 7402 Node* src = argument(1); // type: oop 7403 Node* offset = argument(2); // type: int 7404 Node* length = argument(3); // type: int 7405 7406 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7407 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7408 // failed array check 7409 return false; 7410 } 7411 7412 // Figure out the size and type of the elements we will be copying. 7413 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7414 if (src_elem != T_BYTE) { 7415 return false; 7416 } 7417 7418 // 'src_start' points to src array + scaled offset 7419 src = must_be_not_null(src, true); 7420 Node* src_start = array_element_address(src, offset, src_elem); 7421 7422 // We assume that range check is done by caller. 7423 // TODO: generate range check (offset+length < src.length) in debug VM. 7424 7425 // Call the stub. 7426 address stubAddr = StubRoutines::updateBytesCRC32(); 7427 const char *stubName = "updateBytesCRC32"; 7428 7429 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 7430 stubAddr, stubName, TypePtr::BOTTOM, 7431 crc, src_start, length); 7432 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7433 set_result(result); 7434 return true; 7435 } 7436 7437 /** 7438 * Calculate CRC32 for ByteBuffer. 7439 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 7440 */ 7441 bool LibraryCallKit::inline_updateByteBufferCRC32() { 7442 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7443 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 7444 // no receiver since it is static method 7445 Node* crc = argument(0); // type: int 7446 Node* src = argument(1); // type: long 7447 Node* offset = argument(3); // type: int 7448 Node* length = argument(4); // type: int 7449 7450 src = ConvL2X(src); // adjust Java long to machine word 7451 Node* base = _gvn.transform(new CastX2PNode(src)); 7452 offset = ConvI2X(offset); 7453 7454 // 'src_start' points to src array + scaled offset 7455 Node* src_start = basic_plus_adr(top(), base, offset); 7456 7457 // Call the stub. 7458 address stubAddr = StubRoutines::updateBytesCRC32(); 7459 const char *stubName = "updateBytesCRC32"; 7460 7461 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 7462 stubAddr, stubName, TypePtr::BOTTOM, 7463 crc, src_start, length); 7464 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7465 set_result(result); 7466 return true; 7467 } 7468 7469 //------------------------------get_table_from_crc32c_class----------------------- 7470 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) { 7471 Node* table = load_field_from_object(nullptr, "byteTable", "[I", /*decorators*/ IN_HEAP, /*is_static*/ true, crc32c_class); 7472 assert (table != nullptr, "wrong version of java.util.zip.CRC32C"); 7473 7474 return table; 7475 } 7476 7477 //------------------------------inline_updateBytesCRC32C----------------------- 7478 // 7479 // Calculate CRC32C for byte[] array. 7480 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end) 7481 // 7482 bool LibraryCallKit::inline_updateBytesCRC32C() { 7483 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 7484 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7485 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 7486 // no receiver since it is a static method 7487 Node* crc = argument(0); // type: int 7488 Node* src = argument(1); // type: oop 7489 Node* offset = argument(2); // type: int 7490 Node* end = argument(3); // type: int 7491 7492 Node* length = _gvn.transform(new SubINode(end, offset)); 7493 7494 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7495 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7496 // failed array check 7497 return false; 7498 } 7499 7500 // Figure out the size and type of the elements we will be copying. 7501 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7502 if (src_elem != T_BYTE) { 7503 return false; 7504 } 7505 7506 // 'src_start' points to src array + scaled offset 7507 src = must_be_not_null(src, true); 7508 Node* src_start = array_element_address(src, offset, src_elem); 7509 7510 // static final int[] byteTable in class CRC32C 7511 Node* table = get_table_from_crc32c_class(callee()->holder()); 7512 table = must_be_not_null(table, true); 7513 Node* table_start = array_element_address(table, intcon(0), T_INT); 7514 7515 // We assume that range check is done by caller. 7516 // TODO: generate range check (offset+length < src.length) in debug VM. 7517 7518 // Call the stub. 7519 address stubAddr = StubRoutines::updateBytesCRC32C(); 7520 const char *stubName = "updateBytesCRC32C"; 7521 7522 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 7523 stubAddr, stubName, TypePtr::BOTTOM, 7524 crc, src_start, length, table_start); 7525 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7526 set_result(result); 7527 return true; 7528 } 7529 7530 //------------------------------inline_updateDirectByteBufferCRC32C----------------------- 7531 // 7532 // Calculate CRC32C for DirectByteBuffer. 7533 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end) 7534 // 7535 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() { 7536 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 7537 assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long"); 7538 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 7539 // no receiver since it is a static method 7540 Node* crc = argument(0); // type: int 7541 Node* src = argument(1); // type: long 7542 Node* offset = argument(3); // type: int 7543 Node* end = argument(4); // type: int 7544 7545 Node* length = _gvn.transform(new SubINode(end, offset)); 7546 7547 src = ConvL2X(src); // adjust Java long to machine word 7548 Node* base = _gvn.transform(new CastX2PNode(src)); 7549 offset = ConvI2X(offset); 7550 7551 // 'src_start' points to src array + scaled offset 7552 Node* src_start = basic_plus_adr(top(), base, offset); 7553 7554 // static final int[] byteTable in class CRC32C 7555 Node* table = get_table_from_crc32c_class(callee()->holder()); 7556 table = must_be_not_null(table, true); 7557 Node* table_start = array_element_address(table, intcon(0), T_INT); 7558 7559 // Call the stub. 7560 address stubAddr = StubRoutines::updateBytesCRC32C(); 7561 const char *stubName = "updateBytesCRC32C"; 7562 7563 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 7564 stubAddr, stubName, TypePtr::BOTTOM, 7565 crc, src_start, length, table_start); 7566 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7567 set_result(result); 7568 return true; 7569 } 7570 7571 //------------------------------inline_updateBytesAdler32---------------------- 7572 // 7573 // Calculate Adler32 checksum for byte[] array. 7574 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len) 7575 // 7576 bool LibraryCallKit::inline_updateBytesAdler32() { 7577 assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one 7578 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7579 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 7580 // no receiver since it is static method 7581 Node* crc = argument(0); // type: int 7582 Node* src = argument(1); // type: oop 7583 Node* offset = argument(2); // type: int 7584 Node* length = argument(3); // type: int 7585 7586 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7587 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7588 // failed array check 7589 return false; 7590 } 7591 7592 // Figure out the size and type of the elements we will be copying. 7593 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7594 if (src_elem != T_BYTE) { 7595 return false; 7596 } 7597 7598 // 'src_start' points to src array + scaled offset 7599 Node* src_start = array_element_address(src, offset, src_elem); 7600 7601 // We assume that range check is done by caller. 7602 // TODO: generate range check (offset+length < src.length) in debug VM. 7603 7604 // Call the stub. 7605 address stubAddr = StubRoutines::updateBytesAdler32(); 7606 const char *stubName = "updateBytesAdler32"; 7607 7608 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 7609 stubAddr, stubName, TypePtr::BOTTOM, 7610 crc, src_start, length); 7611 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7612 set_result(result); 7613 return true; 7614 } 7615 7616 //------------------------------inline_updateByteBufferAdler32--------------- 7617 // 7618 // Calculate Adler32 checksum for DirectByteBuffer. 7619 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len) 7620 // 7621 bool LibraryCallKit::inline_updateByteBufferAdler32() { 7622 assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one 7623 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 7624 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 7625 // no receiver since it is static method 7626 Node* crc = argument(0); // type: int 7627 Node* src = argument(1); // type: long 7628 Node* offset = argument(3); // type: int 7629 Node* length = argument(4); // type: int 7630 7631 src = ConvL2X(src); // adjust Java long to machine word 7632 Node* base = _gvn.transform(new CastX2PNode(src)); 7633 offset = ConvI2X(offset); 7634 7635 // 'src_start' points to src array + scaled offset 7636 Node* src_start = basic_plus_adr(top(), base, offset); 7637 7638 // Call the stub. 7639 address stubAddr = StubRoutines::updateBytesAdler32(); 7640 const char *stubName = "updateBytesAdler32"; 7641 7642 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 7643 stubAddr, stubName, TypePtr::BOTTOM, 7644 crc, src_start, length); 7645 7646 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7647 set_result(result); 7648 return true; 7649 } 7650 7651 //----------------------------inline_reference_get0---------------------------- 7652 // public T java.lang.ref.Reference.get(); 7653 bool LibraryCallKit::inline_reference_get0() { 7654 const int referent_offset = java_lang_ref_Reference::referent_offset(); 7655 7656 // Get the argument: 7657 Node* reference_obj = null_check_receiver(); 7658 if (stopped()) return true; 7659 7660 DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF; 7661 Node* result = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;", 7662 decorators, /*is_static*/ false, nullptr); 7663 if (result == nullptr) return false; 7664 7665 // Add memory barrier to prevent commoning reads from this field 7666 // across safepoint since GC can change its value. 7667 insert_mem_bar(Op_MemBarCPUOrder); 7668 7669 set_result(result); 7670 return true; 7671 } 7672 7673 //----------------------------inline_reference_refersTo0---------------------------- 7674 // bool java.lang.ref.Reference.refersTo0(); 7675 // bool java.lang.ref.PhantomReference.refersTo0(); 7676 bool LibraryCallKit::inline_reference_refersTo0(bool is_phantom) { 7677 // Get arguments: 7678 Node* reference_obj = null_check_receiver(); 7679 Node* other_obj = argument(1); 7680 if (stopped()) return true; 7681 7682 DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE; 7683 decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF); 7684 Node* referent = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;", 7685 decorators, /*is_static*/ false, nullptr); 7686 if (referent == nullptr) return false; 7687 7688 // Add memory barrier to prevent commoning reads from this field 7689 // across safepoint since GC can change its value. 7690 insert_mem_bar(Op_MemBarCPUOrder); 7691 7692 Node* cmp = _gvn.transform(new CmpPNode(referent, other_obj)); 7693 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 7694 IfNode* if_node = create_and_map_if(control(), bol, PROB_FAIR, COUNT_UNKNOWN); 7695 7696 RegionNode* region = new RegionNode(3); 7697 PhiNode* phi = new PhiNode(region, TypeInt::BOOL); 7698 7699 Node* if_true = _gvn.transform(new IfTrueNode(if_node)); 7700 region->init_req(1, if_true); 7701 phi->init_req(1, intcon(1)); 7702 7703 Node* if_false = _gvn.transform(new IfFalseNode(if_node)); 7704 region->init_req(2, if_false); 7705 phi->init_req(2, intcon(0)); 7706 7707 set_control(_gvn.transform(region)); 7708 record_for_igvn(region); 7709 set_result(_gvn.transform(phi)); 7710 return true; 7711 } 7712 7713 //----------------------------inline_reference_clear0---------------------------- 7714 // void java.lang.ref.Reference.clear0(); 7715 // void java.lang.ref.PhantomReference.clear0(); 7716 bool LibraryCallKit::inline_reference_clear0(bool is_phantom) { 7717 // This matches the implementation in JVM_ReferenceClear, see the comments there. 7718 7719 // Get arguments 7720 Node* reference_obj = null_check_receiver(); 7721 if (stopped()) return true; 7722 7723 // Common access parameters 7724 DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE; 7725 decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF); 7726 Node* referent_field_addr = basic_plus_adr(reference_obj, java_lang_ref_Reference::referent_offset()); 7727 const TypePtr* referent_field_addr_type = _gvn.type(referent_field_addr)->isa_ptr(); 7728 const Type* val_type = TypeOopPtr::make_from_klass(env()->Object_klass()); 7729 7730 Node* referent = access_load_at(reference_obj, 7731 referent_field_addr, 7732 referent_field_addr_type, 7733 val_type, 7734 T_OBJECT, 7735 decorators); 7736 7737 IdealKit ideal(this); 7738 #define __ ideal. 7739 __ if_then(referent, BoolTest::ne, null()); 7740 sync_kit(ideal); 7741 access_store_at(reference_obj, 7742 referent_field_addr, 7743 referent_field_addr_type, 7744 null(), 7745 val_type, 7746 T_OBJECT, 7747 decorators); 7748 __ sync_kit(this); 7749 __ end_if(); 7750 final_sync(ideal); 7751 #undef __ 7752 7753 return true; 7754 } 7755 7756 Node* LibraryCallKit::load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, 7757 DecoratorSet decorators, bool is_static, 7758 ciInstanceKlass* fromKls) { 7759 if (fromKls == nullptr) { 7760 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 7761 assert(tinst != nullptr, "obj is null"); 7762 assert(tinst->is_loaded(), "obj is not loaded"); 7763 fromKls = tinst->instance_klass(); 7764 } else { 7765 assert(is_static, "only for static field access"); 7766 } 7767 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 7768 ciSymbol::make(fieldTypeString), 7769 is_static); 7770 7771 assert(field != nullptr, "undefined field %s %s %s", fieldTypeString, fromKls->name()->as_utf8(), fieldName); 7772 if (field == nullptr) return (Node *) nullptr; 7773 7774 if (is_static) { 7775 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 7776 fromObj = makecon(tip); 7777 } 7778 7779 // Next code copied from Parse::do_get_xxx(): 7780 7781 // Compute address and memory type. 7782 int offset = field->offset_in_bytes(); 7783 bool is_vol = field->is_volatile(); 7784 ciType* field_klass = field->type(); 7785 assert(field_klass->is_loaded(), "should be loaded"); 7786 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 7787 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 7788 assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()), 7789 "slice of address and input slice don't match"); 7790 BasicType bt = field->layout_type(); 7791 7792 // Build the resultant type of the load 7793 const Type *type; 7794 if (bt == T_OBJECT) { 7795 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 7796 } else { 7797 type = Type::get_const_basic_type(bt); 7798 } 7799 7800 if (is_vol) { 7801 decorators |= MO_SEQ_CST; 7802 } 7803 7804 return access_load_at(fromObj, adr, adr_type, type, bt, decorators); 7805 } 7806 7807 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 7808 bool is_exact /* true */, bool is_static /* false */, 7809 ciInstanceKlass * fromKls /* nullptr */) { 7810 if (fromKls == nullptr) { 7811 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 7812 assert(tinst != nullptr, "obj is null"); 7813 assert(tinst->is_loaded(), "obj is not loaded"); 7814 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 7815 fromKls = tinst->instance_klass(); 7816 } 7817 else { 7818 assert(is_static, "only for static field access"); 7819 } 7820 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 7821 ciSymbol::make(fieldTypeString), 7822 is_static); 7823 7824 assert(field != nullptr, "undefined field"); 7825 assert(!field->is_volatile(), "not defined for volatile fields"); 7826 7827 if (is_static) { 7828 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 7829 fromObj = makecon(tip); 7830 } 7831 7832 // Next code copied from Parse::do_get_xxx(): 7833 7834 // Compute address and memory type. 7835 int offset = field->offset_in_bytes(); 7836 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 7837 7838 return adr; 7839 } 7840 7841 //------------------------------inline_aescrypt_Block----------------------- 7842 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 7843 address stubAddr = nullptr; 7844 const char *stubName; 7845 assert(UseAES, "need AES instruction support"); 7846 7847 switch(id) { 7848 case vmIntrinsics::_aescrypt_encryptBlock: 7849 stubAddr = StubRoutines::aescrypt_encryptBlock(); 7850 stubName = "aescrypt_encryptBlock"; 7851 break; 7852 case vmIntrinsics::_aescrypt_decryptBlock: 7853 stubAddr = StubRoutines::aescrypt_decryptBlock(); 7854 stubName = "aescrypt_decryptBlock"; 7855 break; 7856 default: 7857 break; 7858 } 7859 if (stubAddr == nullptr) return false; 7860 7861 Node* aescrypt_object = argument(0); 7862 Node* src = argument(1); 7863 Node* src_offset = argument(2); 7864 Node* dest = argument(3); 7865 Node* dest_offset = argument(4); 7866 7867 src = must_be_not_null(src, true); 7868 dest = must_be_not_null(dest, true); 7869 7870 // (1) src and dest are arrays. 7871 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7872 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7873 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7874 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7875 7876 // for the quick and dirty code we will skip all the checks. 7877 // we are just trying to get the call to be generated. 7878 Node* src_start = src; 7879 Node* dest_start = dest; 7880 if (src_offset != nullptr || dest_offset != nullptr) { 7881 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7882 src_start = array_element_address(src, src_offset, T_BYTE); 7883 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7884 } 7885 7886 // now need to get the start of its expanded key array 7887 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7888 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 7889 if (k_start == nullptr) return false; 7890 7891 // Call the stub. 7892 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 7893 stubAddr, stubName, TypePtr::BOTTOM, 7894 src_start, dest_start, k_start); 7895 7896 return true; 7897 } 7898 7899 //------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 7900 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 7901 address stubAddr = nullptr; 7902 const char *stubName = nullptr; 7903 7904 assert(UseAES, "need AES instruction support"); 7905 7906 switch(id) { 7907 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 7908 stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 7909 stubName = "cipherBlockChaining_encryptAESCrypt"; 7910 break; 7911 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 7912 stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 7913 stubName = "cipherBlockChaining_decryptAESCrypt"; 7914 break; 7915 default: 7916 break; 7917 } 7918 if (stubAddr == nullptr) return false; 7919 7920 Node* cipherBlockChaining_object = argument(0); 7921 Node* src = argument(1); 7922 Node* src_offset = argument(2); 7923 Node* len = argument(3); 7924 Node* dest = argument(4); 7925 Node* dest_offset = argument(5); 7926 7927 src = must_be_not_null(src, false); 7928 dest = must_be_not_null(dest, false); 7929 7930 // (1) src and dest are arrays. 7931 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7932 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7933 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7934 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7935 7936 // checks are the responsibility of the caller 7937 Node* src_start = src; 7938 Node* dest_start = dest; 7939 if (src_offset != nullptr || dest_offset != nullptr) { 7940 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7941 src_start = array_element_address(src, src_offset, T_BYTE); 7942 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7943 } 7944 7945 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 7946 // (because of the predicated logic executed earlier). 7947 // so we cast it here safely. 7948 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7949 7950 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 7951 if (embeddedCipherObj == nullptr) return false; 7952 7953 // cast it to what we know it will be at runtime 7954 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 7955 assert(tinst != nullptr, "CBC obj is null"); 7956 assert(tinst->is_loaded(), "CBC obj is not loaded"); 7957 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 7958 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 7959 7960 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 7961 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 7962 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 7963 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 7964 aescrypt_object = _gvn.transform(aescrypt_object); 7965 7966 // we need to get the start of the aescrypt_object's expanded key array 7967 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 7968 if (k_start == nullptr) return false; 7969 7970 // similarly, get the start address of the r vector 7971 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B"); 7972 if (objRvec == nullptr) return false; 7973 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 7974 7975 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 7976 Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 7977 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 7978 stubAddr, stubName, TypePtr::BOTTOM, 7979 src_start, dest_start, k_start, r_start, len); 7980 7981 // return cipher length (int) 7982 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms)); 7983 set_result(retvalue); 7984 return true; 7985 } 7986 7987 //------------------------------inline_electronicCodeBook_AESCrypt----------------------- 7988 bool LibraryCallKit::inline_electronicCodeBook_AESCrypt(vmIntrinsics::ID id) { 7989 address stubAddr = nullptr; 7990 const char *stubName = nullptr; 7991 7992 assert(UseAES, "need AES instruction support"); 7993 7994 switch (id) { 7995 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 7996 stubAddr = StubRoutines::electronicCodeBook_encryptAESCrypt(); 7997 stubName = "electronicCodeBook_encryptAESCrypt"; 7998 break; 7999 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 8000 stubAddr = StubRoutines::electronicCodeBook_decryptAESCrypt(); 8001 stubName = "electronicCodeBook_decryptAESCrypt"; 8002 break; 8003 default: 8004 break; 8005 } 8006 8007 if (stubAddr == nullptr) return false; 8008 8009 Node* electronicCodeBook_object = argument(0); 8010 Node* src = argument(1); 8011 Node* src_offset = argument(2); 8012 Node* len = argument(3); 8013 Node* dest = argument(4); 8014 Node* dest_offset = argument(5); 8015 8016 // (1) src and dest are arrays. 8017 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 8018 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 8019 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 8020 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 8021 8022 // checks are the responsibility of the caller 8023 Node* src_start = src; 8024 Node* dest_start = dest; 8025 if (src_offset != nullptr || dest_offset != nullptr) { 8026 assert(src_offset != nullptr && dest_offset != nullptr, ""); 8027 src_start = array_element_address(src, src_offset, T_BYTE); 8028 dest_start = array_element_address(dest, dest_offset, T_BYTE); 8029 } 8030 8031 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 8032 // (because of the predicated logic executed earlier). 8033 // so we cast it here safely. 8034 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 8035 8036 Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8037 if (embeddedCipherObj == nullptr) return false; 8038 8039 // cast it to what we know it will be at runtime 8040 const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr(); 8041 assert(tinst != nullptr, "ECB obj is null"); 8042 assert(tinst->is_loaded(), "ECB obj is not loaded"); 8043 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8044 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 8045 8046 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8047 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 8048 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 8049 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 8050 aescrypt_object = _gvn.transform(aescrypt_object); 8051 8052 // we need to get the start of the aescrypt_object's expanded key array 8053 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 8054 if (k_start == nullptr) return false; 8055 8056 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 8057 Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP, 8058 OptoRuntime::electronicCodeBook_aescrypt_Type(), 8059 stubAddr, stubName, TypePtr::BOTTOM, 8060 src_start, dest_start, k_start, len); 8061 8062 // return cipher length (int) 8063 Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms)); 8064 set_result(retvalue); 8065 return true; 8066 } 8067 8068 //------------------------------inline_counterMode_AESCrypt----------------------- 8069 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) { 8070 assert(UseAES, "need AES instruction support"); 8071 if (!UseAESCTRIntrinsics) return false; 8072 8073 address stubAddr = nullptr; 8074 const char *stubName = nullptr; 8075 if (id == vmIntrinsics::_counterMode_AESCrypt) { 8076 stubAddr = StubRoutines::counterMode_AESCrypt(); 8077 stubName = "counterMode_AESCrypt"; 8078 } 8079 if (stubAddr == nullptr) return false; 8080 8081 Node* counterMode_object = argument(0); 8082 Node* src = argument(1); 8083 Node* src_offset = argument(2); 8084 Node* len = argument(3); 8085 Node* dest = argument(4); 8086 Node* dest_offset = argument(5); 8087 8088 // (1) src and dest are arrays. 8089 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 8090 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 8091 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 8092 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 8093 8094 // checks are the responsibility of the caller 8095 Node* src_start = src; 8096 Node* dest_start = dest; 8097 if (src_offset != nullptr || dest_offset != nullptr) { 8098 assert(src_offset != nullptr && dest_offset != nullptr, ""); 8099 src_start = array_element_address(src, src_offset, T_BYTE); 8100 dest_start = array_element_address(dest, dest_offset, T_BYTE); 8101 } 8102 8103 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 8104 // (because of the predicated logic executed earlier). 8105 // so we cast it here safely. 8106 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 8107 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8108 if (embeddedCipherObj == nullptr) return false; 8109 // cast it to what we know it will be at runtime 8110 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr(); 8111 assert(tinst != nullptr, "CTR obj is null"); 8112 assert(tinst->is_loaded(), "CTR obj is not loaded"); 8113 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8114 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 8115 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8116 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 8117 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 8118 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 8119 aescrypt_object = _gvn.transform(aescrypt_object); 8120 // we need to get the start of the aescrypt_object's expanded key array 8121 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 8122 if (k_start == nullptr) return false; 8123 // similarly, get the start address of the r vector 8124 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B"); 8125 if (obj_counter == nullptr) return false; 8126 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE); 8127 8128 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B"); 8129 if (saved_encCounter == nullptr) return false; 8130 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE); 8131 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false); 8132 8133 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 8134 Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 8135 OptoRuntime::counterMode_aescrypt_Type(), 8136 stubAddr, stubName, TypePtr::BOTTOM, 8137 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used); 8138 8139 // return cipher length (int) 8140 Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms)); 8141 set_result(retvalue); 8142 return true; 8143 } 8144 8145 //------------------------------get_key_start_from_aescrypt_object----------------------- 8146 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 8147 #if defined(PPC64) || defined(S390) || defined(RISCV64) 8148 // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys. 8149 // Intel's extension is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns. 8150 // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption. 8151 // The ppc64 and riscv64 stubs of encryption and decryption use the same round keys (sessionK[0]). 8152 Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I"); 8153 assert (objSessionK != nullptr, "wrong version of com.sun.crypto.provider.AESCrypt"); 8154 if (objSessionK == nullptr) { 8155 return (Node *) nullptr; 8156 } 8157 Node* objAESCryptKey = load_array_element(objSessionK, intcon(0), TypeAryPtr::OOPS, /* set_ctrl */ true); 8158 #else 8159 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I"); 8160 #endif // PPC64 8161 assert (objAESCryptKey != nullptr, "wrong version of com.sun.crypto.provider.AESCrypt"); 8162 if (objAESCryptKey == nullptr) return (Node *) nullptr; 8163 8164 // now have the array, need to get the start address of the K array 8165 Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 8166 return k_start; 8167 } 8168 8169 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 8170 // Return node representing slow path of predicate check. 8171 // the pseudo code we want to emulate with this predicate is: 8172 // for encryption: 8173 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8174 // for decryption: 8175 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8176 // note cipher==plain is more conservative than the original java code but that's OK 8177 // 8178 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 8179 // The receiver was checked for null already. 8180 Node* objCBC = argument(0); 8181 8182 Node* src = argument(1); 8183 Node* dest = argument(4); 8184 8185 // Load embeddedCipher field of CipherBlockChaining object. 8186 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8187 8188 // get AESCrypt klass for instanceOf check 8189 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8190 // will have same classloader as CipherBlockChaining object 8191 const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 8192 assert(tinst != nullptr, "CBCobj is null"); 8193 assert(tinst->is_loaded(), "CBCobj is not loaded"); 8194 8195 // we want to do an instanceof comparison against the AESCrypt class 8196 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8197 if (!klass_AESCrypt->is_loaded()) { 8198 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8199 Node* ctrl = control(); 8200 set_control(top()); // no regular fast path 8201 return ctrl; 8202 } 8203 8204 src = must_be_not_null(src, true); 8205 dest = must_be_not_null(dest, true); 8206 8207 // Resolve oops to stable for CmpP below. 8208 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8209 8210 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 8211 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 8212 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8213 8214 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8215 8216 // for encryption, we are done 8217 if (!decrypting) 8218 return instof_false; // even if it is null 8219 8220 // for decryption, we need to add a further check to avoid 8221 // taking the intrinsic path when cipher and plain are the same 8222 // see the original java code for why. 8223 RegionNode* region = new RegionNode(3); 8224 region->init_req(1, instof_false); 8225 8226 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 8227 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 8228 Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN); 8229 region->init_req(2, src_dest_conjoint); 8230 8231 record_for_igvn(region); 8232 return _gvn.transform(region); 8233 } 8234 8235 //----------------------------inline_electronicCodeBook_AESCrypt_predicate---------------------------- 8236 // Return node representing slow path of predicate check. 8237 // the pseudo code we want to emulate with this predicate is: 8238 // for encryption: 8239 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8240 // for decryption: 8241 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8242 // note cipher==plain is more conservative than the original java code but that's OK 8243 // 8244 Node* LibraryCallKit::inline_electronicCodeBook_AESCrypt_predicate(bool decrypting) { 8245 // The receiver was checked for null already. 8246 Node* objECB = argument(0); 8247 8248 // Load embeddedCipher field of ElectronicCodeBook object. 8249 Node* embeddedCipherObj = load_field_from_object(objECB, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8250 8251 // get AESCrypt klass for instanceOf check 8252 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8253 // will have same classloader as ElectronicCodeBook object 8254 const TypeInstPtr* tinst = _gvn.type(objECB)->isa_instptr(); 8255 assert(tinst != nullptr, "ECBobj is null"); 8256 assert(tinst->is_loaded(), "ECBobj is not loaded"); 8257 8258 // we want to do an instanceof comparison against the AESCrypt class 8259 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8260 if (!klass_AESCrypt->is_loaded()) { 8261 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8262 Node* ctrl = control(); 8263 set_control(top()); // no regular fast path 8264 return ctrl; 8265 } 8266 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8267 8268 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 8269 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 8270 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8271 8272 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8273 8274 // for encryption, we are done 8275 if (!decrypting) 8276 return instof_false; // even if it is null 8277 8278 // for decryption, we need to add a further check to avoid 8279 // taking the intrinsic path when cipher and plain are the same 8280 // see the original java code for why. 8281 RegionNode* region = new RegionNode(3); 8282 region->init_req(1, instof_false); 8283 Node* src = argument(1); 8284 Node* dest = argument(4); 8285 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 8286 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 8287 Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN); 8288 region->init_req(2, src_dest_conjoint); 8289 8290 record_for_igvn(region); 8291 return _gvn.transform(region); 8292 } 8293 8294 //----------------------------inline_counterMode_AESCrypt_predicate---------------------------- 8295 // Return node representing slow path of predicate check. 8296 // the pseudo code we want to emulate with this predicate is: 8297 // for encryption: 8298 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8299 // for decryption: 8300 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8301 // note cipher==plain is more conservative than the original java code but that's OK 8302 // 8303 8304 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() { 8305 // The receiver was checked for null already. 8306 Node* objCTR = argument(0); 8307 8308 // Load embeddedCipher field of CipherBlockChaining object. 8309 Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8310 8311 // get AESCrypt klass for instanceOf check 8312 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8313 // will have same classloader as CipherBlockChaining object 8314 const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr(); 8315 assert(tinst != nullptr, "CTRobj is null"); 8316 assert(tinst->is_loaded(), "CTRobj is not loaded"); 8317 8318 // we want to do an instanceof comparison against the AESCrypt class 8319 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8320 if (!klass_AESCrypt->is_loaded()) { 8321 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8322 Node* ctrl = control(); 8323 set_control(top()); // no regular fast path 8324 return ctrl; 8325 } 8326 8327 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8328 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 8329 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 8330 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8331 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8332 8333 return instof_false; // even if it is null 8334 } 8335 8336 //------------------------------inline_ghash_processBlocks 8337 bool LibraryCallKit::inline_ghash_processBlocks() { 8338 address stubAddr; 8339 const char *stubName; 8340 assert(UseGHASHIntrinsics, "need GHASH intrinsics support"); 8341 8342 stubAddr = StubRoutines::ghash_processBlocks(); 8343 stubName = "ghash_processBlocks"; 8344 8345 Node* data = argument(0); 8346 Node* offset = argument(1); 8347 Node* len = argument(2); 8348 Node* state = argument(3); 8349 Node* subkeyH = argument(4); 8350 8351 state = must_be_not_null(state, true); 8352 subkeyH = must_be_not_null(subkeyH, true); 8353 data = must_be_not_null(data, true); 8354 8355 Node* state_start = array_element_address(state, intcon(0), T_LONG); 8356 assert(state_start, "state is null"); 8357 Node* subkeyH_start = array_element_address(subkeyH, intcon(0), T_LONG); 8358 assert(subkeyH_start, "subkeyH is null"); 8359 Node* data_start = array_element_address(data, offset, T_BYTE); 8360 assert(data_start, "data is null"); 8361 8362 Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP, 8363 OptoRuntime::ghash_processBlocks_Type(), 8364 stubAddr, stubName, TypePtr::BOTTOM, 8365 state_start, subkeyH_start, data_start, len); 8366 return true; 8367 } 8368 8369 //------------------------------inline_chacha20Block 8370 bool LibraryCallKit::inline_chacha20Block() { 8371 address stubAddr; 8372 const char *stubName; 8373 assert(UseChaCha20Intrinsics, "need ChaCha20 intrinsics support"); 8374 8375 stubAddr = StubRoutines::chacha20Block(); 8376 stubName = "chacha20Block"; 8377 8378 Node* state = argument(0); 8379 Node* result = argument(1); 8380 8381 state = must_be_not_null(state, true); 8382 result = must_be_not_null(result, true); 8383 8384 Node* state_start = array_element_address(state, intcon(0), T_INT); 8385 assert(state_start, "state is null"); 8386 Node* result_start = array_element_address(result, intcon(0), T_BYTE); 8387 assert(result_start, "result is null"); 8388 8389 Node* cc20Blk = make_runtime_call(RC_LEAF|RC_NO_FP, 8390 OptoRuntime::chacha20Block_Type(), 8391 stubAddr, stubName, TypePtr::BOTTOM, 8392 state_start, result_start); 8393 // return key stream length (int) 8394 Node* retvalue = _gvn.transform(new ProjNode(cc20Blk, TypeFunc::Parms)); 8395 set_result(retvalue); 8396 return true; 8397 } 8398 8399 //------------------------------inline_kyberNtt 8400 bool LibraryCallKit::inline_kyberNtt() { 8401 address stubAddr; 8402 const char *stubName; 8403 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8404 assert(callee()->signature()->size() == 2, "kyberNtt has 2 parameters"); 8405 8406 stubAddr = StubRoutines::kyberNtt(); 8407 stubName = "kyberNtt"; 8408 if (!stubAddr) return false; 8409 8410 Node* coeffs = argument(0); 8411 Node* ntt_zetas = argument(1); 8412 8413 coeffs = must_be_not_null(coeffs, true); 8414 ntt_zetas = must_be_not_null(ntt_zetas, true); 8415 8416 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8417 assert(coeffs_start, "coeffs is null"); 8418 Node* ntt_zetas_start = array_element_address(ntt_zetas, intcon(0), T_SHORT); 8419 assert(ntt_zetas_start, "ntt_zetas is null"); 8420 Node* kyberNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8421 OptoRuntime::kyberNtt_Type(), 8422 stubAddr, stubName, TypePtr::BOTTOM, 8423 coeffs_start, ntt_zetas_start); 8424 // return an int 8425 Node* retvalue = _gvn.transform(new ProjNode(kyberNtt, TypeFunc::Parms)); 8426 set_result(retvalue); 8427 return true; 8428 } 8429 8430 //------------------------------inline_kyberInverseNtt 8431 bool LibraryCallKit::inline_kyberInverseNtt() { 8432 address stubAddr; 8433 const char *stubName; 8434 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8435 assert(callee()->signature()->size() == 2, "kyberInverseNtt has 2 parameters"); 8436 8437 stubAddr = StubRoutines::kyberInverseNtt(); 8438 stubName = "kyberInverseNtt"; 8439 if (!stubAddr) return false; 8440 8441 Node* coeffs = argument(0); 8442 Node* zetas = argument(1); 8443 8444 coeffs = must_be_not_null(coeffs, true); 8445 zetas = must_be_not_null(zetas, true); 8446 8447 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8448 assert(coeffs_start, "coeffs is null"); 8449 Node* zetas_start = array_element_address(zetas, intcon(0), T_SHORT); 8450 assert(zetas_start, "inverseNtt_zetas is null"); 8451 Node* kyberInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8452 OptoRuntime::kyberInverseNtt_Type(), 8453 stubAddr, stubName, TypePtr::BOTTOM, 8454 coeffs_start, zetas_start); 8455 8456 // return an int 8457 Node* retvalue = _gvn.transform(new ProjNode(kyberInverseNtt, TypeFunc::Parms)); 8458 set_result(retvalue); 8459 return true; 8460 } 8461 8462 //------------------------------inline_kyberNttMult 8463 bool LibraryCallKit::inline_kyberNttMult() { 8464 address stubAddr; 8465 const char *stubName; 8466 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8467 assert(callee()->signature()->size() == 4, "kyberNttMult has 4 parameters"); 8468 8469 stubAddr = StubRoutines::kyberNttMult(); 8470 stubName = "kyberNttMult"; 8471 if (!stubAddr) return false; 8472 8473 Node* result = argument(0); 8474 Node* ntta = argument(1); 8475 Node* nttb = argument(2); 8476 Node* zetas = argument(3); 8477 8478 result = must_be_not_null(result, true); 8479 ntta = must_be_not_null(ntta, true); 8480 nttb = must_be_not_null(nttb, true); 8481 zetas = must_be_not_null(zetas, true); 8482 8483 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8484 assert(result_start, "result is null"); 8485 Node* ntta_start = array_element_address(ntta, intcon(0), T_SHORT); 8486 assert(ntta_start, "ntta is null"); 8487 Node* nttb_start = array_element_address(nttb, intcon(0), T_SHORT); 8488 assert(nttb_start, "nttb is null"); 8489 Node* zetas_start = array_element_address(zetas, intcon(0), T_SHORT); 8490 assert(zetas_start, "nttMult_zetas is null"); 8491 Node* kyberNttMult = make_runtime_call(RC_LEAF|RC_NO_FP, 8492 OptoRuntime::kyberNttMult_Type(), 8493 stubAddr, stubName, TypePtr::BOTTOM, 8494 result_start, ntta_start, nttb_start, 8495 zetas_start); 8496 8497 // return an int 8498 Node* retvalue = _gvn.transform(new ProjNode(kyberNttMult, TypeFunc::Parms)); 8499 set_result(retvalue); 8500 8501 return true; 8502 } 8503 8504 //------------------------------inline_kyberAddPoly_2 8505 bool LibraryCallKit::inline_kyberAddPoly_2() { 8506 address stubAddr; 8507 const char *stubName; 8508 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8509 assert(callee()->signature()->size() == 3, "kyberAddPoly_2 has 3 parameters"); 8510 8511 stubAddr = StubRoutines::kyberAddPoly_2(); 8512 stubName = "kyberAddPoly_2"; 8513 if (!stubAddr) return false; 8514 8515 Node* result = argument(0); 8516 Node* a = argument(1); 8517 Node* b = argument(2); 8518 8519 result = must_be_not_null(result, true); 8520 a = must_be_not_null(a, true); 8521 b = must_be_not_null(b, true); 8522 8523 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8524 assert(result_start, "result is null"); 8525 Node* a_start = array_element_address(a, intcon(0), T_SHORT); 8526 assert(a_start, "a is null"); 8527 Node* b_start = array_element_address(b, intcon(0), T_SHORT); 8528 assert(b_start, "b is null"); 8529 Node* kyberAddPoly_2 = make_runtime_call(RC_LEAF|RC_NO_FP, 8530 OptoRuntime::kyberAddPoly_2_Type(), 8531 stubAddr, stubName, TypePtr::BOTTOM, 8532 result_start, a_start, b_start); 8533 // return an int 8534 Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_2, TypeFunc::Parms)); 8535 set_result(retvalue); 8536 return true; 8537 } 8538 8539 //------------------------------inline_kyberAddPoly_3 8540 bool LibraryCallKit::inline_kyberAddPoly_3() { 8541 address stubAddr; 8542 const char *stubName; 8543 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8544 assert(callee()->signature()->size() == 4, "kyberAddPoly_3 has 4 parameters"); 8545 8546 stubAddr = StubRoutines::kyberAddPoly_3(); 8547 stubName = "kyberAddPoly_3"; 8548 if (!stubAddr) return false; 8549 8550 Node* result = argument(0); 8551 Node* a = argument(1); 8552 Node* b = argument(2); 8553 Node* c = argument(3); 8554 8555 result = must_be_not_null(result, true); 8556 a = must_be_not_null(a, true); 8557 b = must_be_not_null(b, true); 8558 c = must_be_not_null(c, true); 8559 8560 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8561 assert(result_start, "result is null"); 8562 Node* a_start = array_element_address(a, intcon(0), T_SHORT); 8563 assert(a_start, "a is null"); 8564 Node* b_start = array_element_address(b, intcon(0), T_SHORT); 8565 assert(b_start, "b is null"); 8566 Node* c_start = array_element_address(c, intcon(0), T_SHORT); 8567 assert(c_start, "c is null"); 8568 Node* kyberAddPoly_3 = make_runtime_call(RC_LEAF|RC_NO_FP, 8569 OptoRuntime::kyberAddPoly_3_Type(), 8570 stubAddr, stubName, TypePtr::BOTTOM, 8571 result_start, a_start, b_start, c_start); 8572 // return an int 8573 Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_3, TypeFunc::Parms)); 8574 set_result(retvalue); 8575 return true; 8576 } 8577 8578 //------------------------------inline_kyber12To16 8579 bool LibraryCallKit::inline_kyber12To16() { 8580 address stubAddr; 8581 const char *stubName; 8582 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8583 assert(callee()->signature()->size() == 4, "kyber12To16 has 4 parameters"); 8584 8585 stubAddr = StubRoutines::kyber12To16(); 8586 stubName = "kyber12To16"; 8587 if (!stubAddr) return false; 8588 8589 Node* condensed = argument(0); 8590 Node* condensedOffs = argument(1); 8591 Node* parsed = argument(2); 8592 Node* parsedLength = argument(3); 8593 8594 condensed = must_be_not_null(condensed, true); 8595 parsed = must_be_not_null(parsed, true); 8596 8597 Node* condensed_start = array_element_address(condensed, intcon(0), T_BYTE); 8598 assert(condensed_start, "condensed is null"); 8599 Node* parsed_start = array_element_address(parsed, intcon(0), T_SHORT); 8600 assert(parsed_start, "parsed is null"); 8601 Node* kyber12To16 = make_runtime_call(RC_LEAF|RC_NO_FP, 8602 OptoRuntime::kyber12To16_Type(), 8603 stubAddr, stubName, TypePtr::BOTTOM, 8604 condensed_start, condensedOffs, parsed_start, parsedLength); 8605 // return an int 8606 Node* retvalue = _gvn.transform(new ProjNode(kyber12To16, TypeFunc::Parms)); 8607 set_result(retvalue); 8608 return true; 8609 8610 } 8611 8612 //------------------------------inline_kyberBarrettReduce 8613 bool LibraryCallKit::inline_kyberBarrettReduce() { 8614 address stubAddr; 8615 const char *stubName; 8616 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8617 assert(callee()->signature()->size() == 1, "kyberBarrettReduce has 1 parameters"); 8618 8619 stubAddr = StubRoutines::kyberBarrettReduce(); 8620 stubName = "kyberBarrettReduce"; 8621 if (!stubAddr) return false; 8622 8623 Node* coeffs = argument(0); 8624 8625 coeffs = must_be_not_null(coeffs, true); 8626 8627 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8628 assert(coeffs_start, "coeffs is null"); 8629 Node* kyberBarrettReduce = make_runtime_call(RC_LEAF|RC_NO_FP, 8630 OptoRuntime::kyberBarrettReduce_Type(), 8631 stubAddr, stubName, TypePtr::BOTTOM, 8632 coeffs_start); 8633 // return an int 8634 Node* retvalue = _gvn.transform(new ProjNode(kyberBarrettReduce, TypeFunc::Parms)); 8635 set_result(retvalue); 8636 return true; 8637 } 8638 8639 //------------------------------inline_dilithiumAlmostNtt 8640 bool LibraryCallKit::inline_dilithiumAlmostNtt() { 8641 address stubAddr; 8642 const char *stubName; 8643 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8644 assert(callee()->signature()->size() == 2, "dilithiumAlmostNtt has 2 parameters"); 8645 8646 stubAddr = StubRoutines::dilithiumAlmostNtt(); 8647 stubName = "dilithiumAlmostNtt"; 8648 if (!stubAddr) return false; 8649 8650 Node* coeffs = argument(0); 8651 Node* ntt_zetas = argument(1); 8652 8653 coeffs = must_be_not_null(coeffs, true); 8654 ntt_zetas = must_be_not_null(ntt_zetas, true); 8655 8656 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8657 assert(coeffs_start, "coeffs is null"); 8658 Node* ntt_zetas_start = array_element_address(ntt_zetas, intcon(0), T_INT); 8659 assert(ntt_zetas_start, "ntt_zetas is null"); 8660 Node* dilithiumAlmostNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8661 OptoRuntime::dilithiumAlmostNtt_Type(), 8662 stubAddr, stubName, TypePtr::BOTTOM, 8663 coeffs_start, ntt_zetas_start); 8664 // return an int 8665 Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostNtt, TypeFunc::Parms)); 8666 set_result(retvalue); 8667 return true; 8668 } 8669 8670 //------------------------------inline_dilithiumAlmostInverseNtt 8671 bool LibraryCallKit::inline_dilithiumAlmostInverseNtt() { 8672 address stubAddr; 8673 const char *stubName; 8674 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8675 assert(callee()->signature()->size() == 2, "dilithiumAlmostInverseNtt has 2 parameters"); 8676 8677 stubAddr = StubRoutines::dilithiumAlmostInverseNtt(); 8678 stubName = "dilithiumAlmostInverseNtt"; 8679 if (!stubAddr) return false; 8680 8681 Node* coeffs = argument(0); 8682 Node* zetas = argument(1); 8683 8684 coeffs = must_be_not_null(coeffs, true); 8685 zetas = must_be_not_null(zetas, true); 8686 8687 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8688 assert(coeffs_start, "coeffs is null"); 8689 Node* zetas_start = array_element_address(zetas, intcon(0), T_INT); 8690 assert(zetas_start, "inverseNtt_zetas is null"); 8691 Node* dilithiumAlmostInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8692 OptoRuntime::dilithiumAlmostInverseNtt_Type(), 8693 stubAddr, stubName, TypePtr::BOTTOM, 8694 coeffs_start, zetas_start); 8695 // return an int 8696 Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostInverseNtt, TypeFunc::Parms)); 8697 set_result(retvalue); 8698 return true; 8699 } 8700 8701 //------------------------------inline_dilithiumNttMult 8702 bool LibraryCallKit::inline_dilithiumNttMult() { 8703 address stubAddr; 8704 const char *stubName; 8705 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8706 assert(callee()->signature()->size() == 3, "dilithiumNttMult has 3 parameters"); 8707 8708 stubAddr = StubRoutines::dilithiumNttMult(); 8709 stubName = "dilithiumNttMult"; 8710 if (!stubAddr) return false; 8711 8712 Node* result = argument(0); 8713 Node* ntta = argument(1); 8714 Node* nttb = argument(2); 8715 Node* zetas = argument(3); 8716 8717 result = must_be_not_null(result, true); 8718 ntta = must_be_not_null(ntta, true); 8719 nttb = must_be_not_null(nttb, true); 8720 zetas = must_be_not_null(zetas, true); 8721 8722 Node* result_start = array_element_address(result, intcon(0), T_INT); 8723 assert(result_start, "result is null"); 8724 Node* ntta_start = array_element_address(ntta, intcon(0), T_INT); 8725 assert(ntta_start, "ntta is null"); 8726 Node* nttb_start = array_element_address(nttb, intcon(0), T_INT); 8727 assert(nttb_start, "nttb is null"); 8728 Node* dilithiumNttMult = make_runtime_call(RC_LEAF|RC_NO_FP, 8729 OptoRuntime::dilithiumNttMult_Type(), 8730 stubAddr, stubName, TypePtr::BOTTOM, 8731 result_start, ntta_start, nttb_start); 8732 8733 // return an int 8734 Node* retvalue = _gvn.transform(new ProjNode(dilithiumNttMult, TypeFunc::Parms)); 8735 set_result(retvalue); 8736 8737 return true; 8738 } 8739 8740 //------------------------------inline_dilithiumMontMulByConstant 8741 bool LibraryCallKit::inline_dilithiumMontMulByConstant() { 8742 address stubAddr; 8743 const char *stubName; 8744 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8745 assert(callee()->signature()->size() == 2, "dilithiumMontMulByConstant has 2 parameters"); 8746 8747 stubAddr = StubRoutines::dilithiumMontMulByConstant(); 8748 stubName = "dilithiumMontMulByConstant"; 8749 if (!stubAddr) return false; 8750 8751 Node* coeffs = argument(0); 8752 Node* constant = argument(1); 8753 8754 coeffs = must_be_not_null(coeffs, true); 8755 8756 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8757 assert(coeffs_start, "coeffs is null"); 8758 Node* dilithiumMontMulByConstant = make_runtime_call(RC_LEAF|RC_NO_FP, 8759 OptoRuntime::dilithiumMontMulByConstant_Type(), 8760 stubAddr, stubName, TypePtr::BOTTOM, 8761 coeffs_start, constant); 8762 8763 // return an int 8764 Node* retvalue = _gvn.transform(new ProjNode(dilithiumMontMulByConstant, TypeFunc::Parms)); 8765 set_result(retvalue); 8766 return true; 8767 } 8768 8769 8770 //------------------------------inline_dilithiumDecomposePoly 8771 bool LibraryCallKit::inline_dilithiumDecomposePoly() { 8772 address stubAddr; 8773 const char *stubName; 8774 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8775 assert(callee()->signature()->size() == 5, "dilithiumDecomposePoly has 5 parameters"); 8776 8777 stubAddr = StubRoutines::dilithiumDecomposePoly(); 8778 stubName = "dilithiumDecomposePoly"; 8779 if (!stubAddr) return false; 8780 8781 Node* input = argument(0); 8782 Node* lowPart = argument(1); 8783 Node* highPart = argument(2); 8784 Node* twoGamma2 = argument(3); 8785 Node* multiplier = argument(4); 8786 8787 input = must_be_not_null(input, true); 8788 lowPart = must_be_not_null(lowPart, true); 8789 highPart = must_be_not_null(highPart, true); 8790 8791 Node* input_start = array_element_address(input, intcon(0), T_INT); 8792 assert(input_start, "input is null"); 8793 Node* lowPart_start = array_element_address(lowPart, intcon(0), T_INT); 8794 assert(lowPart_start, "lowPart is null"); 8795 Node* highPart_start = array_element_address(highPart, intcon(0), T_INT); 8796 assert(highPart_start, "highPart is null"); 8797 8798 Node* dilithiumDecomposePoly = make_runtime_call(RC_LEAF|RC_NO_FP, 8799 OptoRuntime::dilithiumDecomposePoly_Type(), 8800 stubAddr, stubName, TypePtr::BOTTOM, 8801 input_start, lowPart_start, highPart_start, 8802 twoGamma2, multiplier); 8803 8804 // return an int 8805 Node* retvalue = _gvn.transform(new ProjNode(dilithiumDecomposePoly, TypeFunc::Parms)); 8806 set_result(retvalue); 8807 return true; 8808 } 8809 8810 bool LibraryCallKit::inline_base64_encodeBlock() { 8811 address stubAddr; 8812 const char *stubName; 8813 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 8814 assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters"); 8815 stubAddr = StubRoutines::base64_encodeBlock(); 8816 stubName = "encodeBlock"; 8817 8818 if (!stubAddr) return false; 8819 Node* base64obj = argument(0); 8820 Node* src = argument(1); 8821 Node* offset = argument(2); 8822 Node* len = argument(3); 8823 Node* dest = argument(4); 8824 Node* dp = argument(5); 8825 Node* isURL = argument(6); 8826 8827 src = must_be_not_null(src, true); 8828 dest = must_be_not_null(dest, true); 8829 8830 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 8831 assert(src_start, "source array is null"); 8832 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 8833 assert(dest_start, "destination array is null"); 8834 8835 Node* base64 = make_runtime_call(RC_LEAF, 8836 OptoRuntime::base64_encodeBlock_Type(), 8837 stubAddr, stubName, TypePtr::BOTTOM, 8838 src_start, offset, len, dest_start, dp, isURL); 8839 return true; 8840 } 8841 8842 bool LibraryCallKit::inline_base64_decodeBlock() { 8843 address stubAddr; 8844 const char *stubName; 8845 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 8846 assert(callee()->signature()->size() == 7, "base64_decodeBlock has 7 parameters"); 8847 stubAddr = StubRoutines::base64_decodeBlock(); 8848 stubName = "decodeBlock"; 8849 8850 if (!stubAddr) return false; 8851 Node* base64obj = argument(0); 8852 Node* src = argument(1); 8853 Node* src_offset = argument(2); 8854 Node* len = argument(3); 8855 Node* dest = argument(4); 8856 Node* dest_offset = argument(5); 8857 Node* isURL = argument(6); 8858 Node* isMIME = argument(7); 8859 8860 src = must_be_not_null(src, true); 8861 dest = must_be_not_null(dest, true); 8862 8863 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 8864 assert(src_start, "source array is null"); 8865 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 8866 assert(dest_start, "destination array is null"); 8867 8868 Node* call = make_runtime_call(RC_LEAF, 8869 OptoRuntime::base64_decodeBlock_Type(), 8870 stubAddr, stubName, TypePtr::BOTTOM, 8871 src_start, src_offset, len, dest_start, dest_offset, isURL, isMIME); 8872 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 8873 set_result(result); 8874 return true; 8875 } 8876 8877 bool LibraryCallKit::inline_poly1305_processBlocks() { 8878 address stubAddr; 8879 const char *stubName; 8880 assert(UsePoly1305Intrinsics, "need Poly intrinsics support"); 8881 assert(callee()->signature()->size() == 5, "poly1305_processBlocks has %d parameters", callee()->signature()->size()); 8882 stubAddr = StubRoutines::poly1305_processBlocks(); 8883 stubName = "poly1305_processBlocks"; 8884 8885 if (!stubAddr) return false; 8886 null_check_receiver(); // null-check receiver 8887 if (stopped()) return true; 8888 8889 Node* input = argument(1); 8890 Node* input_offset = argument(2); 8891 Node* len = argument(3); 8892 Node* alimbs = argument(4); 8893 Node* rlimbs = argument(5); 8894 8895 input = must_be_not_null(input, true); 8896 alimbs = must_be_not_null(alimbs, true); 8897 rlimbs = must_be_not_null(rlimbs, true); 8898 8899 Node* input_start = array_element_address(input, input_offset, T_BYTE); 8900 assert(input_start, "input array is null"); 8901 Node* acc_start = array_element_address(alimbs, intcon(0), T_LONG); 8902 assert(acc_start, "acc array is null"); 8903 Node* r_start = array_element_address(rlimbs, intcon(0), T_LONG); 8904 assert(r_start, "r array is null"); 8905 8906 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8907 OptoRuntime::poly1305_processBlocks_Type(), 8908 stubAddr, stubName, TypePtr::BOTTOM, 8909 input_start, len, acc_start, r_start); 8910 return true; 8911 } 8912 8913 bool LibraryCallKit::inline_intpoly_montgomeryMult_P256() { 8914 address stubAddr; 8915 const char *stubName; 8916 assert(UseIntPolyIntrinsics, "need intpoly intrinsics support"); 8917 assert(callee()->signature()->size() == 3, "intpoly_montgomeryMult_P256 has %d parameters", callee()->signature()->size()); 8918 stubAddr = StubRoutines::intpoly_montgomeryMult_P256(); 8919 stubName = "intpoly_montgomeryMult_P256"; 8920 8921 if (!stubAddr) return false; 8922 null_check_receiver(); // null-check receiver 8923 if (stopped()) return true; 8924 8925 Node* a = argument(1); 8926 Node* b = argument(2); 8927 Node* r = argument(3); 8928 8929 a = must_be_not_null(a, true); 8930 b = must_be_not_null(b, true); 8931 r = must_be_not_null(r, true); 8932 8933 Node* a_start = array_element_address(a, intcon(0), T_LONG); 8934 assert(a_start, "a array is null"); 8935 Node* b_start = array_element_address(b, intcon(0), T_LONG); 8936 assert(b_start, "b array is null"); 8937 Node* r_start = array_element_address(r, intcon(0), T_LONG); 8938 assert(r_start, "r array is null"); 8939 8940 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8941 OptoRuntime::intpoly_montgomeryMult_P256_Type(), 8942 stubAddr, stubName, TypePtr::BOTTOM, 8943 a_start, b_start, r_start); 8944 return true; 8945 } 8946 8947 bool LibraryCallKit::inline_intpoly_assign() { 8948 assert(UseIntPolyIntrinsics, "need intpoly intrinsics support"); 8949 assert(callee()->signature()->size() == 3, "intpoly_assign has %d parameters", callee()->signature()->size()); 8950 const char *stubName = "intpoly_assign"; 8951 address stubAddr = StubRoutines::intpoly_assign(); 8952 if (!stubAddr) return false; 8953 8954 Node* set = argument(0); 8955 Node* a = argument(1); 8956 Node* b = argument(2); 8957 Node* arr_length = load_array_length(a); 8958 8959 a = must_be_not_null(a, true); 8960 b = must_be_not_null(b, true); 8961 8962 Node* a_start = array_element_address(a, intcon(0), T_LONG); 8963 assert(a_start, "a array is null"); 8964 Node* b_start = array_element_address(b, intcon(0), T_LONG); 8965 assert(b_start, "b array is null"); 8966 8967 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8968 OptoRuntime::intpoly_assign_Type(), 8969 stubAddr, stubName, TypePtr::BOTTOM, 8970 set, a_start, b_start, arr_length); 8971 return true; 8972 } 8973 8974 //------------------------------inline_digestBase_implCompress----------------------- 8975 // 8976 // Calculate MD5 for single-block byte[] array. 8977 // void com.sun.security.provider.MD5.implCompress(byte[] buf, int ofs) 8978 // 8979 // Calculate SHA (i.e., SHA-1) for single-block byte[] array. 8980 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs) 8981 // 8982 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array. 8983 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs) 8984 // 8985 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array. 8986 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs) 8987 // 8988 // Calculate SHA3 (i.e., SHA3-224 or SHA3-256 or SHA3-384 or SHA3-512) for single-block byte[] array. 8989 // void com.sun.security.provider.SHA3.implCompress(byte[] buf, int ofs) 8990 // 8991 bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) { 8992 assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters"); 8993 8994 Node* digestBase_obj = argument(0); 8995 Node* src = argument(1); // type oop 8996 Node* ofs = argument(2); // type int 8997 8998 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 8999 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 9000 // failed array check 9001 return false; 9002 } 9003 // Figure out the size and type of the elements we will be copying. 9004 BasicType src_elem = src_type->elem()->array_element_basic_type(); 9005 if (src_elem != T_BYTE) { 9006 return false; 9007 } 9008 // 'src_start' points to src array + offset 9009 src = must_be_not_null(src, true); 9010 Node* src_start = array_element_address(src, ofs, src_elem); 9011 Node* state = nullptr; 9012 Node* block_size = nullptr; 9013 address stubAddr; 9014 const char *stubName; 9015 9016 switch(id) { 9017 case vmIntrinsics::_md5_implCompress: 9018 assert(UseMD5Intrinsics, "need MD5 instruction support"); 9019 state = get_state_from_digest_object(digestBase_obj, T_INT); 9020 stubAddr = StubRoutines::md5_implCompress(); 9021 stubName = "md5_implCompress"; 9022 break; 9023 case vmIntrinsics::_sha_implCompress: 9024 assert(UseSHA1Intrinsics, "need SHA1 instruction support"); 9025 state = get_state_from_digest_object(digestBase_obj, T_INT); 9026 stubAddr = StubRoutines::sha1_implCompress(); 9027 stubName = "sha1_implCompress"; 9028 break; 9029 case vmIntrinsics::_sha2_implCompress: 9030 assert(UseSHA256Intrinsics, "need SHA256 instruction support"); 9031 state = get_state_from_digest_object(digestBase_obj, T_INT); 9032 stubAddr = StubRoutines::sha256_implCompress(); 9033 stubName = "sha256_implCompress"; 9034 break; 9035 case vmIntrinsics::_sha5_implCompress: 9036 assert(UseSHA512Intrinsics, "need SHA512 instruction support"); 9037 state = get_state_from_digest_object(digestBase_obj, T_LONG); 9038 stubAddr = StubRoutines::sha512_implCompress(); 9039 stubName = "sha512_implCompress"; 9040 break; 9041 case vmIntrinsics::_sha3_implCompress: 9042 assert(UseSHA3Intrinsics, "need SHA3 instruction support"); 9043 state = get_state_from_digest_object(digestBase_obj, T_LONG); 9044 stubAddr = StubRoutines::sha3_implCompress(); 9045 stubName = "sha3_implCompress"; 9046 block_size = get_block_size_from_digest_object(digestBase_obj); 9047 if (block_size == nullptr) return false; 9048 break; 9049 default: 9050 fatal_unexpected_iid(id); 9051 return false; 9052 } 9053 if (state == nullptr) return false; 9054 9055 assert(stubAddr != nullptr, "Stub %s is not generated", stubName); 9056 if (stubAddr == nullptr) return false; 9057 9058 // Call the stub. 9059 Node* call; 9060 if (block_size == nullptr) { 9061 call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(false), 9062 stubAddr, stubName, TypePtr::BOTTOM, 9063 src_start, state); 9064 } else { 9065 call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(true), 9066 stubAddr, stubName, TypePtr::BOTTOM, 9067 src_start, state, block_size); 9068 } 9069 9070 return true; 9071 } 9072 9073 //------------------------------inline_double_keccak 9074 bool LibraryCallKit::inline_double_keccak() { 9075 address stubAddr; 9076 const char *stubName; 9077 assert(UseSHA3Intrinsics, "need SHA3 intrinsics support"); 9078 assert(callee()->signature()->size() == 2, "double_keccak has 2 parameters"); 9079 9080 stubAddr = StubRoutines::double_keccak(); 9081 stubName = "double_keccak"; 9082 if (!stubAddr) return false; 9083 9084 Node* status0 = argument(0); 9085 Node* status1 = argument(1); 9086 9087 status0 = must_be_not_null(status0, true); 9088 status1 = must_be_not_null(status1, true); 9089 9090 Node* status0_start = array_element_address(status0, intcon(0), T_LONG); 9091 assert(status0_start, "status0 is null"); 9092 Node* status1_start = array_element_address(status1, intcon(0), T_LONG); 9093 assert(status1_start, "status1 is null"); 9094 Node* double_keccak = make_runtime_call(RC_LEAF|RC_NO_FP, 9095 OptoRuntime::double_keccak_Type(), 9096 stubAddr, stubName, TypePtr::BOTTOM, 9097 status0_start, status1_start); 9098 // return an int 9099 Node* retvalue = _gvn.transform(new ProjNode(double_keccak, TypeFunc::Parms)); 9100 set_result(retvalue); 9101 return true; 9102 } 9103 9104 9105 //------------------------------inline_digestBase_implCompressMB----------------------- 9106 // 9107 // Calculate MD5/SHA/SHA2/SHA5/SHA3 for multi-block byte[] array. 9108 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 9109 // 9110 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) { 9111 assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics, 9112 "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support"); 9113 assert((uint)predicate < 5, "sanity"); 9114 assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters"); 9115 9116 Node* digestBase_obj = argument(0); // The receiver was checked for null already. 9117 Node* src = argument(1); // byte[] array 9118 Node* ofs = argument(2); // type int 9119 Node* limit = argument(3); // type int 9120 9121 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 9122 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 9123 // failed array check 9124 return false; 9125 } 9126 // Figure out the size and type of the elements we will be copying. 9127 BasicType src_elem = src_type->elem()->array_element_basic_type(); 9128 if (src_elem != T_BYTE) { 9129 return false; 9130 } 9131 // 'src_start' points to src array + offset 9132 src = must_be_not_null(src, false); 9133 Node* src_start = array_element_address(src, ofs, src_elem); 9134 9135 const char* klass_digestBase_name = nullptr; 9136 const char* stub_name = nullptr; 9137 address stub_addr = nullptr; 9138 BasicType elem_type = T_INT; 9139 9140 switch (predicate) { 9141 case 0: 9142 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_md5_implCompress)) { 9143 klass_digestBase_name = "sun/security/provider/MD5"; 9144 stub_name = "md5_implCompressMB"; 9145 stub_addr = StubRoutines::md5_implCompressMB(); 9146 } 9147 break; 9148 case 1: 9149 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha_implCompress)) { 9150 klass_digestBase_name = "sun/security/provider/SHA"; 9151 stub_name = "sha1_implCompressMB"; 9152 stub_addr = StubRoutines::sha1_implCompressMB(); 9153 } 9154 break; 9155 case 2: 9156 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha2_implCompress)) { 9157 klass_digestBase_name = "sun/security/provider/SHA2"; 9158 stub_name = "sha256_implCompressMB"; 9159 stub_addr = StubRoutines::sha256_implCompressMB(); 9160 } 9161 break; 9162 case 3: 9163 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha5_implCompress)) { 9164 klass_digestBase_name = "sun/security/provider/SHA5"; 9165 stub_name = "sha512_implCompressMB"; 9166 stub_addr = StubRoutines::sha512_implCompressMB(); 9167 elem_type = T_LONG; 9168 } 9169 break; 9170 case 4: 9171 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha3_implCompress)) { 9172 klass_digestBase_name = "sun/security/provider/SHA3"; 9173 stub_name = "sha3_implCompressMB"; 9174 stub_addr = StubRoutines::sha3_implCompressMB(); 9175 elem_type = T_LONG; 9176 } 9177 break; 9178 default: 9179 fatal("unknown DigestBase intrinsic predicate: %d", predicate); 9180 } 9181 if (klass_digestBase_name != nullptr) { 9182 assert(stub_addr != nullptr, "Stub is generated"); 9183 if (stub_addr == nullptr) return false; 9184 9185 // get DigestBase klass to lookup for SHA klass 9186 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr(); 9187 assert(tinst != nullptr, "digestBase_obj is not instance???"); 9188 assert(tinst->is_loaded(), "DigestBase is not loaded"); 9189 9190 ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name)); 9191 assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded"); 9192 ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass(); 9193 return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit); 9194 } 9195 return false; 9196 } 9197 9198 //------------------------------inline_digestBase_implCompressMB----------------------- 9199 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase, 9200 BasicType elem_type, address stubAddr, const char *stubName, 9201 Node* src_start, Node* ofs, Node* limit) { 9202 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase); 9203 const TypeOopPtr* xtype = aklass->cast_to_exactness(false)->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 9204 Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype); 9205 digest_obj = _gvn.transform(digest_obj); 9206 9207 Node* state = get_state_from_digest_object(digest_obj, elem_type); 9208 if (state == nullptr) return false; 9209 9210 Node* block_size = nullptr; 9211 if (strcmp("sha3_implCompressMB", stubName) == 0) { 9212 block_size = get_block_size_from_digest_object(digest_obj); 9213 if (block_size == nullptr) return false; 9214 } 9215 9216 // Call the stub. 9217 Node* call; 9218 if (block_size == nullptr) { 9219 call = make_runtime_call(RC_LEAF|RC_NO_FP, 9220 OptoRuntime::digestBase_implCompressMB_Type(false), 9221 stubAddr, stubName, TypePtr::BOTTOM, 9222 src_start, state, ofs, limit); 9223 } else { 9224 call = make_runtime_call(RC_LEAF|RC_NO_FP, 9225 OptoRuntime::digestBase_implCompressMB_Type(true), 9226 stubAddr, stubName, TypePtr::BOTTOM, 9227 src_start, state, block_size, ofs, limit); 9228 } 9229 9230 // return ofs (int) 9231 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 9232 set_result(result); 9233 9234 return true; 9235 } 9236 9237 //------------------------------inline_galoisCounterMode_AESCrypt----------------------- 9238 bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() { 9239 assert(UseAES, "need AES instruction support"); 9240 address stubAddr = nullptr; 9241 const char *stubName = nullptr; 9242 stubAddr = StubRoutines::galoisCounterMode_AESCrypt(); 9243 stubName = "galoisCounterMode_AESCrypt"; 9244 9245 if (stubAddr == nullptr) return false; 9246 9247 Node* in = argument(0); 9248 Node* inOfs = argument(1); 9249 Node* len = argument(2); 9250 Node* ct = argument(3); 9251 Node* ctOfs = argument(4); 9252 Node* out = argument(5); 9253 Node* outOfs = argument(6); 9254 Node* gctr_object = argument(7); 9255 Node* ghash_object = argument(8); 9256 9257 // (1) in, ct and out are arrays. 9258 const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr(); 9259 const TypeAryPtr* ct_type = ct->Value(&_gvn)->isa_aryptr(); 9260 const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr(); 9261 assert( in_type != nullptr && in_type->elem() != Type::BOTTOM && 9262 ct_type != nullptr && ct_type->elem() != Type::BOTTOM && 9263 out_type != nullptr && out_type->elem() != Type::BOTTOM, "args are strange"); 9264 9265 // checks are the responsibility of the caller 9266 Node* in_start = in; 9267 Node* ct_start = ct; 9268 Node* out_start = out; 9269 if (inOfs != nullptr || ctOfs != nullptr || outOfs != nullptr) { 9270 assert(inOfs != nullptr && ctOfs != nullptr && outOfs != nullptr, ""); 9271 in_start = array_element_address(in, inOfs, T_BYTE); 9272 ct_start = array_element_address(ct, ctOfs, T_BYTE); 9273 out_start = array_element_address(out, outOfs, T_BYTE); 9274 } 9275 9276 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 9277 // (because of the predicated logic executed earlier). 9278 // so we cast it here safely. 9279 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 9280 Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 9281 Node* counter = load_field_from_object(gctr_object, "counter", "[B"); 9282 Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J"); 9283 Node* state = load_field_from_object(ghash_object, "state", "[J"); 9284 9285 if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) { 9286 return false; 9287 } 9288 // cast it to what we know it will be at runtime 9289 const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr(); 9290 assert(tinst != nullptr, "GCTR obj is null"); 9291 assert(tinst->is_loaded(), "GCTR obj is not loaded"); 9292 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 9293 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 9294 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 9295 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 9296 const TypeOopPtr* xtype = aklass->as_instance_type(); 9297 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 9298 aescrypt_object = _gvn.transform(aescrypt_object); 9299 // we need to get the start of the aescrypt_object's expanded key array 9300 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 9301 if (k_start == nullptr) return false; 9302 // similarly, get the start address of the r vector 9303 Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE); 9304 Node* state_start = array_element_address(state, intcon(0), T_LONG); 9305 Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG); 9306 9307 9308 // Call the stub, passing params 9309 Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 9310 OptoRuntime::galoisCounterMode_aescrypt_Type(), 9311 stubAddr, stubName, TypePtr::BOTTOM, 9312 in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start); 9313 9314 // return cipher length (int) 9315 Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms)); 9316 set_result(retvalue); 9317 9318 return true; 9319 } 9320 9321 //----------------------------inline_galoisCounterMode_AESCrypt_predicate---------------------------- 9322 // Return node representing slow path of predicate check. 9323 // the pseudo code we want to emulate with this predicate is: 9324 // for encryption: 9325 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 9326 // for decryption: 9327 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 9328 // note cipher==plain is more conservative than the original java code but that's OK 9329 // 9330 9331 Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() { 9332 // The receiver was checked for null already. 9333 Node* objGCTR = argument(7); 9334 // Load embeddedCipher field of GCTR object. 9335 Node* embeddedCipherObj = load_field_from_object(objGCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 9336 assert(embeddedCipherObj != nullptr, "embeddedCipherObj is null"); 9337 9338 // get AESCrypt klass for instanceOf check 9339 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 9340 // will have same classloader as CipherBlockChaining object 9341 const TypeInstPtr* tinst = _gvn.type(objGCTR)->isa_instptr(); 9342 assert(tinst != nullptr, "GCTR obj is null"); 9343 assert(tinst->is_loaded(), "GCTR obj is not loaded"); 9344 9345 // we want to do an instanceof comparison against the AESCrypt class 9346 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 9347 if (!klass_AESCrypt->is_loaded()) { 9348 // if AESCrypt is not even loaded, we never take the intrinsic fast path 9349 Node* ctrl = control(); 9350 set_control(top()); // no regular fast path 9351 return ctrl; 9352 } 9353 9354 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 9355 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 9356 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 9357 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 9358 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 9359 9360 return instof_false; // even if it is null 9361 } 9362 9363 //------------------------------get_state_from_digest_object----------------------- 9364 Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) { 9365 const char* state_type; 9366 switch (elem_type) { 9367 case T_BYTE: state_type = "[B"; break; 9368 case T_INT: state_type = "[I"; break; 9369 case T_LONG: state_type = "[J"; break; 9370 default: ShouldNotReachHere(); 9371 } 9372 Node* digest_state = load_field_from_object(digest_object, "state", state_type); 9373 assert (digest_state != nullptr, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3"); 9374 if (digest_state == nullptr) return (Node *) nullptr; 9375 9376 // now have the array, need to get the start address of the state array 9377 Node* state = array_element_address(digest_state, intcon(0), elem_type); 9378 return state; 9379 } 9380 9381 //------------------------------get_block_size_from_sha3_object---------------------------------- 9382 Node * LibraryCallKit::get_block_size_from_digest_object(Node *digest_object) { 9383 Node* block_size = load_field_from_object(digest_object, "blockSize", "I"); 9384 assert (block_size != nullptr, "sanity"); 9385 return block_size; 9386 } 9387 9388 //----------------------------inline_digestBase_implCompressMB_predicate---------------------------- 9389 // Return node representing slow path of predicate check. 9390 // the pseudo code we want to emulate with this predicate is: 9391 // if (digestBaseObj instanceof MD5/SHA/SHA2/SHA5/SHA3) do_intrinsic, else do_javapath 9392 // 9393 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) { 9394 assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics, 9395 "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support"); 9396 assert((uint)predicate < 5, "sanity"); 9397 9398 // The receiver was checked for null already. 9399 Node* digestBaseObj = argument(0); 9400 9401 // get DigestBase klass for instanceOf check 9402 const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr(); 9403 assert(tinst != nullptr, "digestBaseObj is null"); 9404 assert(tinst->is_loaded(), "DigestBase is not loaded"); 9405 9406 const char* klass_name = nullptr; 9407 switch (predicate) { 9408 case 0: 9409 if (UseMD5Intrinsics) { 9410 // we want to do an instanceof comparison against the MD5 class 9411 klass_name = "sun/security/provider/MD5"; 9412 } 9413 break; 9414 case 1: 9415 if (UseSHA1Intrinsics) { 9416 // we want to do an instanceof comparison against the SHA class 9417 klass_name = "sun/security/provider/SHA"; 9418 } 9419 break; 9420 case 2: 9421 if (UseSHA256Intrinsics) { 9422 // we want to do an instanceof comparison against the SHA2 class 9423 klass_name = "sun/security/provider/SHA2"; 9424 } 9425 break; 9426 case 3: 9427 if (UseSHA512Intrinsics) { 9428 // we want to do an instanceof comparison against the SHA5 class 9429 klass_name = "sun/security/provider/SHA5"; 9430 } 9431 break; 9432 case 4: 9433 if (UseSHA3Intrinsics) { 9434 // we want to do an instanceof comparison against the SHA3 class 9435 klass_name = "sun/security/provider/SHA3"; 9436 } 9437 break; 9438 default: 9439 fatal("unknown SHA intrinsic predicate: %d", predicate); 9440 } 9441 9442 ciKlass* klass = nullptr; 9443 if (klass_name != nullptr) { 9444 klass = tinst->instance_klass()->find_klass(ciSymbol::make(klass_name)); 9445 } 9446 if ((klass == nullptr) || !klass->is_loaded()) { 9447 // if none of MD5/SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path 9448 Node* ctrl = control(); 9449 set_control(top()); // no intrinsic path 9450 return ctrl; 9451 } 9452 ciInstanceKlass* instklass = klass->as_instance_klass(); 9453 9454 Node* instof = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass))); 9455 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 9456 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 9457 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 9458 9459 return instof_false; // even if it is null 9460 } 9461 9462 //-------------inline_fma----------------------------------- 9463 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) { 9464 Node *a = nullptr; 9465 Node *b = nullptr; 9466 Node *c = nullptr; 9467 Node* result = nullptr; 9468 switch (id) { 9469 case vmIntrinsics::_fmaD: 9470 assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each."); 9471 // no receiver since it is static method 9472 a = argument(0); 9473 b = argument(2); 9474 c = argument(4); 9475 result = _gvn.transform(new FmaDNode(a, b, c)); 9476 break; 9477 case vmIntrinsics::_fmaF: 9478 assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each."); 9479 a = argument(0); 9480 b = argument(1); 9481 c = argument(2); 9482 result = _gvn.transform(new FmaFNode(a, b, c)); 9483 break; 9484 default: 9485 fatal_unexpected_iid(id); break; 9486 } 9487 set_result(result); 9488 return true; 9489 } 9490 9491 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) { 9492 // argument(0) is receiver 9493 Node* codePoint = argument(1); 9494 Node* n = nullptr; 9495 9496 switch (id) { 9497 case vmIntrinsics::_isDigit : 9498 n = new DigitNode(control(), codePoint); 9499 break; 9500 case vmIntrinsics::_isLowerCase : 9501 n = new LowerCaseNode(control(), codePoint); 9502 break; 9503 case vmIntrinsics::_isUpperCase : 9504 n = new UpperCaseNode(control(), codePoint); 9505 break; 9506 case vmIntrinsics::_isWhitespace : 9507 n = new WhitespaceNode(control(), codePoint); 9508 break; 9509 default: 9510 fatal_unexpected_iid(id); 9511 } 9512 9513 set_result(_gvn.transform(n)); 9514 return true; 9515 } 9516 9517 bool LibraryCallKit::inline_profileBoolean() { 9518 Node* counts = argument(1); 9519 const TypeAryPtr* ary = nullptr; 9520 ciArray* aobj = nullptr; 9521 if (counts->is_Con() 9522 && (ary = counts->bottom_type()->isa_aryptr()) != nullptr 9523 && (aobj = ary->const_oop()->as_array()) != nullptr 9524 && (aobj->length() == 2)) { 9525 // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively. 9526 jint false_cnt = aobj->element_value(0).as_int(); 9527 jint true_cnt = aobj->element_value(1).as_int(); 9528 9529 if (C->log() != nullptr) { 9530 C->log()->elem("observe source='profileBoolean' false='%d' true='%d'", 9531 false_cnt, true_cnt); 9532 } 9533 9534 if (false_cnt + true_cnt == 0) { 9535 // According to profile, never executed. 9536 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 9537 Deoptimization::Action_reinterpret); 9538 return true; 9539 } 9540 9541 // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt) 9542 // is a number of each value occurrences. 9543 Node* result = argument(0); 9544 if (false_cnt == 0 || true_cnt == 0) { 9545 // According to profile, one value has been never seen. 9546 int expected_val = (false_cnt == 0) ? 1 : 0; 9547 9548 Node* cmp = _gvn.transform(new CmpINode(result, intcon(expected_val))); 9549 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 9550 9551 IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN); 9552 Node* fast_path = _gvn.transform(new IfTrueNode(check)); 9553 Node* slow_path = _gvn.transform(new IfFalseNode(check)); 9554 9555 { // Slow path: uncommon trap for never seen value and then reexecute 9556 // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows 9557 // the value has been seen at least once. 9558 PreserveJVMState pjvms(this); 9559 PreserveReexecuteState preexecs(this); 9560 jvms()->set_should_reexecute(true); 9561 9562 set_control(slow_path); 9563 set_i_o(i_o()); 9564 9565 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 9566 Deoptimization::Action_reinterpret); 9567 } 9568 // The guard for never seen value enables sharpening of the result and 9569 // returning a constant. It allows to eliminate branches on the same value 9570 // later on. 9571 set_control(fast_path); 9572 result = intcon(expected_val); 9573 } 9574 // Stop profiling. 9575 // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode. 9576 // By replacing method body with profile data (represented as ProfileBooleanNode 9577 // on IR level) we effectively disable profiling. 9578 // It enables full speed execution once optimized code is generated. 9579 Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt)); 9580 C->record_for_igvn(profile); 9581 set_result(profile); 9582 return true; 9583 } else { 9584 // Continue profiling. 9585 // Profile data isn't available at the moment. So, execute method's bytecode version. 9586 // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod 9587 // is compiled and counters aren't available since corresponding MethodHandle 9588 // isn't a compile-time constant. 9589 return false; 9590 } 9591 } 9592 9593 bool LibraryCallKit::inline_isCompileConstant() { 9594 Node* n = argument(0); 9595 set_result(n->is_Con() ? intcon(1) : intcon(0)); 9596 return true; 9597 } 9598 9599 //------------------------------- inline_getObjectSize -------------------------------------- 9600 // 9601 // Calculate the runtime size of the object/array. 9602 // native long sun.instrument.InstrumentationImpl.getObjectSize0(long nativeAgent, Object objectToSize); 9603 // 9604 bool LibraryCallKit::inline_getObjectSize() { 9605 Node* obj = argument(3); 9606 Node* klass_node = load_object_klass(obj); 9607 9608 jint layout_con = Klass::_lh_neutral_value; 9609 Node* layout_val = get_layout_helper(klass_node, layout_con); 9610 int layout_is_con = (layout_val == nullptr); 9611 9612 if (layout_is_con) { 9613 // Layout helper is constant, can figure out things at compile time. 9614 9615 if (Klass::layout_helper_is_instance(layout_con)) { 9616 // Instance case: layout_con contains the size itself. 9617 Node *size = longcon(Klass::layout_helper_size_in_bytes(layout_con)); 9618 set_result(size); 9619 } else { 9620 // Array case: size is round(header + element_size*arraylength). 9621 // Since arraylength is different for every array instance, we have to 9622 // compute the whole thing at runtime. 9623 9624 Node* arr_length = load_array_length(obj); 9625 9626 int round_mask = MinObjAlignmentInBytes - 1; 9627 int hsize = Klass::layout_helper_header_size(layout_con); 9628 int eshift = Klass::layout_helper_log2_element_size(layout_con); 9629 9630 if ((round_mask & ~right_n_bits(eshift)) == 0) { 9631 round_mask = 0; // strength-reduce it if it goes away completely 9632 } 9633 assert((hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded"); 9634 Node* header_size = intcon(hsize + round_mask); 9635 9636 Node* lengthx = ConvI2X(arr_length); 9637 Node* headerx = ConvI2X(header_size); 9638 9639 Node* abody = lengthx; 9640 if (eshift != 0) { 9641 abody = _gvn.transform(new LShiftXNode(lengthx, intcon(eshift))); 9642 } 9643 Node* size = _gvn.transform( new AddXNode(headerx, abody) ); 9644 if (round_mask != 0) { 9645 size = _gvn.transform( new AndXNode(size, MakeConX(~round_mask)) ); 9646 } 9647 size = ConvX2L(size); 9648 set_result(size); 9649 } 9650 } else { 9651 // Layout helper is not constant, need to test for array-ness at runtime. 9652 9653 enum { _instance_path = 1, _array_path, PATH_LIMIT }; 9654 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 9655 PhiNode* result_val = new PhiNode(result_reg, TypeLong::LONG); 9656 record_for_igvn(result_reg); 9657 9658 Node* array_ctl = generate_array_guard(klass_node, nullptr, &obj); 9659 if (array_ctl != nullptr) { 9660 // Array case: size is round(header + element_size*arraylength). 9661 // Since arraylength is different for every array instance, we have to 9662 // compute the whole thing at runtime. 9663 9664 PreserveJVMState pjvms(this); 9665 set_control(array_ctl); 9666 Node* arr_length = load_array_length(obj); 9667 9668 int round_mask = MinObjAlignmentInBytes - 1; 9669 Node* mask = intcon(round_mask); 9670 9671 Node* hss = intcon(Klass::_lh_header_size_shift); 9672 Node* hsm = intcon(Klass::_lh_header_size_mask); 9673 Node* header_size = _gvn.transform(new URShiftINode(layout_val, hss)); 9674 header_size = _gvn.transform(new AndINode(header_size, hsm)); 9675 header_size = _gvn.transform(new AddINode(header_size, mask)); 9676 9677 // There is no need to mask or shift this value. 9678 // The semantics of LShiftINode include an implicit mask to 0x1F. 9679 assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place"); 9680 Node* elem_shift = layout_val; 9681 9682 Node* lengthx = ConvI2X(arr_length); 9683 Node* headerx = ConvI2X(header_size); 9684 9685 Node* abody = _gvn.transform(new LShiftXNode(lengthx, elem_shift)); 9686 Node* size = _gvn.transform(new AddXNode(headerx, abody)); 9687 if (round_mask != 0) { 9688 size = _gvn.transform(new AndXNode(size, MakeConX(~round_mask))); 9689 } 9690 size = ConvX2L(size); 9691 9692 result_reg->init_req(_array_path, control()); 9693 result_val->init_req(_array_path, size); 9694 } 9695 9696 if (!stopped()) { 9697 // Instance case: the layout helper gives us instance size almost directly, 9698 // but we need to mask out the _lh_instance_slow_path_bit. 9699 Node* size = ConvI2X(layout_val); 9700 assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit"); 9701 Node* mask = MakeConX(~(intptr_t) right_n_bits(LogBytesPerLong)); 9702 size = _gvn.transform(new AndXNode(size, mask)); 9703 size = ConvX2L(size); 9704 9705 result_reg->init_req(_instance_path, control()); 9706 result_val->init_req(_instance_path, size); 9707 } 9708 9709 set_result(result_reg, result_val); 9710 } 9711 9712 return true; 9713 } 9714 9715 //------------------------------- inline_blackhole -------------------------------------- 9716 // 9717 // Make sure all arguments to this node are alive. 9718 // This matches methods that were requested to be blackholed through compile commands. 9719 // 9720 bool LibraryCallKit::inline_blackhole() { 9721 assert(callee()->is_static(), "Should have been checked before: only static methods here"); 9722 assert(callee()->is_empty(), "Should have been checked before: only empty methods here"); 9723 assert(callee()->holder()->is_loaded(), "Should have been checked before: only methods for loaded classes here"); 9724 9725 // Blackhole node pinches only the control, not memory. This allows 9726 // the blackhole to be pinned in the loop that computes blackholed 9727 // values, but have no other side effects, like breaking the optimizations 9728 // across the blackhole. 9729 9730 Node* bh = _gvn.transform(new BlackholeNode(control())); 9731 set_control(_gvn.transform(new ProjNode(bh, TypeFunc::Control))); 9732 9733 // Bind call arguments as blackhole arguments to keep them alive 9734 uint nargs = callee()->arg_size(); 9735 for (uint i = 0; i < nargs; i++) { 9736 bh->add_req(argument(i)); 9737 } 9738 9739 return true; 9740 } 9741 9742 Node* LibraryCallKit::unbox_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* box) { 9743 const TypeInstPtr* box_type = _gvn.type(box)->isa_instptr(); 9744 if (box_type == nullptr || box_type->instance_klass() != float16_box_type->instance_klass()) { 9745 return nullptr; // box klass is not Float16 9746 } 9747 9748 // Null check; get notnull casted pointer 9749 Node* null_ctl = top(); 9750 Node* not_null_box = null_check_oop(box, &null_ctl, true); 9751 // If not_null_box is dead, only null-path is taken 9752 if (stopped()) { 9753 set_control(null_ctl); 9754 return nullptr; 9755 } 9756 assert(not_null_box->bottom_type()->is_instptr()->maybe_null() == false, ""); 9757 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 9758 Node* adr = basic_plus_adr(not_null_box, field->offset_in_bytes()); 9759 return access_load_at(not_null_box, adr, adr_type, TypeInt::SHORT, T_SHORT, IN_HEAP); 9760 } 9761 9762 Node* LibraryCallKit::box_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* value) { 9763 PreserveReexecuteState preexecs(this); 9764 jvms()->set_should_reexecute(true); 9765 9766 const TypeKlassPtr* klass_type = float16_box_type->as_klass_type(); 9767 Node* klass_node = makecon(klass_type); 9768 Node* box = new_instance(klass_node); 9769 9770 Node* value_field = basic_plus_adr(box, field->offset_in_bytes()); 9771 const TypePtr* value_adr_type = value_field->bottom_type()->is_ptr(); 9772 9773 Node* field_store = _gvn.transform(access_store_at(box, 9774 value_field, 9775 value_adr_type, 9776 value, 9777 TypeInt::SHORT, 9778 T_SHORT, 9779 IN_HEAP)); 9780 set_memory(field_store, value_adr_type); 9781 return box; 9782 } 9783 9784 bool LibraryCallKit::inline_fp16_operations(vmIntrinsics::ID id, int num_args) { 9785 if (!Matcher::match_rule_supported(Op_ReinterpretS2HF) || 9786 !Matcher::match_rule_supported(Op_ReinterpretHF2S)) { 9787 return false; 9788 } 9789 9790 const TypeInstPtr* box_type = _gvn.type(argument(0))->isa_instptr(); 9791 if (box_type == nullptr || box_type->const_oop() == nullptr) { 9792 return false; 9793 } 9794 9795 ciInstanceKlass* float16_klass = box_type->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); 9796 const TypeInstPtr* float16_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, float16_klass); 9797 ciField* field = float16_klass->get_field_by_name(ciSymbols::value_name(), 9798 ciSymbols::short_signature(), 9799 false); 9800 assert(field != nullptr, ""); 9801 9802 // Transformed nodes 9803 Node* fld1 = nullptr; 9804 Node* fld2 = nullptr; 9805 Node* fld3 = nullptr; 9806 switch(num_args) { 9807 case 3: 9808 fld3 = unbox_fp16_value(float16_box_type, field, argument(3)); 9809 if (fld3 == nullptr) { 9810 return false; 9811 } 9812 fld3 = _gvn.transform(new ReinterpretS2HFNode(fld3)); 9813 // fall-through 9814 case 2: 9815 fld2 = unbox_fp16_value(float16_box_type, field, argument(2)); 9816 if (fld2 == nullptr) { 9817 return false; 9818 } 9819 fld2 = _gvn.transform(new ReinterpretS2HFNode(fld2)); 9820 // fall-through 9821 case 1: 9822 fld1 = unbox_fp16_value(float16_box_type, field, argument(1)); 9823 if (fld1 == nullptr) { 9824 return false; 9825 } 9826 fld1 = _gvn.transform(new ReinterpretS2HFNode(fld1)); 9827 break; 9828 default: fatal("Unsupported number of arguments %d", num_args); 9829 } 9830 9831 Node* result = nullptr; 9832 switch (id) { 9833 // Unary operations 9834 case vmIntrinsics::_sqrt_float16: 9835 result = _gvn.transform(new SqrtHFNode(C, control(), fld1)); 9836 break; 9837 // Ternary operations 9838 case vmIntrinsics::_fma_float16: 9839 result = _gvn.transform(new FmaHFNode(fld1, fld2, fld3)); 9840 break; 9841 default: 9842 fatal_unexpected_iid(id); 9843 break; 9844 } 9845 result = _gvn.transform(new ReinterpretHF2SNode(result)); 9846 set_result(box_fp16_value(float16_box_type, field, result)); 9847 return true; 9848 } 9849