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/ciUtilities.inline.hpp" 30 #include "ci/ciSymbols.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/library_call.hpp" 52 #include "opto/inlinetypenode.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/runtime.hpp" 60 #include "opto/rootnode.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 if (jvms->has_method()) { 150 // Not a root compile. 151 const char* msg; 152 if (callee->intrinsic_candidate()) { 153 msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)"; 154 } else { 155 msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated" 156 : "failed to inline (intrinsic), method not annotated"; 157 } 158 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::FAILURE, msg); 159 C->inline_printer()->record(callee, jvms, InliningResult::FAILURE, msg); 160 } else { 161 // Root compile 162 ResourceMark rm; 163 stringStream msg_stream; 164 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 165 vmIntrinsics::name_at(intrinsic_id()), 166 is_virtual() ? " (virtual)" : "", bci); 167 const char *msg = msg_stream.freeze(); 168 log_debug(jit, inlining)("%s", msg); 169 if (C->print_intrinsics() || C->print_inlining()) { 170 tty->print("%s", msg); 171 } 172 } 173 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 174 175 return nullptr; 176 } 177 178 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) { 179 LibraryCallKit kit(jvms, this); 180 Compile* C = kit.C; 181 int nodes = C->unique(); 182 _last_predicate = predicate; 183 #ifndef PRODUCT 184 assert(is_predicated() && predicate < predicates_count(), "sanity"); 185 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 186 char buf[1000]; 187 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 188 tty->print_cr("Predicate for intrinsic %s", str); 189 } 190 #endif 191 ciMethod* callee = kit.callee(); 192 const int bci = kit.bci(); 193 194 Node* slow_ctl = kit.try_to_predicate(predicate); 195 if (!kit.failing()) { 196 const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)" 197 : "(intrinsic, predicate)"; 198 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, InliningResult::SUCCESS, inline_msg); 199 C->inline_printer()->record(callee, jvms, InliningResult::SUCCESS, inline_msg); 200 201 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 202 if (C->log()) { 203 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 204 vmIntrinsics::name_at(intrinsic_id()), 205 (is_virtual() ? " virtual='1'" : ""), 206 C->unique() - nodes); 207 } 208 return slow_ctl; // Could be null if the check folds. 209 } 210 211 // The intrinsic bailed out 212 if (jvms->has_method()) { 213 // Not a root compile. 214 const char* msg = "failed to generate predicate for intrinsic"; 215 CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, InliningResult::FAILURE, msg); 216 C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg); 217 } else { 218 // Root compile 219 ResourceMark rm; 220 stringStream msg_stream; 221 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 222 vmIntrinsics::name_at(intrinsic_id()), 223 is_virtual() ? " (virtual)" : "", bci); 224 const char *msg = msg_stream.freeze(); 225 log_debug(jit, inlining)("%s", msg); 226 C->inline_printer()->record(kit.callee(), jvms, InliningResult::FAILURE, msg); 227 } 228 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 229 return nullptr; 230 } 231 232 bool LibraryCallKit::try_to_inline(int predicate) { 233 // Handle symbolic names for otherwise undistinguished boolean switches: 234 const bool is_store = true; 235 const bool is_compress = true; 236 const bool is_static = true; 237 const bool is_volatile = true; 238 239 if (!jvms()->has_method()) { 240 // Root JVMState has a null method. 241 assert(map()->memory()->Opcode() == Op_Parm, ""); 242 // Insert the memory aliasing node 243 set_all_memory(reset_memory()); 244 } 245 assert(merged_memory(), ""); 246 247 switch (intrinsic_id()) { 248 case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 249 case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static); 250 case vmIntrinsics::_getClass: return inline_native_getClass(); 251 252 case vmIntrinsics::_ceil: 253 case vmIntrinsics::_floor: 254 case vmIntrinsics::_rint: 255 case vmIntrinsics::_dsin: 256 case vmIntrinsics::_dcos: 257 case vmIntrinsics::_dtan: 258 case vmIntrinsics::_dtanh: 259 case vmIntrinsics::_dabs: 260 case vmIntrinsics::_fabs: 261 case vmIntrinsics::_iabs: 262 case vmIntrinsics::_labs: 263 case vmIntrinsics::_datan2: 264 case vmIntrinsics::_dsqrt: 265 case vmIntrinsics::_dsqrt_strict: 266 case vmIntrinsics::_dexp: 267 case vmIntrinsics::_dlog: 268 case vmIntrinsics::_dlog10: 269 case vmIntrinsics::_dpow: 270 case vmIntrinsics::_dcopySign: 271 case vmIntrinsics::_fcopySign: 272 case vmIntrinsics::_dsignum: 273 case vmIntrinsics::_roundF: 274 case vmIntrinsics::_roundD: 275 case vmIntrinsics::_fsignum: return inline_math_native(intrinsic_id()); 276 277 case vmIntrinsics::_notify: 278 case vmIntrinsics::_notifyAll: 279 return inline_notify(intrinsic_id()); 280 281 case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 282 case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 283 case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 284 case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 285 case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 286 case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 287 case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 288 case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 289 case vmIntrinsics::_multiplyHigh: return inline_math_multiplyHigh(); 290 case vmIntrinsics::_unsignedMultiplyHigh: return inline_math_unsignedMultiplyHigh(); 291 case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 292 case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 293 case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 294 case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 295 296 case vmIntrinsics::_arraycopy: return inline_arraycopy(); 297 298 case vmIntrinsics::_arraySort: return inline_array_sort(); 299 case vmIntrinsics::_arrayPartition: return inline_array_partition(); 300 301 case vmIntrinsics::_compareToL: return inline_string_compareTo(StrIntrinsicNode::LL); 302 case vmIntrinsics::_compareToU: return inline_string_compareTo(StrIntrinsicNode::UU); 303 case vmIntrinsics::_compareToLU: return inline_string_compareTo(StrIntrinsicNode::LU); 304 case vmIntrinsics::_compareToUL: return inline_string_compareTo(StrIntrinsicNode::UL); 305 306 case vmIntrinsics::_indexOfL: return inline_string_indexOf(StrIntrinsicNode::LL); 307 case vmIntrinsics::_indexOfU: return inline_string_indexOf(StrIntrinsicNode::UU); 308 case vmIntrinsics::_indexOfUL: return inline_string_indexOf(StrIntrinsicNode::UL); 309 case vmIntrinsics::_indexOfIL: return inline_string_indexOfI(StrIntrinsicNode::LL); 310 case vmIntrinsics::_indexOfIU: return inline_string_indexOfI(StrIntrinsicNode::UU); 311 case vmIntrinsics::_indexOfIUL: return inline_string_indexOfI(StrIntrinsicNode::UL); 312 case vmIntrinsics::_indexOfU_char: return inline_string_indexOfChar(StrIntrinsicNode::U); 313 case vmIntrinsics::_indexOfL_char: return inline_string_indexOfChar(StrIntrinsicNode::L); 314 315 case vmIntrinsics::_equalsL: return inline_string_equals(StrIntrinsicNode::LL); 316 317 case vmIntrinsics::_vectorizedHashCode: return inline_vectorizedHashCode(); 318 319 case vmIntrinsics::_toBytesStringU: return inline_string_toBytesU(); 320 case vmIntrinsics::_getCharsStringU: return inline_string_getCharsU(); 321 case vmIntrinsics::_getCharStringU: return inline_string_char_access(!is_store); 322 case vmIntrinsics::_putCharStringU: return inline_string_char_access( is_store); 323 324 case vmIntrinsics::_compressStringC: 325 case vmIntrinsics::_compressStringB: return inline_string_copy( is_compress); 326 case vmIntrinsics::_inflateStringC: 327 case vmIntrinsics::_inflateStringB: return inline_string_copy(!is_compress); 328 329 case vmIntrinsics::_makePrivateBuffer: return inline_unsafe_make_private_buffer(); 330 case vmIntrinsics::_finishPrivateBuffer: return inline_unsafe_finish_private_buffer(); 331 case vmIntrinsics::_getReference: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false); 332 case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_store, T_BOOLEAN, Relaxed, false); 333 case vmIntrinsics::_getByte: return inline_unsafe_access(!is_store, T_BYTE, Relaxed, false); 334 case vmIntrinsics::_getShort: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, false); 335 case vmIntrinsics::_getChar: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, false); 336 case vmIntrinsics::_getInt: return inline_unsafe_access(!is_store, T_INT, Relaxed, false); 337 case vmIntrinsics::_getLong: return inline_unsafe_access(!is_store, T_LONG, Relaxed, false); 338 case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_store, T_FLOAT, Relaxed, false); 339 case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_store, T_DOUBLE, Relaxed, false); 340 case vmIntrinsics::_getValue: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false, true); 341 342 case vmIntrinsics::_putReference: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false); 343 case vmIntrinsics::_putBoolean: return inline_unsafe_access( is_store, T_BOOLEAN, Relaxed, false); 344 case vmIntrinsics::_putByte: return inline_unsafe_access( is_store, T_BYTE, Relaxed, false); 345 case vmIntrinsics::_putShort: return inline_unsafe_access( is_store, T_SHORT, Relaxed, false); 346 case vmIntrinsics::_putChar: return inline_unsafe_access( is_store, T_CHAR, Relaxed, false); 347 case vmIntrinsics::_putInt: return inline_unsafe_access( is_store, T_INT, Relaxed, false); 348 case vmIntrinsics::_putLong: return inline_unsafe_access( is_store, T_LONG, Relaxed, false); 349 case vmIntrinsics::_putFloat: return inline_unsafe_access( is_store, T_FLOAT, Relaxed, false); 350 case vmIntrinsics::_putDouble: return inline_unsafe_access( is_store, T_DOUBLE, Relaxed, false); 351 case vmIntrinsics::_putValue: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false, true); 352 353 case vmIntrinsics::_getReferenceVolatile: return inline_unsafe_access(!is_store, T_OBJECT, Volatile, false); 354 case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_store, T_BOOLEAN, Volatile, false); 355 case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_store, T_BYTE, Volatile, false); 356 case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_store, T_SHORT, Volatile, false); 357 case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_store, T_CHAR, Volatile, false); 358 case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_store, T_INT, Volatile, false); 359 case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_store, T_LONG, Volatile, false); 360 case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_store, T_FLOAT, Volatile, false); 361 case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_store, T_DOUBLE, Volatile, false); 362 363 case vmIntrinsics::_putReferenceVolatile: return inline_unsafe_access( is_store, T_OBJECT, Volatile, false); 364 case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access( is_store, T_BOOLEAN, Volatile, false); 365 case vmIntrinsics::_putByteVolatile: return inline_unsafe_access( is_store, T_BYTE, Volatile, false); 366 case vmIntrinsics::_putShortVolatile: return inline_unsafe_access( is_store, T_SHORT, Volatile, false); 367 case vmIntrinsics::_putCharVolatile: return inline_unsafe_access( is_store, T_CHAR, Volatile, false); 368 case vmIntrinsics::_putIntVolatile: return inline_unsafe_access( is_store, T_INT, Volatile, false); 369 case vmIntrinsics::_putLongVolatile: return inline_unsafe_access( is_store, T_LONG, Volatile, false); 370 case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access( is_store, T_FLOAT, Volatile, false); 371 case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access( is_store, T_DOUBLE, Volatile, false); 372 373 case vmIntrinsics::_getShortUnaligned: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, true); 374 case vmIntrinsics::_getCharUnaligned: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, true); 375 case vmIntrinsics::_getIntUnaligned: return inline_unsafe_access(!is_store, T_INT, Relaxed, true); 376 case vmIntrinsics::_getLongUnaligned: return inline_unsafe_access(!is_store, T_LONG, Relaxed, true); 377 378 case vmIntrinsics::_putShortUnaligned: return inline_unsafe_access( is_store, T_SHORT, Relaxed, true); 379 case vmIntrinsics::_putCharUnaligned: return inline_unsafe_access( is_store, T_CHAR, Relaxed, true); 380 case vmIntrinsics::_putIntUnaligned: return inline_unsafe_access( is_store, T_INT, Relaxed, true); 381 case vmIntrinsics::_putLongUnaligned: return inline_unsafe_access( is_store, T_LONG, Relaxed, true); 382 383 case vmIntrinsics::_getReferenceAcquire: return inline_unsafe_access(!is_store, T_OBJECT, Acquire, false); 384 case vmIntrinsics::_getBooleanAcquire: return inline_unsafe_access(!is_store, T_BOOLEAN, Acquire, false); 385 case vmIntrinsics::_getByteAcquire: return inline_unsafe_access(!is_store, T_BYTE, Acquire, false); 386 case vmIntrinsics::_getShortAcquire: return inline_unsafe_access(!is_store, T_SHORT, Acquire, false); 387 case vmIntrinsics::_getCharAcquire: return inline_unsafe_access(!is_store, T_CHAR, Acquire, false); 388 case vmIntrinsics::_getIntAcquire: return inline_unsafe_access(!is_store, T_INT, Acquire, false); 389 case vmIntrinsics::_getLongAcquire: return inline_unsafe_access(!is_store, T_LONG, Acquire, false); 390 case vmIntrinsics::_getFloatAcquire: return inline_unsafe_access(!is_store, T_FLOAT, Acquire, false); 391 case vmIntrinsics::_getDoubleAcquire: return inline_unsafe_access(!is_store, T_DOUBLE, Acquire, false); 392 393 case vmIntrinsics::_putReferenceRelease: return inline_unsafe_access( is_store, T_OBJECT, Release, false); 394 case vmIntrinsics::_putBooleanRelease: return inline_unsafe_access( is_store, T_BOOLEAN, Release, false); 395 case vmIntrinsics::_putByteRelease: return inline_unsafe_access( is_store, T_BYTE, Release, false); 396 case vmIntrinsics::_putShortRelease: return inline_unsafe_access( is_store, T_SHORT, Release, false); 397 case vmIntrinsics::_putCharRelease: return inline_unsafe_access( is_store, T_CHAR, Release, false); 398 case vmIntrinsics::_putIntRelease: return inline_unsafe_access( is_store, T_INT, Release, false); 399 case vmIntrinsics::_putLongRelease: return inline_unsafe_access( is_store, T_LONG, Release, false); 400 case vmIntrinsics::_putFloatRelease: return inline_unsafe_access( is_store, T_FLOAT, Release, false); 401 case vmIntrinsics::_putDoubleRelease: return inline_unsafe_access( is_store, T_DOUBLE, Release, false); 402 403 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false); 404 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false); 405 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false); 406 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false); 407 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false); 408 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false); 409 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false); 410 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false); 411 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false); 412 413 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false); 414 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false); 415 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false); 416 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false); 417 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false); 418 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false); 419 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false); 420 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false); 421 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false); 422 423 case vmIntrinsics::_getFlatValue: return inline_unsafe_flat_access(!is_store, Relaxed); 424 case vmIntrinsics::_putFlatValue: return inline_unsafe_flat_access( is_store, Relaxed); 425 426 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile); 427 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile); 428 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile); 429 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile); 430 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile); 431 432 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed); 433 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire); 434 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release); 435 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile); 436 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed); 437 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire); 438 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release); 439 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile); 440 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed); 441 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire); 442 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release); 443 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile); 444 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed); 445 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire); 446 case vmIntrinsics::_weakCompareAndSetIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Release); 447 case vmIntrinsics::_weakCompareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Volatile); 448 case vmIntrinsics::_weakCompareAndSetLongPlain: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Relaxed); 449 case vmIntrinsics::_weakCompareAndSetLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Acquire); 450 case vmIntrinsics::_weakCompareAndSetLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Release); 451 case vmIntrinsics::_weakCompareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Volatile); 452 453 case vmIntrinsics::_compareAndExchangeReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Volatile); 454 case vmIntrinsics::_compareAndExchangeReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Acquire); 455 case vmIntrinsics::_compareAndExchangeReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Release); 456 case vmIntrinsics::_compareAndExchangeByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Volatile); 457 case vmIntrinsics::_compareAndExchangeByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Acquire); 458 case vmIntrinsics::_compareAndExchangeByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Release); 459 case vmIntrinsics::_compareAndExchangeShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Volatile); 460 case vmIntrinsics::_compareAndExchangeShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Acquire); 461 case vmIntrinsics::_compareAndExchangeShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Release); 462 case vmIntrinsics::_compareAndExchangeInt: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Volatile); 463 case vmIntrinsics::_compareAndExchangeIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Acquire); 464 case vmIntrinsics::_compareAndExchangeIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Release); 465 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile); 466 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire); 467 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release); 468 469 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile); 470 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile); 471 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile); 472 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile); 473 474 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile); 475 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile); 476 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile); 477 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile); 478 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile); 479 480 case vmIntrinsics::_loadFence: 481 case vmIntrinsics::_storeFence: 482 case vmIntrinsics::_storeStoreFence: 483 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id()); 484 485 case vmIntrinsics::_onSpinWait: return inline_onspinwait(); 486 487 case vmIntrinsics::_currentCarrierThread: return inline_native_currentCarrierThread(); 488 case vmIntrinsics::_currentThread: return inline_native_currentThread(); 489 case vmIntrinsics::_setCurrentThread: return inline_native_setCurrentThread(); 490 491 case vmIntrinsics::_scopedValueCache: return inline_native_scopedValueCache(); 492 case vmIntrinsics::_setScopedValueCache: return inline_native_setScopedValueCache(); 493 494 case vmIntrinsics::_Continuation_pin: return inline_native_Continuation_pinning(false); 495 case vmIntrinsics::_Continuation_unpin: return inline_native_Continuation_pinning(true); 496 497 #if INCLUDE_JVMTI 498 case vmIntrinsics::_notifyJvmtiVThreadStart: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_start()), 499 "notifyJvmtiStart", true, false); 500 case vmIntrinsics::_notifyJvmtiVThreadEnd: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_end()), 501 "notifyJvmtiEnd", false, true); 502 case vmIntrinsics::_notifyJvmtiVThreadMount: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_mount()), 503 "notifyJvmtiMount", false, false); 504 case vmIntrinsics::_notifyJvmtiVThreadUnmount: return inline_native_notify_jvmti_funcs(CAST_FROM_FN_PTR(address, OptoRuntime::notify_jvmti_vthread_unmount()), 505 "notifyJvmtiUnmount", false, false); 506 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend: return inline_native_notify_jvmti_sync(); 507 #endif 508 509 #ifdef JFR_HAVE_INTRINSICS 510 case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JfrTime::time_function()), "counterTime"); 511 case vmIntrinsics::_getEventWriter: return inline_native_getEventWriter(); 512 case vmIntrinsics::_jvm_commit: return inline_native_jvm_commit(); 513 #endif 514 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis"); 515 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime"); 516 case vmIntrinsics::_writeback0: return inline_unsafe_writeback0(); 517 case vmIntrinsics::_writebackPreSync0: return inline_unsafe_writebackSync0(true); 518 case vmIntrinsics::_writebackPostSync0: return inline_unsafe_writebackSync0(false); 519 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate(); 520 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory(); 521 case vmIntrinsics::_isFlatArray: return inline_unsafe_isFlatArray(); 522 case vmIntrinsics::_setMemory: return inline_unsafe_setMemory(); 523 case vmIntrinsics::_getLength: return inline_native_getLength(); 524 case vmIntrinsics::_copyOf: return inline_array_copyOf(false); 525 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true); 526 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL); 527 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU); 528 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(T_INT); 529 case vmIntrinsics::_Preconditions_checkLongIndex: return inline_preconditions_checkIndex(T_LONG); 530 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual()); 531 532 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true); 533 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false); 534 case vmIntrinsics::_newNullRestrictedNonAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ false); 535 case vmIntrinsics::_newNullRestrictedAtomicArray: return inline_newArray(/* null_free */ true, /* atomic */ true); 536 case vmIntrinsics::_newNullableAtomicArray: return inline_newArray(/* null_free */ false, /* atomic */ true); 537 538 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check(); 539 540 case vmIntrinsics::_isInstance: 541 case vmIntrinsics::_isHidden: 542 case vmIntrinsics::_getSuperclass: 543 case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id()); 544 545 case vmIntrinsics::_floatToRawIntBits: 546 case vmIntrinsics::_floatToIntBits: 547 case vmIntrinsics::_intBitsToFloat: 548 case vmIntrinsics::_doubleToRawLongBits: 549 case vmIntrinsics::_doubleToLongBits: 550 case vmIntrinsics::_longBitsToDouble: 551 case vmIntrinsics::_floatToFloat16: 552 case vmIntrinsics::_float16ToFloat: return inline_fp_conversions(intrinsic_id()); 553 case vmIntrinsics::_sqrt_float16: return inline_fp16_operations(intrinsic_id(), 1); 554 case vmIntrinsics::_fma_float16: return inline_fp16_operations(intrinsic_id(), 3); 555 case vmIntrinsics::_floatIsFinite: 556 case vmIntrinsics::_floatIsInfinite: 557 case vmIntrinsics::_doubleIsFinite: 558 case vmIntrinsics::_doubleIsInfinite: return inline_fp_range_check(intrinsic_id()); 559 560 case vmIntrinsics::_numberOfLeadingZeros_i: 561 case vmIntrinsics::_numberOfLeadingZeros_l: 562 case vmIntrinsics::_numberOfTrailingZeros_i: 563 case vmIntrinsics::_numberOfTrailingZeros_l: 564 case vmIntrinsics::_bitCount_i: 565 case vmIntrinsics::_bitCount_l: 566 case vmIntrinsics::_reverse_i: 567 case vmIntrinsics::_reverse_l: 568 case vmIntrinsics::_reverseBytes_i: 569 case vmIntrinsics::_reverseBytes_l: 570 case vmIntrinsics::_reverseBytes_s: 571 case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id()); 572 573 case vmIntrinsics::_compress_i: 574 case vmIntrinsics::_compress_l: 575 case vmIntrinsics::_expand_i: 576 case vmIntrinsics::_expand_l: return inline_bitshuffle_methods(intrinsic_id()); 577 578 case vmIntrinsics::_compareUnsigned_i: 579 case vmIntrinsics::_compareUnsigned_l: return inline_compare_unsigned(intrinsic_id()); 580 581 case vmIntrinsics::_divideUnsigned_i: 582 case vmIntrinsics::_divideUnsigned_l: 583 case vmIntrinsics::_remainderUnsigned_i: 584 case vmIntrinsics::_remainderUnsigned_l: return inline_divmod_methods(intrinsic_id()); 585 586 case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass(); 587 588 case vmIntrinsics::_Reference_get: return inline_reference_get(); 589 case vmIntrinsics::_Reference_refersTo0: return inline_reference_refersTo0(false); 590 case vmIntrinsics::_PhantomReference_refersTo0: return inline_reference_refersTo0(true); 591 case vmIntrinsics::_Reference_clear0: return inline_reference_clear0(false); 592 case vmIntrinsics::_PhantomReference_clear0: return inline_reference_clear0(true); 593 594 case vmIntrinsics::_Class_cast: return inline_Class_cast(); 595 596 case vmIntrinsics::_aescrypt_encryptBlock: 597 case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id()); 598 599 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 600 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 601 return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 602 603 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 604 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 605 return inline_electronicCodeBook_AESCrypt(intrinsic_id()); 606 607 case vmIntrinsics::_counterMode_AESCrypt: 608 return inline_counterMode_AESCrypt(intrinsic_id()); 609 610 case vmIntrinsics::_galoisCounterMode_AESCrypt: 611 return inline_galoisCounterMode_AESCrypt(); 612 613 case vmIntrinsics::_md5_implCompress: 614 case vmIntrinsics::_sha_implCompress: 615 case vmIntrinsics::_sha2_implCompress: 616 case vmIntrinsics::_sha5_implCompress: 617 case vmIntrinsics::_sha3_implCompress: 618 return inline_digestBase_implCompress(intrinsic_id()); 619 case vmIntrinsics::_double_keccak: 620 return inline_double_keccak(); 621 622 case vmIntrinsics::_digestBase_implCompressMB: 623 return inline_digestBase_implCompressMB(predicate); 624 625 case vmIntrinsics::_multiplyToLen: 626 return inline_multiplyToLen(); 627 628 case vmIntrinsics::_squareToLen: 629 return inline_squareToLen(); 630 631 case vmIntrinsics::_mulAdd: 632 return inline_mulAdd(); 633 634 case vmIntrinsics::_montgomeryMultiply: 635 return inline_montgomeryMultiply(); 636 case vmIntrinsics::_montgomerySquare: 637 return inline_montgomerySquare(); 638 639 case vmIntrinsics::_bigIntegerRightShiftWorker: 640 return inline_bigIntegerShift(true); 641 case vmIntrinsics::_bigIntegerLeftShiftWorker: 642 return inline_bigIntegerShift(false); 643 644 case vmIntrinsics::_vectorizedMismatch: 645 return inline_vectorizedMismatch(); 646 647 case vmIntrinsics::_ghash_processBlocks: 648 return inline_ghash_processBlocks(); 649 case vmIntrinsics::_chacha20Block: 650 return inline_chacha20Block(); 651 case vmIntrinsics::_kyberNtt: 652 return inline_kyberNtt(); 653 case vmIntrinsics::_kyberInverseNtt: 654 return inline_kyberInverseNtt(); 655 case vmIntrinsics::_kyberNttMult: 656 return inline_kyberNttMult(); 657 case vmIntrinsics::_kyberAddPoly_2: 658 return inline_kyberAddPoly_2(); 659 case vmIntrinsics::_kyberAddPoly_3: 660 return inline_kyberAddPoly_3(); 661 case vmIntrinsics::_kyber12To16: 662 return inline_kyber12To16(); 663 case vmIntrinsics::_kyberBarrettReduce: 664 return inline_kyberBarrettReduce(); 665 case vmIntrinsics::_dilithiumAlmostNtt: 666 return inline_dilithiumAlmostNtt(); 667 case vmIntrinsics::_dilithiumAlmostInverseNtt: 668 return inline_dilithiumAlmostInverseNtt(); 669 case vmIntrinsics::_dilithiumNttMult: 670 return inline_dilithiumNttMult(); 671 case vmIntrinsics::_dilithiumMontMulByConstant: 672 return inline_dilithiumMontMulByConstant(); 673 case vmIntrinsics::_dilithiumDecomposePoly: 674 return inline_dilithiumDecomposePoly(); 675 case vmIntrinsics::_base64_encodeBlock: 676 return inline_base64_encodeBlock(); 677 case vmIntrinsics::_base64_decodeBlock: 678 return inline_base64_decodeBlock(); 679 case vmIntrinsics::_poly1305_processBlocks: 680 return inline_poly1305_processBlocks(); 681 case vmIntrinsics::_intpoly_montgomeryMult_P256: 682 return inline_intpoly_montgomeryMult_P256(); 683 case vmIntrinsics::_intpoly_assign: 684 return inline_intpoly_assign(); 685 case vmIntrinsics::_encodeISOArray: 686 case vmIntrinsics::_encodeByteISOArray: 687 return inline_encodeISOArray(false); 688 case vmIntrinsics::_encodeAsciiArray: 689 return inline_encodeISOArray(true); 690 691 case vmIntrinsics::_updateCRC32: 692 return inline_updateCRC32(); 693 case vmIntrinsics::_updateBytesCRC32: 694 return inline_updateBytesCRC32(); 695 case vmIntrinsics::_updateByteBufferCRC32: 696 return inline_updateByteBufferCRC32(); 697 698 case vmIntrinsics::_updateBytesCRC32C: 699 return inline_updateBytesCRC32C(); 700 case vmIntrinsics::_updateDirectByteBufferCRC32C: 701 return inline_updateDirectByteBufferCRC32C(); 702 703 case vmIntrinsics::_updateBytesAdler32: 704 return inline_updateBytesAdler32(); 705 case vmIntrinsics::_updateByteBufferAdler32: 706 return inline_updateByteBufferAdler32(); 707 708 case vmIntrinsics::_profileBoolean: 709 return inline_profileBoolean(); 710 case vmIntrinsics::_isCompileConstant: 711 return inline_isCompileConstant(); 712 713 case vmIntrinsics::_countPositives: 714 return inline_countPositives(); 715 716 case vmIntrinsics::_fmaD: 717 case vmIntrinsics::_fmaF: 718 return inline_fma(intrinsic_id()); 719 720 case vmIntrinsics::_isDigit: 721 case vmIntrinsics::_isLowerCase: 722 case vmIntrinsics::_isUpperCase: 723 case vmIntrinsics::_isWhitespace: 724 return inline_character_compare(intrinsic_id()); 725 726 case vmIntrinsics::_min: 727 case vmIntrinsics::_max: 728 case vmIntrinsics::_min_strict: 729 case vmIntrinsics::_max_strict: 730 case vmIntrinsics::_minL: 731 case vmIntrinsics::_maxL: 732 case vmIntrinsics::_minF: 733 case vmIntrinsics::_maxF: 734 case vmIntrinsics::_minD: 735 case vmIntrinsics::_maxD: 736 case vmIntrinsics::_minF_strict: 737 case vmIntrinsics::_maxF_strict: 738 case vmIntrinsics::_minD_strict: 739 case vmIntrinsics::_maxD_strict: 740 return inline_min_max(intrinsic_id()); 741 742 case vmIntrinsics::_VectorUnaryOp: 743 return inline_vector_nary_operation(1); 744 case vmIntrinsics::_VectorBinaryOp: 745 return inline_vector_nary_operation(2); 746 case vmIntrinsics::_VectorUnaryLibOp: 747 return inline_vector_call(1); 748 case vmIntrinsics::_VectorBinaryLibOp: 749 return inline_vector_call(2); 750 case vmIntrinsics::_VectorTernaryOp: 751 return inline_vector_nary_operation(3); 752 case vmIntrinsics::_VectorFromBitsCoerced: 753 return inline_vector_frombits_coerced(); 754 case vmIntrinsics::_VectorMaskOp: 755 return inline_vector_mask_operation(); 756 case vmIntrinsics::_VectorLoadOp: 757 return inline_vector_mem_operation(/*is_store=*/false); 758 case vmIntrinsics::_VectorLoadMaskedOp: 759 return inline_vector_mem_masked_operation(/*is_store*/false); 760 case vmIntrinsics::_VectorStoreOp: 761 return inline_vector_mem_operation(/*is_store=*/true); 762 case vmIntrinsics::_VectorStoreMaskedOp: 763 return inline_vector_mem_masked_operation(/*is_store=*/true); 764 case vmIntrinsics::_VectorGatherOp: 765 return inline_vector_gather_scatter(/*is_scatter*/ false); 766 case vmIntrinsics::_VectorScatterOp: 767 return inline_vector_gather_scatter(/*is_scatter*/ true); 768 case vmIntrinsics::_VectorReductionCoerced: 769 return inline_vector_reduction(); 770 case vmIntrinsics::_VectorTest: 771 return inline_vector_test(); 772 case vmIntrinsics::_VectorBlend: 773 return inline_vector_blend(); 774 case vmIntrinsics::_VectorRearrange: 775 return inline_vector_rearrange(); 776 case vmIntrinsics::_VectorSelectFrom: 777 return inline_vector_select_from(); 778 case vmIntrinsics::_VectorCompare: 779 return inline_vector_compare(); 780 case vmIntrinsics::_VectorBroadcastInt: 781 return inline_vector_broadcast_int(); 782 case vmIntrinsics::_VectorConvert: 783 return inline_vector_convert(); 784 case vmIntrinsics::_VectorInsert: 785 return inline_vector_insert(); 786 case vmIntrinsics::_VectorExtract: 787 return inline_vector_extract(); 788 case vmIntrinsics::_VectorCompressExpand: 789 return inline_vector_compress_expand(); 790 case vmIntrinsics::_VectorSelectFromTwoVectorOp: 791 return inline_vector_select_from_two_vectors(); 792 case vmIntrinsics::_IndexVector: 793 return inline_index_vector(); 794 case vmIntrinsics::_IndexPartiallyInUpperRange: 795 return inline_index_partially_in_upper_range(); 796 797 case vmIntrinsics::_getObjectSize: 798 return inline_getObjectSize(); 799 800 case vmIntrinsics::_blackhole: 801 return inline_blackhole(); 802 803 default: 804 // If you get here, it may be that someone has added a new intrinsic 805 // to the list in vmIntrinsics.hpp without implementing it here. 806 #ifndef PRODUCT 807 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 808 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 809 vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id())); 810 } 811 #endif 812 return false; 813 } 814 } 815 816 Node* LibraryCallKit::try_to_predicate(int predicate) { 817 if (!jvms()->has_method()) { 818 // Root JVMState has a null method. 819 assert(map()->memory()->Opcode() == Op_Parm, ""); 820 // Insert the memory aliasing node 821 set_all_memory(reset_memory()); 822 } 823 assert(merged_memory(), ""); 824 825 switch (intrinsic_id()) { 826 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 827 return inline_cipherBlockChaining_AESCrypt_predicate(false); 828 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 829 return inline_cipherBlockChaining_AESCrypt_predicate(true); 830 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 831 return inline_electronicCodeBook_AESCrypt_predicate(false); 832 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 833 return inline_electronicCodeBook_AESCrypt_predicate(true); 834 case vmIntrinsics::_counterMode_AESCrypt: 835 return inline_counterMode_AESCrypt_predicate(); 836 case vmIntrinsics::_digestBase_implCompressMB: 837 return inline_digestBase_implCompressMB_predicate(predicate); 838 case vmIntrinsics::_galoisCounterMode_AESCrypt: 839 return inline_galoisCounterMode_AESCrypt_predicate(); 840 841 default: 842 // If you get here, it may be that someone has added a new intrinsic 843 // to the list in vmIntrinsics.hpp without implementing it here. 844 #ifndef PRODUCT 845 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 846 tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)", 847 vmIntrinsics::name_at(intrinsic_id()), vmIntrinsics::as_int(intrinsic_id())); 848 } 849 #endif 850 Node* slow_ctl = control(); 851 set_control(top()); // No fast path intrinsic 852 return slow_ctl; 853 } 854 } 855 856 //------------------------------set_result------------------------------- 857 // Helper function for finishing intrinsics. 858 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) { 859 record_for_igvn(region); 860 set_control(_gvn.transform(region)); 861 set_result( _gvn.transform(value)); 862 assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity"); 863 } 864 865 //------------------------------generate_guard--------------------------- 866 // Helper function for generating guarded fast-slow graph structures. 867 // The given 'test', if true, guards a slow path. If the test fails 868 // then a fast path can be taken. (We generally hope it fails.) 869 // In all cases, GraphKit::control() is updated to the fast path. 870 // The returned value represents the control for the slow path. 871 // The return value is never 'top'; it is either a valid control 872 // or null if it is obvious that the slow path can never be taken. 873 // Also, if region and the slow control are not null, the slow edge 874 // is appended to the region. 875 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 876 if (stopped()) { 877 // Already short circuited. 878 return nullptr; 879 } 880 881 // Build an if node and its projections. 882 // If test is true we take the slow path, which we assume is uncommon. 883 if (_gvn.type(test) == TypeInt::ZERO) { 884 // The slow branch is never taken. No need to build this guard. 885 return nullptr; 886 } 887 888 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 889 890 Node* if_slow = _gvn.transform(new IfTrueNode(iff)); 891 if (if_slow == top()) { 892 // The slow branch is never taken. No need to build this guard. 893 return nullptr; 894 } 895 896 if (region != nullptr) 897 region->add_req(if_slow); 898 899 Node* if_fast = _gvn.transform(new IfFalseNode(iff)); 900 set_control(if_fast); 901 902 return if_slow; 903 } 904 905 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 906 return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 907 } 908 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 909 return generate_guard(test, region, PROB_FAIR); 910 } 911 912 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 913 Node* *pos_index) { 914 if (stopped()) 915 return nullptr; // already stopped 916 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 917 return nullptr; // index is already adequately typed 918 Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0))); 919 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 920 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 921 if (is_neg != nullptr && pos_index != nullptr) { 922 // Emulate effect of Parse::adjust_map_after_if. 923 Node* ccast = new CastIINode(control(), index, TypeInt::POS); 924 (*pos_index) = _gvn.transform(ccast); 925 } 926 return is_neg; 927 } 928 929 // Make sure that 'position' is a valid limit index, in [0..length]. 930 // There are two equivalent plans for checking this: 931 // A. (offset + copyLength) unsigned<= arrayLength 932 // B. offset <= (arrayLength - copyLength) 933 // We require that all of the values above, except for the sum and 934 // difference, are already known to be non-negative. 935 // Plan A is robust in the face of overflow, if offset and copyLength 936 // are both hugely positive. 937 // 938 // Plan B is less direct and intuitive, but it does not overflow at 939 // all, since the difference of two non-negatives is always 940 // representable. Whenever Java methods must perform the equivalent 941 // check they generally use Plan B instead of Plan A. 942 // For the moment we use Plan A. 943 inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 944 Node* subseq_length, 945 Node* array_length, 946 RegionNode* region) { 947 if (stopped()) 948 return nullptr; // already stopped 949 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 950 if (zero_offset && subseq_length->eqv_uncast(array_length)) 951 return nullptr; // common case of whole-array copy 952 Node* last = subseq_length; 953 if (!zero_offset) // last += offset 954 last = _gvn.transform(new AddINode(last, offset)); 955 Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last)); 956 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 957 Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 958 return is_over; 959 } 960 961 // Emit range checks for the given String.value byte array 962 void LibraryCallKit::generate_string_range_check(Node* array, Node* offset, Node* count, bool char_count) { 963 if (stopped()) { 964 return; // already stopped 965 } 966 RegionNode* bailout = new RegionNode(1); 967 record_for_igvn(bailout); 968 if (char_count) { 969 // Convert char count to byte count 970 count = _gvn.transform(new LShiftINode(count, intcon(1))); 971 } 972 973 // Offset and count must not be negative 974 generate_negative_guard(offset, bailout); 975 generate_negative_guard(count, bailout); 976 // Offset + count must not exceed length of array 977 generate_limit_guard(offset, count, load_array_length(array), bailout); 978 979 if (bailout->req() > 1) { 980 PreserveJVMState pjvms(this); 981 set_control(_gvn.transform(bailout)); 982 uncommon_trap(Deoptimization::Reason_intrinsic, 983 Deoptimization::Action_maybe_recompile); 984 } 985 } 986 987 Node* LibraryCallKit::current_thread_helper(Node*& tls_output, ByteSize handle_offset, 988 bool is_immutable) { 989 ciKlass* thread_klass = env()->Thread_klass(); 990 const Type* thread_type 991 = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 992 993 Node* thread = _gvn.transform(new ThreadLocalNode()); 994 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(handle_offset)); 995 tls_output = thread; 996 997 Node* thread_obj_handle 998 = (is_immutable 999 ? LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(), 1000 TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered) 1001 : make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered)); 1002 thread_obj_handle = _gvn.transform(thread_obj_handle); 1003 1004 DecoratorSet decorators = IN_NATIVE; 1005 if (is_immutable) { 1006 decorators |= C2_IMMUTABLE_MEMORY; 1007 } 1008 return access_load(thread_obj_handle, thread_type, T_OBJECT, decorators); 1009 } 1010 1011 //--------------------------generate_current_thread-------------------- 1012 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1013 return current_thread_helper(tls_output, JavaThread::threadObj_offset(), 1014 /*is_immutable*/false); 1015 } 1016 1017 //--------------------------generate_virtual_thread-------------------- 1018 Node* LibraryCallKit::generate_virtual_thread(Node* tls_output) { 1019 return current_thread_helper(tls_output, JavaThread::vthread_offset(), 1020 !C->method()->changes_current_thread()); 1021 } 1022 1023 //------------------------------make_string_method_node------------------------ 1024 // Helper method for String intrinsic functions. This version is called with 1025 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded 1026 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes 1027 // containing the lengths of str1 and str2. 1028 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) { 1029 Node* result = nullptr; 1030 switch (opcode) { 1031 case Op_StrIndexOf: 1032 result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES), 1033 str1_start, cnt1, str2_start, cnt2, ae); 1034 break; 1035 case Op_StrComp: 1036 result = new StrCompNode(control(), memory(TypeAryPtr::BYTES), 1037 str1_start, cnt1, str2_start, cnt2, ae); 1038 break; 1039 case Op_StrEquals: 1040 // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals'). 1041 // Use the constant length if there is one because optimized match rule may exist. 1042 result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES), 1043 str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae); 1044 break; 1045 default: 1046 ShouldNotReachHere(); 1047 return nullptr; 1048 } 1049 1050 // All these intrinsics have checks. 1051 C->set_has_split_ifs(true); // Has chance for split-if optimization 1052 clear_upper_avx(); 1053 1054 return _gvn.transform(result); 1055 } 1056 1057 //------------------------------inline_string_compareTo------------------------ 1058 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) { 1059 Node* arg1 = argument(0); 1060 Node* arg2 = argument(1); 1061 1062 arg1 = must_be_not_null(arg1, true); 1063 arg2 = must_be_not_null(arg2, true); 1064 1065 // Get start addr and length of first argument 1066 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1067 Node* arg1_cnt = load_array_length(arg1); 1068 1069 // Get start addr and length of second argument 1070 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1071 Node* arg2_cnt = load_array_length(arg2); 1072 1073 Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1074 set_result(result); 1075 return true; 1076 } 1077 1078 //------------------------------inline_string_equals------------------------ 1079 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) { 1080 Node* arg1 = argument(0); 1081 Node* arg2 = argument(1); 1082 1083 // paths (plus control) merge 1084 RegionNode* region = new RegionNode(3); 1085 Node* phi = new PhiNode(region, TypeInt::BOOL); 1086 1087 if (!stopped()) { 1088 1089 arg1 = must_be_not_null(arg1, true); 1090 arg2 = must_be_not_null(arg2, true); 1091 1092 // Get start addr and length of first argument 1093 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1094 Node* arg1_cnt = load_array_length(arg1); 1095 1096 // Get start addr and length of second argument 1097 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1098 Node* arg2_cnt = load_array_length(arg2); 1099 1100 // Check for arg1_cnt != arg2_cnt 1101 Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt)); 1102 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 1103 Node* if_ne = generate_slow_guard(bol, nullptr); 1104 if (if_ne != nullptr) { 1105 phi->init_req(2, intcon(0)); 1106 region->init_req(2, if_ne); 1107 } 1108 1109 // Check for count == 0 is done by assembler code for StrEquals. 1110 1111 if (!stopped()) { 1112 Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1113 phi->init_req(1, equals); 1114 region->init_req(1, control()); 1115 } 1116 } 1117 1118 // post merge 1119 set_control(_gvn.transform(region)); 1120 record_for_igvn(region); 1121 1122 set_result(_gvn.transform(phi)); 1123 return true; 1124 } 1125 1126 //------------------------------inline_array_equals---------------------------- 1127 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) { 1128 assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types"); 1129 Node* arg1 = argument(0); 1130 Node* arg2 = argument(1); 1131 1132 const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES; 1133 set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae))); 1134 clear_upper_avx(); 1135 1136 return true; 1137 } 1138 1139 1140 //------------------------------inline_countPositives------------------------------ 1141 bool LibraryCallKit::inline_countPositives() { 1142 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1143 return false; 1144 } 1145 1146 assert(callee()->signature()->size() == 3, "countPositives has 3 parameters"); 1147 // no receiver since it is static method 1148 Node* ba = argument(0); 1149 Node* offset = argument(1); 1150 Node* len = argument(2); 1151 1152 ba = must_be_not_null(ba, true); 1153 1154 // Range checks 1155 generate_string_range_check(ba, offset, len, false); 1156 if (stopped()) { 1157 return true; 1158 } 1159 Node* ba_start = array_element_address(ba, offset, T_BYTE); 1160 Node* result = new CountPositivesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len); 1161 set_result(_gvn.transform(result)); 1162 clear_upper_avx(); 1163 return true; 1164 } 1165 1166 bool LibraryCallKit::inline_preconditions_checkIndex(BasicType bt) { 1167 Node* index = argument(0); 1168 Node* length = bt == T_INT ? argument(1) : argument(2); 1169 if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) { 1170 return false; 1171 } 1172 1173 // check that length is positive 1174 Node* len_pos_cmp = _gvn.transform(CmpNode::make(length, integercon(0, bt), bt)); 1175 Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge)); 1176 1177 { 1178 BuildCutout unless(this, len_pos_bol, PROB_MAX); 1179 uncommon_trap(Deoptimization::Reason_intrinsic, 1180 Deoptimization::Action_make_not_entrant); 1181 } 1182 1183 if (stopped()) { 1184 // Length is known to be always negative during compilation and the IR graph so far constructed is good so return success 1185 return true; 1186 } 1187 1188 // length is now known positive, add a cast node to make this explicit 1189 jlong upper_bound = _gvn.type(length)->is_integer(bt)->hi_as_long(); 1190 Node* casted_length = ConstraintCastNode::make_cast_for_basic_type( 1191 control(), length, TypeInteger::make(0, upper_bound, Type::WidenMax, bt), 1192 ConstraintCastNode::RegularDependency, bt); 1193 casted_length = _gvn.transform(casted_length); 1194 replace_in_map(length, casted_length); 1195 length = casted_length; 1196 1197 // Use an unsigned comparison for the range check itself 1198 Node* rc_cmp = _gvn.transform(CmpNode::make(index, length, bt, true)); 1199 BoolTest::mask btest = BoolTest::lt; 1200 Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest)); 1201 RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN); 1202 _gvn.set_type(rc, rc->Value(&_gvn)); 1203 if (!rc_bool->is_Con()) { 1204 record_for_igvn(rc); 1205 } 1206 set_control(_gvn.transform(new IfTrueNode(rc))); 1207 { 1208 PreserveJVMState pjvms(this); 1209 set_control(_gvn.transform(new IfFalseNode(rc))); 1210 uncommon_trap(Deoptimization::Reason_range_check, 1211 Deoptimization::Action_make_not_entrant); 1212 } 1213 1214 if (stopped()) { 1215 // Range check is known to always fail during compilation and the IR graph so far constructed is good so return success 1216 return true; 1217 } 1218 1219 // index is now known to be >= 0 and < length, cast it 1220 Node* result = ConstraintCastNode::make_cast_for_basic_type( 1221 control(), index, TypeInteger::make(0, upper_bound, Type::WidenMax, bt), 1222 ConstraintCastNode::RegularDependency, bt); 1223 result = _gvn.transform(result); 1224 set_result(result); 1225 replace_in_map(index, result); 1226 return true; 1227 } 1228 1229 //------------------------------inline_string_indexOf------------------------ 1230 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) { 1231 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1232 return false; 1233 } 1234 Node* src = argument(0); 1235 Node* tgt = argument(1); 1236 1237 // Make the merge point 1238 RegionNode* result_rgn = new RegionNode(4); 1239 Node* result_phi = new PhiNode(result_rgn, TypeInt::INT); 1240 1241 src = must_be_not_null(src, true); 1242 tgt = must_be_not_null(tgt, true); 1243 1244 // Get start addr and length of source string 1245 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 1246 Node* src_count = load_array_length(src); 1247 1248 // Get start addr and length of substring 1249 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1250 Node* tgt_count = load_array_length(tgt); 1251 1252 Node* result = nullptr; 1253 bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr); 1254 1255 if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) { 1256 // Divide src size by 2 if String is UTF16 encoded 1257 src_count = _gvn.transform(new RShiftINode(src_count, intcon(1))); 1258 } 1259 if (ae == StrIntrinsicNode::UU) { 1260 // Divide substring size by 2 if String is UTF16 encoded 1261 tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1))); 1262 } 1263 1264 if (call_opt_stub) { 1265 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(), 1266 StubRoutines::_string_indexof_array[ae], 1267 "stringIndexOf", TypePtr::BOTTOM, src_start, 1268 src_count, tgt_start, tgt_count); 1269 result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 1270 } else { 1271 result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, 1272 result_rgn, result_phi, ae); 1273 } 1274 if (result != nullptr) { 1275 result_phi->init_req(3, result); 1276 result_rgn->init_req(3, control()); 1277 } 1278 set_control(_gvn.transform(result_rgn)); 1279 record_for_igvn(result_rgn); 1280 set_result(_gvn.transform(result_phi)); 1281 1282 return true; 1283 } 1284 1285 //-----------------------------inline_string_indexOfI----------------------- 1286 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) { 1287 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1288 return false; 1289 } 1290 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1291 return false; 1292 } 1293 1294 assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments"); 1295 Node* src = argument(0); // byte[] 1296 Node* src_count = argument(1); // char count 1297 Node* tgt = argument(2); // byte[] 1298 Node* tgt_count = argument(3); // char count 1299 Node* from_index = argument(4); // char index 1300 1301 src = must_be_not_null(src, true); 1302 tgt = must_be_not_null(tgt, true); 1303 1304 // Multiply byte array index by 2 if String is UTF16 encoded 1305 Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1))); 1306 src_count = _gvn.transform(new SubINode(src_count, from_index)); 1307 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1308 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1309 1310 // Range checks 1311 generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL); 1312 generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU); 1313 if (stopped()) { 1314 return true; 1315 } 1316 1317 RegionNode* region = new RegionNode(5); 1318 Node* phi = new PhiNode(region, TypeInt::INT); 1319 Node* result = nullptr; 1320 1321 bool call_opt_stub = (StubRoutines::_string_indexof_array[ae] != nullptr); 1322 1323 if (call_opt_stub) { 1324 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::string_IndexOf_Type(), 1325 StubRoutines::_string_indexof_array[ae], 1326 "stringIndexOf", TypePtr::BOTTOM, src_start, 1327 src_count, tgt_start, tgt_count); 1328 result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 1329 } else { 1330 result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, 1331 region, phi, ae); 1332 } 1333 if (result != nullptr) { 1334 // The result is index relative to from_index if substring was found, -1 otherwise. 1335 // Generate code which will fold into cmove. 1336 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1337 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1338 1339 Node* if_lt = generate_slow_guard(bol, nullptr); 1340 if (if_lt != nullptr) { 1341 // result == -1 1342 phi->init_req(3, result); 1343 region->init_req(3, if_lt); 1344 } 1345 if (!stopped()) { 1346 result = _gvn.transform(new AddINode(result, from_index)); 1347 phi->init_req(4, result); 1348 region->init_req(4, control()); 1349 } 1350 } 1351 1352 set_control(_gvn.transform(region)); 1353 record_for_igvn(region); 1354 set_result(_gvn.transform(phi)); 1355 clear_upper_avx(); 1356 1357 return true; 1358 } 1359 1360 // Create StrIndexOfNode with fast path checks 1361 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count, 1362 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) { 1363 // Check for substr count > string count 1364 Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count)); 1365 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt)); 1366 Node* if_gt = generate_slow_guard(bol, nullptr); 1367 if (if_gt != nullptr) { 1368 phi->init_req(1, intcon(-1)); 1369 region->init_req(1, if_gt); 1370 } 1371 if (!stopped()) { 1372 // Check for substr count == 0 1373 cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0))); 1374 bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 1375 Node* if_zero = generate_slow_guard(bol, nullptr); 1376 if (if_zero != nullptr) { 1377 phi->init_req(2, intcon(0)); 1378 region->init_req(2, if_zero); 1379 } 1380 } 1381 if (!stopped()) { 1382 return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae); 1383 } 1384 return nullptr; 1385 } 1386 1387 //-----------------------------inline_string_indexOfChar----------------------- 1388 bool LibraryCallKit::inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae) { 1389 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1390 return false; 1391 } 1392 if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) { 1393 return false; 1394 } 1395 assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments"); 1396 Node* src = argument(0); // byte[] 1397 Node* int_ch = argument(1); 1398 Node* from_index = argument(2); 1399 Node* max = argument(3); 1400 1401 src = must_be_not_null(src, true); 1402 1403 Node* src_offset = ae == StrIntrinsicNode::L ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1))); 1404 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1405 Node* src_count = _gvn.transform(new SubINode(max, from_index)); 1406 1407 // Range checks 1408 generate_string_range_check(src, src_offset, src_count, ae == StrIntrinsicNode::U); 1409 1410 // Check for int_ch >= 0 1411 Node* int_ch_cmp = _gvn.transform(new CmpINode(int_ch, intcon(0))); 1412 Node* int_ch_bol = _gvn.transform(new BoolNode(int_ch_cmp, BoolTest::ge)); 1413 { 1414 BuildCutout unless(this, int_ch_bol, PROB_MAX); 1415 uncommon_trap(Deoptimization::Reason_intrinsic, 1416 Deoptimization::Action_maybe_recompile); 1417 } 1418 if (stopped()) { 1419 return true; 1420 } 1421 1422 RegionNode* region = new RegionNode(3); 1423 Node* phi = new PhiNode(region, TypeInt::INT); 1424 1425 Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, int_ch, ae); 1426 C->set_has_split_ifs(true); // Has chance for split-if optimization 1427 _gvn.transform(result); 1428 1429 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1430 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1431 1432 Node* if_lt = generate_slow_guard(bol, nullptr); 1433 if (if_lt != nullptr) { 1434 // result == -1 1435 phi->init_req(2, result); 1436 region->init_req(2, if_lt); 1437 } 1438 if (!stopped()) { 1439 result = _gvn.transform(new AddINode(result, from_index)); 1440 phi->init_req(1, result); 1441 region->init_req(1, control()); 1442 } 1443 set_control(_gvn.transform(region)); 1444 record_for_igvn(region); 1445 set_result(_gvn.transform(phi)); 1446 clear_upper_avx(); 1447 1448 return true; 1449 } 1450 //---------------------------inline_string_copy--------------------- 1451 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[]) 1452 // int StringUTF16.compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) 1453 // int StringUTF16.compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1454 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[]) 1455 // void StringLatin1.inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) 1456 // void StringLatin1.inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1457 bool LibraryCallKit::inline_string_copy(bool compress) { 1458 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1459 return false; 1460 } 1461 int nargs = 5; // 2 oops, 3 ints 1462 assert(callee()->signature()->size() == nargs, "string copy has 5 arguments"); 1463 1464 Node* src = argument(0); 1465 Node* src_offset = argument(1); 1466 Node* dst = argument(2); 1467 Node* dst_offset = argument(3); 1468 Node* length = argument(4); 1469 1470 // Check for allocation before we add nodes that would confuse 1471 // tightly_coupled_allocation() 1472 AllocateArrayNode* alloc = tightly_coupled_allocation(dst); 1473 1474 // Figure out the size and type of the elements we will be copying. 1475 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 1476 const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr(); 1477 if (src_type == nullptr || dst_type == nullptr) { 1478 return false; 1479 } 1480 BasicType src_elem = src_type->elem()->array_element_basic_type(); 1481 BasicType dst_elem = dst_type->elem()->array_element_basic_type(); 1482 assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) || 1483 (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)), 1484 "Unsupported array types for inline_string_copy"); 1485 1486 src = must_be_not_null(src, true); 1487 dst = must_be_not_null(dst, true); 1488 1489 // Convert char[] offsets to byte[] offsets 1490 bool convert_src = (compress && src_elem == T_BYTE); 1491 bool convert_dst = (!compress && dst_elem == T_BYTE); 1492 if (convert_src) { 1493 src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1))); 1494 } else if (convert_dst) { 1495 dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1))); 1496 } 1497 1498 // Range checks 1499 generate_string_range_check(src, src_offset, length, convert_src); 1500 generate_string_range_check(dst, dst_offset, length, convert_dst); 1501 if (stopped()) { 1502 return true; 1503 } 1504 1505 Node* src_start = array_element_address(src, src_offset, src_elem); 1506 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 1507 // 'src_start' points to src array + scaled offset 1508 // 'dst_start' points to dst array + scaled offset 1509 Node* count = nullptr; 1510 if (compress) { 1511 count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length); 1512 } else { 1513 inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length); 1514 } 1515 1516 if (alloc != nullptr) { 1517 if (alloc->maybe_set_complete(&_gvn)) { 1518 // "You break it, you buy it." 1519 InitializeNode* init = alloc->initialization(); 1520 assert(init->is_complete(), "we just did this"); 1521 init->set_complete_with_arraycopy(); 1522 assert(dst->is_CheckCastPP(), "sanity"); 1523 assert(dst->in(0)->in(0) == init, "dest pinned"); 1524 } 1525 // Do not let stores that initialize this object be reordered with 1526 // a subsequent store that would make this object accessible by 1527 // other threads. 1528 // Record what AllocateNode this StoreStore protects so that 1529 // escape analysis can go from the MemBarStoreStoreNode to the 1530 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1531 // based on the escape status of the AllocateNode. 1532 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1533 } 1534 if (compress) { 1535 set_result(_gvn.transform(count)); 1536 } 1537 clear_upper_avx(); 1538 1539 return true; 1540 } 1541 1542 #ifdef _LP64 1543 #define XTOP ,top() /*additional argument*/ 1544 #else //_LP64 1545 #define XTOP /*no additional argument*/ 1546 #endif //_LP64 1547 1548 //------------------------inline_string_toBytesU-------------------------- 1549 // public static byte[] StringUTF16.toBytes(char[] value, int off, int len) 1550 bool LibraryCallKit::inline_string_toBytesU() { 1551 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1552 return false; 1553 } 1554 // Get the arguments. 1555 Node* value = argument(0); 1556 Node* offset = argument(1); 1557 Node* length = argument(2); 1558 1559 Node* newcopy = nullptr; 1560 1561 // Set the original stack and the reexecute bit for the interpreter to reexecute 1562 // the bytecode that invokes StringUTF16.toBytes() if deoptimization happens. 1563 { PreserveReexecuteState preexecs(this); 1564 jvms()->set_should_reexecute(true); 1565 1566 // Check if a null path was taken unconditionally. 1567 value = null_check(value); 1568 1569 RegionNode* bailout = new RegionNode(1); 1570 record_for_igvn(bailout); 1571 1572 // Range checks 1573 generate_negative_guard(offset, bailout); 1574 generate_negative_guard(length, bailout); 1575 generate_limit_guard(offset, length, load_array_length(value), bailout); 1576 // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE 1577 generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout); 1578 1579 if (bailout->req() > 1) { 1580 PreserveJVMState pjvms(this); 1581 set_control(_gvn.transform(bailout)); 1582 uncommon_trap(Deoptimization::Reason_intrinsic, 1583 Deoptimization::Action_maybe_recompile); 1584 } 1585 if (stopped()) { 1586 return true; 1587 } 1588 1589 Node* size = _gvn.transform(new LShiftINode(length, intcon(1))); 1590 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE))); 1591 newcopy = new_array(klass_node, size, 0); // no arguments to push 1592 AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy); 1593 guarantee(alloc != nullptr, "created above"); 1594 1595 // Calculate starting addresses. 1596 Node* src_start = array_element_address(value, offset, T_CHAR); 1597 Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE)); 1598 1599 // Check if src array address is aligned to HeapWordSize (dst is always aligned) 1600 const TypeInt* toffset = gvn().type(offset)->is_int(); 1601 bool aligned = toffset->is_con() && ((toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1602 1603 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1604 const char* copyfunc_name = "arraycopy"; 1605 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1606 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1607 OptoRuntime::fast_arraycopy_Type(), 1608 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1609 src_start, dst_start, ConvI2X(length) XTOP); 1610 // Do not let reads from the cloned object float above the arraycopy. 1611 if (alloc->maybe_set_complete(&_gvn)) { 1612 // "You break it, you buy it." 1613 InitializeNode* init = alloc->initialization(); 1614 assert(init->is_complete(), "we just did this"); 1615 init->set_complete_with_arraycopy(); 1616 assert(newcopy->is_CheckCastPP(), "sanity"); 1617 assert(newcopy->in(0)->in(0) == init, "dest pinned"); 1618 } 1619 // Do not let stores that initialize this object be reordered with 1620 // a subsequent store that would make this object accessible by 1621 // other threads. 1622 // Record what AllocateNode this StoreStore protects so that 1623 // escape analysis can go from the MemBarStoreStoreNode to the 1624 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1625 // based on the escape status of the AllocateNode. 1626 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1627 } // original reexecute is set back here 1628 1629 C->set_has_split_ifs(true); // Has chance for split-if optimization 1630 if (!stopped()) { 1631 set_result(newcopy); 1632 } 1633 clear_upper_avx(); 1634 1635 return true; 1636 } 1637 1638 //------------------------inline_string_getCharsU-------------------------- 1639 // public void StringUTF16.getChars(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin) 1640 bool LibraryCallKit::inline_string_getCharsU() { 1641 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1642 return false; 1643 } 1644 1645 // Get the arguments. 1646 Node* src = argument(0); 1647 Node* src_begin = argument(1); 1648 Node* src_end = argument(2); // exclusive offset (i < src_end) 1649 Node* dst = argument(3); 1650 Node* dst_begin = argument(4); 1651 1652 // Check for allocation before we add nodes that would confuse 1653 // tightly_coupled_allocation() 1654 AllocateArrayNode* alloc = tightly_coupled_allocation(dst); 1655 1656 // Check if a null path was taken unconditionally. 1657 src = null_check(src); 1658 dst = null_check(dst); 1659 if (stopped()) { 1660 return true; 1661 } 1662 1663 // Get length and convert char[] offset to byte[] offset 1664 Node* length = _gvn.transform(new SubINode(src_end, src_begin)); 1665 src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1))); 1666 1667 // Range checks 1668 generate_string_range_check(src, src_begin, length, true); 1669 generate_string_range_check(dst, dst_begin, length, false); 1670 if (stopped()) { 1671 return true; 1672 } 1673 1674 if (!stopped()) { 1675 // Calculate starting addresses. 1676 Node* src_start = array_element_address(src, src_begin, T_BYTE); 1677 Node* dst_start = array_element_address(dst, dst_begin, T_CHAR); 1678 1679 // Check if array addresses are aligned to HeapWordSize 1680 const TypeInt* tsrc = gvn().type(src_begin)->is_int(); 1681 const TypeInt* tdst = gvn().type(dst_begin)->is_int(); 1682 bool aligned = tsrc->is_con() && ((tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) && 1683 tdst->is_con() && ((tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1684 1685 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1686 const char* copyfunc_name = "arraycopy"; 1687 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1688 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1689 OptoRuntime::fast_arraycopy_Type(), 1690 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1691 src_start, dst_start, ConvI2X(length) XTOP); 1692 // Do not let reads from the cloned object float above the arraycopy. 1693 if (alloc != nullptr) { 1694 if (alloc->maybe_set_complete(&_gvn)) { 1695 // "You break it, you buy it." 1696 InitializeNode* init = alloc->initialization(); 1697 assert(init->is_complete(), "we just did this"); 1698 init->set_complete_with_arraycopy(); 1699 assert(dst->is_CheckCastPP(), "sanity"); 1700 assert(dst->in(0)->in(0) == init, "dest pinned"); 1701 } 1702 // Do not let stores that initialize this object be reordered with 1703 // a subsequent store that would make this object accessible by 1704 // other threads. 1705 // Record what AllocateNode this StoreStore protects so that 1706 // escape analysis can go from the MemBarStoreStoreNode to the 1707 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1708 // based on the escape status of the AllocateNode. 1709 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1710 } else { 1711 insert_mem_bar(Op_MemBarCPUOrder); 1712 } 1713 } 1714 1715 C->set_has_split_ifs(true); // Has chance for split-if optimization 1716 return true; 1717 } 1718 1719 //----------------------inline_string_char_access---------------------------- 1720 // Store/Load char to/from byte[] array. 1721 // static void StringUTF16.putChar(byte[] val, int index, int c) 1722 // static char StringUTF16.getChar(byte[] val, int index) 1723 bool LibraryCallKit::inline_string_char_access(bool is_store) { 1724 Node* value = argument(0); 1725 Node* index = argument(1); 1726 Node* ch = is_store ? argument(2) : nullptr; 1727 1728 // This intrinsic accesses byte[] array as char[] array. Computing the offsets 1729 // correctly requires matched array shapes. 1730 assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE), 1731 "sanity: byte[] and char[] bases agree"); 1732 assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2, 1733 "sanity: byte[] and char[] scales agree"); 1734 1735 // Bail when getChar over constants is requested: constant folding would 1736 // reject folding mismatched char access over byte[]. A normal inlining for getChar 1737 // Java method would constant fold nicely instead. 1738 if (!is_store && value->is_Con() && index->is_Con()) { 1739 return false; 1740 } 1741 1742 // Save state and restore on bailout 1743 uint old_sp = sp(); 1744 SafePointNode* old_map = clone_map(); 1745 1746 value = must_be_not_null(value, true); 1747 1748 Node* adr = array_element_address(value, index, T_CHAR); 1749 if (adr->is_top()) { 1750 set_map(old_map); 1751 set_sp(old_sp); 1752 return false; 1753 } 1754 destruct_map_clone(old_map); 1755 if (is_store) { 1756 access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED); 1757 } else { 1758 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); 1759 set_result(ch); 1760 } 1761 return true; 1762 } 1763 1764 1765 //------------------------------inline_math----------------------------------- 1766 // public static double Math.abs(double) 1767 // public static double Math.sqrt(double) 1768 // public static double Math.log(double) 1769 // public static double Math.log10(double) 1770 // public static double Math.round(double) 1771 bool LibraryCallKit::inline_double_math(vmIntrinsics::ID id) { 1772 Node* arg = argument(0); 1773 Node* n = nullptr; 1774 switch (id) { 1775 case vmIntrinsics::_dabs: n = new AbsDNode( arg); break; 1776 case vmIntrinsics::_dsqrt: 1777 case vmIntrinsics::_dsqrt_strict: 1778 n = new SqrtDNode(C, control(), arg); break; 1779 case vmIntrinsics::_ceil: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_ceil); break; 1780 case vmIntrinsics::_floor: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_floor); break; 1781 case vmIntrinsics::_rint: n = RoundDoubleModeNode::make(_gvn, arg, RoundDoubleModeNode::rmode_rint); break; 1782 case vmIntrinsics::_roundD: n = new RoundDNode(arg); break; 1783 case vmIntrinsics::_dcopySign: n = CopySignDNode::make(_gvn, arg, argument(2)); break; 1784 case vmIntrinsics::_dsignum: n = SignumDNode::make(_gvn, arg); break; 1785 default: fatal_unexpected_iid(id); break; 1786 } 1787 set_result(_gvn.transform(n)); 1788 return true; 1789 } 1790 1791 //------------------------------inline_math----------------------------------- 1792 // public static float Math.abs(float) 1793 // public static int Math.abs(int) 1794 // public static long Math.abs(long) 1795 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) { 1796 Node* arg = argument(0); 1797 Node* n = nullptr; 1798 switch (id) { 1799 case vmIntrinsics::_fabs: n = new AbsFNode( arg); break; 1800 case vmIntrinsics::_iabs: n = new AbsINode( arg); break; 1801 case vmIntrinsics::_labs: n = new AbsLNode( arg); break; 1802 case vmIntrinsics::_fcopySign: n = new CopySignFNode(arg, argument(1)); break; 1803 case vmIntrinsics::_fsignum: n = SignumFNode::make(_gvn, arg); break; 1804 case vmIntrinsics::_roundF: n = new RoundFNode(arg); break; 1805 default: fatal_unexpected_iid(id); break; 1806 } 1807 set_result(_gvn.transform(n)); 1808 return true; 1809 } 1810 1811 //------------------------------runtime_math----------------------------- 1812 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1813 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1814 "must be (DD)D or (D)D type"); 1815 1816 // Inputs 1817 Node* a = argument(0); 1818 Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? argument(2) : nullptr; 1819 1820 const TypePtr* no_memory_effects = nullptr; 1821 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1822 no_memory_effects, 1823 a, top(), b, b ? top() : nullptr); 1824 Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0)); 1825 #ifdef ASSERT 1826 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1)); 1827 assert(value_top == top(), "second value must be top"); 1828 #endif 1829 1830 set_result(value); 1831 return true; 1832 } 1833 1834 //------------------------------inline_math_pow----------------------------- 1835 bool LibraryCallKit::inline_math_pow() { 1836 Node* exp = argument(2); 1837 const TypeD* d = _gvn.type(exp)->isa_double_constant(); 1838 if (d != nullptr) { 1839 if (d->getd() == 2.0) { 1840 // Special case: pow(x, 2.0) => x * x 1841 Node* base = argument(0); 1842 set_result(_gvn.transform(new MulDNode(base, base))); 1843 return true; 1844 } else if (d->getd() == 0.5 && Matcher::match_rule_supported(Op_SqrtD)) { 1845 // Special case: pow(x, 0.5) => sqrt(x) 1846 Node* base = argument(0); 1847 Node* zero = _gvn.zerocon(T_DOUBLE); 1848 1849 RegionNode* region = new RegionNode(3); 1850 Node* phi = new PhiNode(region, Type::DOUBLE); 1851 1852 Node* cmp = _gvn.transform(new CmpDNode(base, zero)); 1853 // According to the API specs, pow(-0.0, 0.5) = 0.0 and sqrt(-0.0) = -0.0. 1854 // So pow(-0.0, 0.5) shouldn't be replaced with sqrt(-0.0). 1855 // -0.0/+0.0 are both excluded since floating-point comparison doesn't distinguish -0.0 from +0.0. 1856 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::le)); 1857 1858 Node* if_pow = generate_slow_guard(test, nullptr); 1859 Node* value_sqrt = _gvn.transform(new SqrtDNode(C, control(), base)); 1860 phi->init_req(1, value_sqrt); 1861 region->init_req(1, control()); 1862 1863 if (if_pow != nullptr) { 1864 set_control(if_pow); 1865 address target = StubRoutines::dpow() != nullptr ? StubRoutines::dpow() : 1866 CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 1867 const TypePtr* no_memory_effects = nullptr; 1868 Node* trig = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(), target, "POW", 1869 no_memory_effects, base, top(), exp, top()); 1870 Node* value_pow = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0)); 1871 #ifdef ASSERT 1872 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1)); 1873 assert(value_top == top(), "second value must be top"); 1874 #endif 1875 phi->init_req(2, value_pow); 1876 region->init_req(2, _gvn.transform(new ProjNode(trig, TypeFunc::Control))); 1877 } 1878 1879 C->set_has_split_ifs(true); // Has chance for split-if optimization 1880 set_control(_gvn.transform(region)); 1881 record_for_igvn(region); 1882 set_result(_gvn.transform(phi)); 1883 1884 return true; 1885 } 1886 } 1887 1888 return StubRoutines::dpow() != nullptr ? 1889 runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") : 1890 runtime_math(OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW"); 1891 } 1892 1893 //------------------------------inline_math_native----------------------------- 1894 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1895 switch (id) { 1896 case vmIntrinsics::_dsin: 1897 return StubRoutines::dsin() != nullptr ? 1898 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") : 1899 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin), "SIN"); 1900 case vmIntrinsics::_dcos: 1901 return StubRoutines::dcos() != nullptr ? 1902 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") : 1903 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos), "COS"); 1904 case vmIntrinsics::_dtan: 1905 return StubRoutines::dtan() != nullptr ? 1906 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") : 1907 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN"); 1908 case vmIntrinsics::_dtanh: 1909 return StubRoutines::dtanh() != nullptr ? 1910 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtanh(), "dtanh") : false; 1911 case vmIntrinsics::_dexp: 1912 return StubRoutines::dexp() != nullptr ? 1913 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") : 1914 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP"); 1915 case vmIntrinsics::_dlog: 1916 return StubRoutines::dlog() != nullptr ? 1917 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") : 1918 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog), "LOG"); 1919 case vmIntrinsics::_dlog10: 1920 return StubRoutines::dlog10() != nullptr ? 1921 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") : 1922 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10"); 1923 1924 case vmIntrinsics::_roundD: return Matcher::match_rule_supported(Op_RoundD) ? inline_double_math(id) : false; 1925 case vmIntrinsics::_ceil: 1926 case vmIntrinsics::_floor: 1927 case vmIntrinsics::_rint: return Matcher::match_rule_supported(Op_RoundDoubleMode) ? inline_double_math(id) : false; 1928 1929 case vmIntrinsics::_dsqrt: 1930 case vmIntrinsics::_dsqrt_strict: 1931 return Matcher::match_rule_supported(Op_SqrtD) ? inline_double_math(id) : false; 1932 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_double_math(id) : false; 1933 case vmIntrinsics::_fabs: return Matcher::match_rule_supported(Op_AbsF) ? inline_math(id) : false; 1934 case vmIntrinsics::_iabs: return Matcher::match_rule_supported(Op_AbsI) ? inline_math(id) : false; 1935 case vmIntrinsics::_labs: return Matcher::match_rule_supported(Op_AbsL) ? inline_math(id) : false; 1936 1937 case vmIntrinsics::_dpow: return inline_math_pow(); 1938 case vmIntrinsics::_dcopySign: return inline_double_math(id); 1939 case vmIntrinsics::_fcopySign: return inline_math(id); 1940 case vmIntrinsics::_dsignum: return Matcher::match_rule_supported(Op_SignumD) ? inline_double_math(id) : false; 1941 case vmIntrinsics::_fsignum: return Matcher::match_rule_supported(Op_SignumF) ? inline_math(id) : false; 1942 case vmIntrinsics::_roundF: return Matcher::match_rule_supported(Op_RoundF) ? inline_math(id) : false; 1943 1944 // These intrinsics are not yet correctly implemented 1945 case vmIntrinsics::_datan2: 1946 return false; 1947 1948 default: 1949 fatal_unexpected_iid(id); 1950 return false; 1951 } 1952 } 1953 1954 //----------------------------inline_notify-----------------------------------* 1955 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) { 1956 const TypeFunc* ftype = OptoRuntime::monitor_notify_Type(); 1957 address func; 1958 if (id == vmIntrinsics::_notify) { 1959 func = OptoRuntime::monitor_notify_Java(); 1960 } else { 1961 func = OptoRuntime::monitor_notifyAll_Java(); 1962 } 1963 Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, nullptr, TypeRawPtr::BOTTOM, argument(0)); 1964 make_slow_call_ex(call, env()->Throwable_klass(), false); 1965 return true; 1966 } 1967 1968 1969 //----------------------------inline_min_max----------------------------------- 1970 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 1971 Node* a = nullptr; 1972 Node* b = nullptr; 1973 Node* n = nullptr; 1974 switch (id) { 1975 case vmIntrinsics::_min: 1976 case vmIntrinsics::_max: 1977 case vmIntrinsics::_minF: 1978 case vmIntrinsics::_maxF: 1979 case vmIntrinsics::_minF_strict: 1980 case vmIntrinsics::_maxF_strict: 1981 case vmIntrinsics::_min_strict: 1982 case vmIntrinsics::_max_strict: 1983 assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each."); 1984 a = argument(0); 1985 b = argument(1); 1986 break; 1987 case vmIntrinsics::_minD: 1988 case vmIntrinsics::_maxD: 1989 case vmIntrinsics::_minD_strict: 1990 case vmIntrinsics::_maxD_strict: 1991 assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each."); 1992 a = argument(0); 1993 b = argument(2); 1994 break; 1995 case vmIntrinsics::_minL: 1996 case vmIntrinsics::_maxL: 1997 assert(callee()->signature()->size() == 4, "minL/maxL has 2 parameters of size 2 each."); 1998 a = argument(0); 1999 b = argument(2); 2000 break; 2001 default: 2002 fatal_unexpected_iid(id); 2003 break; 2004 } 2005 2006 switch (id) { 2007 case vmIntrinsics::_min: 2008 case vmIntrinsics::_min_strict: 2009 n = new MinINode(a, b); 2010 break; 2011 case vmIntrinsics::_max: 2012 case vmIntrinsics::_max_strict: 2013 n = new MaxINode(a, b); 2014 break; 2015 case vmIntrinsics::_minF: 2016 case vmIntrinsics::_minF_strict: 2017 n = new MinFNode(a, b); 2018 break; 2019 case vmIntrinsics::_maxF: 2020 case vmIntrinsics::_maxF_strict: 2021 n = new MaxFNode(a, b); 2022 break; 2023 case vmIntrinsics::_minD: 2024 case vmIntrinsics::_minD_strict: 2025 n = new MinDNode(a, b); 2026 break; 2027 case vmIntrinsics::_maxD: 2028 case vmIntrinsics::_maxD_strict: 2029 n = new MaxDNode(a, b); 2030 break; 2031 case vmIntrinsics::_minL: 2032 n = new MinLNode(_gvn.C, a, b); 2033 break; 2034 case vmIntrinsics::_maxL: 2035 n = new MaxLNode(_gvn.C, a, b); 2036 break; 2037 default: 2038 fatal_unexpected_iid(id); 2039 break; 2040 } 2041 2042 set_result(_gvn.transform(n)); 2043 return true; 2044 } 2045 2046 bool LibraryCallKit::inline_math_mathExact(Node* math, Node* test) { 2047 if (builtin_throw_too_many_traps(Deoptimization::Reason_intrinsic, 2048 env()->ArithmeticException_instance())) { 2049 // It has been already too many times, but we cannot use builtin_throw (e.g. we care about backtraces), 2050 // so let's bail out intrinsic rather than risking deopting again. 2051 return false; 2052 } 2053 2054 Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) ); 2055 IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 2056 Node* fast_path = _gvn.transform( new IfFalseNode(check)); 2057 Node* slow_path = _gvn.transform( new IfTrueNode(check) ); 2058 2059 { 2060 PreserveJVMState pjvms(this); 2061 PreserveReexecuteState preexecs(this); 2062 jvms()->set_should_reexecute(true); 2063 2064 set_control(slow_path); 2065 set_i_o(i_o()); 2066 2067 builtin_throw(Deoptimization::Reason_intrinsic, 2068 env()->ArithmeticException_instance(), 2069 /*allow_too_many_traps*/ false); 2070 } 2071 2072 set_control(fast_path); 2073 set_result(math); 2074 return true; 2075 } 2076 2077 template <typename OverflowOp> 2078 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) { 2079 typedef typename OverflowOp::MathOp MathOp; 2080 2081 MathOp* mathOp = new MathOp(arg1, arg2); 2082 Node* operation = _gvn.transform( mathOp ); 2083 Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) ); 2084 return inline_math_mathExact(operation, ofcheck); 2085 } 2086 2087 bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 2088 return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1)); 2089 } 2090 2091 bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 2092 return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2)); 2093 } 2094 2095 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 2096 return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1)); 2097 } 2098 2099 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 2100 return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2)); 2101 } 2102 2103 bool LibraryCallKit::inline_math_negateExactI() { 2104 return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0)); 2105 } 2106 2107 bool LibraryCallKit::inline_math_negateExactL() { 2108 return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0)); 2109 } 2110 2111 bool LibraryCallKit::inline_math_multiplyExactI() { 2112 return inline_math_overflow<OverflowMulINode>(argument(0), argument(1)); 2113 } 2114 2115 bool LibraryCallKit::inline_math_multiplyExactL() { 2116 return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2)); 2117 } 2118 2119 bool LibraryCallKit::inline_math_multiplyHigh() { 2120 set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2)))); 2121 return true; 2122 } 2123 2124 bool LibraryCallKit::inline_math_unsignedMultiplyHigh() { 2125 set_result(_gvn.transform(new UMulHiLNode(argument(0), argument(2)))); 2126 return true; 2127 } 2128 2129 inline int 2130 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) { 2131 const TypePtr* base_type = TypePtr::NULL_PTR; 2132 if (base != nullptr) base_type = _gvn.type(base)->isa_ptr(); 2133 if (base_type == nullptr) { 2134 // Unknown type. 2135 return Type::AnyPtr; 2136 } else if (_gvn.type(base->uncast()) == TypePtr::NULL_PTR) { 2137 // Since this is a null+long form, we have to switch to a rawptr. 2138 base = _gvn.transform(new CastX2PNode(offset)); 2139 offset = MakeConX(0); 2140 return Type::RawPtr; 2141 } else if (base_type->base() == Type::RawPtr) { 2142 return Type::RawPtr; 2143 } else if (base_type->isa_oopptr()) { 2144 // Base is never null => always a heap address. 2145 if (!TypePtr::NULL_PTR->higher_equal(base_type)) { 2146 return Type::OopPtr; 2147 } 2148 // Offset is small => always a heap address. 2149 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 2150 if (offset_type != nullptr && 2151 base_type->offset() == 0 && // (should always be?) 2152 offset_type->_lo >= 0 && 2153 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 2154 return Type::OopPtr; 2155 } else if (type == T_OBJECT) { 2156 // off heap access to an oop doesn't make any sense. Has to be on 2157 // heap. 2158 return Type::OopPtr; 2159 } 2160 // Otherwise, it might either be oop+off or null+addr. 2161 return Type::AnyPtr; 2162 } else { 2163 // No information: 2164 return Type::AnyPtr; 2165 } 2166 } 2167 2168 Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, BasicType type, bool can_cast) { 2169 Node* uncasted_base = base; 2170 int kind = classify_unsafe_addr(uncasted_base, offset, type); 2171 if (kind == Type::RawPtr) { 2172 return basic_plus_adr(top(), uncasted_base, offset); 2173 } else if (kind == Type::AnyPtr) { 2174 assert(base == uncasted_base, "unexpected base change"); 2175 if (can_cast) { 2176 if (!_gvn.type(base)->speculative_maybe_null() && 2177 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2178 // According to profiling, this access is always on 2179 // heap. Casting the base to not null and thus avoiding membars 2180 // around the access should allow better optimizations 2181 Node* null_ctl = top(); 2182 base = null_check_oop(base, &null_ctl, true, true, true); 2183 assert(null_ctl->is_top(), "no null control here"); 2184 return basic_plus_adr(base, offset); 2185 } else if (_gvn.type(base)->speculative_always_null() && 2186 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) { 2187 // According to profiling, this access is always off 2188 // heap. 2189 base = null_assert(base); 2190 Node* raw_base = _gvn.transform(new CastX2PNode(offset)); 2191 offset = MakeConX(0); 2192 return basic_plus_adr(top(), raw_base, offset); 2193 } 2194 } 2195 // We don't know if it's an on heap or off heap access. Fall back 2196 // to raw memory access. 2197 Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM)); 2198 return basic_plus_adr(top(), raw, offset); 2199 } else { 2200 assert(base == uncasted_base, "unexpected base change"); 2201 // We know it's an on heap access so base can't be null 2202 if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) { 2203 base = must_be_not_null(base, true); 2204 } 2205 return basic_plus_adr(base, offset); 2206 } 2207 } 2208 2209 //--------------------------inline_number_methods----------------------------- 2210 // inline int Integer.numberOfLeadingZeros(int) 2211 // inline int Long.numberOfLeadingZeros(long) 2212 // 2213 // inline int Integer.numberOfTrailingZeros(int) 2214 // inline int Long.numberOfTrailingZeros(long) 2215 // 2216 // inline int Integer.bitCount(int) 2217 // inline int Long.bitCount(long) 2218 // 2219 // inline char Character.reverseBytes(char) 2220 // inline short Short.reverseBytes(short) 2221 // inline int Integer.reverseBytes(int) 2222 // inline long Long.reverseBytes(long) 2223 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 2224 Node* arg = argument(0); 2225 Node* n = nullptr; 2226 switch (id) { 2227 case vmIntrinsics::_numberOfLeadingZeros_i: n = new CountLeadingZerosINode( arg); break; 2228 case vmIntrinsics::_numberOfLeadingZeros_l: n = new CountLeadingZerosLNode( arg); break; 2229 case vmIntrinsics::_numberOfTrailingZeros_i: n = new CountTrailingZerosINode(arg); break; 2230 case vmIntrinsics::_numberOfTrailingZeros_l: n = new CountTrailingZerosLNode(arg); break; 2231 case vmIntrinsics::_bitCount_i: n = new PopCountINode( arg); break; 2232 case vmIntrinsics::_bitCount_l: n = new PopCountLNode( arg); break; 2233 case vmIntrinsics::_reverseBytes_c: n = new ReverseBytesUSNode( arg); break; 2234 case vmIntrinsics::_reverseBytes_s: n = new ReverseBytesSNode( arg); break; 2235 case vmIntrinsics::_reverseBytes_i: n = new ReverseBytesINode( arg); break; 2236 case vmIntrinsics::_reverseBytes_l: n = new ReverseBytesLNode( arg); break; 2237 case vmIntrinsics::_reverse_i: n = new ReverseINode( arg); break; 2238 case vmIntrinsics::_reverse_l: n = new ReverseLNode( arg); break; 2239 default: fatal_unexpected_iid(id); break; 2240 } 2241 set_result(_gvn.transform(n)); 2242 return true; 2243 } 2244 2245 //--------------------------inline_bitshuffle_methods----------------------------- 2246 // inline int Integer.compress(int, int) 2247 // inline int Integer.expand(int, int) 2248 // inline long Long.compress(long, long) 2249 // inline long Long.expand(long, long) 2250 bool LibraryCallKit::inline_bitshuffle_methods(vmIntrinsics::ID id) { 2251 Node* n = nullptr; 2252 switch (id) { 2253 case vmIntrinsics::_compress_i: n = new CompressBitsNode(argument(0), argument(1), TypeInt::INT); break; 2254 case vmIntrinsics::_expand_i: n = new ExpandBitsNode(argument(0), argument(1), TypeInt::INT); break; 2255 case vmIntrinsics::_compress_l: n = new CompressBitsNode(argument(0), argument(2), TypeLong::LONG); break; 2256 case vmIntrinsics::_expand_l: n = new ExpandBitsNode(argument(0), argument(2), TypeLong::LONG); break; 2257 default: fatal_unexpected_iid(id); break; 2258 } 2259 set_result(_gvn.transform(n)); 2260 return true; 2261 } 2262 2263 //--------------------------inline_number_methods----------------------------- 2264 // inline int Integer.compareUnsigned(int, int) 2265 // inline int Long.compareUnsigned(long, long) 2266 bool LibraryCallKit::inline_compare_unsigned(vmIntrinsics::ID id) { 2267 Node* arg1 = argument(0); 2268 Node* arg2 = (id == vmIntrinsics::_compareUnsigned_l) ? argument(2) : argument(1); 2269 Node* n = nullptr; 2270 switch (id) { 2271 case vmIntrinsics::_compareUnsigned_i: n = new CmpU3Node(arg1, arg2); break; 2272 case vmIntrinsics::_compareUnsigned_l: n = new CmpUL3Node(arg1, arg2); break; 2273 default: fatal_unexpected_iid(id); break; 2274 } 2275 set_result(_gvn.transform(n)); 2276 return true; 2277 } 2278 2279 //--------------------------inline_unsigned_divmod_methods----------------------------- 2280 // inline int Integer.divideUnsigned(int, int) 2281 // inline int Integer.remainderUnsigned(int, int) 2282 // inline long Long.divideUnsigned(long, long) 2283 // inline long Long.remainderUnsigned(long, long) 2284 bool LibraryCallKit::inline_divmod_methods(vmIntrinsics::ID id) { 2285 Node* n = nullptr; 2286 switch (id) { 2287 case vmIntrinsics::_divideUnsigned_i: { 2288 zero_check_int(argument(1)); 2289 // Compile-time detect of null-exception 2290 if (stopped()) { 2291 return true; // keep the graph constructed so far 2292 } 2293 n = new UDivINode(control(), argument(0), argument(1)); 2294 break; 2295 } 2296 case vmIntrinsics::_divideUnsigned_l: { 2297 zero_check_long(argument(2)); 2298 // Compile-time detect of null-exception 2299 if (stopped()) { 2300 return true; // keep the graph constructed so far 2301 } 2302 n = new UDivLNode(control(), argument(0), argument(2)); 2303 break; 2304 } 2305 case vmIntrinsics::_remainderUnsigned_i: { 2306 zero_check_int(argument(1)); 2307 // Compile-time detect of null-exception 2308 if (stopped()) { 2309 return true; // keep the graph constructed so far 2310 } 2311 n = new UModINode(control(), argument(0), argument(1)); 2312 break; 2313 } 2314 case vmIntrinsics::_remainderUnsigned_l: { 2315 zero_check_long(argument(2)); 2316 // Compile-time detect of null-exception 2317 if (stopped()) { 2318 return true; // keep the graph constructed so far 2319 } 2320 n = new UModLNode(control(), argument(0), argument(2)); 2321 break; 2322 } 2323 default: fatal_unexpected_iid(id); break; 2324 } 2325 set_result(_gvn.transform(n)); 2326 return true; 2327 } 2328 2329 //----------------------------inline_unsafe_access---------------------------- 2330 2331 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { 2332 // Attempt to infer a sharper value type from the offset and base type. 2333 ciKlass* sharpened_klass = nullptr; 2334 bool null_free = false; 2335 2336 // See if it is an instance field, with an object type. 2337 if (alias_type->field() != nullptr) { 2338 if (alias_type->field()->type()->is_klass()) { 2339 sharpened_klass = alias_type->field()->type()->as_klass(); 2340 null_free = alias_type->field()->is_null_free(); 2341 } 2342 } 2343 2344 const TypeOopPtr* result = nullptr; 2345 // See if it is a narrow oop array. 2346 if (adr_type->isa_aryptr()) { 2347 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) { 2348 const TypeOopPtr* elem_type = adr_type->is_aryptr()->elem()->make_oopptr(); 2349 null_free = adr_type->is_aryptr()->is_null_free(); 2350 if (elem_type != nullptr && elem_type->is_loaded()) { 2351 // Sharpen the value type. 2352 result = elem_type; 2353 } 2354 } 2355 } 2356 2357 // The sharpened class might be unloaded if there is no class loader 2358 // contraint in place. 2359 if (result == nullptr && sharpened_klass != nullptr && sharpened_klass->is_loaded()) { 2360 // Sharpen the value type. 2361 result = TypeOopPtr::make_from_klass(sharpened_klass); 2362 if (null_free) { 2363 result = result->join_speculative(TypePtr::NOTNULL)->is_oopptr(); 2364 } 2365 } 2366 if (result != nullptr) { 2367 #ifndef PRODUCT 2368 if (C->print_intrinsics() || C->print_inlining()) { 2369 tty->print(" from base type: "); adr_type->dump(); tty->cr(); 2370 tty->print(" sharpened value: "); result->dump(); tty->cr(); 2371 } 2372 #endif 2373 } 2374 return result; 2375 } 2376 2377 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) { 2378 switch (kind) { 2379 case Relaxed: 2380 return MO_UNORDERED; 2381 case Opaque: 2382 return MO_RELAXED; 2383 case Acquire: 2384 return MO_ACQUIRE; 2385 case Release: 2386 return MO_RELEASE; 2387 case Volatile: 2388 return MO_SEQ_CST; 2389 default: 2390 ShouldNotReachHere(); 2391 return 0; 2392 } 2393 } 2394 2395 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned, const bool is_flat) { 2396 if (callee()->is_static()) return false; // caller must have the capability! 2397 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2398 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); 2399 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); 2400 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); 2401 2402 if (is_reference_type(type)) { 2403 decorators |= ON_UNKNOWN_OOP_REF; 2404 } 2405 2406 if (unaligned) { 2407 decorators |= C2_UNALIGNED; 2408 } 2409 2410 #ifndef PRODUCT 2411 { 2412 ResourceMark rm; 2413 // Check the signatures. 2414 ciSignature* sig = callee()->signature(); 2415 #ifdef ASSERT 2416 if (!is_store) { 2417 // Object getReference(Object base, int/long offset), etc. 2418 BasicType rtype = sig->return_type()->basic_type(); 2419 assert(rtype == type, "getter must return the expected value"); 2420 assert(sig->count() == 2 || (is_flat && sig->count() == 3), "oop getter has 2 or 3 arguments"); 2421 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 2422 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 2423 } else { 2424 // void putReference(Object base, int/long offset, Object x), etc. 2425 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 2426 assert(sig->count() == 3 || (is_flat && sig->count() == 4), "oop putter has 3 arguments"); 2427 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 2428 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 2429 BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 2430 assert(vtype == type, "putter must accept the expected value"); 2431 } 2432 #endif // ASSERT 2433 } 2434 #endif //PRODUCT 2435 2436 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2437 2438 Node* receiver = argument(0); // type: oop 2439 2440 // Build address expression. 2441 Node* heap_base_oop = top(); 2442 2443 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2444 Node* base = argument(1); // type: oop 2445 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2446 Node* offset = argument(2); // type: long 2447 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2448 // to be plain byte offsets, which are also the same as those accepted 2449 // by oopDesc::field_addr. 2450 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2451 "fieldOffset must be byte-scaled"); 2452 2453 ciInlineKlass* inline_klass = nullptr; 2454 if (is_flat) { 2455 const TypeInstPtr* cls = _gvn.type(argument(4))->isa_instptr(); 2456 if (cls == nullptr || cls->const_oop() == nullptr) { 2457 return false; 2458 } 2459 ciType* mirror_type = cls->const_oop()->as_instance()->java_mirror_type(); 2460 if (!mirror_type->is_inlinetype()) { 2461 return false; 2462 } 2463 inline_klass = mirror_type->as_inline_klass(); 2464 } 2465 2466 if (base->is_InlineType()) { 2467 assert(!is_store, "InlineTypeNodes are non-larval value objects"); 2468 InlineTypeNode* vt = base->as_InlineType(); 2469 if (offset->is_Con()) { 2470 long off = find_long_con(offset, 0); 2471 ciInlineKlass* vk = vt->type()->inline_klass(); 2472 if ((long)(int)off != off || !vk->contains_field_offset(off)) { 2473 return false; 2474 } 2475 2476 ciField* field = vk->get_non_flat_field_by_offset(off); 2477 if (field != nullptr) { 2478 BasicType bt = type2field[field->type()->basic_type()]; 2479 if (bt == T_ARRAY || bt == T_NARROWOOP) { 2480 bt = T_OBJECT; 2481 } 2482 if (bt == type && (!field->is_flat() || field->type() == inline_klass)) { 2483 Node* value = vt->field_value_by_offset(off, false); 2484 if (value->is_InlineType()) { 2485 value = value->as_InlineType()->adjust_scalarization_depth(this); 2486 } 2487 set_result(value); 2488 return true; 2489 } 2490 } 2491 } 2492 { 2493 // Re-execute the unsafe access if allocation triggers deoptimization. 2494 PreserveReexecuteState preexecs(this); 2495 jvms()->set_should_reexecute(true); 2496 vt = vt->buffer(this); 2497 } 2498 base = vt->get_oop(); 2499 } 2500 2501 // 32-bit machines ignore the high half! 2502 offset = ConvL2X(offset); 2503 2504 // Save state and restore on bailout 2505 uint old_sp = sp(); 2506 SafePointNode* old_map = clone_map(); 2507 2508 Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed); 2509 assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly"); 2510 2511 if (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR) { 2512 if (type != T_OBJECT && (inline_klass == nullptr || !inline_klass->has_object_fields())) { 2513 decorators |= IN_NATIVE; // off-heap primitive access 2514 } else { 2515 set_map(old_map); 2516 set_sp(old_sp); 2517 return false; // off-heap oop accesses are not supported 2518 } 2519 } else { 2520 heap_base_oop = base; // on-heap or mixed access 2521 } 2522 2523 // Can base be null? Otherwise, always on-heap access. 2524 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base)); 2525 2526 if (!can_access_non_heap) { 2527 decorators |= IN_HEAP; 2528 } 2529 2530 Node* val = is_store ? argument(4 + (is_flat ? 1 : 0)) : nullptr; 2531 2532 const TypePtr* adr_type = _gvn.type(adr)->isa_ptr(); 2533 if (adr_type == TypePtr::NULL_PTR) { 2534 set_map(old_map); 2535 set_sp(old_sp); 2536 return false; // off-heap access with zero address 2537 } 2538 2539 // Try to categorize the address. 2540 Compile::AliasType* alias_type = C->alias_type(adr_type); 2541 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2542 2543 if (alias_type->adr_type() == TypeInstPtr::KLASS || 2544 alias_type->adr_type() == TypeAryPtr::RANGE) { 2545 set_map(old_map); 2546 set_sp(old_sp); 2547 return false; // not supported 2548 } 2549 2550 bool mismatched = false; 2551 BasicType bt = T_ILLEGAL; 2552 ciField* field = nullptr; 2553 if (adr_type->isa_instptr()) { 2554 const TypeInstPtr* instptr = adr_type->is_instptr(); 2555 ciInstanceKlass* k = instptr->instance_klass(); 2556 int off = instptr->offset(); 2557 if (instptr->const_oop() != nullptr && 2558 k == ciEnv::current()->Class_klass() && 2559 instptr->offset() >= (k->size_helper() * wordSize)) { 2560 k = instptr->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); 2561 field = k->get_field_by_offset(off, true); 2562 } else { 2563 field = k->get_non_flat_field_by_offset(off); 2564 } 2565 if (field != nullptr) { 2566 bt = type2field[field->type()->basic_type()]; 2567 } 2568 if (bt != alias_type->basic_type()) { 2569 // Type mismatch. Is it an access to a nested flat field? 2570 field = k->get_field_by_offset(off, false); 2571 if (field != nullptr) { 2572 bt = type2field[field->type()->basic_type()]; 2573 } 2574 } 2575 assert(bt == alias_type->basic_type() || is_flat, "should match"); 2576 } else { 2577 bt = alias_type->basic_type(); 2578 } 2579 2580 if (bt != T_ILLEGAL) { 2581 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access"); 2582 if (bt == T_BYTE && adr_type->isa_aryptr()) { 2583 // Alias type doesn't differentiate between byte[] and boolean[]). 2584 // Use address type to get the element type. 2585 bt = adr_type->is_aryptr()->elem()->array_element_basic_type(); 2586 } 2587 if (is_reference_type(bt, true)) { 2588 // accessing an array field with getReference is not a mismatch 2589 bt = T_OBJECT; 2590 } 2591 if ((bt == T_OBJECT) != (type == T_OBJECT)) { 2592 // Don't intrinsify mismatched object accesses 2593 set_map(old_map); 2594 set_sp(old_sp); 2595 return false; 2596 } 2597 mismatched = (bt != type); 2598 } else if (alias_type->adr_type()->isa_oopptr()) { 2599 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched 2600 } 2601 2602 if (is_flat) { 2603 if (adr_type->isa_instptr()) { 2604 if (field == nullptr || field->type() != inline_klass) { 2605 mismatched = true; 2606 } 2607 } else if (adr_type->isa_aryptr()) { 2608 const Type* elem = adr_type->is_aryptr()->elem(); 2609 if (!adr_type->is_flat() || elem->inline_klass() != inline_klass) { 2610 mismatched = true; 2611 } 2612 } else { 2613 mismatched = true; 2614 } 2615 if (is_store) { 2616 const Type* val_t = _gvn.type(val); 2617 if (!val_t->is_inlinetypeptr() || val_t->inline_klass() != inline_klass) { 2618 set_map(old_map); 2619 set_sp(old_sp); 2620 return false; 2621 } 2622 } 2623 } 2624 2625 destruct_map_clone(old_map); 2626 assert(!mismatched || is_flat || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); 2627 2628 if (mismatched) { 2629 decorators |= C2_MISMATCHED; 2630 } 2631 2632 // First guess at the value type. 2633 const Type *value_type = Type::get_const_basic_type(type); 2634 2635 // Figure out the memory ordering. 2636 decorators |= mo_decorator_for_access_kind(kind); 2637 2638 if (!is_store) { 2639 if (type == T_OBJECT && !is_flat) { 2640 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2641 if (tjp != nullptr) { 2642 value_type = tjp; 2643 } 2644 } 2645 } 2646 2647 receiver = null_check(receiver); 2648 if (stopped()) { 2649 return true; 2650 } 2651 // Heap pointers get a null-check from the interpreter, 2652 // as a courtesy. However, this is not guaranteed by Unsafe, 2653 // and it is not possible to fully distinguish unintended nulls 2654 // from intended ones in this API. 2655 2656 if (!is_store) { 2657 Node* p = nullptr; 2658 // Try to constant fold a load from a constant field 2659 2660 if (heap_base_oop != top() && field != nullptr && field->is_constant() && !field->is_flat() && !mismatched) { 2661 // final or stable field 2662 p = make_constant_from_field(field, heap_base_oop); 2663 } 2664 2665 if (p == nullptr) { // Could not constant fold the load 2666 if (is_flat) { 2667 p = InlineTypeNode::make_from_flat(this, inline_klass, base, adr, adr_type, false, false, true); 2668 } else { 2669 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators); 2670 const TypeOopPtr* ptr = value_type->make_oopptr(); 2671 if (ptr != nullptr && ptr->is_inlinetypeptr()) { 2672 // Load a non-flattened inline type from memory 2673 p = InlineTypeNode::make_from_oop(this, p, ptr->inline_klass()); 2674 } 2675 } 2676 // Normalize the value returned by getBoolean in the following cases 2677 if (type == T_BOOLEAN && 2678 (mismatched || 2679 heap_base_oop == top() || // - heap_base_oop is null or 2680 (can_access_non_heap && field == nullptr)) // - heap_base_oop is potentially null 2681 // and the unsafe access is made to large offset 2682 // (i.e., larger than the maximum offset necessary for any 2683 // field access) 2684 ) { 2685 IdealKit ideal = IdealKit(this); 2686 #define __ ideal. 2687 IdealVariable normalized_result(ideal); 2688 __ declarations_done(); 2689 __ set(normalized_result, p); 2690 __ if_then(p, BoolTest::ne, ideal.ConI(0)); 2691 __ set(normalized_result, ideal.ConI(1)); 2692 ideal.end_if(); 2693 final_sync(ideal); 2694 p = __ value(normalized_result); 2695 #undef __ 2696 } 2697 } 2698 if (type == T_ADDRESS) { 2699 p = gvn().transform(new CastP2XNode(nullptr, p)); 2700 p = ConvX2UL(p); 2701 } 2702 // The load node has the control of the preceding MemBarCPUOrder. All 2703 // following nodes will have the control of the MemBarCPUOrder inserted at 2704 // the end of this method. So, pushing the load onto the stack at a later 2705 // point is fine. 2706 set_result(p); 2707 } else { 2708 if (bt == T_ADDRESS) { 2709 // Repackage the long as a pointer. 2710 val = ConvL2X(val); 2711 val = gvn().transform(new CastX2PNode(val)); 2712 } 2713 if (is_flat) { 2714 val->as_InlineType()->store_flat(this, base, adr, false, false, true, decorators); 2715 } else { 2716 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators); 2717 } 2718 } 2719 2720 return true; 2721 } 2722 2723 bool LibraryCallKit::inline_unsafe_flat_access(bool is_store, AccessKind kind) { 2724 #ifdef ASSERT 2725 { 2726 ResourceMark rm; 2727 // Check the signatures. 2728 ciSignature* sig = callee()->signature(); 2729 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base should be object, but is %s", type2name(sig->type_at(0)->basic_type())); 2730 assert(sig->type_at(1)->basic_type() == T_LONG, "offset should be long, but is %s", type2name(sig->type_at(1)->basic_type())); 2731 assert(sig->type_at(2)->basic_type() == T_INT, "layout kind should be int, but is %s", type2name(sig->type_at(3)->basic_type())); 2732 assert(sig->type_at(3)->basic_type() == T_OBJECT, "value klass should be object, but is %s", type2name(sig->type_at(4)->basic_type())); 2733 if (is_store) { 2734 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value, but returns %s", type2name(sig->return_type()->basic_type())); 2735 assert(sig->count() == 5, "flat putter should have 5 arguments, but has %d", sig->count()); 2736 assert(sig->type_at(4)->basic_type() == T_OBJECT, "put value should be object, but is %s", type2name(sig->type_at(5)->basic_type())); 2737 } else { 2738 assert(sig->return_type()->basic_type() == T_OBJECT, "getter must return an object, but returns %s", type2name(sig->return_type()->basic_type())); 2739 assert(sig->count() == 4, "flat getter should have 4 arguments, but has %d", sig->count()); 2740 } 2741 } 2742 #endif // ASSERT 2743 2744 assert(kind == Relaxed, "Only plain accesses for now"); 2745 if (callee()->is_static()) { 2746 // caller must have the capability! 2747 return false; 2748 } 2749 C->set_has_unsafe_access(true); 2750 2751 const TypeInstPtr* value_klass_node = _gvn.type(argument(5))->isa_instptr(); 2752 if (value_klass_node == nullptr || value_klass_node->const_oop() == nullptr) { 2753 // parameter valueType is not a constant 2754 return false; 2755 } 2756 ciInlineKlass* value_klass = value_klass_node->const_oop()->as_instance()->java_mirror_type()->as_inline_klass(); 2757 2758 const TypeInt* layout_type = _gvn.type(argument(4))->isa_int(); 2759 if (layout_type == nullptr || !layout_type->is_con()) { 2760 // parameter layoutKind is not a constant 2761 return false; 2762 } 2763 assert(layout_type->get_con() >= static_cast<int>(LayoutKind::REFERENCE) && 2764 layout_type->get_con() <= static_cast<int>(LayoutKind::UNKNOWN), 2765 "invalid layoutKind %d", layout_type->get_con()); 2766 LayoutKind layout = static_cast<LayoutKind>(layout_type->get_con()); 2767 assert(layout == LayoutKind::REFERENCE || layout == LayoutKind::NON_ATOMIC_FLAT || 2768 layout == LayoutKind::ATOMIC_FLAT || layout == LayoutKind::NULLABLE_ATOMIC_FLAT, 2769 "unexpected layoutKind %d", layout_type->get_con()); 2770 2771 null_check(argument(0)); 2772 if (stopped()) { 2773 return true; 2774 } 2775 2776 Node* base = must_be_not_null(argument(1), true); 2777 Node* offset = argument(2); 2778 const Type* base_type = _gvn.type(base); 2779 2780 Node* ptr; 2781 bool immutable_memory = false; 2782 DecoratorSet decorators = C2_UNSAFE_ACCESS | IN_HEAP | MO_UNORDERED; 2783 if (base_type->isa_instptr()) { 2784 const TypeLong* offset_type = _gvn.type(offset)->isa_long(); 2785 if (offset_type == nullptr || !offset_type->is_con()) { 2786 // Offset into a non-array should be a constant 2787 decorators |= C2_MISMATCHED; 2788 } else { 2789 int offset_con = checked_cast<int>(offset_type->get_con()); 2790 ciInstanceKlass* base_klass = base_type->is_instptr()->instance_klass(); 2791 ciField* field = base_klass->get_non_flat_field_by_offset(offset_con); 2792 if (field == nullptr) { 2793 assert(!base_klass->is_final(), "non-existence field at offset %d of class %s", offset_con, base_klass->name()->as_utf8()); 2794 decorators |= C2_MISMATCHED; 2795 } else { 2796 assert(field->type() == value_klass, "field at offset %d of %s is of type %s, but valueType is %s", 2797 offset_con, base_klass->name()->as_utf8(), field->type()->name(), value_klass->name()->as_utf8()); 2798 immutable_memory = field->is_strict() && field->is_final(); 2799 2800 if (base->is_InlineType()) { 2801 assert(!is_store, "Cannot store into a non-larval value object"); 2802 set_result(base->as_InlineType()->field_value_by_offset(offset_con, false)); 2803 return true; 2804 } 2805 } 2806 } 2807 2808 if (base->is_InlineType()) { 2809 assert(!is_store, "Cannot store into a non-larval value object"); 2810 base = base->as_InlineType()->buffer(this, true); 2811 } 2812 ptr = basic_plus_adr(base, ConvL2X(offset)); 2813 } else if (base_type->isa_aryptr()) { 2814 decorators |= IS_ARRAY; 2815 if (layout == LayoutKind::REFERENCE) { 2816 if (!base_type->is_aryptr()->is_not_flat()) { 2817 const TypeAryPtr* array_type = base_type->is_aryptr()->cast_to_not_flat(); 2818 Node* new_base = _gvn.transform(new CastPPNode(control(), base, array_type, ConstraintCastNode::StrongDependency)); 2819 replace_in_map(base, new_base); 2820 base = new_base; 2821 } 2822 ptr = basic_plus_adr(base, ConvL2X(offset)); 2823 } else { 2824 // Flat array must have an exact type 2825 bool is_null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2826 bool is_atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2827 Node* new_base = cast_to_flat_array(base, value_klass, is_null_free, !is_null_free, is_atomic); 2828 replace_in_map(base, new_base); 2829 base = new_base; 2830 ptr = basic_plus_adr(base, ConvL2X(offset)); 2831 const TypeAryPtr* ptr_type = _gvn.type(ptr)->is_aryptr(); 2832 if (ptr_type->field_offset().get() != 0) { 2833 ptr = _gvn.transform(new CastPPNode(control(), ptr, ptr_type->with_field_offset(0), ConstraintCastNode::StrongDependency)); 2834 } 2835 } 2836 } else { 2837 decorators |= C2_MISMATCHED; 2838 ptr = basic_plus_adr(base, ConvL2X(offset)); 2839 } 2840 2841 if (is_store) { 2842 Node* value = argument(6); 2843 const Type* value_type = _gvn.type(value); 2844 if (!value_type->is_inlinetypeptr()) { 2845 value_type = Type::get_const_type(value_klass)->filter_speculative(value_type); 2846 Node* new_value = _gvn.transform(new CastPPNode(control(), value, value_type, ConstraintCastNode::StrongDependency)); 2847 new_value = InlineTypeNode::make_from_oop(this, new_value, value_klass); 2848 replace_in_map(value, new_value); 2849 value = new_value; 2850 } 2851 2852 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()); 2853 if (layout == LayoutKind::REFERENCE) { 2854 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr(); 2855 access_store_at(base, ptr, ptr_type, value, value_type, T_OBJECT, decorators); 2856 } else { 2857 bool atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2858 bool null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2859 value->as_InlineType()->store_flat(this, base, ptr, atomic, immutable_memory, null_free, decorators); 2860 } 2861 2862 return true; 2863 } else { 2864 decorators |= (C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD); 2865 InlineTypeNode* result; 2866 if (layout == LayoutKind::REFERENCE) { 2867 const TypePtr* ptr_type = (decorators & C2_MISMATCHED) != 0 ? TypeRawPtr::BOTTOM : _gvn.type(ptr)->is_ptr(); 2868 Node* oop = access_load_at(base, ptr, ptr_type, Type::get_const_type(value_klass), T_OBJECT, decorators); 2869 result = InlineTypeNode::make_from_oop(this, oop, value_klass); 2870 } else { 2871 bool atomic = layout != LayoutKind::NON_ATOMIC_FLAT; 2872 bool null_free = layout != LayoutKind::NULLABLE_ATOMIC_FLAT; 2873 result = InlineTypeNode::make_from_flat(this, value_klass, base, ptr, atomic, immutable_memory, null_free, decorators); 2874 } 2875 2876 set_result(result); 2877 return true; 2878 } 2879 } 2880 2881 bool LibraryCallKit::inline_unsafe_make_private_buffer() { 2882 Node* receiver = argument(0); 2883 Node* value = argument(1); 2884 2885 const Type* type = gvn().type(value); 2886 if (!type->is_inlinetypeptr()) { 2887 C->record_method_not_compilable("value passed to Unsafe::makePrivateBuffer is not of a constant value type"); 2888 return false; 2889 } 2890 2891 null_check(receiver); 2892 if (stopped()) { 2893 return true; 2894 } 2895 2896 value = null_check(value); 2897 if (stopped()) { 2898 return true; 2899 } 2900 2901 ciInlineKlass* vk = type->inline_klass(); 2902 Node* klass = makecon(TypeKlassPtr::make(vk)); 2903 Node* obj = new_instance(klass); 2904 AllocateNode::Ideal_allocation(obj)->_larval = true; 2905 2906 assert(value->is_InlineType(), "must be an InlineTypeNode"); 2907 Node* payload_ptr = basic_plus_adr(obj, vk->payload_offset()); 2908 value->as_InlineType()->store_flat(this, obj, payload_ptr, false, true, true, IN_HEAP | MO_UNORDERED); 2909 2910 set_result(obj); 2911 return true; 2912 } 2913 2914 bool LibraryCallKit::inline_unsafe_finish_private_buffer() { 2915 Node* receiver = argument(0); 2916 Node* buffer = argument(1); 2917 2918 const Type* type = gvn().type(buffer); 2919 if (!type->is_inlinetypeptr()) { 2920 C->record_method_not_compilable("value passed to Unsafe::finishPrivateBuffer is not of a constant value type"); 2921 return false; 2922 } 2923 2924 AllocateNode* alloc = AllocateNode::Ideal_allocation(buffer); 2925 if (alloc == nullptr) { 2926 C->record_method_not_compilable("value passed to Unsafe::finishPrivateBuffer must be allocated by Unsafe::makePrivateBuffer"); 2927 return false; 2928 } 2929 2930 null_check(receiver); 2931 if (stopped()) { 2932 return true; 2933 } 2934 2935 // Unset the larval bit in the object header 2936 Node* old_header = make_load(control(), buffer, TypeX_X, TypeX_X->basic_type(), MemNode::unordered, LoadNode::Pinned); 2937 Node* new_header = gvn().transform(new AndXNode(old_header, MakeConX(~markWord::larval_bit_in_place))); 2938 access_store_at(buffer, buffer, type->is_ptr(), new_header, TypeX_X, TypeX_X->basic_type(), MO_UNORDERED | IN_HEAP); 2939 2940 // We must ensure that the buffer is properly published 2941 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 2942 assert(!type->maybe_null(), "result of an allocation should not be null"); 2943 set_result(InlineTypeNode::make_from_oop(this, buffer, type->inline_klass())); 2944 return true; 2945 } 2946 2947 //----------------------------inline_unsafe_load_store---------------------------- 2948 // This method serves a couple of different customers (depending on LoadStoreKind): 2949 // 2950 // LS_cmp_swap: 2951 // 2952 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x); 2953 // boolean compareAndSetInt( Object o, long offset, int expected, int x); 2954 // boolean compareAndSetLong( Object o, long offset, long expected, long x); 2955 // 2956 // LS_cmp_swap_weak: 2957 // 2958 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x); 2959 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x); 2960 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x); 2961 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x); 2962 // 2963 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x); 2964 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x); 2965 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x); 2966 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x); 2967 // 2968 // boolean weakCompareAndSetLong( Object o, long offset, long expected, long x); 2969 // boolean weakCompareAndSetLongPlain( Object o, long offset, long expected, long x); 2970 // boolean weakCompareAndSetLongAcquire( Object o, long offset, long expected, long x); 2971 // boolean weakCompareAndSetLongRelease( Object o, long offset, long expected, long x); 2972 // 2973 // LS_cmp_exchange: 2974 // 2975 // Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x); 2976 // Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x); 2977 // Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x); 2978 // 2979 // Object compareAndExchangeIntVolatile( Object o, long offset, Object expected, Object x); 2980 // Object compareAndExchangeIntAcquire( Object o, long offset, Object expected, Object x); 2981 // Object compareAndExchangeIntRelease( Object o, long offset, Object expected, Object x); 2982 // 2983 // Object compareAndExchangeLongVolatile( Object o, long offset, Object expected, Object x); 2984 // Object compareAndExchangeLongAcquire( Object o, long offset, Object expected, Object x); 2985 // Object compareAndExchangeLongRelease( Object o, long offset, Object expected, Object x); 2986 // 2987 // LS_get_add: 2988 // 2989 // int getAndAddInt( Object o, long offset, int delta) 2990 // long getAndAddLong(Object o, long offset, long delta) 2991 // 2992 // LS_get_set: 2993 // 2994 // int getAndSet(Object o, long offset, int newValue) 2995 // long getAndSet(Object o, long offset, long newValue) 2996 // Object getAndSet(Object o, long offset, Object newValue) 2997 // 2998 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) { 2999 // This basic scheme here is the same as inline_unsafe_access, but 3000 // differs in enough details that combining them would make the code 3001 // overly confusing. (This is a true fact! I originally combined 3002 // them, but even I was confused by it!) As much code/comments as 3003 // possible are retained from inline_unsafe_access though to make 3004 // the correspondences clearer. - dl 3005 3006 if (callee()->is_static()) return false; // caller must have the capability! 3007 3008 DecoratorSet decorators = C2_UNSAFE_ACCESS; 3009 decorators |= mo_decorator_for_access_kind(access_kind); 3010 3011 #ifndef PRODUCT 3012 BasicType rtype; 3013 { 3014 ResourceMark rm; 3015 // Check the signatures. 3016 ciSignature* sig = callee()->signature(); 3017 rtype = sig->return_type()->basic_type(); 3018 switch(kind) { 3019 case LS_get_add: 3020 case LS_get_set: { 3021 // Check the signatures. 3022 #ifdef ASSERT 3023 assert(rtype == type, "get and set must return the expected type"); 3024 assert(sig->count() == 3, "get and set has 3 arguments"); 3025 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 3026 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 3027 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 3028 assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation"); 3029 #endif // ASSERT 3030 break; 3031 } 3032 case LS_cmp_swap: 3033 case LS_cmp_swap_weak: { 3034 // Check the signatures. 3035 #ifdef ASSERT 3036 assert(rtype == T_BOOLEAN, "CAS must return boolean"); 3037 assert(sig->count() == 4, "CAS has 4 arguments"); 3038 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 3039 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 3040 #endif // ASSERT 3041 break; 3042 } 3043 case LS_cmp_exchange: { 3044 // Check the signatures. 3045 #ifdef ASSERT 3046 assert(rtype == type, "CAS must return the expected type"); 3047 assert(sig->count() == 4, "CAS has 4 arguments"); 3048 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 3049 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 3050 #endif // ASSERT 3051 break; 3052 } 3053 default: 3054 ShouldNotReachHere(); 3055 } 3056 } 3057 #endif //PRODUCT 3058 3059 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 3060 3061 // Get arguments: 3062 Node* receiver = nullptr; 3063 Node* base = nullptr; 3064 Node* offset = nullptr; 3065 Node* oldval = nullptr; 3066 Node* newval = nullptr; 3067 switch(kind) { 3068 case LS_cmp_swap: 3069 case LS_cmp_swap_weak: 3070 case LS_cmp_exchange: { 3071 const bool two_slot_type = type2size[type] == 2; 3072 receiver = argument(0); // type: oop 3073 base = argument(1); // type: oop 3074 offset = argument(2); // type: long 3075 oldval = argument(4); // type: oop, int, or long 3076 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 3077 break; 3078 } 3079 case LS_get_add: 3080 case LS_get_set: { 3081 receiver = argument(0); // type: oop 3082 base = argument(1); // type: oop 3083 offset = argument(2); // type: long 3084 oldval = nullptr; 3085 newval = argument(4); // type: oop, int, or long 3086 break; 3087 } 3088 default: 3089 ShouldNotReachHere(); 3090 } 3091 3092 // Build field offset expression. 3093 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 3094 // to be plain byte offsets, which are also the same as those accepted 3095 // by oopDesc::field_addr. 3096 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 3097 // 32-bit machines ignore the high half of long offsets 3098 offset = ConvL2X(offset); 3099 // Save state and restore on bailout 3100 uint old_sp = sp(); 3101 SafePointNode* old_map = clone_map(); 3102 Node* adr = make_unsafe_address(base, offset,type, false); 3103 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 3104 3105 Compile::AliasType* alias_type = C->alias_type(adr_type); 3106 BasicType bt = alias_type->basic_type(); 3107 if (bt != T_ILLEGAL && 3108 (is_reference_type(bt) != (type == T_OBJECT))) { 3109 // Don't intrinsify mismatched object accesses. 3110 set_map(old_map); 3111 set_sp(old_sp); 3112 return false; 3113 } 3114 3115 destruct_map_clone(old_map); 3116 3117 // For CAS, unlike inline_unsafe_access, there seems no point in 3118 // trying to refine types. Just use the coarse types here. 3119 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 3120 const Type *value_type = Type::get_const_basic_type(type); 3121 3122 switch (kind) { 3123 case LS_get_set: 3124 case LS_cmp_exchange: { 3125 if (type == T_OBJECT) { 3126 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 3127 if (tjp != nullptr) { 3128 value_type = tjp; 3129 } 3130 } 3131 break; 3132 } 3133 case LS_cmp_swap: 3134 case LS_cmp_swap_weak: 3135 case LS_get_add: 3136 break; 3137 default: 3138 ShouldNotReachHere(); 3139 } 3140 3141 // Null check receiver. 3142 receiver = null_check(receiver); 3143 if (stopped()) { 3144 return true; 3145 } 3146 3147 int alias_idx = C->get_alias_index(adr_type); 3148 3149 if (is_reference_type(type)) { 3150 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF; 3151 3152 if (oldval != nullptr && oldval->is_InlineType()) { 3153 // Re-execute the unsafe access if allocation triggers deoptimization. 3154 PreserveReexecuteState preexecs(this); 3155 jvms()->set_should_reexecute(true); 3156 oldval = oldval->as_InlineType()->buffer(this)->get_oop(); 3157 } 3158 if (newval != nullptr && newval->is_InlineType()) { 3159 // Re-execute the unsafe access if allocation triggers deoptimization. 3160 PreserveReexecuteState preexecs(this); 3161 jvms()->set_should_reexecute(true); 3162 newval = newval->as_InlineType()->buffer(this)->get_oop(); 3163 } 3164 3165 // Transformation of a value which could be null pointer (CastPP #null) 3166 // could be delayed during Parse (for example, in adjust_map_after_if()). 3167 // Execute transformation here to avoid barrier generation in such case. 3168 if (_gvn.type(newval) == TypePtr::NULL_PTR) 3169 newval = _gvn.makecon(TypePtr::NULL_PTR); 3170 3171 if (oldval != nullptr && _gvn.type(oldval) == TypePtr::NULL_PTR) { 3172 // Refine the value to a null constant, when it is known to be null 3173 oldval = _gvn.makecon(TypePtr::NULL_PTR); 3174 } 3175 } 3176 3177 Node* result = nullptr; 3178 switch (kind) { 3179 case LS_cmp_exchange: { 3180 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx, 3181 oldval, newval, value_type, type, decorators); 3182 break; 3183 } 3184 case LS_cmp_swap_weak: 3185 decorators |= C2_WEAK_CMPXCHG; 3186 case LS_cmp_swap: { 3187 result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx, 3188 oldval, newval, value_type, type, decorators); 3189 break; 3190 } 3191 case LS_get_set: { 3192 result = access_atomic_xchg_at(base, adr, adr_type, alias_idx, 3193 newval, value_type, type, decorators); 3194 break; 3195 } 3196 case LS_get_add: { 3197 result = access_atomic_add_at(base, adr, adr_type, alias_idx, 3198 newval, value_type, type, decorators); 3199 break; 3200 } 3201 default: 3202 ShouldNotReachHere(); 3203 } 3204 3205 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 3206 set_result(result); 3207 return true; 3208 } 3209 3210 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 3211 // Regardless of form, don't allow previous ld/st to move down, 3212 // then issue acquire, release, or volatile mem_bar. 3213 insert_mem_bar(Op_MemBarCPUOrder); 3214 switch(id) { 3215 case vmIntrinsics::_loadFence: 3216 insert_mem_bar(Op_LoadFence); 3217 return true; 3218 case vmIntrinsics::_storeFence: 3219 insert_mem_bar(Op_StoreFence); 3220 return true; 3221 case vmIntrinsics::_storeStoreFence: 3222 insert_mem_bar(Op_StoreStoreFence); 3223 return true; 3224 case vmIntrinsics::_fullFence: 3225 insert_mem_bar(Op_MemBarVolatile); 3226 return true; 3227 default: 3228 fatal_unexpected_iid(id); 3229 return false; 3230 } 3231 } 3232 3233 bool LibraryCallKit::inline_onspinwait() { 3234 insert_mem_bar(Op_OnSpinWait); 3235 return true; 3236 } 3237 3238 bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 3239 if (!kls->is_Con()) { 3240 return true; 3241 } 3242 const TypeInstKlassPtr* klsptr = kls->bottom_type()->isa_instklassptr(); 3243 if (klsptr == nullptr) { 3244 return true; 3245 } 3246 ciInstanceKlass* ik = klsptr->instance_klass(); 3247 // don't need a guard for a klass that is already initialized 3248 return !ik->is_initialized(); 3249 } 3250 3251 //----------------------------inline_unsafe_writeback0------------------------- 3252 // public native void Unsafe.writeback0(long address) 3253 bool LibraryCallKit::inline_unsafe_writeback0() { 3254 if (!Matcher::has_match_rule(Op_CacheWB)) { 3255 return false; 3256 } 3257 #ifndef PRODUCT 3258 assert(Matcher::has_match_rule(Op_CacheWBPreSync), "found match rule for CacheWB but not CacheWBPreSync"); 3259 assert(Matcher::has_match_rule(Op_CacheWBPostSync), "found match rule for CacheWB but not CacheWBPostSync"); 3260 ciSignature* sig = callee()->signature(); 3261 assert(sig->type_at(0)->basic_type() == T_LONG, "Unsafe_writeback0 address is long!"); 3262 #endif 3263 null_check_receiver(); // null-check, then ignore 3264 Node *addr = argument(1); 3265 addr = new CastX2PNode(addr); 3266 addr = _gvn.transform(addr); 3267 Node *flush = new CacheWBNode(control(), memory(TypeRawPtr::BOTTOM), addr); 3268 flush = _gvn.transform(flush); 3269 set_memory(flush, TypeRawPtr::BOTTOM); 3270 return true; 3271 } 3272 3273 //----------------------------inline_unsafe_writeback0------------------------- 3274 // public native void Unsafe.writeback0(long address) 3275 bool LibraryCallKit::inline_unsafe_writebackSync0(bool is_pre) { 3276 if (is_pre && !Matcher::has_match_rule(Op_CacheWBPreSync)) { 3277 return false; 3278 } 3279 if (!is_pre && !Matcher::has_match_rule(Op_CacheWBPostSync)) { 3280 return false; 3281 } 3282 #ifndef PRODUCT 3283 assert(Matcher::has_match_rule(Op_CacheWB), 3284 (is_pre ? "found match rule for CacheWBPreSync but not CacheWB" 3285 : "found match rule for CacheWBPostSync but not CacheWB")); 3286 3287 #endif 3288 null_check_receiver(); // null-check, then ignore 3289 Node *sync; 3290 if (is_pre) { 3291 sync = new CacheWBPreSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 3292 } else { 3293 sync = new CacheWBPostSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 3294 } 3295 sync = _gvn.transform(sync); 3296 set_memory(sync, TypeRawPtr::BOTTOM); 3297 return true; 3298 } 3299 3300 //----------------------------inline_unsafe_allocate--------------------------- 3301 // public native Object Unsafe.allocateInstance(Class<?> cls); 3302 bool LibraryCallKit::inline_unsafe_allocate() { 3303 3304 #if INCLUDE_JVMTI 3305 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 3306 return false; 3307 } 3308 #endif //INCLUDE_JVMTI 3309 3310 if (callee()->is_static()) return false; // caller must have the capability! 3311 3312 null_check_receiver(); // null-check, then ignore 3313 Node* cls = null_check(argument(1)); 3314 if (stopped()) return true; 3315 3316 Node* kls = load_klass_from_mirror(cls, false, nullptr, 0); 3317 kls = null_check(kls); 3318 if (stopped()) return true; // argument was like int.class 3319 3320 #if INCLUDE_JVMTI 3321 // Don't try to access new allocated obj in the intrinsic. 3322 // It causes perfomance issues even when jvmti event VmObjectAlloc is disabled. 3323 // Deoptimize and allocate in interpreter instead. 3324 Node* addr = makecon(TypeRawPtr::make((address) &JvmtiExport::_should_notify_object_alloc)); 3325 Node* should_post_vm_object_alloc = make_load(this->control(), addr, TypeInt::INT, T_INT, MemNode::unordered); 3326 Node* chk = _gvn.transform(new CmpINode(should_post_vm_object_alloc, intcon(0))); 3327 Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq)); 3328 { 3329 BuildCutout unless(this, tst, PROB_MAX); 3330 uncommon_trap(Deoptimization::Reason_intrinsic, 3331 Deoptimization::Action_make_not_entrant); 3332 } 3333 if (stopped()) { 3334 return true; 3335 } 3336 #endif //INCLUDE_JVMTI 3337 3338 Node* test = nullptr; 3339 if (LibraryCallKit::klass_needs_init_guard(kls)) { 3340 // Note: The argument might still be an illegal value like 3341 // Serializable.class or Object[].class. The runtime will handle it. 3342 // But we must make an explicit check for initialization. 3343 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 3344 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 3345 // can generate code to load it as unsigned byte. 3346 Node* inst = make_load(nullptr, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::acquire); 3347 Node* bits = intcon(InstanceKlass::fully_initialized); 3348 test = _gvn.transform(new SubINode(inst, bits)); 3349 // The 'test' is non-zero if we need to take a slow path. 3350 } 3351 Node* obj = nullptr; 3352 const TypeInstKlassPtr* tkls = _gvn.type(kls)->isa_instklassptr(); 3353 if (tkls != nullptr && tkls->instance_klass()->is_inlinetype()) { 3354 obj = InlineTypeNode::make_all_zero(_gvn, tkls->instance_klass()->as_inline_klass())->buffer(this); 3355 } else { 3356 obj = new_instance(kls, test); 3357 } 3358 set_result(obj); 3359 return true; 3360 } 3361 3362 //------------------------inline_native_time_funcs-------------- 3363 // inline code for System.currentTimeMillis() and System.nanoTime() 3364 // these have the same type and signature 3365 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 3366 const TypeFunc* tf = OptoRuntime::void_long_Type(); 3367 const TypePtr* no_memory_effects = nullptr; 3368 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 3369 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0)); 3370 #ifdef ASSERT 3371 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1)); 3372 assert(value_top == top(), "second value must be top"); 3373 #endif 3374 set_result(value); 3375 return true; 3376 } 3377 3378 3379 #if INCLUDE_JVMTI 3380 3381 // When notifications are disabled then just update the VTMS transition bit and return. 3382 // Otherwise, the bit is updated in the given function call implementing JVMTI notification protocol. 3383 bool LibraryCallKit::inline_native_notify_jvmti_funcs(address funcAddr, const char* funcName, bool is_start, bool is_end) { 3384 if (!DoJVMTIVirtualThreadTransitions) { 3385 return true; 3386 } 3387 Node* vt_oop = _gvn.transform(must_be_not_null(argument(0), true)); // VirtualThread this argument 3388 IdealKit ideal(this); 3389 3390 Node* ONE = ideal.ConI(1); 3391 Node* hide = is_start ? ideal.ConI(0) : (is_end ? ideal.ConI(1) : _gvn.transform(argument(1))); 3392 Node* addr = makecon(TypeRawPtr::make((address)&JvmtiVTMSTransitionDisabler::_VTMS_notify_jvmti_events)); 3393 Node* notify_jvmti_enabled = ideal.load(ideal.ctrl(), addr, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw); 3394 3395 ideal.if_then(notify_jvmti_enabled, BoolTest::eq, ONE); { 3396 sync_kit(ideal); 3397 // if notifyJvmti enabled then make a call to the given SharedRuntime function 3398 const TypeFunc* tf = OptoRuntime::notify_jvmti_vthread_Type(); 3399 make_runtime_call(RC_NO_LEAF, tf, funcAddr, funcName, TypePtr::BOTTOM, vt_oop, hide); 3400 ideal.sync_kit(this); 3401 } ideal.else_(); { 3402 // set hide value to the VTMS transition bit in current JavaThread and VirtualThread object 3403 Node* thread = ideal.thread(); 3404 Node* jt_addr = basic_plus_adr(thread, in_bytes(JavaThread::is_in_VTMS_transition_offset())); 3405 Node* vt_addr = basic_plus_adr(vt_oop, java_lang_Thread::is_in_VTMS_transition_offset()); 3406 3407 sync_kit(ideal); 3408 access_store_at(nullptr, jt_addr, _gvn.type(jt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3409 access_store_at(nullptr, vt_addr, _gvn.type(vt_addr)->is_ptr(), hide, _gvn.type(hide), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3410 3411 ideal.sync_kit(this); 3412 } ideal.end_if(); 3413 final_sync(ideal); 3414 3415 return true; 3416 } 3417 3418 // Always update the is_disable_suspend bit. 3419 bool LibraryCallKit::inline_native_notify_jvmti_sync() { 3420 if (!DoJVMTIVirtualThreadTransitions) { 3421 return true; 3422 } 3423 IdealKit ideal(this); 3424 3425 { 3426 // unconditionally update the is_disable_suspend bit in current JavaThread 3427 Node* thread = ideal.thread(); 3428 Node* arg = _gvn.transform(argument(0)); // argument for notification 3429 Node* addr = basic_plus_adr(thread, in_bytes(JavaThread::is_disable_suspend_offset())); 3430 const TypePtr *addr_type = _gvn.type(addr)->isa_ptr(); 3431 3432 sync_kit(ideal); 3433 access_store_at(nullptr, addr, addr_type, arg, _gvn.type(arg), T_BOOLEAN, IN_NATIVE | MO_UNORDERED); 3434 ideal.sync_kit(this); 3435 } 3436 final_sync(ideal); 3437 3438 return true; 3439 } 3440 3441 #endif // INCLUDE_JVMTI 3442 3443 #ifdef JFR_HAVE_INTRINSICS 3444 3445 /** 3446 * if oop->klass != null 3447 * // normal class 3448 * epoch = _epoch_state ? 2 : 1 3449 * if oop->klass->trace_id & ((epoch << META_SHIFT) | epoch)) != epoch { 3450 * ... // enter slow path when the klass is first recorded or the epoch of JFR shifts 3451 * } 3452 * id = oop->klass->trace_id >> TRACE_ID_SHIFT // normal class path 3453 * else 3454 * // primitive class 3455 * if oop->array_klass != null 3456 * id = (oop->array_klass->trace_id >> TRACE_ID_SHIFT) + 1 // primitive class path 3457 * else 3458 * id = LAST_TYPE_ID + 1 // void class path 3459 * if (!signaled) 3460 * signaled = true 3461 */ 3462 bool LibraryCallKit::inline_native_classID() { 3463 Node* cls = argument(0); 3464 3465 IdealKit ideal(this); 3466 #define __ ideal. 3467 IdealVariable result(ideal); __ declarations_done(); 3468 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), 3469 basic_plus_adr(cls, java_lang_Class::klass_offset()), 3470 TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 3471 3472 3473 __ if_then(kls, BoolTest::ne, null()); { 3474 Node* kls_trace_id_addr = basic_plus_adr(kls, in_bytes(KLASS_TRACE_ID_OFFSET)); 3475 Node* kls_trace_id_raw = ideal.load(ideal.ctrl(), kls_trace_id_addr,TypeLong::LONG, T_LONG, Compile::AliasIdxRaw); 3476 3477 Node* epoch_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_address())); 3478 Node* epoch = ideal.load(ideal.ctrl(), epoch_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw); 3479 epoch = _gvn.transform(new LShiftLNode(longcon(1), epoch)); 3480 Node* mask = _gvn.transform(new LShiftLNode(epoch, intcon(META_SHIFT))); 3481 mask = _gvn.transform(new OrLNode(mask, epoch)); 3482 Node* kls_trace_id_raw_and_mask = _gvn.transform(new AndLNode(kls_trace_id_raw, mask)); 3483 3484 float unlikely = PROB_UNLIKELY(0.999); 3485 __ if_then(kls_trace_id_raw_and_mask, BoolTest::ne, epoch, unlikely); { 3486 sync_kit(ideal); 3487 make_runtime_call(RC_LEAF, 3488 OptoRuntime::class_id_load_barrier_Type(), 3489 CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::load_barrier), 3490 "class id load barrier", 3491 TypePtr::BOTTOM, 3492 kls); 3493 ideal.sync_kit(this); 3494 } __ end_if(); 3495 3496 ideal.set(result, _gvn.transform(new URShiftLNode(kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT)))); 3497 } __ else_(); { 3498 Node* array_kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), 3499 basic_plus_adr(cls, java_lang_Class::array_klass_offset()), 3500 TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 3501 __ if_then(array_kls, BoolTest::ne, null()); { 3502 Node* array_kls_trace_id_addr = basic_plus_adr(array_kls, in_bytes(KLASS_TRACE_ID_OFFSET)); 3503 Node* array_kls_trace_id_raw = ideal.load(ideal.ctrl(), array_kls_trace_id_addr, TypeLong::LONG, T_LONG, Compile::AliasIdxRaw); 3504 Node* array_kls_trace_id = _gvn.transform(new URShiftLNode(array_kls_trace_id_raw, ideal.ConI(TRACE_ID_SHIFT))); 3505 ideal.set(result, _gvn.transform(new AddLNode(array_kls_trace_id, longcon(1)))); 3506 } __ else_(); { 3507 // void class case 3508 ideal.set(result, _gvn.transform(longcon(LAST_TYPE_ID + 1))); 3509 } __ end_if(); 3510 3511 Node* signaled_flag_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::signal_address())); 3512 Node* signaled = ideal.load(ideal.ctrl(), signaled_flag_address, TypeInt::BOOL, T_BOOLEAN, Compile::AliasIdxRaw, true, MemNode::acquire); 3513 __ if_then(signaled, BoolTest::ne, ideal.ConI(1)); { 3514 ideal.store(ideal.ctrl(), signaled_flag_address, ideal.ConI(1), T_BOOLEAN, Compile::AliasIdxRaw, MemNode::release, true); 3515 } __ end_if(); 3516 } __ end_if(); 3517 3518 final_sync(ideal); 3519 set_result(ideal.value(result)); 3520 #undef __ 3521 return true; 3522 } 3523 3524 //------------------------inline_native_jvm_commit------------------ 3525 bool LibraryCallKit::inline_native_jvm_commit() { 3526 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 3527 3528 // Save input memory and i_o state. 3529 Node* input_memory_state = reset_memory(); 3530 set_all_memory(input_memory_state); 3531 Node* input_io_state = i_o(); 3532 3533 // TLS. 3534 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 3535 // Jfr java buffer. 3536 Node* java_buffer_offset = _gvn.transform(new AddPNode(top(), tls_ptr, _gvn.transform(MakeConX(in_bytes(JAVA_BUFFER_OFFSET_JFR))))); 3537 Node* java_buffer = _gvn.transform(new LoadPNode(control(), input_memory_state, java_buffer_offset, TypePtr::BOTTOM, TypeRawPtr::NOTNULL, MemNode::unordered)); 3538 Node* java_buffer_pos_offset = _gvn.transform(new AddPNode(top(), java_buffer, _gvn.transform(MakeConX(in_bytes(JFR_BUFFER_POS_OFFSET))))); 3539 3540 // Load the current value of the notified field in the JfrThreadLocal. 3541 Node* notified_offset = basic_plus_adr(top(), tls_ptr, in_bytes(NOTIFY_OFFSET_JFR)); 3542 Node* notified = make_load(control(), notified_offset, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered); 3543 3544 // Test for notification. 3545 Node* notified_cmp = _gvn.transform(new CmpINode(notified, _gvn.intcon(1))); 3546 Node* test_notified = _gvn.transform(new BoolNode(notified_cmp, BoolTest::eq)); 3547 IfNode* iff_notified = create_and_map_if(control(), test_notified, PROB_MIN, COUNT_UNKNOWN); 3548 3549 // True branch, is notified. 3550 Node* is_notified = _gvn.transform(new IfTrueNode(iff_notified)); 3551 set_control(is_notified); 3552 3553 // Reset notified state. 3554 store_to_memory(control(), notified_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::unordered); 3555 Node* notified_reset_memory = reset_memory(); 3556 3557 // 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. 3558 Node* current_pos_X = _gvn.transform(new LoadXNode(control(), input_memory_state, java_buffer_pos_offset, TypeRawPtr::NOTNULL, TypeX_X, MemNode::unordered)); 3559 // Convert the machine-word to a long. 3560 Node* current_pos = _gvn.transform(ConvX2L(current_pos_X)); 3561 3562 // False branch, not notified. 3563 Node* not_notified = _gvn.transform(new IfFalseNode(iff_notified)); 3564 set_control(not_notified); 3565 set_all_memory(input_memory_state); 3566 3567 // Arg is the next position as a long. 3568 Node* arg = argument(0); 3569 // Convert long to machine-word. 3570 Node* next_pos_X = _gvn.transform(ConvL2X(arg)); 3571 3572 // Store the next_position to the underlying jfr java buffer. 3573 store_to_memory(control(), java_buffer_pos_offset, next_pos_X, LP64_ONLY(T_LONG) NOT_LP64(T_INT), MemNode::release); 3574 3575 Node* commit_memory = reset_memory(); 3576 set_all_memory(commit_memory); 3577 3578 // 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. 3579 Node* java_buffer_flags_offset = _gvn.transform(new AddPNode(top(), java_buffer, _gvn.transform(MakeConX(in_bytes(JFR_BUFFER_FLAGS_OFFSET))))); 3580 Node* flags = make_load(control(), java_buffer_flags_offset, TypeInt::UBYTE, T_BYTE, MemNode::unordered); 3581 Node* lease_constant = _gvn.transform(_gvn.intcon(4)); 3582 3583 // And flags with lease constant. 3584 Node* lease = _gvn.transform(new AndINode(flags, lease_constant)); 3585 3586 // Branch on lease to conditionalize returning the leased java buffer. 3587 Node* lease_cmp = _gvn.transform(new CmpINode(lease, lease_constant)); 3588 Node* test_lease = _gvn.transform(new BoolNode(lease_cmp, BoolTest::eq)); 3589 IfNode* iff_lease = create_and_map_if(control(), test_lease, PROB_MIN, COUNT_UNKNOWN); 3590 3591 // False branch, not a lease. 3592 Node* not_lease = _gvn.transform(new IfFalseNode(iff_lease)); 3593 3594 // True branch, is lease. 3595 Node* is_lease = _gvn.transform(new IfTrueNode(iff_lease)); 3596 set_control(is_lease); 3597 3598 // Make a runtime call, which can safepoint, to return the leased buffer. This updates both the JfrThreadLocal and the Java event writer oop. 3599 Node* call_return_lease = make_runtime_call(RC_NO_LEAF, 3600 OptoRuntime::void_void_Type(), 3601 SharedRuntime::jfr_return_lease(), 3602 "return_lease", TypePtr::BOTTOM); 3603 Node* call_return_lease_control = _gvn.transform(new ProjNode(call_return_lease, TypeFunc::Control)); 3604 3605 RegionNode* lease_compare_rgn = new RegionNode(PATH_LIMIT); 3606 record_for_igvn(lease_compare_rgn); 3607 PhiNode* lease_compare_mem = new PhiNode(lease_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3608 record_for_igvn(lease_compare_mem); 3609 PhiNode* lease_compare_io = new PhiNode(lease_compare_rgn, Type::ABIO); 3610 record_for_igvn(lease_compare_io); 3611 PhiNode* lease_result_value = new PhiNode(lease_compare_rgn, TypeLong::LONG); 3612 record_for_igvn(lease_result_value); 3613 3614 // Update control and phi nodes. 3615 lease_compare_rgn->init_req(_true_path, call_return_lease_control); 3616 lease_compare_rgn->init_req(_false_path, not_lease); 3617 3618 lease_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3619 lease_compare_mem->init_req(_false_path, commit_memory); 3620 3621 lease_compare_io->init_req(_true_path, i_o()); 3622 lease_compare_io->init_req(_false_path, input_io_state); 3623 3624 lease_result_value->init_req(_true_path, null()); // if the lease was returned, return 0. 3625 lease_result_value->init_req(_false_path, arg); // if not lease, return new updated position. 3626 3627 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 3628 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 3629 PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO); 3630 PhiNode* result_value = new PhiNode(result_rgn, TypeLong::LONG); 3631 3632 // Update control and phi nodes. 3633 result_rgn->init_req(_true_path, is_notified); 3634 result_rgn->init_req(_false_path, _gvn.transform(lease_compare_rgn)); 3635 3636 result_mem->init_req(_true_path, notified_reset_memory); 3637 result_mem->init_req(_false_path, _gvn.transform(lease_compare_mem)); 3638 3639 result_io->init_req(_true_path, input_io_state); 3640 result_io->init_req(_false_path, _gvn.transform(lease_compare_io)); 3641 3642 result_value->init_req(_true_path, current_pos); 3643 result_value->init_req(_false_path, _gvn.transform(lease_result_value)); 3644 3645 // Set output state. 3646 set_control(_gvn.transform(result_rgn)); 3647 set_all_memory(_gvn.transform(result_mem)); 3648 set_i_o(_gvn.transform(result_io)); 3649 set_result(result_rgn, result_value); 3650 return true; 3651 } 3652 3653 /* 3654 * The intrinsic is a model of this pseudo-code: 3655 * 3656 * JfrThreadLocal* const tl = Thread::jfr_thread_local() 3657 * jobject h_event_writer = tl->java_event_writer(); 3658 * if (h_event_writer == nullptr) { 3659 * return nullptr; 3660 * } 3661 * oop threadObj = Thread::threadObj(); 3662 * oop vthread = java_lang_Thread::vthread(threadObj); 3663 * traceid tid; 3664 * bool pinVirtualThread; 3665 * bool excluded; 3666 * if (vthread != threadObj) { // i.e. current thread is virtual 3667 * tid = java_lang_Thread::tid(vthread); 3668 * u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(vthread); 3669 * pinVirtualThread = VMContinuations; 3670 * excluded = vthread_epoch_raw & excluded_mask; 3671 * if (!excluded) { 3672 * traceid current_epoch = JfrTraceIdEpoch::current_generation(); 3673 * u2 vthread_epoch = vthread_epoch_raw & epoch_mask; 3674 * if (vthread_epoch != current_epoch) { 3675 * write_checkpoint(); 3676 * } 3677 * } 3678 * } else { 3679 * tid = java_lang_Thread::tid(threadObj); 3680 * u2 thread_epoch_raw = java_lang_Thread::jfr_epoch(threadObj); 3681 * pinVirtualThread = false; 3682 * excluded = thread_epoch_raw & excluded_mask; 3683 * } 3684 * oop event_writer = JNIHandles::resolve_non_null(h_event_writer); 3685 * traceid tid_in_event_writer = getField(event_writer, "threadID"); 3686 * if (tid_in_event_writer != tid) { 3687 * setField(event_writer, "pinVirtualThread", pinVirtualThread); 3688 * setField(event_writer, "excluded", excluded); 3689 * setField(event_writer, "threadID", tid); 3690 * } 3691 * return event_writer 3692 */ 3693 bool LibraryCallKit::inline_native_getEventWriter() { 3694 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 3695 3696 // Save input memory and i_o state. 3697 Node* input_memory_state = reset_memory(); 3698 set_all_memory(input_memory_state); 3699 Node* input_io_state = i_o(); 3700 3701 // The most significant bit of the u2 is used to denote thread exclusion 3702 Node* excluded_shift = _gvn.intcon(15); 3703 Node* excluded_mask = _gvn.intcon(1 << 15); 3704 // The epoch generation is the range [1-32767] 3705 Node* epoch_mask = _gvn.intcon(32767); 3706 3707 // TLS 3708 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 3709 3710 // Load the address of java event writer jobject handle from the jfr_thread_local structure. 3711 Node* jobj_ptr = basic_plus_adr(top(), tls_ptr, in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR)); 3712 3713 // Load the eventwriter jobject handle. 3714 Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); 3715 3716 // Null check the jobject handle. 3717 Node* jobj_cmp_null = _gvn.transform(new CmpPNode(jobj, null())); 3718 Node* test_jobj_not_equal_null = _gvn.transform(new BoolNode(jobj_cmp_null, BoolTest::ne)); 3719 IfNode* iff_jobj_not_equal_null = create_and_map_if(control(), test_jobj_not_equal_null, PROB_MAX, COUNT_UNKNOWN); 3720 3721 // False path, jobj is null. 3722 Node* jobj_is_null = _gvn.transform(new IfFalseNode(iff_jobj_not_equal_null)); 3723 3724 // True path, jobj is not null. 3725 Node* jobj_is_not_null = _gvn.transform(new IfTrueNode(iff_jobj_not_equal_null)); 3726 3727 set_control(jobj_is_not_null); 3728 3729 // Load the threadObj for the CarrierThread. 3730 Node* threadObj = generate_current_thread(tls_ptr); 3731 3732 // Load the vthread. 3733 Node* vthread = generate_virtual_thread(tls_ptr); 3734 3735 // If vthread != threadObj, this is a virtual thread. 3736 Node* vthread_cmp_threadObj = _gvn.transform(new CmpPNode(vthread, threadObj)); 3737 Node* test_vthread_not_equal_threadObj = _gvn.transform(new BoolNode(vthread_cmp_threadObj, BoolTest::ne)); 3738 IfNode* iff_vthread_not_equal_threadObj = 3739 create_and_map_if(jobj_is_not_null, test_vthread_not_equal_threadObj, PROB_FAIR, COUNT_UNKNOWN); 3740 3741 // False branch, fallback to threadObj. 3742 Node* vthread_equal_threadObj = _gvn.transform(new IfFalseNode(iff_vthread_not_equal_threadObj)); 3743 set_control(vthread_equal_threadObj); 3744 3745 // Load the tid field from the vthread object. 3746 Node* thread_obj_tid = load_field_from_object(threadObj, "tid", "J"); 3747 3748 // Load the raw epoch value from the threadObj. 3749 Node* threadObj_epoch_offset = basic_plus_adr(threadObj, java_lang_Thread::jfr_epoch_offset()); 3750 Node* threadObj_epoch_raw = access_load_at(threadObj, threadObj_epoch_offset, 3751 _gvn.type(threadObj_epoch_offset)->isa_ptr(), 3752 TypeInt::CHAR, T_CHAR, 3753 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 3754 3755 // Mask off the excluded information from the epoch. 3756 Node * threadObj_is_excluded = _gvn.transform(new AndINode(threadObj_epoch_raw, excluded_mask)); 3757 3758 // True branch, this is a virtual thread. 3759 Node* vthread_not_equal_threadObj = _gvn.transform(new IfTrueNode(iff_vthread_not_equal_threadObj)); 3760 set_control(vthread_not_equal_threadObj); 3761 3762 // Load the tid field from the vthread object. 3763 Node* vthread_tid = load_field_from_object(vthread, "tid", "J"); 3764 3765 // Continuation support determines if a virtual thread should be pinned. 3766 Node* global_addr = makecon(TypeRawPtr::make((address)&VMContinuations)); 3767 Node* continuation_support = make_load(control(), global_addr, TypeInt::BOOL, T_BOOLEAN, MemNode::unordered); 3768 3769 // Load the raw epoch value from the vthread. 3770 Node* vthread_epoch_offset = basic_plus_adr(vthread, java_lang_Thread::jfr_epoch_offset()); 3771 Node* vthread_epoch_raw = access_load_at(vthread, vthread_epoch_offset, _gvn.type(vthread_epoch_offset)->is_ptr(), 3772 TypeInt::CHAR, T_CHAR, 3773 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 3774 3775 // Mask off the excluded information from the epoch. 3776 Node * vthread_is_excluded = _gvn.transform(new AndINode(vthread_epoch_raw, _gvn.transform(excluded_mask))); 3777 3778 // Branch on excluded to conditionalize updating the epoch for the virtual thread. 3779 Node* is_excluded_cmp = _gvn.transform(new CmpINode(vthread_is_excluded, _gvn.transform(excluded_mask))); 3780 Node* test_not_excluded = _gvn.transform(new BoolNode(is_excluded_cmp, BoolTest::ne)); 3781 IfNode* iff_not_excluded = create_and_map_if(control(), test_not_excluded, PROB_MAX, COUNT_UNKNOWN); 3782 3783 // False branch, vthread is excluded, no need to write epoch info. 3784 Node* excluded = _gvn.transform(new IfFalseNode(iff_not_excluded)); 3785 3786 // True branch, vthread is included, update epoch info. 3787 Node* included = _gvn.transform(new IfTrueNode(iff_not_excluded)); 3788 set_control(included); 3789 3790 // Get epoch value. 3791 Node* epoch = _gvn.transform(new AndINode(vthread_epoch_raw, _gvn.transform(epoch_mask))); 3792 3793 // Load the current epoch generation. The value is unsigned 16-bit, so we type it as T_CHAR. 3794 Node* epoch_generation_address = makecon(TypeRawPtr::make(JfrIntrinsicSupport::epoch_generation_address())); 3795 Node* current_epoch_generation = make_load(control(), epoch_generation_address, TypeInt::CHAR, T_CHAR, MemNode::unordered); 3796 3797 // Compare the epoch in the vthread to the current epoch generation. 3798 Node* const epoch_cmp = _gvn.transform(new CmpUNode(current_epoch_generation, epoch)); 3799 Node* test_epoch_not_equal = _gvn.transform(new BoolNode(epoch_cmp, BoolTest::ne)); 3800 IfNode* iff_epoch_not_equal = create_and_map_if(control(), test_epoch_not_equal, PROB_FAIR, COUNT_UNKNOWN); 3801 3802 // False path, epoch is equal, checkpoint information is valid. 3803 Node* epoch_is_equal = _gvn.transform(new IfFalseNode(iff_epoch_not_equal)); 3804 3805 // True path, epoch is not equal, write a checkpoint for the vthread. 3806 Node* epoch_is_not_equal = _gvn.transform(new IfTrueNode(iff_epoch_not_equal)); 3807 3808 set_control(epoch_is_not_equal); 3809 3810 // Make a runtime call, which can safepoint, to write a checkpoint for the vthread for this epoch. 3811 // The call also updates the native thread local thread id and the vthread with the current epoch. 3812 Node* call_write_checkpoint = make_runtime_call(RC_NO_LEAF, 3813 OptoRuntime::jfr_write_checkpoint_Type(), 3814 SharedRuntime::jfr_write_checkpoint(), 3815 "write_checkpoint", TypePtr::BOTTOM); 3816 Node* call_write_checkpoint_control = _gvn.transform(new ProjNode(call_write_checkpoint, TypeFunc::Control)); 3817 3818 // vthread epoch != current epoch 3819 RegionNode* epoch_compare_rgn = new RegionNode(PATH_LIMIT); 3820 record_for_igvn(epoch_compare_rgn); 3821 PhiNode* epoch_compare_mem = new PhiNode(epoch_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3822 record_for_igvn(epoch_compare_mem); 3823 PhiNode* epoch_compare_io = new PhiNode(epoch_compare_rgn, Type::ABIO); 3824 record_for_igvn(epoch_compare_io); 3825 3826 // Update control and phi nodes. 3827 epoch_compare_rgn->init_req(_true_path, call_write_checkpoint_control); 3828 epoch_compare_rgn->init_req(_false_path, epoch_is_equal); 3829 epoch_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3830 epoch_compare_mem->init_req(_false_path, input_memory_state); 3831 epoch_compare_io->init_req(_true_path, i_o()); 3832 epoch_compare_io->init_req(_false_path, input_io_state); 3833 3834 // excluded != true 3835 RegionNode* exclude_compare_rgn = new RegionNode(PATH_LIMIT); 3836 record_for_igvn(exclude_compare_rgn); 3837 PhiNode* exclude_compare_mem = new PhiNode(exclude_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3838 record_for_igvn(exclude_compare_mem); 3839 PhiNode* exclude_compare_io = new PhiNode(exclude_compare_rgn, Type::ABIO); 3840 record_for_igvn(exclude_compare_io); 3841 3842 // Update control and phi nodes. 3843 exclude_compare_rgn->init_req(_true_path, _gvn.transform(epoch_compare_rgn)); 3844 exclude_compare_rgn->init_req(_false_path, excluded); 3845 exclude_compare_mem->init_req(_true_path, _gvn.transform(epoch_compare_mem)); 3846 exclude_compare_mem->init_req(_false_path, input_memory_state); 3847 exclude_compare_io->init_req(_true_path, _gvn.transform(epoch_compare_io)); 3848 exclude_compare_io->init_req(_false_path, input_io_state); 3849 3850 // vthread != threadObj 3851 RegionNode* vthread_compare_rgn = new RegionNode(PATH_LIMIT); 3852 record_for_igvn(vthread_compare_rgn); 3853 PhiNode* vthread_compare_mem = new PhiNode(vthread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3854 PhiNode* vthread_compare_io = new PhiNode(vthread_compare_rgn, Type::ABIO); 3855 record_for_igvn(vthread_compare_io); 3856 PhiNode* tid = new PhiNode(vthread_compare_rgn, TypeLong::LONG); 3857 record_for_igvn(tid); 3858 PhiNode* exclusion = new PhiNode(vthread_compare_rgn, TypeInt::CHAR); 3859 record_for_igvn(exclusion); 3860 PhiNode* pinVirtualThread = new PhiNode(vthread_compare_rgn, TypeInt::BOOL); 3861 record_for_igvn(pinVirtualThread); 3862 3863 // Update control and phi nodes. 3864 vthread_compare_rgn->init_req(_true_path, _gvn.transform(exclude_compare_rgn)); 3865 vthread_compare_rgn->init_req(_false_path, vthread_equal_threadObj); 3866 vthread_compare_mem->init_req(_true_path, _gvn.transform(exclude_compare_mem)); 3867 vthread_compare_mem->init_req(_false_path, input_memory_state); 3868 vthread_compare_io->init_req(_true_path, _gvn.transform(exclude_compare_io)); 3869 vthread_compare_io->init_req(_false_path, input_io_state); 3870 tid->init_req(_true_path, _gvn.transform(vthread_tid)); 3871 tid->init_req(_false_path, _gvn.transform(thread_obj_tid)); 3872 exclusion->init_req(_true_path, _gvn.transform(vthread_is_excluded)); 3873 exclusion->init_req(_false_path, _gvn.transform(threadObj_is_excluded)); 3874 pinVirtualThread->init_req(_true_path, _gvn.transform(continuation_support)); 3875 pinVirtualThread->init_req(_false_path, _gvn.intcon(0)); 3876 3877 // Update branch state. 3878 set_control(_gvn.transform(vthread_compare_rgn)); 3879 set_all_memory(_gvn.transform(vthread_compare_mem)); 3880 set_i_o(_gvn.transform(vthread_compare_io)); 3881 3882 // Load the event writer oop by dereferencing the jobject handle. 3883 ciKlass* klass_EventWriter = env()->find_system_klass(ciSymbol::make("jdk/jfr/internal/event/EventWriter")); 3884 assert(klass_EventWriter->is_loaded(), "invariant"); 3885 ciInstanceKlass* const instklass_EventWriter = klass_EventWriter->as_instance_klass(); 3886 const TypeKlassPtr* const aklass = TypeKlassPtr::make(instklass_EventWriter); 3887 const TypeOopPtr* const xtype = aklass->as_instance_type(); 3888 Node* jobj_untagged = _gvn.transform(new AddPNode(top(), jobj, _gvn.MakeConX(-JNIHandles::TypeTag::global))); 3889 Node* event_writer = access_load(jobj_untagged, xtype, T_OBJECT, IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD); 3890 3891 // Load the current thread id from the event writer object. 3892 Node* const event_writer_tid = load_field_from_object(event_writer, "threadID", "J"); 3893 // Get the field offset to, conditionally, store an updated tid value later. 3894 Node* const event_writer_tid_field = field_address_from_object(event_writer, "threadID", "J", false); 3895 // Get the field offset to, conditionally, store an updated exclusion value later. 3896 Node* const event_writer_excluded_field = field_address_from_object(event_writer, "excluded", "Z", false); 3897 // Get the field offset to, conditionally, store an updated pinVirtualThread value later. 3898 Node* const event_writer_pin_field = field_address_from_object(event_writer, "pinVirtualThread", "Z", false); 3899 3900 RegionNode* event_writer_tid_compare_rgn = new RegionNode(PATH_LIMIT); 3901 record_for_igvn(event_writer_tid_compare_rgn); 3902 PhiNode* event_writer_tid_compare_mem = new PhiNode(event_writer_tid_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 3903 record_for_igvn(event_writer_tid_compare_mem); 3904 PhiNode* event_writer_tid_compare_io = new PhiNode(event_writer_tid_compare_rgn, Type::ABIO); 3905 record_for_igvn(event_writer_tid_compare_io); 3906 3907 // Compare the current tid from the thread object to what is currently stored in the event writer object. 3908 Node* const tid_cmp = _gvn.transform(new CmpLNode(event_writer_tid, _gvn.transform(tid))); 3909 Node* test_tid_not_equal = _gvn.transform(new BoolNode(tid_cmp, BoolTest::ne)); 3910 IfNode* iff_tid_not_equal = create_and_map_if(_gvn.transform(vthread_compare_rgn), test_tid_not_equal, PROB_FAIR, COUNT_UNKNOWN); 3911 3912 // False path, tids are the same. 3913 Node* tid_is_equal = _gvn.transform(new IfFalseNode(iff_tid_not_equal)); 3914 3915 // True path, tid is not equal, need to update the tid in the event writer. 3916 Node* tid_is_not_equal = _gvn.transform(new IfTrueNode(iff_tid_not_equal)); 3917 record_for_igvn(tid_is_not_equal); 3918 3919 // Store the pin state to the event writer. 3920 store_to_memory(tid_is_not_equal, event_writer_pin_field, _gvn.transform(pinVirtualThread), T_BOOLEAN, MemNode::unordered); 3921 3922 // Store the exclusion state to the event writer. 3923 Node* excluded_bool = _gvn.transform(new URShiftINode(_gvn.transform(exclusion), excluded_shift)); 3924 store_to_memory(tid_is_not_equal, event_writer_excluded_field, excluded_bool, T_BOOLEAN, MemNode::unordered); 3925 3926 // Store the tid to the event writer. 3927 store_to_memory(tid_is_not_equal, event_writer_tid_field, tid, T_LONG, MemNode::unordered); 3928 3929 // Update control and phi nodes. 3930 event_writer_tid_compare_rgn->init_req(_true_path, tid_is_not_equal); 3931 event_writer_tid_compare_rgn->init_req(_false_path, tid_is_equal); 3932 event_writer_tid_compare_mem->init_req(_true_path, _gvn.transform(reset_memory())); 3933 event_writer_tid_compare_mem->init_req(_false_path, _gvn.transform(vthread_compare_mem)); 3934 event_writer_tid_compare_io->init_req(_true_path, _gvn.transform(i_o())); 3935 event_writer_tid_compare_io->init_req(_false_path, _gvn.transform(vthread_compare_io)); 3936 3937 // Result of top level CFG, Memory, IO and Value. 3938 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 3939 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 3940 PhiNode* result_io = new PhiNode(result_rgn, Type::ABIO); 3941 PhiNode* result_value = new PhiNode(result_rgn, TypeInstPtr::BOTTOM); 3942 3943 // Result control. 3944 result_rgn->init_req(_true_path, _gvn.transform(event_writer_tid_compare_rgn)); 3945 result_rgn->init_req(_false_path, jobj_is_null); 3946 3947 // Result memory. 3948 result_mem->init_req(_true_path, _gvn.transform(event_writer_tid_compare_mem)); 3949 result_mem->init_req(_false_path, _gvn.transform(input_memory_state)); 3950 3951 // Result IO. 3952 result_io->init_req(_true_path, _gvn.transform(event_writer_tid_compare_io)); 3953 result_io->init_req(_false_path, _gvn.transform(input_io_state)); 3954 3955 // Result value. 3956 result_value->init_req(_true_path, _gvn.transform(event_writer)); // return event writer oop 3957 result_value->init_req(_false_path, null()); // return null 3958 3959 // Set output state. 3960 set_control(_gvn.transform(result_rgn)); 3961 set_all_memory(_gvn.transform(result_mem)); 3962 set_i_o(_gvn.transform(result_io)); 3963 set_result(result_rgn, result_value); 3964 return true; 3965 } 3966 3967 /* 3968 * The intrinsic is a model of this pseudo-code: 3969 * 3970 * JfrThreadLocal* const tl = thread->jfr_thread_local(); 3971 * if (carrierThread != thread) { // is virtual thread 3972 * const u2 vthread_epoch_raw = java_lang_Thread::jfr_epoch(thread); 3973 * bool excluded = vthread_epoch_raw & excluded_mask; 3974 * Atomic::store(&tl->_contextual_tid, java_lang_Thread::tid(thread)); 3975 * Atomic::store(&tl->_contextual_thread_excluded, is_excluded); 3976 * if (!excluded) { 3977 * const u2 vthread_epoch = vthread_epoch_raw & epoch_mask; 3978 * Atomic::store(&tl->_vthread_epoch, vthread_epoch); 3979 * } 3980 * Atomic::release_store(&tl->_vthread, true); 3981 * return; 3982 * } 3983 * Atomic::release_store(&tl->_vthread, false); 3984 */ 3985 void LibraryCallKit::extend_setCurrentThread(Node* jt, Node* thread) { 3986 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 3987 3988 Node* input_memory_state = reset_memory(); 3989 set_all_memory(input_memory_state); 3990 3991 // The most significant bit of the u2 is used to denote thread exclusion 3992 Node* excluded_mask = _gvn.intcon(1 << 15); 3993 // The epoch generation is the range [1-32767] 3994 Node* epoch_mask = _gvn.intcon(32767); 3995 3996 Node* const carrierThread = generate_current_thread(jt); 3997 // If thread != carrierThread, this is a virtual thread. 3998 Node* thread_cmp_carrierThread = _gvn.transform(new CmpPNode(thread, carrierThread)); 3999 Node* test_thread_not_equal_carrierThread = _gvn.transform(new BoolNode(thread_cmp_carrierThread, BoolTest::ne)); 4000 IfNode* iff_thread_not_equal_carrierThread = 4001 create_and_map_if(control(), test_thread_not_equal_carrierThread, PROB_FAIR, COUNT_UNKNOWN); 4002 4003 Node* vthread_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_OFFSET_JFR)); 4004 4005 // False branch, is carrierThread. 4006 Node* thread_equal_carrierThread = _gvn.transform(new IfFalseNode(iff_thread_not_equal_carrierThread)); 4007 // Store release 4008 Node* vthread_false_memory = store_to_memory(thread_equal_carrierThread, vthread_offset, _gvn.intcon(0), T_BOOLEAN, MemNode::release, true); 4009 4010 set_all_memory(input_memory_state); 4011 4012 // True branch, is virtual thread. 4013 Node* thread_not_equal_carrierThread = _gvn.transform(new IfTrueNode(iff_thread_not_equal_carrierThread)); 4014 set_control(thread_not_equal_carrierThread); 4015 4016 // Load the raw epoch value from the vthread. 4017 Node* epoch_offset = basic_plus_adr(thread, java_lang_Thread::jfr_epoch_offset()); 4018 Node* epoch_raw = access_load_at(thread, epoch_offset, _gvn.type(epoch_offset)->is_ptr(), TypeInt::CHAR, T_CHAR, 4019 IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 4020 4021 // Mask off the excluded information from the epoch. 4022 Node * const is_excluded = _gvn.transform(new AndINode(epoch_raw, _gvn.transform(excluded_mask))); 4023 4024 // Load the tid field from the thread. 4025 Node* tid = load_field_from_object(thread, "tid", "J"); 4026 4027 // Store the vthread tid to the jfr thread local. 4028 Node* thread_id_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_ID_OFFSET_JFR)); 4029 Node* tid_memory = store_to_memory(control(), thread_id_offset, tid, T_LONG, MemNode::unordered, true); 4030 4031 // Branch is_excluded to conditionalize updating the epoch . 4032 Node* excluded_cmp = _gvn.transform(new CmpINode(is_excluded, _gvn.transform(excluded_mask))); 4033 Node* test_excluded = _gvn.transform(new BoolNode(excluded_cmp, BoolTest::eq)); 4034 IfNode* iff_excluded = create_and_map_if(control(), test_excluded, PROB_MIN, COUNT_UNKNOWN); 4035 4036 // True branch, vthread is excluded, no need to write epoch info. 4037 Node* excluded = _gvn.transform(new IfTrueNode(iff_excluded)); 4038 set_control(excluded); 4039 Node* vthread_is_excluded = _gvn.intcon(1); 4040 4041 // False branch, vthread is included, update epoch info. 4042 Node* included = _gvn.transform(new IfFalseNode(iff_excluded)); 4043 set_control(included); 4044 Node* vthread_is_included = _gvn.intcon(0); 4045 4046 // Get epoch value. 4047 Node* epoch = _gvn.transform(new AndINode(epoch_raw, _gvn.transform(epoch_mask))); 4048 4049 // Store the vthread epoch to the jfr thread local. 4050 Node* vthread_epoch_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EPOCH_OFFSET_JFR)); 4051 Node* included_memory = store_to_memory(control(), vthread_epoch_offset, epoch, T_CHAR, MemNode::unordered, true); 4052 4053 RegionNode* excluded_rgn = new RegionNode(PATH_LIMIT); 4054 record_for_igvn(excluded_rgn); 4055 PhiNode* excluded_mem = new PhiNode(excluded_rgn, Type::MEMORY, TypePtr::BOTTOM); 4056 record_for_igvn(excluded_mem); 4057 PhiNode* exclusion = new PhiNode(excluded_rgn, TypeInt::BOOL); 4058 record_for_igvn(exclusion); 4059 4060 // Merge the excluded control and memory. 4061 excluded_rgn->init_req(_true_path, excluded); 4062 excluded_rgn->init_req(_false_path, included); 4063 excluded_mem->init_req(_true_path, tid_memory); 4064 excluded_mem->init_req(_false_path, included_memory); 4065 exclusion->init_req(_true_path, _gvn.transform(vthread_is_excluded)); 4066 exclusion->init_req(_false_path, _gvn.transform(vthread_is_included)); 4067 4068 // Set intermediate state. 4069 set_control(_gvn.transform(excluded_rgn)); 4070 set_all_memory(excluded_mem); 4071 4072 // Store the vthread exclusion state to the jfr thread local. 4073 Node* thread_local_excluded_offset = basic_plus_adr(jt, in_bytes(THREAD_LOCAL_OFFSET_JFR + VTHREAD_EXCLUDED_OFFSET_JFR)); 4074 store_to_memory(control(), thread_local_excluded_offset, _gvn.transform(exclusion), T_BOOLEAN, MemNode::unordered, true); 4075 4076 // Store release 4077 Node * vthread_true_memory = store_to_memory(control(), vthread_offset, _gvn.intcon(1), T_BOOLEAN, MemNode::release, true); 4078 4079 RegionNode* thread_compare_rgn = new RegionNode(PATH_LIMIT); 4080 record_for_igvn(thread_compare_rgn); 4081 PhiNode* thread_compare_mem = new PhiNode(thread_compare_rgn, Type::MEMORY, TypePtr::BOTTOM); 4082 record_for_igvn(thread_compare_mem); 4083 PhiNode* vthread = new PhiNode(thread_compare_rgn, TypeInt::BOOL); 4084 record_for_igvn(vthread); 4085 4086 // Merge the thread_compare control and memory. 4087 thread_compare_rgn->init_req(_true_path, control()); 4088 thread_compare_rgn->init_req(_false_path, thread_equal_carrierThread); 4089 thread_compare_mem->init_req(_true_path, vthread_true_memory); 4090 thread_compare_mem->init_req(_false_path, vthread_false_memory); 4091 4092 // Set output state. 4093 set_control(_gvn.transform(thread_compare_rgn)); 4094 set_all_memory(_gvn.transform(thread_compare_mem)); 4095 } 4096 4097 #endif // JFR_HAVE_INTRINSICS 4098 4099 //------------------------inline_native_currentCarrierThread------------------ 4100 bool LibraryCallKit::inline_native_currentCarrierThread() { 4101 Node* junk = nullptr; 4102 set_result(generate_current_thread(junk)); 4103 return true; 4104 } 4105 4106 //------------------------inline_native_currentThread------------------ 4107 bool LibraryCallKit::inline_native_currentThread() { 4108 Node* junk = nullptr; 4109 set_result(generate_virtual_thread(junk)); 4110 return true; 4111 } 4112 4113 //------------------------inline_native_setVthread------------------ 4114 bool LibraryCallKit::inline_native_setCurrentThread() { 4115 assert(C->method()->changes_current_thread(), 4116 "method changes current Thread but is not annotated ChangesCurrentThread"); 4117 Node* arr = argument(1); 4118 Node* thread = _gvn.transform(new ThreadLocalNode()); 4119 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::vthread_offset())); 4120 Node* thread_obj_handle 4121 = make_load(nullptr, p, p->bottom_type()->is_ptr(), T_OBJECT, MemNode::unordered); 4122 thread_obj_handle = _gvn.transform(thread_obj_handle); 4123 const TypePtr *adr_type = _gvn.type(thread_obj_handle)->isa_ptr(); 4124 access_store_at(nullptr, thread_obj_handle, adr_type, arr, _gvn.type(arr), T_OBJECT, IN_NATIVE | MO_UNORDERED); 4125 4126 // Change the _monitor_owner_id of the JavaThread 4127 Node* tid = load_field_from_object(arr, "tid", "J"); 4128 Node* monitor_owner_id_offset = basic_plus_adr(thread, in_bytes(JavaThread::monitor_owner_id_offset())); 4129 store_to_memory(control(), monitor_owner_id_offset, tid, T_LONG, MemNode::unordered, true); 4130 4131 JFR_ONLY(extend_setCurrentThread(thread, arr);) 4132 return true; 4133 } 4134 4135 const Type* LibraryCallKit::scopedValueCache_type() { 4136 ciKlass* objects_klass = ciObjArrayKlass::make(env()->Object_klass()); 4137 const TypeOopPtr* etype = TypeOopPtr::make_from_klass(env()->Object_klass()); 4138 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true); 4139 4140 // Because we create the scopedValue cache lazily we have to make the 4141 // type of the result BotPTR. 4142 bool xk = etype->klass_is_exact(); 4143 const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, TypeAryPtr::Offset(0)); 4144 return objects_type; 4145 } 4146 4147 Node* LibraryCallKit::scopedValueCache_helper() { 4148 Node* thread = _gvn.transform(new ThreadLocalNode()); 4149 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::scopedValueCache_offset())); 4150 // We cannot use immutable_memory() because we might flip onto a 4151 // different carrier thread, at which point we'll need to use that 4152 // carrier thread's cache. 4153 // return _gvn.transform(LoadNode::make(_gvn, nullptr, immutable_memory(), p, p->bottom_type()->is_ptr(), 4154 // TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered)); 4155 return make_load(nullptr, p, p->bottom_type()->is_ptr(), T_ADDRESS, MemNode::unordered); 4156 } 4157 4158 //------------------------inline_native_scopedValueCache------------------ 4159 bool LibraryCallKit::inline_native_scopedValueCache() { 4160 Node* cache_obj_handle = scopedValueCache_helper(); 4161 const Type* objects_type = scopedValueCache_type(); 4162 set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE)); 4163 4164 return true; 4165 } 4166 4167 //------------------------inline_native_setScopedValueCache------------------ 4168 bool LibraryCallKit::inline_native_setScopedValueCache() { 4169 Node* arr = argument(0); 4170 Node* cache_obj_handle = scopedValueCache_helper(); 4171 const Type* objects_type = scopedValueCache_type(); 4172 4173 const TypePtr *adr_type = _gvn.type(cache_obj_handle)->isa_ptr(); 4174 access_store_at(nullptr, cache_obj_handle, adr_type, arr, objects_type, T_OBJECT, IN_NATIVE | MO_UNORDERED); 4175 4176 return true; 4177 } 4178 4179 //------------------------inline_native_Continuation_pin and unpin----------- 4180 4181 // Shared implementation routine for both pin and unpin. 4182 bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) { 4183 enum { _true_path = 1, _false_path = 2, PATH_LIMIT }; 4184 4185 // Save input memory. 4186 Node* input_memory_state = reset_memory(); 4187 set_all_memory(input_memory_state); 4188 4189 // TLS 4190 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 4191 Node* last_continuation_offset = basic_plus_adr(top(), tls_ptr, in_bytes(JavaThread::cont_entry_offset())); 4192 Node* last_continuation = make_load(control(), last_continuation_offset, last_continuation_offset->get_ptr_type(), T_ADDRESS, MemNode::unordered); 4193 4194 // Null check the last continuation object. 4195 Node* continuation_cmp_null = _gvn.transform(new CmpPNode(last_continuation, null())); 4196 Node* test_continuation_not_equal_null = _gvn.transform(new BoolNode(continuation_cmp_null, BoolTest::ne)); 4197 IfNode* iff_continuation_not_equal_null = create_and_map_if(control(), test_continuation_not_equal_null, PROB_MAX, COUNT_UNKNOWN); 4198 4199 // False path, last continuation is null. 4200 Node* continuation_is_null = _gvn.transform(new IfFalseNode(iff_continuation_not_equal_null)); 4201 4202 // True path, last continuation is not null. 4203 Node* continuation_is_not_null = _gvn.transform(new IfTrueNode(iff_continuation_not_equal_null)); 4204 4205 set_control(continuation_is_not_null); 4206 4207 // Load the pin count from the last continuation. 4208 Node* pin_count_offset = basic_plus_adr(top(), last_continuation, in_bytes(ContinuationEntry::pin_count_offset())); 4209 Node* pin_count = make_load(control(), pin_count_offset, TypeInt::INT, T_INT, MemNode::unordered); 4210 4211 // The loaded pin count is compared against a context specific rhs for over/underflow detection. 4212 Node* pin_count_rhs; 4213 if (unpin) { 4214 pin_count_rhs = _gvn.intcon(0); 4215 } else { 4216 pin_count_rhs = _gvn.intcon(UINT32_MAX); 4217 } 4218 Node* pin_count_cmp = _gvn.transform(new CmpUNode(_gvn.transform(pin_count), pin_count_rhs)); 4219 Node* test_pin_count_over_underflow = _gvn.transform(new BoolNode(pin_count_cmp, BoolTest::eq)); 4220 IfNode* iff_pin_count_over_underflow = create_and_map_if(control(), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN); 4221 4222 // True branch, pin count over/underflow. 4223 Node* pin_count_over_underflow = _gvn.transform(new IfTrueNode(iff_pin_count_over_underflow)); 4224 { 4225 // Trap (but not deoptimize (Action_none)) and continue in the interpreter 4226 // which will throw IllegalStateException for pin count over/underflow. 4227 // No memory changed so far - we can use memory create by reset_memory() 4228 // at the beginning of this intrinsic. No need to call reset_memory() again. 4229 PreserveJVMState pjvms(this); 4230 set_control(pin_count_over_underflow); 4231 uncommon_trap(Deoptimization::Reason_intrinsic, 4232 Deoptimization::Action_none); 4233 assert(stopped(), "invariant"); 4234 } 4235 4236 // False branch, no pin count over/underflow. Increment or decrement pin count and store back. 4237 Node* valid_pin_count = _gvn.transform(new IfFalseNode(iff_pin_count_over_underflow)); 4238 set_control(valid_pin_count); 4239 4240 Node* next_pin_count; 4241 if (unpin) { 4242 next_pin_count = _gvn.transform(new SubINode(pin_count, _gvn.intcon(1))); 4243 } else { 4244 next_pin_count = _gvn.transform(new AddINode(pin_count, _gvn.intcon(1))); 4245 } 4246 4247 store_to_memory(control(), pin_count_offset, next_pin_count, T_INT, MemNode::unordered); 4248 4249 // Result of top level CFG and Memory. 4250 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 4251 record_for_igvn(result_rgn); 4252 PhiNode* result_mem = new PhiNode(result_rgn, Type::MEMORY, TypePtr::BOTTOM); 4253 record_for_igvn(result_mem); 4254 4255 result_rgn->init_req(_true_path, _gvn.transform(valid_pin_count)); 4256 result_rgn->init_req(_false_path, _gvn.transform(continuation_is_null)); 4257 result_mem->init_req(_true_path, _gvn.transform(reset_memory())); 4258 result_mem->init_req(_false_path, _gvn.transform(input_memory_state)); 4259 4260 // Set output state. 4261 set_control(_gvn.transform(result_rgn)); 4262 set_all_memory(_gvn.transform(result_mem)); 4263 4264 return true; 4265 } 4266 4267 //-----------------------load_klass_from_mirror_common------------------------- 4268 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 4269 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 4270 // and branch to the given path on the region. 4271 // If never_see_null, take an uncommon trap on null, so we can optimistically 4272 // compile for the non-null case. 4273 // If the region is null, force never_see_null = true. 4274 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 4275 bool never_see_null, 4276 RegionNode* region, 4277 int null_path, 4278 int offset) { 4279 if (region == nullptr) never_see_null = true; 4280 Node* p = basic_plus_adr(mirror, offset); 4281 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL; 4282 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 4283 Node* null_ctl = top(); 4284 kls = null_check_oop(kls, &null_ctl, never_see_null); 4285 if (region != nullptr) { 4286 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 4287 region->init_req(null_path, null_ctl); 4288 } else { 4289 assert(null_ctl == top(), "no loose ends"); 4290 } 4291 return kls; 4292 } 4293 4294 //--------------------(inline_native_Class_query helpers)--------------------- 4295 // Use this for JVM_ACC_INTERFACE. 4296 // Fall through if (mods & mask) == bits, take the guard otherwise. 4297 Node* LibraryCallKit::generate_klass_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region, 4298 ByteSize offset, const Type* type, BasicType bt) { 4299 // Branch around if the given klass has the given modifier bit set. 4300 // Like generate_guard, adds a new path onto the region. 4301 Node* modp = basic_plus_adr(kls, in_bytes(offset)); 4302 Node* mods = make_load(nullptr, modp, type, bt, MemNode::unordered); 4303 Node* mask = intcon(modifier_mask); 4304 Node* bits = intcon(modifier_bits); 4305 Node* mbit = _gvn.transform(new AndINode(mods, mask)); 4306 Node* cmp = _gvn.transform(new CmpINode(mbit, bits)); 4307 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 4308 return generate_fair_guard(bol, region); 4309 } 4310 4311 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 4312 return generate_klass_flags_guard(kls, JVM_ACC_INTERFACE, 0, region, 4313 Klass::access_flags_offset(), TypeInt::CHAR, T_CHAR); 4314 } 4315 4316 // Use this for testing if Klass is_hidden, has_finalizer, and is_cloneable_fast. 4317 Node* LibraryCallKit::generate_misc_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 4318 return generate_klass_flags_guard(kls, modifier_mask, modifier_bits, region, 4319 Klass::misc_flags_offset(), TypeInt::UBYTE, T_BOOLEAN); 4320 } 4321 4322 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) { 4323 return generate_misc_flags_guard(kls, KlassFlags::_misc_is_hidden_class, 0, region); 4324 } 4325 4326 //-------------------------inline_native_Class_query------------------- 4327 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 4328 const Type* return_type = TypeInt::BOOL; 4329 Node* prim_return_value = top(); // what happens if it's a primitive class? 4330 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4331 bool expect_prim = false; // most of these guys expect to work on refs 4332 4333 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 4334 4335 Node* mirror = argument(0); 4336 Node* obj = top(); 4337 4338 switch (id) { 4339 case vmIntrinsics::_isInstance: 4340 // nothing is an instance of a primitive type 4341 prim_return_value = intcon(0); 4342 obj = argument(1); 4343 break; 4344 case vmIntrinsics::_isHidden: 4345 prim_return_value = intcon(0); 4346 break; 4347 case vmIntrinsics::_getSuperclass: 4348 prim_return_value = null(); 4349 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 4350 break; 4351 case vmIntrinsics::_getClassAccessFlags: 4352 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 4353 return_type = TypeInt::CHAR; 4354 break; 4355 default: 4356 fatal_unexpected_iid(id); 4357 break; 4358 } 4359 4360 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 4361 if (mirror_con == nullptr) return false; // cannot happen? 4362 4363 #ifndef PRODUCT 4364 if (C->print_intrinsics() || C->print_inlining()) { 4365 ciType* k = mirror_con->java_mirror_type(); 4366 if (k) { 4367 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 4368 k->print_name(); 4369 tty->cr(); 4370 } 4371 } 4372 #endif 4373 4374 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 4375 RegionNode* region = new RegionNode(PATH_LIMIT); 4376 record_for_igvn(region); 4377 PhiNode* phi = new PhiNode(region, return_type); 4378 4379 // The mirror will never be null of Reflection.getClassAccessFlags, however 4380 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 4381 // if it is. See bug 4774291. 4382 4383 // For Reflection.getClassAccessFlags(), the null check occurs in 4384 // the wrong place; see inline_unsafe_access(), above, for a similar 4385 // situation. 4386 mirror = null_check(mirror); 4387 // If mirror or obj is dead, only null-path is taken. 4388 if (stopped()) return true; 4389 4390 if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 4391 4392 // Now load the mirror's klass metaobject, and null-check it. 4393 // Side-effects region with the control path if the klass is null. 4394 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 4395 // If kls is null, we have a primitive mirror. 4396 phi->init_req(_prim_path, prim_return_value); 4397 if (stopped()) { set_result(region, phi); return true; } 4398 bool safe_for_replace = (region->in(_prim_path) == top()); 4399 4400 Node* p; // handy temp 4401 Node* null_ctl; 4402 4403 // Now that we have the non-null klass, we can perform the real query. 4404 // For constant classes, the query will constant-fold in LoadNode::Value. 4405 Node* query_value = top(); 4406 switch (id) { 4407 case vmIntrinsics::_isInstance: 4408 // nothing is an instance of a primitive type 4409 query_value = gen_instanceof(obj, kls, safe_for_replace); 4410 break; 4411 4412 case vmIntrinsics::_isHidden: 4413 // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.) 4414 if (generate_hidden_class_guard(kls, region) != nullptr) 4415 // A guard was added. If the guard is taken, it was an hidden class. 4416 phi->add_req(intcon(1)); 4417 // If we fall through, it's a plain class. 4418 query_value = intcon(0); 4419 break; 4420 4421 4422 case vmIntrinsics::_getSuperclass: 4423 // The rules here are somewhat unfortunate, but we can still do better 4424 // with random logic than with a JNI call. 4425 // Interfaces store null or Object as _super, but must report null. 4426 // Arrays store an intermediate super as _super, but must report Object. 4427 // Other types can report the actual _super. 4428 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 4429 if (generate_interface_guard(kls, region) != nullptr) 4430 // A guard was added. If the guard is taken, it was an interface. 4431 phi->add_req(null()); 4432 if (generate_array_guard(kls, region) != nullptr) 4433 // A guard was added. If the guard is taken, it was an array. 4434 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 4435 // If we fall through, it's a plain class. Get its _super. 4436 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 4437 kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT_OR_NULL)); 4438 null_ctl = top(); 4439 kls = null_check_oop(kls, &null_ctl); 4440 if (null_ctl != top()) { 4441 // If the guard is taken, Object.superClass is null (both klass and mirror). 4442 region->add_req(null_ctl); 4443 phi ->add_req(null()); 4444 } 4445 if (!stopped()) { 4446 query_value = load_mirror_from_klass(kls); 4447 } 4448 break; 4449 4450 case vmIntrinsics::_getClassAccessFlags: 4451 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 4452 query_value = make_load(nullptr, p, TypeInt::CHAR, T_CHAR, MemNode::unordered); 4453 break; 4454 4455 default: 4456 fatal_unexpected_iid(id); 4457 break; 4458 } 4459 4460 // Fall-through is the normal case of a query to a real class. 4461 phi->init_req(1, query_value); 4462 region->init_req(1, control()); 4463 4464 C->set_has_split_ifs(true); // Has chance for split-if optimization 4465 set_result(region, phi); 4466 return true; 4467 } 4468 4469 4470 //-------------------------inline_Class_cast------------------- 4471 bool LibraryCallKit::inline_Class_cast() { 4472 Node* mirror = argument(0); // Class 4473 Node* obj = argument(1); 4474 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 4475 if (mirror_con == nullptr) { 4476 return false; // dead path (mirror->is_top()). 4477 } 4478 if (obj == nullptr || obj->is_top()) { 4479 return false; // dead path 4480 } 4481 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr(); 4482 4483 // First, see if Class.cast() can be folded statically. 4484 // java_mirror_type() returns non-null for compile-time Class constants. 4485 bool is_null_free_array = false; 4486 ciType* tm = mirror_con->java_mirror_type(&is_null_free_array); 4487 if (tm != nullptr && tm->is_klass() && 4488 tp != nullptr) { 4489 if (!tp->is_loaded()) { 4490 // Don't use intrinsic when class is not loaded. 4491 return false; 4492 } else { 4493 const TypeKlassPtr* tklass = TypeKlassPtr::make(tm->as_klass(), Type::trust_interfaces); 4494 if (is_null_free_array) { 4495 tklass = tklass->is_aryklassptr()->cast_to_null_free(); 4496 } 4497 int static_res = C->static_subtype_check(tklass, tp->as_klass_type()); 4498 if (static_res == Compile::SSC_always_true) { 4499 // isInstance() is true - fold the code. 4500 set_result(obj); 4501 return true; 4502 } else if (static_res == Compile::SSC_always_false) { 4503 // Don't use intrinsic, have to throw ClassCastException. 4504 // If the reference is null, the non-intrinsic bytecode will 4505 // be optimized appropriately. 4506 return false; 4507 } 4508 } 4509 } 4510 4511 // Bailout intrinsic and do normal inlining if exception path is frequent. 4512 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 4513 return false; 4514 } 4515 4516 // Generate dynamic checks. 4517 // Class.cast() is java implementation of _checkcast bytecode. 4518 // Do checkcast (Parse::do_checkcast()) optimizations here. 4519 4520 mirror = null_check(mirror); 4521 // If mirror is dead, only null-path is taken. 4522 if (stopped()) { 4523 return true; 4524 } 4525 4526 // Not-subtype or the mirror's klass ptr is nullptr (in case it is a primitive). 4527 enum { _bad_type_path = 1, _prim_path = 2, _npe_path = 3, PATH_LIMIT }; 4528 RegionNode* region = new RegionNode(PATH_LIMIT); 4529 record_for_igvn(region); 4530 4531 // Now load the mirror's klass metaobject, and null-check it. 4532 // If kls is null, we have a primitive mirror and 4533 // nothing is an instance of a primitive type. 4534 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path); 4535 4536 Node* res = top(); 4537 Node* io = i_o(); 4538 Node* mem = merged_memory(); 4539 if (!stopped()) { 4540 4541 Node* bad_type_ctrl = top(); 4542 // Do checkcast optimizations. 4543 res = gen_checkcast(obj, kls, &bad_type_ctrl); 4544 region->init_req(_bad_type_path, bad_type_ctrl); 4545 } 4546 if (region->in(_prim_path) != top() || 4547 region->in(_bad_type_path) != top() || 4548 region->in(_npe_path) != top()) { 4549 // Let Interpreter throw ClassCastException. 4550 PreserveJVMState pjvms(this); 4551 set_control(_gvn.transform(region)); 4552 // Set IO and memory because gen_checkcast may override them when buffering inline types 4553 set_i_o(io); 4554 set_all_memory(mem); 4555 uncommon_trap(Deoptimization::Reason_intrinsic, 4556 Deoptimization::Action_maybe_recompile); 4557 } 4558 if (!stopped()) { 4559 set_result(res); 4560 } 4561 return true; 4562 } 4563 4564 4565 //--------------------------inline_native_subtype_check------------------------ 4566 // This intrinsic takes the JNI calls out of the heart of 4567 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 4568 bool LibraryCallKit::inline_native_subtype_check() { 4569 // Pull both arguments off the stack. 4570 Node* args[2]; // two java.lang.Class mirrors: superc, subc 4571 args[0] = argument(0); 4572 args[1] = argument(1); 4573 Node* klasses[2]; // corresponding Klasses: superk, subk 4574 klasses[0] = klasses[1] = top(); 4575 4576 enum { 4577 // A full decision tree on {superc is prim, subc is prim}: 4578 _prim_0_path = 1, // {P,N} => false 4579 // {P,P} & superc!=subc => false 4580 _prim_same_path, // {P,P} & superc==subc => true 4581 _prim_1_path, // {N,P} => false 4582 _ref_subtype_path, // {N,N} & subtype check wins => true 4583 _both_ref_path, // {N,N} & subtype check loses => false 4584 PATH_LIMIT 4585 }; 4586 4587 RegionNode* region = new RegionNode(PATH_LIMIT); 4588 RegionNode* prim_region = new RegionNode(2); 4589 Node* phi = new PhiNode(region, TypeInt::BOOL); 4590 record_for_igvn(region); 4591 record_for_igvn(prim_region); 4592 4593 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 4594 const TypeKlassPtr* kls_type = TypeInstKlassPtr::OBJECT_OR_NULL; 4595 int class_klass_offset = java_lang_Class::klass_offset(); 4596 4597 // First null-check both mirrors and load each mirror's klass metaobject. 4598 int which_arg; 4599 for (which_arg = 0; which_arg <= 1; which_arg++) { 4600 Node* arg = args[which_arg]; 4601 arg = null_check(arg); 4602 if (stopped()) break; 4603 args[which_arg] = arg; 4604 4605 Node* p = basic_plus_adr(arg, class_klass_offset); 4606 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type); 4607 klasses[which_arg] = _gvn.transform(kls); 4608 } 4609 4610 // Having loaded both klasses, test each for null. 4611 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4612 for (which_arg = 0; which_arg <= 1; which_arg++) { 4613 Node* kls = klasses[which_arg]; 4614 Node* null_ctl = top(); 4615 kls = null_check_oop(kls, &null_ctl, never_see_null); 4616 if (which_arg == 0) { 4617 prim_region->init_req(1, null_ctl); 4618 } else { 4619 region->init_req(_prim_1_path, null_ctl); 4620 } 4621 if (stopped()) break; 4622 klasses[which_arg] = kls; 4623 } 4624 4625 if (!stopped()) { 4626 // now we have two reference types, in klasses[0..1] 4627 Node* subk = klasses[1]; // the argument to isAssignableFrom 4628 Node* superk = klasses[0]; // the receiver 4629 region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 4630 region->set_req(_ref_subtype_path, control()); 4631 } 4632 4633 // If both operands are primitive (both klasses null), then 4634 // we must return true when they are identical primitives. 4635 // It is convenient to test this after the first null klass check. 4636 // This path is also used if superc is a value mirror. 4637 set_control(_gvn.transform(prim_region)); 4638 if (!stopped()) { 4639 // Since superc is primitive, make a guard for the superc==subc case. 4640 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1])); 4641 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq)); 4642 generate_fair_guard(bol_eq, region); 4643 if (region->req() == PATH_LIMIT+1) { 4644 // A guard was added. If the added guard is taken, superc==subc. 4645 region->swap_edges(PATH_LIMIT, _prim_same_path); 4646 region->del_req(PATH_LIMIT); 4647 } 4648 region->set_req(_prim_0_path, control()); // Not equal after all. 4649 } 4650 4651 // these are the only paths that produce 'true': 4652 phi->set_req(_prim_same_path, intcon(1)); 4653 phi->set_req(_ref_subtype_path, intcon(1)); 4654 4655 // pull together the cases: 4656 assert(region->req() == PATH_LIMIT, "sane region"); 4657 for (uint i = 1; i < region->req(); i++) { 4658 Node* ctl = region->in(i); 4659 if (ctl == nullptr || ctl == top()) { 4660 region->set_req(i, top()); 4661 phi ->set_req(i, top()); 4662 } else if (phi->in(i) == nullptr) { 4663 phi->set_req(i, intcon(0)); // all other paths produce 'false' 4664 } 4665 } 4666 4667 set_control(_gvn.transform(region)); 4668 set_result(_gvn.transform(phi)); 4669 return true; 4670 } 4671 4672 //---------------------generate_array_guard_common------------------------ 4673 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind, Node** obj) { 4674 4675 if (stopped()) { 4676 return nullptr; 4677 } 4678 4679 // Like generate_guard, adds a new path onto the region. 4680 jint layout_con = 0; 4681 Node* layout_val = get_layout_helper(kls, layout_con); 4682 if (layout_val == nullptr) { 4683 bool query = 0; 4684 switch(kind) { 4685 case ObjectArray: query = Klass::layout_helper_is_objArray(layout_con); break; 4686 case NonObjectArray: query = !Klass::layout_helper_is_objArray(layout_con); break; 4687 case TypeArray: query = Klass::layout_helper_is_typeArray(layout_con); break; 4688 case AnyArray: query = Klass::layout_helper_is_array(layout_con); break; 4689 case NonArray: query = !Klass::layout_helper_is_array(layout_con); break; 4690 default: 4691 ShouldNotReachHere(); 4692 } 4693 if (!query) { 4694 return nullptr; // never a branch 4695 } else { // always a branch 4696 Node* always_branch = control(); 4697 if (region != nullptr) 4698 region->add_req(always_branch); 4699 set_control(top()); 4700 return always_branch; 4701 } 4702 } 4703 unsigned int value = 0; 4704 BoolTest::mask btest = BoolTest::illegal; 4705 switch(kind) { 4706 case ObjectArray: 4707 case NonObjectArray: { 4708 value = Klass::_lh_array_tag_obj_value; 4709 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift))); 4710 btest = (kind == ObjectArray) ? BoolTest::eq : BoolTest::ne; 4711 break; 4712 } 4713 case TypeArray: { 4714 value = Klass::_lh_array_tag_type_value; 4715 layout_val = _gvn.transform(new RShiftINode(layout_val, intcon(Klass::_lh_array_tag_shift))); 4716 btest = BoolTest::eq; 4717 break; 4718 } 4719 case AnyArray: value = Klass::_lh_neutral_value; btest = BoolTest::lt; break; 4720 case NonArray: value = Klass::_lh_neutral_value; btest = BoolTest::gt; break; 4721 default: 4722 ShouldNotReachHere(); 4723 } 4724 // Now test the correct condition. 4725 jint nval = (jint)value; 4726 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval))); 4727 Node* bol = _gvn.transform(new BoolNode(cmp, btest)); 4728 Node* ctrl = generate_fair_guard(bol, region); 4729 Node* is_array_ctrl = kind == NonArray ? control() : ctrl; 4730 if (obj != nullptr && is_array_ctrl != nullptr && is_array_ctrl != top()) { 4731 // Keep track of the fact that 'obj' is an array to prevent 4732 // array specific accesses from floating above the guard. 4733 *obj = _gvn.transform(new CastPPNode(is_array_ctrl, *obj, TypeAryPtr::BOTTOM)); 4734 } 4735 return ctrl; 4736 } 4737 4738 // public static native Object[] newNullRestrictedAtomicArray(Class<?> componentType, int length, Object initVal); 4739 // public static native Object[] newNullRestrictedNonAtomicArray(Class<?> componentType, int length, Object initVal); 4740 // public static native Object[] newNullableAtomicArray(Class<?> componentType, int length); 4741 bool LibraryCallKit::inline_newArray(bool null_free, bool atomic) { 4742 assert(null_free || atomic, "nullable implies atomic"); 4743 Node* componentType = argument(0); 4744 Node* length = argument(1); 4745 Node* init_val = null_free ? argument(2) : nullptr; 4746 4747 const TypeInstPtr* tp = _gvn.type(componentType)->isa_instptr(); 4748 if (tp != nullptr) { 4749 ciInstanceKlass* ik = tp->instance_klass(); 4750 if (ik == C->env()->Class_klass()) { 4751 ciType* t = tp->java_mirror_type(); 4752 if (t != nullptr && t->is_inlinetype()) { 4753 ciInlineKlass* vk = t->as_inline_klass(); 4754 bool flat = vk->maybe_flat_in_array(); 4755 if (flat && atomic) { 4756 // Only flat if we have a corresponding atomic layout 4757 flat = null_free ? vk->has_atomic_layout() : vk->has_nullable_atomic_layout(); 4758 } 4759 // TODO 8350865 refactor 4760 if (flat && !atomic) { 4761 flat = vk->has_non_atomic_layout(); 4762 } 4763 4764 // TOOD 8350865 ZGC needs card marks on initializing oop stores 4765 if (UseZGC && null_free && !flat) { 4766 return false; 4767 } 4768 4769 ciArrayKlass* array_klass = ciArrayKlass::make(t, flat, null_free, atomic); 4770 if (array_klass->is_loaded() && array_klass->element_klass()->as_inline_klass()->is_initialized()) { 4771 const TypeAryKlassPtr* array_klass_type = TypeAryKlassPtr::make(array_klass, Type::trust_interfaces); 4772 if (null_free) { 4773 if (init_val->is_InlineType()) { 4774 if (array_klass_type->is_flat() && init_val->as_InlineType()->is_all_zero(&gvn(), /* flat */ true)) { 4775 // Zeroing is enough because the init value is the all-zero value 4776 init_val = nullptr; 4777 } else { 4778 init_val = init_val->as_InlineType()->buffer(this); 4779 } 4780 } 4781 // TODO 8350865 Should we add a check of the init_val type (maybe in debug only + halt)? 4782 } 4783 Node* obj = new_array(makecon(array_klass_type), length, 0, nullptr, false, init_val); 4784 const TypeAryPtr* arytype = gvn().type(obj)->is_aryptr(); 4785 assert(arytype->is_null_free() == null_free, "inconsistency"); 4786 assert(arytype->is_not_null_free() == !null_free, "inconsistency"); 4787 assert(arytype->is_flat() == flat, "inconsistency"); 4788 assert(arytype->is_aryptr()->is_not_flat() == !flat, "inconsistency"); 4789 set_result(obj); 4790 return true; 4791 } 4792 } 4793 } 4794 } 4795 return false; 4796 } 4797 4798 //-----------------------inline_native_newArray-------------------------- 4799 // private static native Object java.lang.reflect.Array.newArray(Class<?> componentType, int length); 4800 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size); 4801 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) { 4802 Node* mirror; 4803 Node* count_val; 4804 if (uninitialized) { 4805 null_check_receiver(); 4806 mirror = argument(1); 4807 count_val = argument(2); 4808 } else { 4809 mirror = argument(0); 4810 count_val = argument(1); 4811 } 4812 4813 mirror = null_check(mirror); 4814 // If mirror or obj is dead, only null-path is taken. 4815 if (stopped()) return true; 4816 4817 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 4818 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 4819 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 4820 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 4821 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 4822 4823 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 4824 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 4825 result_reg, _slow_path); 4826 Node* normal_ctl = control(); 4827 Node* no_array_ctl = result_reg->in(_slow_path); 4828 4829 // Generate code for the slow case. We make a call to newArray(). 4830 set_control(no_array_ctl); 4831 if (!stopped()) { 4832 // Either the input type is void.class, or else the 4833 // array klass has not yet been cached. Either the 4834 // ensuing call will throw an exception, or else it 4835 // will cache the array klass for next time. 4836 PreserveJVMState pjvms(this); 4837 CallJavaNode* slow_call = nullptr; 4838 if (uninitialized) { 4839 // Generate optimized virtual call (holder class 'Unsafe' is final) 4840 slow_call = generate_method_call(vmIntrinsics::_allocateUninitializedArray, false, false, true); 4841 } else { 4842 slow_call = generate_method_call_static(vmIntrinsics::_newArray, true); 4843 } 4844 Node* slow_result = set_results_for_java_call(slow_call); 4845 // this->control() comes from set_results_for_java_call 4846 result_reg->set_req(_slow_path, control()); 4847 result_val->set_req(_slow_path, slow_result); 4848 result_io ->set_req(_slow_path, i_o()); 4849 result_mem->set_req(_slow_path, reset_memory()); 4850 } 4851 4852 set_control(normal_ctl); 4853 if (!stopped()) { 4854 // Normal case: The array type has been cached in the java.lang.Class. 4855 // The following call works fine even if the array type is polymorphic. 4856 // It could be a dynamic mix of int[], boolean[], Object[], etc. 4857 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 4858 result_reg->init_req(_normal_path, control()); 4859 result_val->init_req(_normal_path, obj); 4860 result_io ->init_req(_normal_path, i_o()); 4861 result_mem->init_req(_normal_path, reset_memory()); 4862 4863 if (uninitialized) { 4864 // Mark the allocation so that zeroing is skipped 4865 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj); 4866 alloc->maybe_set_complete(&_gvn); 4867 } 4868 } 4869 4870 // Return the combined state. 4871 set_i_o( _gvn.transform(result_io) ); 4872 set_all_memory( _gvn.transform(result_mem)); 4873 4874 C->set_has_split_ifs(true); // Has chance for split-if optimization 4875 set_result(result_reg, result_val); 4876 return true; 4877 } 4878 4879 //----------------------inline_native_getLength-------------------------- 4880 // public static native int java.lang.reflect.Array.getLength(Object array); 4881 bool LibraryCallKit::inline_native_getLength() { 4882 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 4883 4884 Node* array = null_check(argument(0)); 4885 // If array is dead, only null-path is taken. 4886 if (stopped()) return true; 4887 4888 // Deoptimize if it is a non-array. 4889 Node* non_array = generate_non_array_guard(load_object_klass(array), nullptr, &array); 4890 4891 if (non_array != nullptr) { 4892 PreserveJVMState pjvms(this); 4893 set_control(non_array); 4894 uncommon_trap(Deoptimization::Reason_intrinsic, 4895 Deoptimization::Action_maybe_recompile); 4896 } 4897 4898 // If control is dead, only non-array-path is taken. 4899 if (stopped()) return true; 4900 4901 // The works fine even if the array type is polymorphic. 4902 // It could be a dynamic mix of int[], boolean[], Object[], etc. 4903 Node* result = load_array_length(array); 4904 4905 C->set_has_split_ifs(true); // Has chance for split-if optimization 4906 set_result(result); 4907 return true; 4908 } 4909 4910 //------------------------inline_array_copyOf---------------------------- 4911 // public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 4912 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 4913 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 4914 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 4915 4916 // Get the arguments. 4917 Node* original = argument(0); 4918 Node* start = is_copyOfRange? argument(1): intcon(0); 4919 Node* end = is_copyOfRange? argument(2): argument(1); 4920 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 4921 4922 Node* newcopy = nullptr; 4923 4924 // Set the original stack and the reexecute bit for the interpreter to reexecute 4925 // the bytecode that invokes Arrays.copyOf if deoptimization happens. 4926 { PreserveReexecuteState preexecs(this); 4927 jvms()->set_should_reexecute(true); 4928 4929 array_type_mirror = null_check(array_type_mirror); 4930 original = null_check(original); 4931 4932 // Check if a null path was taken unconditionally. 4933 if (stopped()) return true; 4934 4935 Node* orig_length = load_array_length(original); 4936 4937 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, nullptr, 0); 4938 klass_node = null_check(klass_node); 4939 4940 RegionNode* bailout = new RegionNode(1); 4941 record_for_igvn(bailout); 4942 4943 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 4944 // Bail out if that is so. 4945 // Inline type array may have object field that would require a 4946 // write barrier. Conservatively, go to slow path. 4947 // TODO 8251971: Optimize for the case when flat src/dst are later found 4948 // to not contain oops (i.e., move this check to the macro expansion phase). 4949 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 4950 const TypeAryPtr* orig_t = _gvn.type(original)->isa_aryptr(); 4951 const TypeKlassPtr* tklass = _gvn.type(klass_node)->is_klassptr(); 4952 bool exclude_flat = UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, false, false, BarrierSetC2::Parsing) && 4953 // Can src array be flat and contain oops? 4954 (orig_t == nullptr || (!orig_t->is_not_flat() && (!orig_t->is_flat() || orig_t->elem()->inline_klass()->contains_oops()))) && 4955 // Can dest array be flat and contain oops? 4956 tklass->can_be_inline_array() && (!tklass->is_flat() || tklass->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->as_inline_klass()->contains_oops()); 4957 Node* not_objArray = exclude_flat ? generate_non_objArray_guard(klass_node, bailout) : generate_typeArray_guard(klass_node, bailout); 4958 if (not_objArray != nullptr) { 4959 // Improve the klass node's type from the new optimistic assumption: 4960 ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 4961 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 4962 Node* cast = new CastPPNode(control(), klass_node, akls); 4963 klass_node = _gvn.transform(cast); 4964 } 4965 4966 // Bail out if either start or end is negative. 4967 generate_negative_guard(start, bailout, &start); 4968 generate_negative_guard(end, bailout, &end); 4969 4970 Node* length = end; 4971 if (_gvn.type(start) != TypeInt::ZERO) { 4972 length = _gvn.transform(new SubINode(end, start)); 4973 } 4974 4975 // Bail out if length is negative (i.e., if start > end). 4976 // Without this the new_array would throw 4977 // NegativeArraySizeException but IllegalArgumentException is what 4978 // should be thrown 4979 generate_negative_guard(length, bailout, &length); 4980 4981 // Handle inline type arrays 4982 bool can_validate = !too_many_traps(Deoptimization::Reason_class_check); 4983 if (!stopped()) { 4984 // TODO JDK-8329224 4985 if (!orig_t->is_null_free()) { 4986 // Not statically known to be null free, add a check 4987 generate_fair_guard(null_free_array_test(original), bailout); 4988 } 4989 orig_t = _gvn.type(original)->isa_aryptr(); 4990 if (orig_t != nullptr && orig_t->is_flat()) { 4991 // Src is flat, check that dest is flat as well 4992 if (exclude_flat) { 4993 // Dest can't be flat, bail out 4994 bailout->add_req(control()); 4995 set_control(top()); 4996 } else { 4997 generate_fair_guard(flat_array_test(klass_node, /* flat = */ false), bailout); 4998 } 4999 // TODO 8350865 This is not correct anymore. Write tests and fix logic similar to arraycopy. 5000 } else if (UseArrayFlattening && (orig_t == nullptr || !orig_t->is_not_flat()) && 5001 // If dest is flat, src must be flat as well (guaranteed by src <: dest check if validated). 5002 ((!tklass->is_flat() && tklass->can_be_inline_array()) || !can_validate)) { 5003 // Src might be flat and dest might not be flat. Go to the slow path if src is flat. 5004 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat. 5005 generate_fair_guard(flat_array_test(load_object_klass(original)), bailout); 5006 if (orig_t != nullptr) { 5007 orig_t = orig_t->cast_to_not_flat(); 5008 original = _gvn.transform(new CheckCastPPNode(control(), original, orig_t)); 5009 } 5010 } 5011 if (!can_validate) { 5012 // No validation. The subtype check emitted at macro expansion time will not go to the slow 5013 // path but call checkcast_arraycopy which can not handle flat/null-free inline type arrays. 5014 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat/null-free. 5015 generate_fair_guard(flat_array_test(klass_node), bailout); 5016 generate_fair_guard(null_free_array_test(original), bailout); 5017 } 5018 } 5019 5020 // Bail out if start is larger than the original length 5021 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start)); 5022 generate_negative_guard(orig_tail, bailout, &orig_tail); 5023 5024 if (bailout->req() > 1) { 5025 PreserveJVMState pjvms(this); 5026 set_control(_gvn.transform(bailout)); 5027 uncommon_trap(Deoptimization::Reason_intrinsic, 5028 Deoptimization::Action_maybe_recompile); 5029 } 5030 5031 if (!stopped()) { 5032 // How many elements will we copy from the original? 5033 // The answer is MinI(orig_tail, length). 5034 Node* moved = _gvn.transform(new MinINode(orig_tail, length)); 5035 5036 // Generate a direct call to the right arraycopy function(s). 5037 // We know the copy is disjoint but we might not know if the 5038 // oop stores need checking. 5039 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 5040 // This will fail a store-check if x contains any non-nulls. 5041 5042 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to 5043 // loads/stores but it is legal only if we're sure the 5044 // Arrays.copyOf would succeed. So we need all input arguments 5045 // to the copyOf to be validated, including that the copy to the 5046 // new array won't trigger an ArrayStoreException. That subtype 5047 // check can be optimized if we know something on the type of 5048 // the input array from type speculation. 5049 if (_gvn.type(klass_node)->singleton()) { 5050 const TypeKlassPtr* subk = _gvn.type(load_object_klass(original))->is_klassptr(); 5051 const TypeKlassPtr* superk = _gvn.type(klass_node)->is_klassptr(); 5052 5053 int test = C->static_subtype_check(superk, subk); 5054 if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) { 5055 const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr(); 5056 if (t_original->speculative_type() != nullptr) { 5057 original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true); 5058 } 5059 } 5060 } 5061 5062 bool validated = false; 5063 // Reason_class_check rather than Reason_intrinsic because we 5064 // want to intrinsify even if this traps. 5065 if (can_validate) { 5066 Node* not_subtype_ctrl = gen_subtype_check(original, klass_node); 5067 5068 if (not_subtype_ctrl != top()) { 5069 PreserveJVMState pjvms(this); 5070 set_control(not_subtype_ctrl); 5071 uncommon_trap(Deoptimization::Reason_class_check, 5072 Deoptimization::Action_make_not_entrant); 5073 assert(stopped(), "Should be stopped"); 5074 } 5075 validated = true; 5076 } 5077 5078 if (!stopped()) { 5079 newcopy = new_array(klass_node, length, 0); // no arguments to push 5080 5081 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, true, 5082 load_object_klass(original), klass_node); 5083 if (!is_copyOfRange) { 5084 ac->set_copyof(validated); 5085 } else { 5086 ac->set_copyofrange(validated); 5087 } 5088 Node* n = _gvn.transform(ac); 5089 if (n == ac) { 5090 ac->connect_outputs(this); 5091 } else { 5092 assert(validated, "shouldn't transform if all arguments not validated"); 5093 set_all_memory(n); 5094 } 5095 } 5096 } 5097 } // original reexecute is set back here 5098 5099 C->set_has_split_ifs(true); // Has chance for split-if optimization 5100 if (!stopped()) { 5101 set_result(newcopy); 5102 } 5103 return true; 5104 } 5105 5106 5107 //----------------------generate_virtual_guard--------------------------- 5108 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 5109 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 5110 RegionNode* slow_region) { 5111 ciMethod* method = callee(); 5112 int vtable_index = method->vtable_index(); 5113 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 5114 "bad index %d", vtable_index); 5115 // Get the Method* out of the appropriate vtable entry. 5116 int entry_offset = in_bytes(Klass::vtable_start_offset()) + 5117 vtable_index*vtableEntry::size_in_bytes() + 5118 in_bytes(vtableEntry::method_offset()); 5119 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 5120 Node* target_call = make_load(nullptr, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 5121 5122 // Compare the target method with the expected method (e.g., Object.hashCode). 5123 const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 5124 5125 Node* native_call = makecon(native_call_addr); 5126 Node* chk_native = _gvn.transform(new CmpPNode(target_call, native_call)); 5127 Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne)); 5128 5129 return generate_slow_guard(test_native, slow_region); 5130 } 5131 5132 //-----------------------generate_method_call---------------------------- 5133 // Use generate_method_call to make a slow-call to the real 5134 // method if the fast path fails. An alternative would be to 5135 // use a stub like OptoRuntime::slow_arraycopy_Java. 5136 // This only works for expanding the current library call, 5137 // not another intrinsic. (E.g., don't use this for making an 5138 // arraycopy call inside of the copyOf intrinsic.) 5139 CallJavaNode* 5140 LibraryCallKit::generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null) { 5141 // When compiling the intrinsic method itself, do not use this technique. 5142 guarantee(callee() != C->method(), "cannot make slow-call to self"); 5143 5144 ciMethod* method = callee(); 5145 // ensure the JVMS we have will be correct for this call 5146 guarantee(method_id == method->intrinsic_id(), "must match"); 5147 5148 const TypeFunc* tf = TypeFunc::make(method); 5149 if (res_not_null) { 5150 assert(tf->return_type() == T_OBJECT, ""); 5151 const TypeTuple* range = tf->range_cc(); 5152 const Type** fields = TypeTuple::fields(range->cnt()); 5153 fields[TypeFunc::Parms] = range->field_at(TypeFunc::Parms)->filter_speculative(TypePtr::NOTNULL); 5154 const TypeTuple* new_range = TypeTuple::make(range->cnt(), fields); 5155 tf = TypeFunc::make(tf->domain_cc(), new_range); 5156 } 5157 CallJavaNode* slow_call; 5158 if (is_static) { 5159 assert(!is_virtual, ""); 5160 slow_call = new CallStaticJavaNode(C, tf, 5161 SharedRuntime::get_resolve_static_call_stub(), method); 5162 } else if (is_virtual) { 5163 assert(!gvn().type(argument(0))->maybe_null(), "should not be null"); 5164 int vtable_index = Method::invalid_vtable_index; 5165 if (UseInlineCaches) { 5166 // Suppress the vtable call 5167 } else { 5168 // hashCode and clone are not a miranda methods, 5169 // so the vtable index is fixed. 5170 // No need to use the linkResolver to get it. 5171 vtable_index = method->vtable_index(); 5172 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 5173 "bad index %d", vtable_index); 5174 } 5175 slow_call = new CallDynamicJavaNode(tf, 5176 SharedRuntime::get_resolve_virtual_call_stub(), 5177 method, vtable_index); 5178 } else { // neither virtual nor static: opt_virtual 5179 assert(!gvn().type(argument(0))->maybe_null(), "should not be null"); 5180 slow_call = new CallStaticJavaNode(C, tf, 5181 SharedRuntime::get_resolve_opt_virtual_call_stub(), method); 5182 slow_call->set_optimized_virtual(true); 5183 } 5184 if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) { 5185 // To be able to issue a direct call (optimized virtual or virtual) 5186 // and skip a call to MH.linkTo*/invokeBasic adapter, additional information 5187 // about the method being invoked should be attached to the call site to 5188 // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C). 5189 slow_call->set_override_symbolic_info(true); 5190 } 5191 set_arguments_for_java_call(slow_call); 5192 set_edges_for_java_call(slow_call); 5193 return slow_call; 5194 } 5195 5196 5197 /** 5198 * Build special case code for calls to hashCode on an object. This call may 5199 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate 5200 * slightly different code. 5201 */ 5202 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 5203 assert(is_static == callee()->is_static(), "correct intrinsic selection"); 5204 assert(!(is_virtual && is_static), "either virtual, special, or static"); 5205 5206 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 5207 5208 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 5209 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT); 5210 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 5211 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 5212 Node* obj = argument(0); 5213 5214 // Don't intrinsify hashcode on inline types for now. 5215 // The "is locked" runtime check below also serves as inline type check and goes to the slow path. 5216 if (gvn().type(obj)->is_inlinetypeptr()) { 5217 return false; 5218 } 5219 5220 if (!is_static) { 5221 // Check for hashing null object 5222 obj = null_check_receiver(); 5223 if (stopped()) return true; // unconditionally null 5224 result_reg->init_req(_null_path, top()); 5225 result_val->init_req(_null_path, top()); 5226 } else { 5227 // Do a null check, and return zero if null. 5228 // System.identityHashCode(null) == 0 5229 Node* null_ctl = top(); 5230 obj = null_check_oop(obj, &null_ctl); 5231 result_reg->init_req(_null_path, null_ctl); 5232 result_val->init_req(_null_path, _gvn.intcon(0)); 5233 } 5234 5235 // Unconditionally null? Then return right away. 5236 if (stopped()) { 5237 set_control( result_reg->in(_null_path)); 5238 if (!stopped()) 5239 set_result(result_val->in(_null_path)); 5240 return true; 5241 } 5242 5243 // We only go to the fast case code if we pass a number of guards. The 5244 // paths which do not pass are accumulated in the slow_region. 5245 RegionNode* slow_region = new RegionNode(1); 5246 record_for_igvn(slow_region); 5247 5248 // If this is a virtual call, we generate a funny guard. We pull out 5249 // the vtable entry corresponding to hashCode() from the target object. 5250 // If the target method which we are calling happens to be the native 5251 // Object hashCode() method, we pass the guard. We do not need this 5252 // guard for non-virtual calls -- the caller is known to be the native 5253 // Object hashCode(). 5254 if (is_virtual) { 5255 // After null check, get the object's klass. 5256 Node* obj_klass = load_object_klass(obj); 5257 generate_virtual_guard(obj_klass, slow_region); 5258 } 5259 5260 // Get the header out of the object, use LoadMarkNode when available 5261 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 5262 // The control of the load must be null. Otherwise, the load can move before 5263 // the null check after castPP removal. 5264 Node* no_ctrl = nullptr; 5265 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 5266 5267 if (!UseObjectMonitorTable) { 5268 // Test the header to see if it is safe to read w.r.t. locking. 5269 // This also serves as guard against inline types 5270 Node *lock_mask = _gvn.MakeConX(markWord::inline_type_mask_in_place); 5271 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask)); 5272 if (LockingMode == LM_LIGHTWEIGHT) { 5273 Node *monitor_val = _gvn.MakeConX(markWord::monitor_value); 5274 Node *chk_monitor = _gvn.transform(new CmpXNode(lmasked_header, monitor_val)); 5275 Node *test_monitor = _gvn.transform(new BoolNode(chk_monitor, BoolTest::eq)); 5276 5277 generate_slow_guard(test_monitor, slow_region); 5278 } else { 5279 Node *unlocked_val = _gvn.MakeConX(markWord::unlocked_value); 5280 Node *chk_unlocked = _gvn.transform(new CmpXNode(lmasked_header, unlocked_val)); 5281 Node *test_not_unlocked = _gvn.transform(new BoolNode(chk_unlocked, BoolTest::ne)); 5282 5283 generate_slow_guard(test_not_unlocked, slow_region); 5284 } 5285 } 5286 5287 // Get the hash value and check to see that it has been properly assigned. 5288 // We depend on hash_mask being at most 32 bits and avoid the use of 5289 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 5290 // vm: see markWord.hpp. 5291 Node *hash_mask = _gvn.intcon(markWord::hash_mask); 5292 Node *hash_shift = _gvn.intcon(markWord::hash_shift); 5293 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift)); 5294 // This hack lets the hash bits live anywhere in the mark object now, as long 5295 // as the shift drops the relevant bits into the low 32 bits. Note that 5296 // Java spec says that HashCode is an int so there's no point in capturing 5297 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 5298 hshifted_header = ConvX2I(hshifted_header); 5299 Node *hash_val = _gvn.transform(new AndINode(hshifted_header, hash_mask)); 5300 5301 Node *no_hash_val = _gvn.intcon(markWord::no_hash); 5302 Node *chk_assigned = _gvn.transform(new CmpINode( hash_val, no_hash_val)); 5303 Node *test_assigned = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq)); 5304 5305 generate_slow_guard(test_assigned, slow_region); 5306 5307 Node* init_mem = reset_memory(); 5308 // fill in the rest of the null path: 5309 result_io ->init_req(_null_path, i_o()); 5310 result_mem->init_req(_null_path, init_mem); 5311 5312 result_val->init_req(_fast_path, hash_val); 5313 result_reg->init_req(_fast_path, control()); 5314 result_io ->init_req(_fast_path, i_o()); 5315 result_mem->init_req(_fast_path, init_mem); 5316 5317 // Generate code for the slow case. We make a call to hashCode(). 5318 set_control(_gvn.transform(slow_region)); 5319 if (!stopped()) { 5320 // No need for PreserveJVMState, because we're using up the present state. 5321 set_all_memory(init_mem); 5322 vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 5323 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static, false); 5324 Node* slow_result = set_results_for_java_call(slow_call); 5325 // this->control() comes from set_results_for_java_call 5326 result_reg->init_req(_slow_path, control()); 5327 result_val->init_req(_slow_path, slow_result); 5328 result_io ->set_req(_slow_path, i_o()); 5329 result_mem ->set_req(_slow_path, reset_memory()); 5330 } 5331 5332 // Return the combined state. 5333 set_i_o( _gvn.transform(result_io) ); 5334 set_all_memory( _gvn.transform(result_mem)); 5335 5336 set_result(result_reg, result_val); 5337 return true; 5338 } 5339 5340 //---------------------------inline_native_getClass---------------------------- 5341 // public final native Class<?> java.lang.Object.getClass(); 5342 // 5343 // Build special case code for calls to getClass on an object. 5344 bool LibraryCallKit::inline_native_getClass() { 5345 Node* obj = argument(0); 5346 if (obj->is_InlineType()) { 5347 const Type* t = _gvn.type(obj); 5348 if (t->maybe_null()) { 5349 null_check(obj); 5350 } 5351 set_result(makecon(TypeInstPtr::make(t->inline_klass()->java_mirror()))); 5352 return true; 5353 } 5354 obj = null_check_receiver(); 5355 if (stopped()) return true; 5356 set_result(load_mirror_from_klass(load_object_klass(obj))); 5357 return true; 5358 } 5359 5360 //-----------------inline_native_Reflection_getCallerClass--------------------- 5361 // public static native Class<?> sun.reflect.Reflection.getCallerClass(); 5362 // 5363 // In the presence of deep enough inlining, getCallerClass() becomes a no-op. 5364 // 5365 // NOTE: This code must perform the same logic as JVM_GetCallerClass 5366 // in that it must skip particular security frames and checks for 5367 // caller sensitive methods. 5368 bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 5369 #ifndef PRODUCT 5370 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5371 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 5372 } 5373 #endif 5374 5375 if (!jvms()->has_method()) { 5376 #ifndef PRODUCT 5377 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5378 tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 5379 } 5380 #endif 5381 return false; 5382 } 5383 5384 // Walk back up the JVM state to find the caller at the required 5385 // depth. 5386 JVMState* caller_jvms = jvms(); 5387 5388 // Cf. JVM_GetCallerClass 5389 // NOTE: Start the loop at depth 1 because the current JVM state does 5390 // not include the Reflection.getCallerClass() frame. 5391 for (int n = 1; caller_jvms != nullptr; caller_jvms = caller_jvms->caller(), n++) { 5392 ciMethod* m = caller_jvms->method(); 5393 switch (n) { 5394 case 0: 5395 fatal("current JVM state does not include the Reflection.getCallerClass frame"); 5396 break; 5397 case 1: 5398 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 5399 if (!m->caller_sensitive()) { 5400 #ifndef PRODUCT 5401 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5402 tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 5403 } 5404 #endif 5405 return false; // bail-out; let JVM_GetCallerClass do the work 5406 } 5407 break; 5408 default: 5409 if (!m->is_ignored_by_security_stack_walk()) { 5410 // We have reached the desired frame; return the holder class. 5411 // Acquire method holder as java.lang.Class and push as constant. 5412 ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 5413 ciInstance* caller_mirror = caller_klass->java_mirror(); 5414 set_result(makecon(TypeInstPtr::make(caller_mirror))); 5415 5416 #ifndef PRODUCT 5417 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5418 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()); 5419 tty->print_cr(" JVM state at this point:"); 5420 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 5421 ciMethod* m = jvms()->of_depth(i)->method(); 5422 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 5423 } 5424 } 5425 #endif 5426 return true; 5427 } 5428 break; 5429 } 5430 } 5431 5432 #ifndef PRODUCT 5433 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 5434 tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 5435 tty->print_cr(" JVM state at this point:"); 5436 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 5437 ciMethod* m = jvms()->of_depth(i)->method(); 5438 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 5439 } 5440 } 5441 #endif 5442 5443 return false; // bail-out; let JVM_GetCallerClass do the work 5444 } 5445 5446 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 5447 Node* arg = argument(0); 5448 Node* result = nullptr; 5449 5450 switch (id) { 5451 case vmIntrinsics::_floatToRawIntBits: result = new MoveF2INode(arg); break; 5452 case vmIntrinsics::_intBitsToFloat: result = new MoveI2FNode(arg); break; 5453 case vmIntrinsics::_doubleToRawLongBits: result = new MoveD2LNode(arg); break; 5454 case vmIntrinsics::_longBitsToDouble: result = new MoveL2DNode(arg); break; 5455 case vmIntrinsics::_floatToFloat16: result = new ConvF2HFNode(arg); break; 5456 case vmIntrinsics::_float16ToFloat: result = new ConvHF2FNode(arg); break; 5457 5458 case vmIntrinsics::_doubleToLongBits: { 5459 // two paths (plus control) merge in a wood 5460 RegionNode *r = new RegionNode(3); 5461 Node *phi = new PhiNode(r, TypeLong::LONG); 5462 5463 Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg)); 5464 // Build the boolean node 5465 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 5466 5467 // Branch either way. 5468 // NaN case is less traveled, which makes all the difference. 5469 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 5470 Node *opt_isnan = _gvn.transform(ifisnan); 5471 assert( opt_isnan->is_If(), "Expect an IfNode"); 5472 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 5473 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 5474 5475 set_control(iftrue); 5476 5477 static const jlong nan_bits = CONST64(0x7ff8000000000000); 5478 Node *slow_result = longcon(nan_bits); // return NaN 5479 phi->init_req(1, _gvn.transform( slow_result )); 5480 r->init_req(1, iftrue); 5481 5482 // Else fall through 5483 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 5484 set_control(iffalse); 5485 5486 phi->init_req(2, _gvn.transform(new MoveD2LNode(arg))); 5487 r->init_req(2, iffalse); 5488 5489 // Post merge 5490 set_control(_gvn.transform(r)); 5491 record_for_igvn(r); 5492 5493 C->set_has_split_ifs(true); // Has chance for split-if optimization 5494 result = phi; 5495 assert(result->bottom_type()->isa_long(), "must be"); 5496 break; 5497 } 5498 5499 case vmIntrinsics::_floatToIntBits: { 5500 // two paths (plus control) merge in a wood 5501 RegionNode *r = new RegionNode(3); 5502 Node *phi = new PhiNode(r, TypeInt::INT); 5503 5504 Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg)); 5505 // Build the boolean node 5506 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 5507 5508 // Branch either way. 5509 // NaN case is less traveled, which makes all the difference. 5510 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 5511 Node *opt_isnan = _gvn.transform(ifisnan); 5512 assert( opt_isnan->is_If(), "Expect an IfNode"); 5513 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 5514 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 5515 5516 set_control(iftrue); 5517 5518 static const jint nan_bits = 0x7fc00000; 5519 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 5520 phi->init_req(1, _gvn.transform( slow_result )); 5521 r->init_req(1, iftrue); 5522 5523 // Else fall through 5524 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 5525 set_control(iffalse); 5526 5527 phi->init_req(2, _gvn.transform(new MoveF2INode(arg))); 5528 r->init_req(2, iffalse); 5529 5530 // Post merge 5531 set_control(_gvn.transform(r)); 5532 record_for_igvn(r); 5533 5534 C->set_has_split_ifs(true); // Has chance for split-if optimization 5535 result = phi; 5536 assert(result->bottom_type()->isa_int(), "must be"); 5537 break; 5538 } 5539 5540 default: 5541 fatal_unexpected_iid(id); 5542 break; 5543 } 5544 set_result(_gvn.transform(result)); 5545 return true; 5546 } 5547 5548 bool LibraryCallKit::inline_fp_range_check(vmIntrinsics::ID id) { 5549 Node* arg = argument(0); 5550 Node* result = nullptr; 5551 5552 switch (id) { 5553 case vmIntrinsics::_floatIsInfinite: 5554 result = new IsInfiniteFNode(arg); 5555 break; 5556 case vmIntrinsics::_floatIsFinite: 5557 result = new IsFiniteFNode(arg); 5558 break; 5559 case vmIntrinsics::_doubleIsInfinite: 5560 result = new IsInfiniteDNode(arg); 5561 break; 5562 case vmIntrinsics::_doubleIsFinite: 5563 result = new IsFiniteDNode(arg); 5564 break; 5565 default: 5566 fatal_unexpected_iid(id); 5567 break; 5568 } 5569 set_result(_gvn.transform(result)); 5570 return true; 5571 } 5572 5573 //----------------------inline_unsafe_copyMemory------------------------- 5574 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 5575 5576 static bool has_wide_mem(PhaseGVN& gvn, Node* addr, Node* base) { 5577 const TypeAryPtr* addr_t = gvn.type(addr)->isa_aryptr(); 5578 const Type* base_t = gvn.type(base); 5579 5580 bool in_native = (base_t == TypePtr::NULL_PTR); 5581 bool in_heap = !TypePtr::NULL_PTR->higher_equal(base_t); 5582 bool is_mixed = !in_heap && !in_native; 5583 5584 if (is_mixed) { 5585 return true; // mixed accesses can touch both on-heap and off-heap memory 5586 } 5587 if (in_heap) { 5588 bool is_prim_array = (addr_t != nullptr) && (addr_t->elem() != Type::BOTTOM); 5589 if (!is_prim_array) { 5590 // Though Unsafe.copyMemory() ensures at runtime for on-heap accesses that base is a primitive array, 5591 // there's not enough type information available to determine proper memory slice for it. 5592 return true; 5593 } 5594 } 5595 return false; 5596 } 5597 5598 bool LibraryCallKit::inline_unsafe_copyMemory() { 5599 if (callee()->is_static()) return false; // caller must have the capability! 5600 null_check_receiver(); // null-check receiver 5601 if (stopped()) return true; 5602 5603 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 5604 5605 Node* src_base = argument(1); // type: oop 5606 Node* src_off = ConvL2X(argument(2)); // type: long 5607 Node* dst_base = argument(4); // type: oop 5608 Node* dst_off = ConvL2X(argument(5)); // type: long 5609 Node* size = ConvL2X(argument(7)); // type: long 5610 5611 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 5612 "fieldOffset must be byte-scaled"); 5613 5614 Node* src_addr = make_unsafe_address(src_base, src_off); 5615 Node* dst_addr = make_unsafe_address(dst_base, dst_off); 5616 5617 Node* thread = _gvn.transform(new ThreadLocalNode()); 5618 Node* doing_unsafe_access_addr = basic_plus_adr(top(), thread, in_bytes(JavaThread::doing_unsafe_access_offset())); 5619 BasicType doing_unsafe_access_bt = T_BYTE; 5620 assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented"); 5621 5622 // update volatile field 5623 store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered); 5624 5625 int flags = RC_LEAF | RC_NO_FP; 5626 5627 const TypePtr* dst_type = TypePtr::BOTTOM; 5628 5629 // Adjust memory effects of the runtime call based on input values. 5630 if (!has_wide_mem(_gvn, src_addr, src_base) && 5631 !has_wide_mem(_gvn, dst_addr, dst_base)) { 5632 dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory 5633 5634 const TypePtr* src_type = _gvn.type(src_addr)->is_ptr(); 5635 if (C->get_alias_index(src_type) == C->get_alias_index(dst_type)) { 5636 flags |= RC_NARROW_MEM; // narrow in memory 5637 } 5638 } 5639 5640 // Call it. Note that the length argument is not scaled. 5641 make_runtime_call(flags, 5642 OptoRuntime::fast_arraycopy_Type(), 5643 StubRoutines::unsafe_arraycopy(), 5644 "unsafe_arraycopy", 5645 dst_type, 5646 src_addr, dst_addr, size XTOP); 5647 5648 store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered); 5649 5650 return true; 5651 } 5652 5653 // unsafe_setmemory(void *base, ulong offset, size_t length, char fill_value); 5654 // Fill 'length' bytes starting from 'base[offset]' with 'fill_value' 5655 bool LibraryCallKit::inline_unsafe_setMemory() { 5656 if (callee()->is_static()) return false; // caller must have the capability! 5657 null_check_receiver(); // null-check receiver 5658 if (stopped()) return true; 5659 5660 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 5661 5662 Node* dst_base = argument(1); // type: oop 5663 Node* dst_off = ConvL2X(argument(2)); // type: long 5664 Node* size = ConvL2X(argument(4)); // type: long 5665 Node* byte = argument(6); // type: byte 5666 5667 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 5668 "fieldOffset must be byte-scaled"); 5669 5670 Node* dst_addr = make_unsafe_address(dst_base, dst_off); 5671 5672 Node* thread = _gvn.transform(new ThreadLocalNode()); 5673 Node* doing_unsafe_access_addr = basic_plus_adr(top(), thread, in_bytes(JavaThread::doing_unsafe_access_offset())); 5674 BasicType doing_unsafe_access_bt = T_BYTE; 5675 assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented"); 5676 5677 // update volatile field 5678 store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, MemNode::unordered); 5679 5680 int flags = RC_LEAF | RC_NO_FP; 5681 5682 const TypePtr* dst_type = TypePtr::BOTTOM; 5683 5684 // Adjust memory effects of the runtime call based on input values. 5685 if (!has_wide_mem(_gvn, dst_addr, dst_base)) { 5686 dst_type = _gvn.type(dst_addr)->is_ptr(); // narrow out memory 5687 5688 flags |= RC_NARROW_MEM; // narrow in memory 5689 } 5690 5691 // Call it. Note that the length argument is not scaled. 5692 make_runtime_call(flags, 5693 OptoRuntime::unsafe_setmemory_Type(), 5694 StubRoutines::unsafe_setmemory(), 5695 "unsafe_setmemory", 5696 dst_type, 5697 dst_addr, size XTOP, byte); 5698 5699 store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, MemNode::unordered); 5700 5701 return true; 5702 } 5703 5704 #undef XTOP 5705 5706 //----------------------inline_unsafe_isFlatArray------------------------ 5707 // public native boolean Unsafe.isFlatArray(Class<?> arrayClass); 5708 // This intrinsic exploits assumptions made by the native implementation 5709 // (arrayClass is neither null nor primitive) to avoid unnecessary null checks. 5710 bool LibraryCallKit::inline_unsafe_isFlatArray() { 5711 Node* cls = argument(1); 5712 Node* p = basic_plus_adr(cls, java_lang_Class::klass_offset()); 5713 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, immutable_memory(), p, 5714 TypeRawPtr::BOTTOM, TypeInstKlassPtr::OBJECT)); 5715 Node* result = flat_array_test(kls); 5716 set_result(result); 5717 return true; 5718 } 5719 5720 //------------------------clone_coping----------------------------------- 5721 // Helper function for inline_native_clone. 5722 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) { 5723 assert(obj_size != nullptr, ""); 5724 Node* raw_obj = alloc_obj->in(1); 5725 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 5726 5727 AllocateNode* alloc = nullptr; 5728 if (ReduceBulkZeroing && 5729 // If we are implementing an array clone without knowing its source type 5730 // (can happen when compiling the array-guarded branch of a reflective 5731 // Object.clone() invocation), initialize the array within the allocation. 5732 // This is needed because some GCs (e.g. ZGC) might fall back in this case 5733 // to a runtime clone call that assumes fully initialized source arrays. 5734 (!is_array || obj->get_ptr_type()->isa_aryptr() != nullptr)) { 5735 // We will be completely responsible for initializing this object - 5736 // mark Initialize node as complete. 5737 alloc = AllocateNode::Ideal_allocation(alloc_obj); 5738 // The object was just allocated - there should be no any stores! 5739 guarantee(alloc != nullptr && alloc->maybe_set_complete(&_gvn), ""); 5740 // Mark as complete_with_arraycopy so that on AllocateNode 5741 // expansion, we know this AllocateNode is initialized by an array 5742 // copy and a StoreStore barrier exists after the array copy. 5743 alloc->initialization()->set_complete_with_arraycopy(); 5744 } 5745 5746 Node* size = _gvn.transform(obj_size); 5747 access_clone(obj, alloc_obj, size, is_array); 5748 5749 // Do not let reads from the cloned object float above the arraycopy. 5750 if (alloc != nullptr) { 5751 // Do not let stores that initialize this object be reordered with 5752 // a subsequent store that would make this object accessible by 5753 // other threads. 5754 // Record what AllocateNode this StoreStore protects so that 5755 // escape analysis can go from the MemBarStoreStoreNode to the 5756 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 5757 // based on the escape status of the AllocateNode. 5758 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 5759 } else { 5760 insert_mem_bar(Op_MemBarCPUOrder); 5761 } 5762 } 5763 5764 //------------------------inline_native_clone---------------------------- 5765 // protected native Object java.lang.Object.clone(); 5766 // 5767 // Here are the simple edge cases: 5768 // null receiver => normal trap 5769 // virtual and clone was overridden => slow path to out-of-line clone 5770 // not cloneable or finalizer => slow path to out-of-line Object.clone 5771 // 5772 // The general case has two steps, allocation and copying. 5773 // Allocation has two cases, and uses GraphKit::new_instance or new_array. 5774 // 5775 // Copying also has two cases, oop arrays and everything else. 5776 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 5777 // Everything else uses the tight inline loop supplied by CopyArrayNode. 5778 // 5779 // These steps fold up nicely if and when the cloned object's klass 5780 // can be sharply typed as an object array, a type array, or an instance. 5781 // 5782 bool LibraryCallKit::inline_native_clone(bool is_virtual) { 5783 PhiNode* result_val; 5784 5785 // Set the reexecute bit for the interpreter to reexecute 5786 // the bytecode that invokes Object.clone if deoptimization happens. 5787 { PreserveReexecuteState preexecs(this); 5788 jvms()->set_should_reexecute(true); 5789 5790 Node* obj = argument(0); 5791 obj = null_check_receiver(); 5792 if (stopped()) return true; 5793 5794 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 5795 if (obj_type->is_inlinetypeptr()) { 5796 // If the object to clone is an inline type, we can simply return it (i.e. a nop) since inline types have 5797 // no identity. 5798 set_result(obj); 5799 return true; 5800 } 5801 5802 // If we are going to clone an instance, we need its exact type to 5803 // know the number and types of fields to convert the clone to 5804 // loads/stores. Maybe a speculative type can help us. 5805 if (!obj_type->klass_is_exact() && 5806 obj_type->speculative_type() != nullptr && 5807 obj_type->speculative_type()->is_instance_klass() && 5808 !obj_type->speculative_type()->is_inlinetype()) { 5809 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass(); 5810 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem && 5811 !spec_ik->has_injected_fields()) { 5812 if (!obj_type->isa_instptr() || 5813 obj_type->is_instptr()->instance_klass()->has_subklass()) { 5814 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false); 5815 } 5816 } 5817 } 5818 5819 // Conservatively insert a memory barrier on all memory slices. 5820 // Do not let writes into the original float below the clone. 5821 insert_mem_bar(Op_MemBarCPUOrder); 5822 5823 // paths into result_reg: 5824 enum { 5825 _slow_path = 1, // out-of-line call to clone method (virtual or not) 5826 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 5827 _array_path, // plain array allocation, plus arrayof_long_arraycopy 5828 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 5829 PATH_LIMIT 5830 }; 5831 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 5832 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 5833 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); 5834 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 5835 record_for_igvn(result_reg); 5836 5837 // TODO 8350865 For arrays, this might be folded and then not account for atomic arrays 5838 Node* obj_klass = load_object_klass(obj); 5839 // We only go to the fast case code if we pass a number of guards. 5840 // The paths which do not pass are accumulated in the slow_region. 5841 RegionNode* slow_region = new RegionNode(1); 5842 record_for_igvn(slow_region); 5843 5844 Node* array_obj = obj; 5845 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)nullptr, &array_obj); 5846 if (array_ctl != nullptr) { 5847 // It's an array. 5848 PreserveJVMState pjvms(this); 5849 set_control(array_ctl); 5850 5851 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 5852 const TypeAryPtr* ary_ptr = obj_type->isa_aryptr(); 5853 if (UseArrayFlattening && bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Expansion) && 5854 obj_type->can_be_inline_array() && 5855 (ary_ptr == nullptr || (!ary_ptr->is_not_flat() && (!ary_ptr->is_flat() || ary_ptr->elem()->inline_klass()->contains_oops())))) { 5856 // Flat inline type array may have object field that would require a 5857 // write barrier. Conservatively, go to slow path. 5858 generate_fair_guard(flat_array_test(obj_klass), slow_region); 5859 } 5860 5861 if (!stopped()) { 5862 Node* obj_length = load_array_length(array_obj); 5863 Node* array_size = nullptr; // Size of the array without object alignment padding. 5864 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &array_size, /*deoptimize_on_exception=*/true); 5865 5866 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 5867 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, false, BarrierSetC2::Parsing)) { 5868 // If it is an oop array, it requires very special treatment, 5869 // because gc barriers are required when accessing the array. 5870 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)nullptr); 5871 if (is_obja != nullptr) { 5872 PreserveJVMState pjvms2(this); 5873 set_control(is_obja); 5874 // Generate a direct call to the right arraycopy function(s). 5875 // Clones are always tightly coupled. 5876 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, array_obj, intcon(0), alloc_obj, intcon(0), obj_length, true, false); 5877 ac->set_clone_oop_array(); 5878 Node* n = _gvn.transform(ac); 5879 assert(n == ac, "cannot disappear"); 5880 ac->connect_outputs(this, /*deoptimize_on_exception=*/true); 5881 5882 result_reg->init_req(_objArray_path, control()); 5883 result_val->init_req(_objArray_path, alloc_obj); 5884 result_i_o ->set_req(_objArray_path, i_o()); 5885 result_mem ->set_req(_objArray_path, reset_memory()); 5886 } 5887 } 5888 // Otherwise, there are no barriers to worry about. 5889 // (We can dispense with card marks if we know the allocation 5890 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 5891 // causes the non-eden paths to take compensating steps to 5892 // simulate a fresh allocation, so that no further 5893 // card marks are required in compiled code to initialize 5894 // the object.) 5895 5896 if (!stopped()) { 5897 copy_to_clone(obj, alloc_obj, array_size, true); 5898 5899 // Present the results of the copy. 5900 result_reg->init_req(_array_path, control()); 5901 result_val->init_req(_array_path, alloc_obj); 5902 result_i_o ->set_req(_array_path, i_o()); 5903 result_mem ->set_req(_array_path, reset_memory()); 5904 } 5905 } 5906 } 5907 5908 if (!stopped()) { 5909 // It's an instance (we did array above). Make the slow-path tests. 5910 // If this is a virtual call, we generate a funny guard. We grab 5911 // the vtable entry corresponding to clone() from the target object. 5912 // If the target method which we are calling happens to be the 5913 // Object clone() method, we pass the guard. We do not need this 5914 // guard for non-virtual calls; the caller is known to be the native 5915 // Object clone(). 5916 if (is_virtual) { 5917 generate_virtual_guard(obj_klass, slow_region); 5918 } 5919 5920 // The object must be easily cloneable and must not have a finalizer. 5921 // Both of these conditions may be checked in a single test. 5922 // We could optimize the test further, but we don't care. 5923 generate_misc_flags_guard(obj_klass, 5924 // Test both conditions: 5925 KlassFlags::_misc_is_cloneable_fast | KlassFlags::_misc_has_finalizer, 5926 // Must be cloneable but not finalizer: 5927 KlassFlags::_misc_is_cloneable_fast, 5928 slow_region); 5929 } 5930 5931 if (!stopped()) { 5932 // It's an instance, and it passed the slow-path tests. 5933 PreserveJVMState pjvms(this); 5934 Node* obj_size = nullptr; // Total object size, including object alignment padding. 5935 // Need to deoptimize on exception from allocation since Object.clone intrinsic 5936 // is reexecuted if deoptimization occurs and there could be problems when merging 5937 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). 5938 Node* alloc_obj = new_instance(obj_klass, nullptr, &obj_size, /*deoptimize_on_exception=*/true); 5939 5940 copy_to_clone(obj, alloc_obj, obj_size, false); 5941 5942 // Present the results of the slow call. 5943 result_reg->init_req(_instance_path, control()); 5944 result_val->init_req(_instance_path, alloc_obj); 5945 result_i_o ->set_req(_instance_path, i_o()); 5946 result_mem ->set_req(_instance_path, reset_memory()); 5947 } 5948 5949 // Generate code for the slow case. We make a call to clone(). 5950 set_control(_gvn.transform(slow_region)); 5951 if (!stopped()) { 5952 PreserveJVMState pjvms(this); 5953 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual, false, true); 5954 // We need to deoptimize on exception (see comment above) 5955 Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true); 5956 // this->control() comes from set_results_for_java_call 5957 result_reg->init_req(_slow_path, control()); 5958 result_val->init_req(_slow_path, slow_result); 5959 result_i_o ->set_req(_slow_path, i_o()); 5960 result_mem ->set_req(_slow_path, reset_memory()); 5961 } 5962 5963 // Return the combined state. 5964 set_control( _gvn.transform(result_reg)); 5965 set_i_o( _gvn.transform(result_i_o)); 5966 set_all_memory( _gvn.transform(result_mem)); 5967 } // original reexecute is set back here 5968 5969 set_result(_gvn.transform(result_val)); 5970 return true; 5971 } 5972 5973 // If we have a tightly coupled allocation, the arraycopy may take care 5974 // of the array initialization. If one of the guards we insert between 5975 // the allocation and the arraycopy causes a deoptimization, an 5976 // uninitialized array will escape the compiled method. To prevent that 5977 // we set the JVM state for uncommon traps between the allocation and 5978 // the arraycopy to the state before the allocation so, in case of 5979 // deoptimization, we'll reexecute the allocation and the 5980 // initialization. 5981 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) { 5982 if (alloc != nullptr) { 5983 ciMethod* trap_method = alloc->jvms()->method(); 5984 int trap_bci = alloc->jvms()->bci(); 5985 5986 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 5987 !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) { 5988 // Make sure there's no store between the allocation and the 5989 // arraycopy otherwise visible side effects could be rexecuted 5990 // in case of deoptimization and cause incorrect execution. 5991 bool no_interfering_store = true; 5992 Node* mem = alloc->in(TypeFunc::Memory); 5993 if (mem->is_MergeMem()) { 5994 for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) { 5995 Node* n = mms.memory(); 5996 if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 5997 assert(n->is_Store(), "what else?"); 5998 no_interfering_store = false; 5999 break; 6000 } 6001 } 6002 } else { 6003 for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { 6004 Node* n = mms.memory(); 6005 if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 6006 assert(n->is_Store(), "what else?"); 6007 no_interfering_store = false; 6008 break; 6009 } 6010 } 6011 } 6012 6013 if (no_interfering_store) { 6014 SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc); 6015 6016 JVMState* saved_jvms = jvms(); 6017 saved_reexecute_sp = _reexecute_sp; 6018 6019 set_jvms(sfpt->jvms()); 6020 _reexecute_sp = jvms()->sp(); 6021 6022 return saved_jvms; 6023 } 6024 } 6025 } 6026 return nullptr; 6027 } 6028 6029 // Clone the JVMState of the array allocation and create a new safepoint with it. Re-push the array length to the stack 6030 // such that uncommon traps can be emitted to re-execute the array allocation in the interpreter. 6031 SafePointNode* LibraryCallKit::create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const { 6032 JVMState* old_jvms = alloc->jvms()->clone_shallow(C); 6033 uint size = alloc->req(); 6034 SafePointNode* sfpt = new SafePointNode(size, old_jvms); 6035 old_jvms->set_map(sfpt); 6036 for (uint i = 0; i < size; i++) { 6037 sfpt->init_req(i, alloc->in(i)); 6038 } 6039 int adjustment = 1; 6040 const TypeAryKlassPtr* ary_klass_ptr = alloc->in(AllocateNode::KlassNode)->bottom_type()->is_aryklassptr(); 6041 if (ary_klass_ptr->is_null_free()) { 6042 // A null-free, tightly coupled array allocation can only come from LibraryCallKit::inline_newArray which 6043 // also requires the componentType and initVal on stack for re-execution. 6044 // Re-create and push the componentType. 6045 ciArrayKlass* klass = ary_klass_ptr->exact_klass()->as_array_klass(); 6046 ciInstance* instance = klass->component_mirror_instance(); 6047 const TypeInstPtr* t_instance = TypeInstPtr::make(instance); 6048 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), makecon(t_instance)); 6049 adjustment++; 6050 } 6051 // re-push array length for deoptimization 6052 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment - 1, alloc->in(AllocateNode::ALength)); 6053 if (ary_klass_ptr->is_null_free()) { 6054 // Re-create and push the initVal. 6055 Node* init_val = alloc->in(AllocateNode::InitValue); 6056 if (init_val == nullptr) { 6057 init_val = InlineTypeNode::make_all_zero(_gvn, ary_klass_ptr->elem()->is_instklassptr()->instance_klass()->as_inline_klass()); 6058 } else if (UseCompressedOops) { 6059 init_val = _gvn.transform(new DecodeNNode(init_val, init_val->bottom_type()->make_ptr())); 6060 } 6061 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp() + adjustment, init_val); 6062 adjustment++; 6063 } 6064 old_jvms->set_sp(old_jvms->sp() + adjustment); 6065 old_jvms->set_monoff(old_jvms->monoff() + adjustment); 6066 old_jvms->set_scloff(old_jvms->scloff() + adjustment); 6067 old_jvms->set_endoff(old_jvms->endoff() + adjustment); 6068 old_jvms->set_should_reexecute(true); 6069 6070 sfpt->set_i_o(map()->i_o()); 6071 sfpt->set_memory(map()->memory()); 6072 sfpt->set_control(map()->control()); 6073 return sfpt; 6074 } 6075 6076 // In case of a deoptimization, we restart execution at the 6077 // allocation, allocating a new array. We would leave an uninitialized 6078 // array in the heap that GCs wouldn't expect. Move the allocation 6079 // after the traps so we don't allocate the array if we 6080 // deoptimize. This is possible because tightly_coupled_allocation() 6081 // guarantees there's no observer of the allocated array at this point 6082 // and the control flow is simple enough. 6083 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms_before_guards, 6084 int saved_reexecute_sp, uint new_idx) { 6085 if (saved_jvms_before_guards != nullptr && !stopped()) { 6086 replace_unrelated_uncommon_traps_with_alloc_state(alloc, saved_jvms_before_guards); 6087 6088 assert(alloc != nullptr, "only with a tightly coupled allocation"); 6089 // restore JVM state to the state at the arraycopy 6090 saved_jvms_before_guards->map()->set_control(map()->control()); 6091 assert(saved_jvms_before_guards->map()->memory() == map()->memory(), "memory state changed?"); 6092 assert(saved_jvms_before_guards->map()->i_o() == map()->i_o(), "IO state changed?"); 6093 // If we've improved the types of some nodes (null check) while 6094 // emitting the guards, propagate them to the current state 6095 map()->replaced_nodes().apply(saved_jvms_before_guards->map(), new_idx); 6096 set_jvms(saved_jvms_before_guards); 6097 _reexecute_sp = saved_reexecute_sp; 6098 6099 // Remove the allocation from above the guards 6100 CallProjections* callprojs = alloc->extract_projections(true); 6101 InitializeNode* init = alloc->initialization(); 6102 Node* alloc_mem = alloc->in(TypeFunc::Memory); 6103 C->gvn_replace_by(callprojs->fallthrough_ioproj, alloc->in(TypeFunc::I_O)); 6104 C->gvn_replace_by(init->proj_out(TypeFunc::Memory), alloc_mem); 6105 6106 // The CastIINode created in GraphKit::new_array (in AllocateArrayNode::make_ideal_length) must stay below 6107 // the allocation (i.e. is only valid if the allocation succeeds): 6108 // 1) replace CastIINode with AllocateArrayNode's length here 6109 // 2) Create CastIINode again once allocation has moved (see below) at the end of this method 6110 // 6111 // Multiple identical CastIINodes might exist here. Each GraphKit::load_array_length() call will generate 6112 // new separate CastIINode (arraycopy guard checks or any array length use between array allocation and ararycopy) 6113 Node* init_control = init->proj_out(TypeFunc::Control); 6114 Node* alloc_length = alloc->Ideal_length(); 6115 #ifdef ASSERT 6116 Node* prev_cast = nullptr; 6117 #endif 6118 for (uint i = 0; i < init_control->outcnt(); i++) { 6119 Node* init_out = init_control->raw_out(i); 6120 if (init_out->is_CastII() && init_out->in(TypeFunc::Control) == init_control && init_out->in(1) == alloc_length) { 6121 #ifdef ASSERT 6122 if (prev_cast == nullptr) { 6123 prev_cast = init_out; 6124 } else { 6125 if (prev_cast->cmp(*init_out) == false) { 6126 prev_cast->dump(); 6127 init_out->dump(); 6128 assert(false, "not equal CastIINode"); 6129 } 6130 } 6131 #endif 6132 C->gvn_replace_by(init_out, alloc_length); 6133 } 6134 } 6135 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0)); 6136 6137 // move the allocation here (after the guards) 6138 _gvn.hash_delete(alloc); 6139 alloc->set_req(TypeFunc::Control, control()); 6140 alloc->set_req(TypeFunc::I_O, i_o()); 6141 Node *mem = reset_memory(); 6142 set_all_memory(mem); 6143 alloc->set_req(TypeFunc::Memory, mem); 6144 set_control(init->proj_out_or_null(TypeFunc::Control)); 6145 set_i_o(callprojs->fallthrough_ioproj); 6146 6147 // Update memory as done in GraphKit::set_output_for_allocation() 6148 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength)); 6149 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type(); 6150 if (ary_type->isa_aryptr() && length_type != nullptr) { 6151 ary_type = ary_type->is_aryptr()->cast_to_size(length_type); 6152 } 6153 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot); 6154 int elemidx = C->get_alias_index(telemref); 6155 set_memory(init->proj_out_or_null(TypeFunc::Memory), Compile::AliasIdxRaw); 6156 set_memory(init->proj_out_or_null(TypeFunc::Memory), elemidx); 6157 6158 Node* allocx = _gvn.transform(alloc); 6159 assert(allocx == alloc, "where has the allocation gone?"); 6160 assert(dest->is_CheckCastPP(), "not an allocation result?"); 6161 6162 _gvn.hash_delete(dest); 6163 dest->set_req(0, control()); 6164 Node* destx = _gvn.transform(dest); 6165 assert(destx == dest, "where has the allocation result gone?"); 6166 6167 array_ideal_length(alloc, ary_type, true); 6168 } 6169 } 6170 6171 // Unrelated UCTs between the array allocation and the array copy, which are considered safe by tightly_coupled_allocation(), 6172 // need to be replaced by an UCT with a state before the array allocation (including the array length). This is necessary 6173 // because we could hit one of these UCTs (which are executed before the emitted array copy guards and the actual array 6174 // allocation which is moved down in arraycopy_move_allocation_here()). When later resuming execution in the interpreter, 6175 // we would have wrongly skipped the array allocation. To prevent this, we resume execution at the array allocation in 6176 // the interpreter similar to what we are doing for the newly emitted guards for the array copy. 6177 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc, 6178 JVMState* saved_jvms_before_guards) { 6179 if (saved_jvms_before_guards->map()->control()->is_IfProj()) { 6180 // There is at least one unrelated uncommon trap which needs to be replaced. 6181 SafePointNode* sfpt = create_safepoint_with_state_before_array_allocation(alloc); 6182 6183 JVMState* saved_jvms = jvms(); 6184 const int saved_reexecute_sp = _reexecute_sp; 6185 set_jvms(sfpt->jvms()); 6186 _reexecute_sp = jvms()->sp(); 6187 6188 replace_unrelated_uncommon_traps_with_alloc_state(saved_jvms_before_guards); 6189 6190 // Restore state 6191 set_jvms(saved_jvms); 6192 _reexecute_sp = saved_reexecute_sp; 6193 } 6194 } 6195 6196 // Replace the unrelated uncommon traps with new uncommon trap nodes by reusing the action and reason. The new uncommon 6197 // traps will have the state of the array allocation. Let the old uncommon trap nodes die. 6198 void LibraryCallKit::replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards) { 6199 Node* if_proj = saved_jvms_before_guards->map()->control(); // Start the search right before the newly emitted guards 6200 while (if_proj->is_IfProj()) { 6201 CallStaticJavaNode* uncommon_trap = get_uncommon_trap_from_success_proj(if_proj); 6202 if (uncommon_trap != nullptr) { 6203 create_new_uncommon_trap(uncommon_trap); 6204 } 6205 assert(if_proj->in(0)->is_If(), "must be If"); 6206 if_proj = if_proj->in(0)->in(0); 6207 } 6208 assert(if_proj->is_Proj() && if_proj->in(0)->is_Initialize(), 6209 "must have reached control projection of init node"); 6210 } 6211 6212 void LibraryCallKit::create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call) { 6213 const int trap_request = uncommon_trap_call->uncommon_trap_request(); 6214 assert(trap_request != 0, "no valid UCT trap request"); 6215 PreserveJVMState pjvms(this); 6216 set_control(uncommon_trap_call->in(0)); 6217 uncommon_trap(Deoptimization::trap_request_reason(trap_request), 6218 Deoptimization::trap_request_action(trap_request)); 6219 assert(stopped(), "Should be stopped"); 6220 _gvn.hash_delete(uncommon_trap_call); 6221 uncommon_trap_call->set_req(0, top()); // not used anymore, kill it 6222 } 6223 6224 // Common checks for array sorting intrinsics arguments. 6225 // Returns `true` if checks passed. 6226 bool LibraryCallKit::check_array_sort_arguments(Node* elementType, Node* obj, BasicType& bt) { 6227 // check address of the class 6228 if (elementType == nullptr || elementType->is_top()) { 6229 return false; // dead path 6230 } 6231 const TypeInstPtr* elem_klass = gvn().type(elementType)->isa_instptr(); 6232 if (elem_klass == nullptr) { 6233 return false; // dead path 6234 } 6235 // java_mirror_type() returns non-null for compile-time Class constants only 6236 ciType* elem_type = elem_klass->java_mirror_type(); 6237 if (elem_type == nullptr) { 6238 return false; 6239 } 6240 bt = elem_type->basic_type(); 6241 // Disable the intrinsic if the CPU does not support SIMD sort 6242 if (!Matcher::supports_simd_sort(bt)) { 6243 return false; 6244 } 6245 // check address of the array 6246 if (obj == nullptr || obj->is_top()) { 6247 return false; // dead path 6248 } 6249 const TypeAryPtr* obj_t = _gvn.type(obj)->isa_aryptr(); 6250 if (obj_t == nullptr || obj_t->elem() == Type::BOTTOM) { 6251 return false; // failed input validation 6252 } 6253 return true; 6254 } 6255 6256 //------------------------------inline_array_partition----------------------- 6257 bool LibraryCallKit::inline_array_partition() { 6258 address stubAddr = StubRoutines::select_array_partition_function(); 6259 if (stubAddr == nullptr) { 6260 return false; // Intrinsic's stub is not implemented on this platform 6261 } 6262 assert(callee()->signature()->size() == 9, "arrayPartition has 8 parameters (one long)"); 6263 6264 // no receiver because it is a static method 6265 Node* elementType = argument(0); 6266 Node* obj = argument(1); 6267 Node* offset = argument(2); // long 6268 Node* fromIndex = argument(4); 6269 Node* toIndex = argument(5); 6270 Node* indexPivot1 = argument(6); 6271 Node* indexPivot2 = argument(7); 6272 // PartitionOperation: argument(8) is ignored 6273 6274 Node* pivotIndices = nullptr; 6275 BasicType bt = T_ILLEGAL; 6276 6277 if (!check_array_sort_arguments(elementType, obj, bt)) { 6278 return false; 6279 } 6280 null_check(obj); 6281 // If obj is dead, only null-path is taken. 6282 if (stopped()) { 6283 return true; 6284 } 6285 // Set the original stack and the reexecute bit for the interpreter to reexecute 6286 // the bytecode that invokes DualPivotQuicksort.partition() if deoptimization happens. 6287 { PreserveReexecuteState preexecs(this); 6288 jvms()->set_should_reexecute(true); 6289 6290 Node* obj_adr = make_unsafe_address(obj, offset); 6291 6292 // create the pivotIndices array of type int and size = 2 6293 Node* size = intcon(2); 6294 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_INT))); 6295 pivotIndices = new_array(klass_node, size, 0); // no arguments to push 6296 AllocateArrayNode* alloc = tightly_coupled_allocation(pivotIndices); 6297 guarantee(alloc != nullptr, "created above"); 6298 Node* pivotIndices_adr = basic_plus_adr(pivotIndices, arrayOopDesc::base_offset_in_bytes(T_INT)); 6299 6300 // pass the basic type enum to the stub 6301 Node* elemType = intcon(bt); 6302 6303 // Call the stub 6304 const char *stubName = "array_partition_stub"; 6305 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_partition_Type(), 6306 stubAddr, stubName, TypePtr::BOTTOM, 6307 obj_adr, elemType, fromIndex, toIndex, pivotIndices_adr, 6308 indexPivot1, indexPivot2); 6309 6310 } // original reexecute is set back here 6311 6312 if (!stopped()) { 6313 set_result(pivotIndices); 6314 } 6315 6316 return true; 6317 } 6318 6319 6320 //------------------------------inline_array_sort----------------------- 6321 bool LibraryCallKit::inline_array_sort() { 6322 address stubAddr = StubRoutines::select_arraysort_function(); 6323 if (stubAddr == nullptr) { 6324 return false; // Intrinsic's stub is not implemented on this platform 6325 } 6326 assert(callee()->signature()->size() == 7, "arraySort has 6 parameters (one long)"); 6327 6328 // no receiver because it is a static method 6329 Node* elementType = argument(0); 6330 Node* obj = argument(1); 6331 Node* offset = argument(2); // long 6332 Node* fromIndex = argument(4); 6333 Node* toIndex = argument(5); 6334 // SortOperation: argument(6) is ignored 6335 6336 BasicType bt = T_ILLEGAL; 6337 6338 if (!check_array_sort_arguments(elementType, obj, bt)) { 6339 return false; 6340 } 6341 null_check(obj); 6342 // If obj is dead, only null-path is taken. 6343 if (stopped()) { 6344 return true; 6345 } 6346 Node* obj_adr = make_unsafe_address(obj, offset); 6347 6348 // pass the basic type enum to the stub 6349 Node* elemType = intcon(bt); 6350 6351 // Call the stub. 6352 const char *stubName = "arraysort_stub"; 6353 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::array_sort_Type(), 6354 stubAddr, stubName, TypePtr::BOTTOM, 6355 obj_adr, elemType, fromIndex, toIndex); 6356 6357 return true; 6358 } 6359 6360 6361 //------------------------------inline_arraycopy----------------------- 6362 // public static native void java.lang.System.arraycopy(Object src, int srcPos, 6363 // Object dest, int destPos, 6364 // int length); 6365 bool LibraryCallKit::inline_arraycopy() { 6366 // Get the arguments. 6367 Node* src = argument(0); // type: oop 6368 Node* src_offset = argument(1); // type: int 6369 Node* dest = argument(2); // type: oop 6370 Node* dest_offset = argument(3); // type: int 6371 Node* length = argument(4); // type: int 6372 6373 uint new_idx = C->unique(); 6374 6375 // Check for allocation before we add nodes that would confuse 6376 // tightly_coupled_allocation() 6377 AllocateArrayNode* alloc = tightly_coupled_allocation(dest); 6378 6379 int saved_reexecute_sp = -1; 6380 JVMState* saved_jvms_before_guards = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp); 6381 // See arraycopy_restore_alloc_state() comment 6382 // if alloc == null we don't have to worry about a tightly coupled allocation so we can emit all needed guards 6383 // if saved_jvms_before_guards is not null (then alloc is not null) then we can handle guards and a tightly coupled allocation 6384 // if saved_jvms_before_guards is null and alloc is not null, we can't emit any guards 6385 bool can_emit_guards = (alloc == nullptr || saved_jvms_before_guards != nullptr); 6386 6387 // The following tests must be performed 6388 // (1) src and dest are arrays. 6389 // (2) src and dest arrays must have elements of the same BasicType 6390 // (3) src and dest must not be null. 6391 // (4) src_offset must not be negative. 6392 // (5) dest_offset must not be negative. 6393 // (6) length must not be negative. 6394 // (7) src_offset + length must not exceed length of src. 6395 // (8) dest_offset + length must not exceed length of dest. 6396 // (9) each element of an oop array must be assignable 6397 6398 // (3) src and dest must not be null. 6399 // always do this here because we need the JVM state for uncommon traps 6400 Node* null_ctl = top(); 6401 src = saved_jvms_before_guards != nullptr ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY); 6402 assert(null_ctl->is_top(), "no null control here"); 6403 dest = null_check(dest, T_ARRAY); 6404 6405 if (!can_emit_guards) { 6406 // if saved_jvms_before_guards is null and alloc is not null, we don't emit any 6407 // guards but the arraycopy node could still take advantage of a 6408 // tightly allocated allocation. tightly_coupled_allocation() is 6409 // called again to make sure it takes the null check above into 6410 // account: the null check is mandatory and if it caused an 6411 // uncommon trap to be emitted then the allocation can't be 6412 // considered tightly coupled in this context. 6413 alloc = tightly_coupled_allocation(dest); 6414 } 6415 6416 bool validated = false; 6417 6418 const Type* src_type = _gvn.type(src); 6419 const Type* dest_type = _gvn.type(dest); 6420 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6421 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 6422 6423 // Do we have the type of src? 6424 bool has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM); 6425 // Do we have the type of dest? 6426 bool has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM); 6427 // Is the type for src from speculation? 6428 bool src_spec = false; 6429 // Is the type for dest from speculation? 6430 bool dest_spec = false; 6431 6432 if ((!has_src || !has_dest) && can_emit_guards) { 6433 // We don't have sufficient type information, let's see if 6434 // speculative types can help. We need to have types for both src 6435 // and dest so that it pays off. 6436 6437 // Do we already have or could we have type information for src 6438 bool could_have_src = has_src; 6439 // Do we already have or could we have type information for dest 6440 bool could_have_dest = has_dest; 6441 6442 ciKlass* src_k = nullptr; 6443 if (!has_src) { 6444 src_k = src_type->speculative_type_not_null(); 6445 if (src_k != nullptr && src_k->is_array_klass()) { 6446 could_have_src = true; 6447 } 6448 } 6449 6450 ciKlass* dest_k = nullptr; 6451 if (!has_dest) { 6452 dest_k = dest_type->speculative_type_not_null(); 6453 if (dest_k != nullptr && dest_k->is_array_klass()) { 6454 could_have_dest = true; 6455 } 6456 } 6457 6458 if (could_have_src && could_have_dest) { 6459 // This is going to pay off so emit the required guards 6460 if (!has_src) { 6461 src = maybe_cast_profiled_obj(src, src_k, true); 6462 src_type = _gvn.type(src); 6463 top_src = src_type->isa_aryptr(); 6464 has_src = (top_src != nullptr && top_src->elem() != Type::BOTTOM); 6465 src_spec = true; 6466 } 6467 if (!has_dest) { 6468 dest = maybe_cast_profiled_obj(dest, dest_k, true); 6469 dest_type = _gvn.type(dest); 6470 top_dest = dest_type->isa_aryptr(); 6471 has_dest = (top_dest != nullptr && top_dest->elem() != Type::BOTTOM); 6472 dest_spec = true; 6473 } 6474 } 6475 } 6476 6477 if (has_src && has_dest && can_emit_guards) { 6478 BasicType src_elem = top_src->isa_aryptr()->elem()->array_element_basic_type(); 6479 BasicType dest_elem = top_dest->isa_aryptr()->elem()->array_element_basic_type(); 6480 if (is_reference_type(src_elem, true)) src_elem = T_OBJECT; 6481 if (is_reference_type(dest_elem, true)) dest_elem = T_OBJECT; 6482 6483 if (src_elem == dest_elem && top_src->is_flat() == top_dest->is_flat() && src_elem == T_OBJECT) { 6484 // If both arrays are object arrays then having the exact types 6485 // for both will remove the need for a subtype check at runtime 6486 // before the call and may make it possible to pick a faster copy 6487 // routine (without a subtype check on every element) 6488 // Do we have the exact type of src? 6489 bool could_have_src = src_spec; 6490 // Do we have the exact type of dest? 6491 bool could_have_dest = dest_spec; 6492 ciKlass* src_k = nullptr; 6493 ciKlass* dest_k = nullptr; 6494 if (!src_spec) { 6495 src_k = src_type->speculative_type_not_null(); 6496 if (src_k != nullptr && src_k->is_array_klass()) { 6497 could_have_src = true; 6498 } 6499 } 6500 if (!dest_spec) { 6501 dest_k = dest_type->speculative_type_not_null(); 6502 if (dest_k != nullptr && dest_k->is_array_klass()) { 6503 could_have_dest = true; 6504 } 6505 } 6506 if (could_have_src && could_have_dest) { 6507 // If we can have both exact types, emit the missing guards 6508 if (could_have_src && !src_spec) { 6509 src = maybe_cast_profiled_obj(src, src_k, true); 6510 src_type = _gvn.type(src); 6511 top_src = src_type->isa_aryptr(); 6512 } 6513 if (could_have_dest && !dest_spec) { 6514 dest = maybe_cast_profiled_obj(dest, dest_k, true); 6515 dest_type = _gvn.type(dest); 6516 top_dest = dest_type->isa_aryptr(); 6517 } 6518 } 6519 } 6520 } 6521 6522 ciMethod* trap_method = method(); 6523 int trap_bci = bci(); 6524 if (saved_jvms_before_guards != nullptr) { 6525 trap_method = alloc->jvms()->method(); 6526 trap_bci = alloc->jvms()->bci(); 6527 } 6528 6529 bool negative_length_guard_generated = false; 6530 6531 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 6532 can_emit_guards && !src->is_top() && !dest->is_top()) { 6533 // validate arguments: enables transformation the ArrayCopyNode 6534 validated = true; 6535 6536 RegionNode* slow_region = new RegionNode(1); 6537 record_for_igvn(slow_region); 6538 6539 // (1) src and dest are arrays. 6540 generate_non_array_guard(load_object_klass(src), slow_region, &src); 6541 generate_non_array_guard(load_object_klass(dest), slow_region, &dest); 6542 6543 // (2) src and dest arrays must have elements of the same BasicType 6544 // done at macro expansion or at Ideal transformation time 6545 6546 // (4) src_offset must not be negative. 6547 generate_negative_guard(src_offset, slow_region); 6548 6549 // (5) dest_offset must not be negative. 6550 generate_negative_guard(dest_offset, slow_region); 6551 6552 // (7) src_offset + length must not exceed length of src. 6553 generate_limit_guard(src_offset, length, 6554 load_array_length(src), 6555 slow_region); 6556 6557 // (8) dest_offset + length must not exceed length of dest. 6558 generate_limit_guard(dest_offset, length, 6559 load_array_length(dest), 6560 slow_region); 6561 6562 // (6) length must not be negative. 6563 // This is also checked in generate_arraycopy() during macro expansion, but 6564 // we also have to check it here for the case where the ArrayCopyNode will 6565 // be eliminated by Escape Analysis. 6566 if (EliminateAllocations) { 6567 generate_negative_guard(length, slow_region); 6568 negative_length_guard_generated = true; 6569 } 6570 6571 // (9) each element of an oop array must be assignable 6572 Node* dest_klass = load_object_klass(dest); 6573 if (src != dest) { 6574 Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass); 6575 slow_region->add_req(not_subtype_ctrl); 6576 } 6577 6578 // TODO 8350865 Fix below logic. Also handle atomicity. 6579 generate_fair_guard(flat_array_test(src), slow_region); 6580 generate_fair_guard(flat_array_test(dest), slow_region); 6581 6582 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr(); 6583 const Type* toop = dest_klass_t->cast_to_exactness(false)->as_instance_type(); 6584 src = _gvn.transform(new CheckCastPPNode(control(), src, toop)); 6585 src_type = _gvn.type(src); 6586 top_src = src_type->isa_aryptr(); 6587 6588 // Handle flat inline type arrays (null-free arrays are handled by the subtype check above) 6589 if (!stopped() && UseArrayFlattening) { 6590 // If dest is flat, src must be flat as well (guaranteed by src <: dest check). Handle flat src here. 6591 assert(top_dest == nullptr || !top_dest->is_flat() || top_src->is_flat(), "src array must be flat"); 6592 if (top_src != nullptr && top_src->is_flat()) { 6593 // Src is flat, check that dest is flat as well 6594 if (top_dest != nullptr && !top_dest->is_flat()) { 6595 generate_fair_guard(flat_array_test(dest_klass, /* flat = */ false), slow_region); 6596 // Since dest is flat and src <: dest, dest must have the same type as src. 6597 top_dest = top_src->cast_to_exactness(false); 6598 assert(top_dest->is_flat(), "dest must be flat"); 6599 dest = _gvn.transform(new CheckCastPPNode(control(), dest, top_dest)); 6600 } 6601 } else if (top_src == nullptr || !top_src->is_not_flat()) { 6602 // Src might be flat and dest might not be flat. Go to the slow path if src is flat. 6603 // TODO 8251971: Optimize for the case when src/dest are later found to be both flat. 6604 assert(top_dest == nullptr || !top_dest->is_flat(), "dest array must not be flat"); 6605 generate_fair_guard(flat_array_test(src), slow_region); 6606 if (top_src != nullptr) { 6607 top_src = top_src->cast_to_not_flat(); 6608 src = _gvn.transform(new CheckCastPPNode(control(), src, top_src)); 6609 } 6610 } 6611 } 6612 6613 { 6614 PreserveJVMState pjvms(this); 6615 set_control(_gvn.transform(slow_region)); 6616 uncommon_trap(Deoptimization::Reason_intrinsic, 6617 Deoptimization::Action_make_not_entrant); 6618 assert(stopped(), "Should be stopped"); 6619 } 6620 arraycopy_move_allocation_here(alloc, dest, saved_jvms_before_guards, saved_reexecute_sp, new_idx); 6621 } 6622 6623 if (stopped()) { 6624 return true; 6625 } 6626 6627 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != nullptr, negative_length_guard_generated, 6628 // Create LoadRange and LoadKlass nodes for use during macro expansion here 6629 // so the compiler has a chance to eliminate them: during macro expansion, 6630 // we have to set their control (CastPP nodes are eliminated). 6631 load_object_klass(src), load_object_klass(dest), 6632 load_array_length(src), load_array_length(dest)); 6633 6634 ac->set_arraycopy(validated); 6635 6636 Node* n = _gvn.transform(ac); 6637 if (n == ac) { 6638 ac->connect_outputs(this); 6639 } else { 6640 assert(validated, "shouldn't transform if all arguments not validated"); 6641 set_all_memory(n); 6642 } 6643 clear_upper_avx(); 6644 6645 6646 return true; 6647 } 6648 6649 6650 // Helper function which determines if an arraycopy immediately follows 6651 // an allocation, with no intervening tests or other escapes for the object. 6652 AllocateArrayNode* 6653 LibraryCallKit::tightly_coupled_allocation(Node* ptr) { 6654 if (stopped()) return nullptr; // no fast path 6655 if (!C->do_aliasing()) return nullptr; // no MergeMems around 6656 6657 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr); 6658 if (alloc == nullptr) return nullptr; 6659 6660 Node* rawmem = memory(Compile::AliasIdxRaw); 6661 // Is the allocation's memory state untouched? 6662 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 6663 // Bail out if there have been raw-memory effects since the allocation. 6664 // (Example: There might have been a call or safepoint.) 6665 return nullptr; 6666 } 6667 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 6668 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 6669 return nullptr; 6670 } 6671 6672 // There must be no unexpected observers of this allocation. 6673 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 6674 Node* obs = ptr->fast_out(i); 6675 if (obs != this->map()) { 6676 return nullptr; 6677 } 6678 } 6679 6680 // This arraycopy must unconditionally follow the allocation of the ptr. 6681 Node* alloc_ctl = ptr->in(0); 6682 Node* ctl = control(); 6683 while (ctl != alloc_ctl) { 6684 // There may be guards which feed into the slow_region. 6685 // Any other control flow means that we might not get a chance 6686 // to finish initializing the allocated object. 6687 // Various low-level checks bottom out in uncommon traps. These 6688 // are considered safe since we've already checked above that 6689 // there is no unexpected observer of this allocation. 6690 if (get_uncommon_trap_from_success_proj(ctl) != nullptr) { 6691 assert(ctl->in(0)->is_If(), "must be If"); 6692 ctl = ctl->in(0)->in(0); 6693 } else { 6694 return nullptr; 6695 } 6696 } 6697 6698 // If we get this far, we have an allocation which immediately 6699 // precedes the arraycopy, and we can take over zeroing the new object. 6700 // The arraycopy will finish the initialization, and provide 6701 // a new control state to which we will anchor the destination pointer. 6702 6703 return alloc; 6704 } 6705 6706 CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* node) { 6707 if (node->is_IfProj()) { 6708 Node* other_proj = node->as_IfProj()->other_if_proj(); 6709 for (DUIterator_Fast jmax, j = other_proj->fast_outs(jmax); j < jmax; j++) { 6710 Node* obs = other_proj->fast_out(j); 6711 if (obs->in(0) == other_proj && obs->is_CallStaticJava() && 6712 (obs->as_CallStaticJava()->entry_point() == OptoRuntime::uncommon_trap_blob()->entry_point())) { 6713 return obs->as_CallStaticJava(); 6714 } 6715 } 6716 } 6717 return nullptr; 6718 } 6719 6720 //-------------inline_encodeISOArray----------------------------------- 6721 // encode char[] to byte[] in ISO_8859_1 or ASCII 6722 bool LibraryCallKit::inline_encodeISOArray(bool ascii) { 6723 assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 6724 // no receiver since it is static method 6725 Node *src = argument(0); 6726 Node *src_offset = argument(1); 6727 Node *dst = argument(2); 6728 Node *dst_offset = argument(3); 6729 Node *length = argument(4); 6730 6731 src = must_be_not_null(src, true); 6732 dst = must_be_not_null(dst, true); 6733 6734 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 6735 const TypeAryPtr* dst_type = dst->Value(&_gvn)->isa_aryptr(); 6736 if (src_type == nullptr || src_type->elem() == Type::BOTTOM || 6737 dst_type == nullptr || dst_type->elem() == Type::BOTTOM) { 6738 // failed array check 6739 return false; 6740 } 6741 6742 // Figure out the size and type of the elements we will be copying. 6743 BasicType src_elem = src_type->elem()->array_element_basic_type(); 6744 BasicType dst_elem = dst_type->elem()->array_element_basic_type(); 6745 if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) { 6746 return false; 6747 } 6748 6749 Node* src_start = array_element_address(src, src_offset, T_CHAR); 6750 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 6751 // 'src_start' points to src array + scaled offset 6752 // 'dst_start' points to dst array + scaled offset 6753 6754 const TypeAryPtr* mtype = TypeAryPtr::BYTES; 6755 Node* enc = new EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length, ascii); 6756 enc = _gvn.transform(enc); 6757 Node* res_mem = _gvn.transform(new SCMemProjNode(enc)); 6758 set_memory(res_mem, mtype); 6759 set_result(enc); 6760 clear_upper_avx(); 6761 6762 return true; 6763 } 6764 6765 //-------------inline_multiplyToLen----------------------------------- 6766 bool LibraryCallKit::inline_multiplyToLen() { 6767 assert(UseMultiplyToLenIntrinsic, "not implemented on this platform"); 6768 6769 address stubAddr = StubRoutines::multiplyToLen(); 6770 if (stubAddr == nullptr) { 6771 return false; // Intrinsic's stub is not implemented on this platform 6772 } 6773 const char* stubName = "multiplyToLen"; 6774 6775 assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters"); 6776 6777 // no receiver because it is a static method 6778 Node* x = argument(0); 6779 Node* xlen = argument(1); 6780 Node* y = argument(2); 6781 Node* ylen = argument(3); 6782 Node* z = argument(4); 6783 6784 x = must_be_not_null(x, true); 6785 y = must_be_not_null(y, true); 6786 6787 const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr(); 6788 const TypeAryPtr* y_type = y->Value(&_gvn)->isa_aryptr(); 6789 if (x_type == nullptr || x_type->elem() == Type::BOTTOM || 6790 y_type == nullptr || y_type->elem() == Type::BOTTOM) { 6791 // failed array check 6792 return false; 6793 } 6794 6795 BasicType x_elem = x_type->elem()->array_element_basic_type(); 6796 BasicType y_elem = y_type->elem()->array_element_basic_type(); 6797 if (x_elem != T_INT || y_elem != T_INT) { 6798 return false; 6799 } 6800 6801 Node* x_start = array_element_address(x, intcon(0), x_elem); 6802 Node* y_start = array_element_address(y, intcon(0), y_elem); 6803 // 'x_start' points to x array + scaled xlen 6804 // 'y_start' points to y array + scaled ylen 6805 6806 Node* z_start = array_element_address(z, intcon(0), T_INT); 6807 6808 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6809 OptoRuntime::multiplyToLen_Type(), 6810 stubAddr, stubName, TypePtr::BOTTOM, 6811 x_start, xlen, y_start, ylen, z_start); 6812 6813 C->set_has_split_ifs(true); // Has chance for split-if optimization 6814 set_result(z); 6815 return true; 6816 } 6817 6818 //-------------inline_squareToLen------------------------------------ 6819 bool LibraryCallKit::inline_squareToLen() { 6820 assert(UseSquareToLenIntrinsic, "not implemented on this platform"); 6821 6822 address stubAddr = StubRoutines::squareToLen(); 6823 if (stubAddr == nullptr) { 6824 return false; // Intrinsic's stub is not implemented on this platform 6825 } 6826 const char* stubName = "squareToLen"; 6827 6828 assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters"); 6829 6830 Node* x = argument(0); 6831 Node* len = argument(1); 6832 Node* z = argument(2); 6833 Node* zlen = argument(3); 6834 6835 x = must_be_not_null(x, true); 6836 z = must_be_not_null(z, true); 6837 6838 const TypeAryPtr* x_type = x->Value(&_gvn)->isa_aryptr(); 6839 const TypeAryPtr* z_type = z->Value(&_gvn)->isa_aryptr(); 6840 if (x_type == nullptr || x_type->elem() == Type::BOTTOM || 6841 z_type == nullptr || z_type->elem() == Type::BOTTOM) { 6842 // failed array check 6843 return false; 6844 } 6845 6846 BasicType x_elem = x_type->elem()->array_element_basic_type(); 6847 BasicType z_elem = z_type->elem()->array_element_basic_type(); 6848 if (x_elem != T_INT || z_elem != T_INT) { 6849 return false; 6850 } 6851 6852 6853 Node* x_start = array_element_address(x, intcon(0), x_elem); 6854 Node* z_start = array_element_address(z, intcon(0), z_elem); 6855 6856 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6857 OptoRuntime::squareToLen_Type(), 6858 stubAddr, stubName, TypePtr::BOTTOM, 6859 x_start, len, z_start, zlen); 6860 6861 set_result(z); 6862 return true; 6863 } 6864 6865 //-------------inline_mulAdd------------------------------------------ 6866 bool LibraryCallKit::inline_mulAdd() { 6867 assert(UseMulAddIntrinsic, "not implemented on this platform"); 6868 6869 address stubAddr = StubRoutines::mulAdd(); 6870 if (stubAddr == nullptr) { 6871 return false; // Intrinsic's stub is not implemented on this platform 6872 } 6873 const char* stubName = "mulAdd"; 6874 6875 assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters"); 6876 6877 Node* out = argument(0); 6878 Node* in = argument(1); 6879 Node* offset = argument(2); 6880 Node* len = argument(3); 6881 Node* k = argument(4); 6882 6883 in = must_be_not_null(in, true); 6884 out = must_be_not_null(out, true); 6885 6886 const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr(); 6887 const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr(); 6888 if (out_type == nullptr || out_type->elem() == Type::BOTTOM || 6889 in_type == nullptr || in_type->elem() == Type::BOTTOM) { 6890 // failed array check 6891 return false; 6892 } 6893 6894 BasicType out_elem = out_type->elem()->array_element_basic_type(); 6895 BasicType in_elem = in_type->elem()->array_element_basic_type(); 6896 if (out_elem != T_INT || in_elem != T_INT) { 6897 return false; 6898 } 6899 6900 Node* outlen = load_array_length(out); 6901 Node* new_offset = _gvn.transform(new SubINode(outlen, offset)); 6902 Node* out_start = array_element_address(out, intcon(0), out_elem); 6903 Node* in_start = array_element_address(in, intcon(0), in_elem); 6904 6905 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6906 OptoRuntime::mulAdd_Type(), 6907 stubAddr, stubName, TypePtr::BOTTOM, 6908 out_start,in_start, new_offset, len, k); 6909 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 6910 set_result(result); 6911 return true; 6912 } 6913 6914 //-------------inline_montgomeryMultiply----------------------------------- 6915 bool LibraryCallKit::inline_montgomeryMultiply() { 6916 address stubAddr = StubRoutines::montgomeryMultiply(); 6917 if (stubAddr == nullptr) { 6918 return false; // Intrinsic's stub is not implemented on this platform 6919 } 6920 6921 assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform"); 6922 const char* stubName = "montgomery_multiply"; 6923 6924 assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters"); 6925 6926 Node* a = argument(0); 6927 Node* b = argument(1); 6928 Node* n = argument(2); 6929 Node* len = argument(3); 6930 Node* inv = argument(4); 6931 Node* m = argument(6); 6932 6933 const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr(); 6934 const TypeAryPtr* b_type = b->Value(&_gvn)->isa_aryptr(); 6935 const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr(); 6936 const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr(); 6937 if (a_type == nullptr || a_type->elem() == Type::BOTTOM || 6938 b_type == nullptr || b_type->elem() == Type::BOTTOM || 6939 n_type == nullptr || n_type->elem() == Type::BOTTOM || 6940 m_type == nullptr || m_type->elem() == Type::BOTTOM) { 6941 // failed array check 6942 return false; 6943 } 6944 6945 BasicType a_elem = a_type->elem()->array_element_basic_type(); 6946 BasicType b_elem = b_type->elem()->array_element_basic_type(); 6947 BasicType n_elem = n_type->elem()->array_element_basic_type(); 6948 BasicType m_elem = m_type->elem()->array_element_basic_type(); 6949 if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 6950 return false; 6951 } 6952 6953 // Make the call 6954 { 6955 Node* a_start = array_element_address(a, intcon(0), a_elem); 6956 Node* b_start = array_element_address(b, intcon(0), b_elem); 6957 Node* n_start = array_element_address(n, intcon(0), n_elem); 6958 Node* m_start = array_element_address(m, intcon(0), m_elem); 6959 6960 Node* call = make_runtime_call(RC_LEAF, 6961 OptoRuntime::montgomeryMultiply_Type(), 6962 stubAddr, stubName, TypePtr::BOTTOM, 6963 a_start, b_start, n_start, len, inv, top(), 6964 m_start); 6965 set_result(m); 6966 } 6967 6968 return true; 6969 } 6970 6971 bool LibraryCallKit::inline_montgomerySquare() { 6972 address stubAddr = StubRoutines::montgomerySquare(); 6973 if (stubAddr == nullptr) { 6974 return false; // Intrinsic's stub is not implemented on this platform 6975 } 6976 6977 assert(UseMontgomerySquareIntrinsic, "not implemented on this platform"); 6978 const char* stubName = "montgomery_square"; 6979 6980 assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters"); 6981 6982 Node* a = argument(0); 6983 Node* n = argument(1); 6984 Node* len = argument(2); 6985 Node* inv = argument(3); 6986 Node* m = argument(5); 6987 6988 const TypeAryPtr* a_type = a->Value(&_gvn)->isa_aryptr(); 6989 const TypeAryPtr* n_type = n->Value(&_gvn)->isa_aryptr(); 6990 const TypeAryPtr* m_type = m->Value(&_gvn)->isa_aryptr(); 6991 if (a_type == nullptr || a_type->elem() == Type::BOTTOM || 6992 n_type == nullptr || n_type->elem() == Type::BOTTOM || 6993 m_type == nullptr || m_type->elem() == Type::BOTTOM) { 6994 // failed array check 6995 return false; 6996 } 6997 6998 BasicType a_elem = a_type->elem()->array_element_basic_type(); 6999 BasicType n_elem = n_type->elem()->array_element_basic_type(); 7000 BasicType m_elem = m_type->elem()->array_element_basic_type(); 7001 if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 7002 return false; 7003 } 7004 7005 // Make the call 7006 { 7007 Node* a_start = array_element_address(a, intcon(0), a_elem); 7008 Node* n_start = array_element_address(n, intcon(0), n_elem); 7009 Node* m_start = array_element_address(m, intcon(0), m_elem); 7010 7011 Node* call = make_runtime_call(RC_LEAF, 7012 OptoRuntime::montgomerySquare_Type(), 7013 stubAddr, stubName, TypePtr::BOTTOM, 7014 a_start, n_start, len, inv, top(), 7015 m_start); 7016 set_result(m); 7017 } 7018 7019 return true; 7020 } 7021 7022 bool LibraryCallKit::inline_bigIntegerShift(bool isRightShift) { 7023 address stubAddr = nullptr; 7024 const char* stubName = nullptr; 7025 7026 stubAddr = isRightShift? StubRoutines::bigIntegerRightShift(): StubRoutines::bigIntegerLeftShift(); 7027 if (stubAddr == nullptr) { 7028 return false; // Intrinsic's stub is not implemented on this platform 7029 } 7030 7031 stubName = isRightShift? "bigIntegerRightShiftWorker" : "bigIntegerLeftShiftWorker"; 7032 7033 assert(callee()->signature()->size() == 5, "expected 5 arguments"); 7034 7035 Node* newArr = argument(0); 7036 Node* oldArr = argument(1); 7037 Node* newIdx = argument(2); 7038 Node* shiftCount = argument(3); 7039 Node* numIter = argument(4); 7040 7041 const TypeAryPtr* newArr_type = newArr->Value(&_gvn)->isa_aryptr(); 7042 const TypeAryPtr* oldArr_type = oldArr->Value(&_gvn)->isa_aryptr(); 7043 if (newArr_type == nullptr || newArr_type->elem() == Type::BOTTOM || 7044 oldArr_type == nullptr || oldArr_type->elem() == Type::BOTTOM) { 7045 return false; 7046 } 7047 7048 BasicType newArr_elem = newArr_type->elem()->array_element_basic_type(); 7049 BasicType oldArr_elem = oldArr_type->elem()->array_element_basic_type(); 7050 if (newArr_elem != T_INT || oldArr_elem != T_INT) { 7051 return false; 7052 } 7053 7054 // Make the call 7055 { 7056 Node* newArr_start = array_element_address(newArr, intcon(0), newArr_elem); 7057 Node* oldArr_start = array_element_address(oldArr, intcon(0), oldArr_elem); 7058 7059 Node* call = make_runtime_call(RC_LEAF, 7060 OptoRuntime::bigIntegerShift_Type(), 7061 stubAddr, 7062 stubName, 7063 TypePtr::BOTTOM, 7064 newArr_start, 7065 oldArr_start, 7066 newIdx, 7067 shiftCount, 7068 numIter); 7069 } 7070 7071 return true; 7072 } 7073 7074 //-------------inline_vectorizedMismatch------------------------------ 7075 bool LibraryCallKit::inline_vectorizedMismatch() { 7076 assert(UseVectorizedMismatchIntrinsic, "not implemented on this platform"); 7077 7078 assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters"); 7079 Node* obja = argument(0); // Object 7080 Node* aoffset = argument(1); // long 7081 Node* objb = argument(3); // Object 7082 Node* boffset = argument(4); // long 7083 Node* length = argument(6); // int 7084 Node* scale = argument(7); // int 7085 7086 const TypeAryPtr* obja_t = _gvn.type(obja)->isa_aryptr(); 7087 const TypeAryPtr* objb_t = _gvn.type(objb)->isa_aryptr(); 7088 if (obja_t == nullptr || obja_t->elem() == Type::BOTTOM || 7089 objb_t == nullptr || objb_t->elem() == Type::BOTTOM || 7090 scale == top()) { 7091 return false; // failed input validation 7092 } 7093 7094 Node* obja_adr = make_unsafe_address(obja, aoffset); 7095 Node* objb_adr = make_unsafe_address(objb, boffset); 7096 7097 // Partial inlining handling for inputs smaller than ArrayOperationPartialInlineSize bytes in size. 7098 // 7099 // inline_limit = ArrayOperationPartialInlineSize / element_size; 7100 // if (length <= inline_limit) { 7101 // inline_path: 7102 // vmask = VectorMaskGen length 7103 // vload1 = LoadVectorMasked obja, vmask 7104 // vload2 = LoadVectorMasked objb, vmask 7105 // result1 = VectorCmpMasked vload1, vload2, vmask 7106 // } else { 7107 // call_stub_path: 7108 // result2 = call vectorizedMismatch_stub(obja, objb, length, scale) 7109 // } 7110 // exit_block: 7111 // return Phi(result1, result2); 7112 // 7113 enum { inline_path = 1, // input is small enough to process it all at once 7114 stub_path = 2, // input is too large; call into the VM 7115 PATH_LIMIT = 3 7116 }; 7117 7118 Node* exit_block = new RegionNode(PATH_LIMIT); 7119 Node* result_phi = new PhiNode(exit_block, TypeInt::INT); 7120 Node* memory_phi = new PhiNode(exit_block, Type::MEMORY, TypePtr::BOTTOM); 7121 7122 Node* call_stub_path = control(); 7123 7124 BasicType elem_bt = T_ILLEGAL; 7125 7126 const TypeInt* scale_t = _gvn.type(scale)->is_int(); 7127 if (scale_t->is_con()) { 7128 switch (scale_t->get_con()) { 7129 case 0: elem_bt = T_BYTE; break; 7130 case 1: elem_bt = T_SHORT; break; 7131 case 2: elem_bt = T_INT; break; 7132 case 3: elem_bt = T_LONG; break; 7133 7134 default: elem_bt = T_ILLEGAL; break; // not supported 7135 } 7136 } 7137 7138 int inline_limit = 0; 7139 bool do_partial_inline = false; 7140 7141 if (elem_bt != T_ILLEGAL && ArrayOperationPartialInlineSize > 0) { 7142 inline_limit = ArrayOperationPartialInlineSize / type2aelembytes(elem_bt); 7143 do_partial_inline = inline_limit >= 16; 7144 } 7145 7146 if (do_partial_inline) { 7147 assert(elem_bt != T_ILLEGAL, "sanity"); 7148 7149 if (Matcher::match_rule_supported_vector(Op_VectorMaskGen, inline_limit, elem_bt) && 7150 Matcher::match_rule_supported_vector(Op_LoadVectorMasked, inline_limit, elem_bt) && 7151 Matcher::match_rule_supported_vector(Op_VectorCmpMasked, inline_limit, elem_bt)) { 7152 7153 const TypeVect* vt = TypeVect::make(elem_bt, inline_limit); 7154 Node* cmp_length = _gvn.transform(new CmpINode(length, intcon(inline_limit))); 7155 Node* bol_gt = _gvn.transform(new BoolNode(cmp_length, BoolTest::gt)); 7156 7157 call_stub_path = generate_guard(bol_gt, nullptr, PROB_MIN); 7158 7159 if (!stopped()) { 7160 Node* casted_length = _gvn.transform(new CastIINode(control(), length, TypeInt::make(0, inline_limit, Type::WidenMin))); 7161 7162 const TypePtr* obja_adr_t = _gvn.type(obja_adr)->isa_ptr(); 7163 const TypePtr* objb_adr_t = _gvn.type(objb_adr)->isa_ptr(); 7164 Node* obja_adr_mem = memory(C->get_alias_index(obja_adr_t)); 7165 Node* objb_adr_mem = memory(C->get_alias_index(objb_adr_t)); 7166 7167 Node* vmask = _gvn.transform(VectorMaskGenNode::make(ConvI2X(casted_length), elem_bt)); 7168 Node* vload_obja = _gvn.transform(new LoadVectorMaskedNode(control(), obja_adr_mem, obja_adr, obja_adr_t, vt, vmask)); 7169 Node* vload_objb = _gvn.transform(new LoadVectorMaskedNode(control(), objb_adr_mem, objb_adr, objb_adr_t, vt, vmask)); 7170 Node* result = _gvn.transform(new VectorCmpMaskedNode(vload_obja, vload_objb, vmask, TypeInt::INT)); 7171 7172 exit_block->init_req(inline_path, control()); 7173 memory_phi->init_req(inline_path, map()->memory()); 7174 result_phi->init_req(inline_path, result); 7175 7176 C->set_max_vector_size(MAX2((uint)ArrayOperationPartialInlineSize, C->max_vector_size())); 7177 clear_upper_avx(); 7178 } 7179 } 7180 } 7181 7182 if (call_stub_path != nullptr) { 7183 set_control(call_stub_path); 7184 7185 Node* call = make_runtime_call(RC_LEAF, 7186 OptoRuntime::vectorizedMismatch_Type(), 7187 StubRoutines::vectorizedMismatch(), "vectorizedMismatch", TypePtr::BOTTOM, 7188 obja_adr, objb_adr, length, scale); 7189 7190 exit_block->init_req(stub_path, control()); 7191 memory_phi->init_req(stub_path, map()->memory()); 7192 result_phi->init_req(stub_path, _gvn.transform(new ProjNode(call, TypeFunc::Parms))); 7193 } 7194 7195 exit_block = _gvn.transform(exit_block); 7196 memory_phi = _gvn.transform(memory_phi); 7197 result_phi = _gvn.transform(result_phi); 7198 7199 set_control(exit_block); 7200 set_all_memory(memory_phi); 7201 set_result(result_phi); 7202 7203 return true; 7204 } 7205 7206 //------------------------------inline_vectorizedHashcode---------------------------- 7207 bool LibraryCallKit::inline_vectorizedHashCode() { 7208 assert(UseVectorizedHashCodeIntrinsic, "not implemented on this platform"); 7209 7210 assert(callee()->signature()->size() == 5, "vectorizedHashCode has 5 parameters"); 7211 Node* array = argument(0); 7212 Node* offset = argument(1); 7213 Node* length = argument(2); 7214 Node* initialValue = argument(3); 7215 Node* basic_type = argument(4); 7216 7217 if (basic_type == top()) { 7218 return false; // failed input validation 7219 } 7220 7221 const TypeInt* basic_type_t = _gvn.type(basic_type)->is_int(); 7222 if (!basic_type_t->is_con()) { 7223 return false; // Only intrinsify if mode argument is constant 7224 } 7225 7226 array = must_be_not_null(array, true); 7227 7228 BasicType bt = (BasicType)basic_type_t->get_con(); 7229 7230 // Resolve address of first element 7231 Node* array_start = array_element_address(array, offset, bt); 7232 7233 set_result(_gvn.transform(new VectorizedHashCodeNode(control(), memory(TypeAryPtr::get_array_body_type(bt)), 7234 array_start, length, initialValue, basic_type))); 7235 clear_upper_avx(); 7236 7237 return true; 7238 } 7239 7240 /** 7241 * Calculate CRC32 for byte. 7242 * int java.util.zip.CRC32.update(int crc, int b) 7243 */ 7244 bool LibraryCallKit::inline_updateCRC32() { 7245 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7246 assert(callee()->signature()->size() == 2, "update has 2 parameters"); 7247 // no receiver since it is static method 7248 Node* crc = argument(0); // type: int 7249 Node* b = argument(1); // type: int 7250 7251 /* 7252 * int c = ~ crc; 7253 * b = timesXtoThe32[(b ^ c) & 0xFF]; 7254 * b = b ^ (c >>> 8); 7255 * crc = ~b; 7256 */ 7257 7258 Node* M1 = intcon(-1); 7259 crc = _gvn.transform(new XorINode(crc, M1)); 7260 Node* result = _gvn.transform(new XorINode(crc, b)); 7261 result = _gvn.transform(new AndINode(result, intcon(0xFF))); 7262 7263 Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 7264 Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2))); 7265 Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 7266 result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 7267 7268 crc = _gvn.transform(new URShiftINode(crc, intcon(8))); 7269 result = _gvn.transform(new XorINode(crc, result)); 7270 result = _gvn.transform(new XorINode(result, M1)); 7271 set_result(result); 7272 return true; 7273 } 7274 7275 /** 7276 * Calculate CRC32 for byte[] array. 7277 * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 7278 */ 7279 bool LibraryCallKit::inline_updateBytesCRC32() { 7280 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7281 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7282 // no receiver since it is static method 7283 Node* crc = argument(0); // type: int 7284 Node* src = argument(1); // type: oop 7285 Node* offset = argument(2); // type: int 7286 Node* length = argument(3); // type: int 7287 7288 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7289 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7290 // failed array check 7291 return false; 7292 } 7293 7294 // Figure out the size and type of the elements we will be copying. 7295 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7296 if (src_elem != T_BYTE) { 7297 return false; 7298 } 7299 7300 // 'src_start' points to src array + scaled offset 7301 src = must_be_not_null(src, true); 7302 Node* src_start = array_element_address(src, offset, src_elem); 7303 7304 // We assume that range check is done by caller. 7305 // TODO: generate range check (offset+length < src.length) in debug VM. 7306 7307 // Call the stub. 7308 address stubAddr = StubRoutines::updateBytesCRC32(); 7309 const char *stubName = "updateBytesCRC32"; 7310 7311 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 7312 stubAddr, stubName, TypePtr::BOTTOM, 7313 crc, src_start, length); 7314 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7315 set_result(result); 7316 return true; 7317 } 7318 7319 /** 7320 * Calculate CRC32 for ByteBuffer. 7321 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 7322 */ 7323 bool LibraryCallKit::inline_updateByteBufferCRC32() { 7324 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions support"); 7325 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 7326 // no receiver since it is static method 7327 Node* crc = argument(0); // type: int 7328 Node* src = argument(1); // type: long 7329 Node* offset = argument(3); // type: int 7330 Node* length = argument(4); // type: int 7331 7332 src = ConvL2X(src); // adjust Java long to machine word 7333 Node* base = _gvn.transform(new CastX2PNode(src)); 7334 offset = ConvI2X(offset); 7335 7336 // 'src_start' points to src array + scaled offset 7337 Node* src_start = basic_plus_adr(top(), base, offset); 7338 7339 // Call the stub. 7340 address stubAddr = StubRoutines::updateBytesCRC32(); 7341 const char *stubName = "updateBytesCRC32"; 7342 7343 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 7344 stubAddr, stubName, TypePtr::BOTTOM, 7345 crc, src_start, length); 7346 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7347 set_result(result); 7348 return true; 7349 } 7350 7351 //------------------------------get_table_from_crc32c_class----------------------- 7352 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) { 7353 Node* table = load_field_from_object(nullptr, "byteTable", "[I", /*decorators*/ IN_HEAP, /*is_static*/ true, crc32c_class); 7354 assert (table != nullptr, "wrong version of java.util.zip.CRC32C"); 7355 7356 return table; 7357 } 7358 7359 //------------------------------inline_updateBytesCRC32C----------------------- 7360 // 7361 // Calculate CRC32C for byte[] array. 7362 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end) 7363 // 7364 bool LibraryCallKit::inline_updateBytesCRC32C() { 7365 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 7366 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7367 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 7368 // no receiver since it is a static method 7369 Node* crc = argument(0); // type: int 7370 Node* src = argument(1); // type: oop 7371 Node* offset = argument(2); // type: int 7372 Node* end = argument(3); // type: int 7373 7374 Node* length = _gvn.transform(new SubINode(end, offset)); 7375 7376 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7377 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7378 // failed array check 7379 return false; 7380 } 7381 7382 // Figure out the size and type of the elements we will be copying. 7383 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7384 if (src_elem != T_BYTE) { 7385 return false; 7386 } 7387 7388 // 'src_start' points to src array + scaled offset 7389 src = must_be_not_null(src, true); 7390 Node* src_start = array_element_address(src, offset, src_elem); 7391 7392 // static final int[] byteTable in class CRC32C 7393 Node* table = get_table_from_crc32c_class(callee()->holder()); 7394 table = must_be_not_null(table, true); 7395 Node* table_start = array_element_address(table, intcon(0), T_INT); 7396 7397 // We assume that range check is done by caller. 7398 // TODO: generate range check (offset+length < src.length) in debug VM. 7399 7400 // Call the stub. 7401 address stubAddr = StubRoutines::updateBytesCRC32C(); 7402 const char *stubName = "updateBytesCRC32C"; 7403 7404 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 7405 stubAddr, stubName, TypePtr::BOTTOM, 7406 crc, src_start, length, table_start); 7407 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7408 set_result(result); 7409 return true; 7410 } 7411 7412 //------------------------------inline_updateDirectByteBufferCRC32C----------------------- 7413 // 7414 // Calculate CRC32C for DirectByteBuffer. 7415 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end) 7416 // 7417 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() { 7418 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 7419 assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long"); 7420 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 7421 // no receiver since it is a static method 7422 Node* crc = argument(0); // type: int 7423 Node* src = argument(1); // type: long 7424 Node* offset = argument(3); // type: int 7425 Node* end = argument(4); // type: int 7426 7427 Node* length = _gvn.transform(new SubINode(end, offset)); 7428 7429 src = ConvL2X(src); // adjust Java long to machine word 7430 Node* base = _gvn.transform(new CastX2PNode(src)); 7431 offset = ConvI2X(offset); 7432 7433 // 'src_start' points to src array + scaled offset 7434 Node* src_start = basic_plus_adr(top(), base, offset); 7435 7436 // static final int[] byteTable in class CRC32C 7437 Node* table = get_table_from_crc32c_class(callee()->holder()); 7438 table = must_be_not_null(table, true); 7439 Node* table_start = array_element_address(table, intcon(0), T_INT); 7440 7441 // Call the stub. 7442 address stubAddr = StubRoutines::updateBytesCRC32C(); 7443 const char *stubName = "updateBytesCRC32C"; 7444 7445 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 7446 stubAddr, stubName, TypePtr::BOTTOM, 7447 crc, src_start, length, table_start); 7448 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7449 set_result(result); 7450 return true; 7451 } 7452 7453 //------------------------------inline_updateBytesAdler32---------------------- 7454 // 7455 // Calculate Adler32 checksum for byte[] array. 7456 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len) 7457 // 7458 bool LibraryCallKit::inline_updateBytesAdler32() { 7459 assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one 7460 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 7461 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 7462 // no receiver since it is static method 7463 Node* crc = argument(0); // type: int 7464 Node* src = argument(1); // type: oop 7465 Node* offset = argument(2); // type: int 7466 Node* length = argument(3); // type: int 7467 7468 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7469 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 7470 // failed array check 7471 return false; 7472 } 7473 7474 // Figure out the size and type of the elements we will be copying. 7475 BasicType src_elem = src_type->elem()->array_element_basic_type(); 7476 if (src_elem != T_BYTE) { 7477 return false; 7478 } 7479 7480 // 'src_start' points to src array + scaled offset 7481 Node* src_start = array_element_address(src, offset, src_elem); 7482 7483 // We assume that range check is done by caller. 7484 // TODO: generate range check (offset+length < src.length) in debug VM. 7485 7486 // Call the stub. 7487 address stubAddr = StubRoutines::updateBytesAdler32(); 7488 const char *stubName = "updateBytesAdler32"; 7489 7490 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 7491 stubAddr, stubName, TypePtr::BOTTOM, 7492 crc, src_start, length); 7493 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7494 set_result(result); 7495 return true; 7496 } 7497 7498 //------------------------------inline_updateByteBufferAdler32--------------- 7499 // 7500 // Calculate Adler32 checksum for DirectByteBuffer. 7501 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len) 7502 // 7503 bool LibraryCallKit::inline_updateByteBufferAdler32() { 7504 assert(UseAdler32Intrinsics, "Adler32 Intrinsic support need"); // check if we actually need to check this flag or check a different one 7505 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 7506 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 7507 // no receiver since it is static method 7508 Node* crc = argument(0); // type: int 7509 Node* src = argument(1); // type: long 7510 Node* offset = argument(3); // type: int 7511 Node* length = argument(4); // type: int 7512 7513 src = ConvL2X(src); // adjust Java long to machine word 7514 Node* base = _gvn.transform(new CastX2PNode(src)); 7515 offset = ConvI2X(offset); 7516 7517 // 'src_start' points to src array + scaled offset 7518 Node* src_start = basic_plus_adr(top(), base, offset); 7519 7520 // Call the stub. 7521 address stubAddr = StubRoutines::updateBytesAdler32(); 7522 const char *stubName = "updateBytesAdler32"; 7523 7524 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 7525 stubAddr, stubName, TypePtr::BOTTOM, 7526 crc, src_start, length); 7527 7528 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 7529 set_result(result); 7530 return true; 7531 } 7532 7533 //----------------------------inline_reference_get---------------------------- 7534 // public T java.lang.ref.Reference.get(); 7535 bool LibraryCallKit::inline_reference_get() { 7536 const int referent_offset = java_lang_ref_Reference::referent_offset(); 7537 7538 // Get the argument: 7539 Node* reference_obj = null_check_receiver(); 7540 if (stopped()) return true; 7541 7542 DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF; 7543 Node* result = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;", 7544 decorators, /*is_static*/ false, nullptr); 7545 if (result == nullptr) return false; 7546 7547 // Add memory barrier to prevent commoning reads from this field 7548 // across safepoint since GC can change its value. 7549 insert_mem_bar(Op_MemBarCPUOrder); 7550 7551 set_result(result); 7552 return true; 7553 } 7554 7555 //----------------------------inline_reference_refersTo0---------------------------- 7556 // bool java.lang.ref.Reference.refersTo0(); 7557 // bool java.lang.ref.PhantomReference.refersTo0(); 7558 bool LibraryCallKit::inline_reference_refersTo0(bool is_phantom) { 7559 // Get arguments: 7560 Node* reference_obj = null_check_receiver(); 7561 Node* other_obj = argument(1); 7562 if (stopped()) return true; 7563 7564 DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE; 7565 decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF); 7566 Node* referent = load_field_from_object(reference_obj, "referent", "Ljava/lang/Object;", 7567 decorators, /*is_static*/ false, nullptr); 7568 if (referent == nullptr) return false; 7569 7570 // Add memory barrier to prevent commoning reads from this field 7571 // across safepoint since GC can change its value. 7572 insert_mem_bar(Op_MemBarCPUOrder); 7573 7574 Node* cmp = _gvn.transform(new CmpPNode(referent, other_obj)); 7575 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 7576 IfNode* if_node = create_and_map_if(control(), bol, PROB_FAIR, COUNT_UNKNOWN); 7577 7578 RegionNode* region = new RegionNode(3); 7579 PhiNode* phi = new PhiNode(region, TypeInt::BOOL); 7580 7581 Node* if_true = _gvn.transform(new IfTrueNode(if_node)); 7582 region->init_req(1, if_true); 7583 phi->init_req(1, intcon(1)); 7584 7585 Node* if_false = _gvn.transform(new IfFalseNode(if_node)); 7586 region->init_req(2, if_false); 7587 phi->init_req(2, intcon(0)); 7588 7589 set_control(_gvn.transform(region)); 7590 record_for_igvn(region); 7591 set_result(_gvn.transform(phi)); 7592 return true; 7593 } 7594 7595 //----------------------------inline_reference_clear0---------------------------- 7596 // void java.lang.ref.Reference.clear0(); 7597 // void java.lang.ref.PhantomReference.clear0(); 7598 bool LibraryCallKit::inline_reference_clear0(bool is_phantom) { 7599 // This matches the implementation in JVM_ReferenceClear, see the comments there. 7600 7601 // Get arguments 7602 Node* reference_obj = null_check_receiver(); 7603 if (stopped()) return true; 7604 7605 // Common access parameters 7606 DecoratorSet decorators = IN_HEAP | AS_NO_KEEPALIVE; 7607 decorators |= (is_phantom ? ON_PHANTOM_OOP_REF : ON_WEAK_OOP_REF); 7608 Node* referent_field_addr = basic_plus_adr(reference_obj, java_lang_ref_Reference::referent_offset()); 7609 const TypePtr* referent_field_addr_type = _gvn.type(referent_field_addr)->isa_ptr(); 7610 const Type* val_type = TypeOopPtr::make_from_klass(env()->Object_klass()); 7611 7612 Node* referent = access_load_at(reference_obj, 7613 referent_field_addr, 7614 referent_field_addr_type, 7615 val_type, 7616 T_OBJECT, 7617 decorators); 7618 7619 IdealKit ideal(this); 7620 #define __ ideal. 7621 __ if_then(referent, BoolTest::ne, null()); 7622 sync_kit(ideal); 7623 access_store_at(reference_obj, 7624 referent_field_addr, 7625 referent_field_addr_type, 7626 null(), 7627 val_type, 7628 T_OBJECT, 7629 decorators); 7630 __ sync_kit(this); 7631 __ end_if(); 7632 final_sync(ideal); 7633 #undef __ 7634 7635 return true; 7636 } 7637 7638 Node* LibraryCallKit::load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, 7639 DecoratorSet decorators, bool is_static, 7640 ciInstanceKlass* fromKls) { 7641 if (fromKls == nullptr) { 7642 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 7643 assert(tinst != nullptr, "obj is null"); 7644 assert(tinst->is_loaded(), "obj is not loaded"); 7645 fromKls = tinst->instance_klass(); 7646 } else { 7647 assert(is_static, "only for static field access"); 7648 } 7649 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 7650 ciSymbol::make(fieldTypeString), 7651 is_static); 7652 7653 assert(field != nullptr, "undefined field %s %s %s", fieldTypeString, fromKls->name()->as_utf8(), fieldName); 7654 if (field == nullptr) return (Node *) nullptr; 7655 7656 if (is_static) { 7657 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 7658 fromObj = makecon(tip); 7659 } 7660 7661 // Next code copied from Parse::do_get_xxx(): 7662 7663 // Compute address and memory type. 7664 int offset = field->offset_in_bytes(); 7665 bool is_vol = field->is_volatile(); 7666 ciType* field_klass = field->type(); 7667 assert(field_klass->is_loaded(), "should be loaded"); 7668 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 7669 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 7670 assert(C->get_alias_index(adr_type) == C->get_alias_index(_gvn.type(adr)->isa_ptr()), 7671 "slice of address and input slice don't match"); 7672 BasicType bt = field->layout_type(); 7673 7674 // Build the resultant type of the load 7675 const Type *type; 7676 if (bt == T_OBJECT) { 7677 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 7678 } else { 7679 type = Type::get_const_basic_type(bt); 7680 } 7681 7682 if (is_vol) { 7683 decorators |= MO_SEQ_CST; 7684 } 7685 7686 return access_load_at(fromObj, adr, adr_type, type, bt, decorators); 7687 } 7688 7689 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 7690 bool is_exact /* true */, bool is_static /* false */, 7691 ciInstanceKlass * fromKls /* nullptr */) { 7692 if (fromKls == nullptr) { 7693 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 7694 assert(tinst != nullptr, "obj is null"); 7695 assert(tinst->is_loaded(), "obj is not loaded"); 7696 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 7697 fromKls = tinst->instance_klass(); 7698 } 7699 else { 7700 assert(is_static, "only for static field access"); 7701 } 7702 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 7703 ciSymbol::make(fieldTypeString), 7704 is_static); 7705 7706 assert(field != nullptr, "undefined field"); 7707 assert(!field->is_volatile(), "not defined for volatile fields"); 7708 7709 if (is_static) { 7710 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 7711 fromObj = makecon(tip); 7712 } 7713 7714 // Next code copied from Parse::do_get_xxx(): 7715 7716 // Compute address and memory type. 7717 int offset = field->offset_in_bytes(); 7718 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 7719 7720 return adr; 7721 } 7722 7723 //------------------------------inline_aescrypt_Block----------------------- 7724 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 7725 address stubAddr = nullptr; 7726 const char *stubName; 7727 assert(UseAES, "need AES instruction support"); 7728 7729 switch(id) { 7730 case vmIntrinsics::_aescrypt_encryptBlock: 7731 stubAddr = StubRoutines::aescrypt_encryptBlock(); 7732 stubName = "aescrypt_encryptBlock"; 7733 break; 7734 case vmIntrinsics::_aescrypt_decryptBlock: 7735 stubAddr = StubRoutines::aescrypt_decryptBlock(); 7736 stubName = "aescrypt_decryptBlock"; 7737 break; 7738 default: 7739 break; 7740 } 7741 if (stubAddr == nullptr) return false; 7742 7743 Node* aescrypt_object = argument(0); 7744 Node* src = argument(1); 7745 Node* src_offset = argument(2); 7746 Node* dest = argument(3); 7747 Node* dest_offset = argument(4); 7748 7749 src = must_be_not_null(src, true); 7750 dest = must_be_not_null(dest, true); 7751 7752 // (1) src and dest are arrays. 7753 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7754 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7755 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7756 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7757 7758 // for the quick and dirty code we will skip all the checks. 7759 // we are just trying to get the call to be generated. 7760 Node* src_start = src; 7761 Node* dest_start = dest; 7762 if (src_offset != nullptr || dest_offset != nullptr) { 7763 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7764 src_start = array_element_address(src, src_offset, T_BYTE); 7765 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7766 } 7767 7768 // now need to get the start of its expanded key array 7769 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7770 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 7771 if (k_start == nullptr) return false; 7772 7773 // Call the stub. 7774 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 7775 stubAddr, stubName, TypePtr::BOTTOM, 7776 src_start, dest_start, k_start); 7777 7778 return true; 7779 } 7780 7781 //------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 7782 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 7783 address stubAddr = nullptr; 7784 const char *stubName = nullptr; 7785 7786 assert(UseAES, "need AES instruction support"); 7787 7788 switch(id) { 7789 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 7790 stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 7791 stubName = "cipherBlockChaining_encryptAESCrypt"; 7792 break; 7793 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 7794 stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 7795 stubName = "cipherBlockChaining_decryptAESCrypt"; 7796 break; 7797 default: 7798 break; 7799 } 7800 if (stubAddr == nullptr) return false; 7801 7802 Node* cipherBlockChaining_object = argument(0); 7803 Node* src = argument(1); 7804 Node* src_offset = argument(2); 7805 Node* len = argument(3); 7806 Node* dest = argument(4); 7807 Node* dest_offset = argument(5); 7808 7809 src = must_be_not_null(src, false); 7810 dest = must_be_not_null(dest, false); 7811 7812 // (1) src and dest are arrays. 7813 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7814 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7815 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7816 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7817 7818 // checks are the responsibility of the caller 7819 Node* src_start = src; 7820 Node* dest_start = dest; 7821 if (src_offset != nullptr || dest_offset != nullptr) { 7822 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7823 src_start = array_element_address(src, src_offset, T_BYTE); 7824 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7825 } 7826 7827 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 7828 // (because of the predicated logic executed earlier). 7829 // so we cast it here safely. 7830 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7831 7832 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 7833 if (embeddedCipherObj == nullptr) return false; 7834 7835 // cast it to what we know it will be at runtime 7836 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 7837 assert(tinst != nullptr, "CBC obj is null"); 7838 assert(tinst->is_loaded(), "CBC obj is not loaded"); 7839 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 7840 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 7841 7842 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 7843 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 7844 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 7845 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 7846 aescrypt_object = _gvn.transform(aescrypt_object); 7847 7848 // we need to get the start of the aescrypt_object's expanded key array 7849 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 7850 if (k_start == nullptr) return false; 7851 7852 // similarly, get the start address of the r vector 7853 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B"); 7854 if (objRvec == nullptr) return false; 7855 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 7856 7857 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 7858 Node* cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 7859 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 7860 stubAddr, stubName, TypePtr::BOTTOM, 7861 src_start, dest_start, k_start, r_start, len); 7862 7863 // return cipher length (int) 7864 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms)); 7865 set_result(retvalue); 7866 return true; 7867 } 7868 7869 //------------------------------inline_electronicCodeBook_AESCrypt----------------------- 7870 bool LibraryCallKit::inline_electronicCodeBook_AESCrypt(vmIntrinsics::ID id) { 7871 address stubAddr = nullptr; 7872 const char *stubName = nullptr; 7873 7874 assert(UseAES, "need AES instruction support"); 7875 7876 switch (id) { 7877 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 7878 stubAddr = StubRoutines::electronicCodeBook_encryptAESCrypt(); 7879 stubName = "electronicCodeBook_encryptAESCrypt"; 7880 break; 7881 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 7882 stubAddr = StubRoutines::electronicCodeBook_decryptAESCrypt(); 7883 stubName = "electronicCodeBook_decryptAESCrypt"; 7884 break; 7885 default: 7886 break; 7887 } 7888 7889 if (stubAddr == nullptr) return false; 7890 7891 Node* electronicCodeBook_object = argument(0); 7892 Node* src = argument(1); 7893 Node* src_offset = argument(2); 7894 Node* len = argument(3); 7895 Node* dest = argument(4); 7896 Node* dest_offset = argument(5); 7897 7898 // (1) src and dest are arrays. 7899 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7900 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7901 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7902 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7903 7904 // checks are the responsibility of the caller 7905 Node* src_start = src; 7906 Node* dest_start = dest; 7907 if (src_offset != nullptr || dest_offset != nullptr) { 7908 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7909 src_start = array_element_address(src, src_offset, T_BYTE); 7910 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7911 } 7912 7913 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 7914 // (because of the predicated logic executed earlier). 7915 // so we cast it here safely. 7916 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7917 7918 Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 7919 if (embeddedCipherObj == nullptr) return false; 7920 7921 // cast it to what we know it will be at runtime 7922 const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr(); 7923 assert(tinst != nullptr, "ECB obj is null"); 7924 assert(tinst->is_loaded(), "ECB obj is not loaded"); 7925 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 7926 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 7927 7928 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 7929 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 7930 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 7931 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 7932 aescrypt_object = _gvn.transform(aescrypt_object); 7933 7934 // we need to get the start of the aescrypt_object's expanded key array 7935 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 7936 if (k_start == nullptr) return false; 7937 7938 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 7939 Node* ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP, 7940 OptoRuntime::electronicCodeBook_aescrypt_Type(), 7941 stubAddr, stubName, TypePtr::BOTTOM, 7942 src_start, dest_start, k_start, len); 7943 7944 // return cipher length (int) 7945 Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms)); 7946 set_result(retvalue); 7947 return true; 7948 } 7949 7950 //------------------------------inline_counterMode_AESCrypt----------------------- 7951 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) { 7952 assert(UseAES, "need AES instruction support"); 7953 if (!UseAESCTRIntrinsics) return false; 7954 7955 address stubAddr = nullptr; 7956 const char *stubName = nullptr; 7957 if (id == vmIntrinsics::_counterMode_AESCrypt) { 7958 stubAddr = StubRoutines::counterMode_AESCrypt(); 7959 stubName = "counterMode_AESCrypt"; 7960 } 7961 if (stubAddr == nullptr) return false; 7962 7963 Node* counterMode_object = argument(0); 7964 Node* src = argument(1); 7965 Node* src_offset = argument(2); 7966 Node* len = argument(3); 7967 Node* dest = argument(4); 7968 Node* dest_offset = argument(5); 7969 7970 // (1) src and dest are arrays. 7971 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 7972 const TypeAryPtr* dest_type = dest->Value(&_gvn)->isa_aryptr(); 7973 assert( src_type != nullptr && src_type->elem() != Type::BOTTOM && 7974 dest_type != nullptr && dest_type->elem() != Type::BOTTOM, "args are strange"); 7975 7976 // checks are the responsibility of the caller 7977 Node* src_start = src; 7978 Node* dest_start = dest; 7979 if (src_offset != nullptr || dest_offset != nullptr) { 7980 assert(src_offset != nullptr && dest_offset != nullptr, ""); 7981 src_start = array_element_address(src, src_offset, T_BYTE); 7982 dest_start = array_element_address(dest, dest_offset, T_BYTE); 7983 } 7984 7985 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 7986 // (because of the predicated logic executed earlier). 7987 // so we cast it here safely. 7988 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 7989 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 7990 if (embeddedCipherObj == nullptr) return false; 7991 // cast it to what we know it will be at runtime 7992 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr(); 7993 assert(tinst != nullptr, "CTR obj is null"); 7994 assert(tinst->is_loaded(), "CTR obj is not loaded"); 7995 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 7996 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 7997 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 7998 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 7999 const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 8000 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 8001 aescrypt_object = _gvn.transform(aescrypt_object); 8002 // we need to get the start of the aescrypt_object's expanded key array 8003 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 8004 if (k_start == nullptr) return false; 8005 // similarly, get the start address of the r vector 8006 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B"); 8007 if (obj_counter == nullptr) return false; 8008 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE); 8009 8010 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B"); 8011 if (saved_encCounter == nullptr) return false; 8012 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE); 8013 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false); 8014 8015 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 8016 Node* ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 8017 OptoRuntime::counterMode_aescrypt_Type(), 8018 stubAddr, stubName, TypePtr::BOTTOM, 8019 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used); 8020 8021 // return cipher length (int) 8022 Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms)); 8023 set_result(retvalue); 8024 return true; 8025 } 8026 8027 //------------------------------get_key_start_from_aescrypt_object----------------------- 8028 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 8029 #if defined(PPC64) || defined(S390) || defined(RISCV64) 8030 // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys. 8031 // Intel's extension is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns. 8032 // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption. 8033 // The ppc64 and riscv64 stubs of encryption and decryption use the same round keys (sessionK[0]). 8034 Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I"); 8035 assert (objSessionK != nullptr, "wrong version of com.sun.crypto.provider.AESCrypt"); 8036 if (objSessionK == nullptr) { 8037 return (Node *) nullptr; 8038 } 8039 Node* objAESCryptKey = load_array_element(objSessionK, intcon(0), TypeAryPtr::OOPS, /* set_ctrl */ true); 8040 #else 8041 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I"); 8042 #endif // PPC64 8043 assert (objAESCryptKey != nullptr, "wrong version of com.sun.crypto.provider.AESCrypt"); 8044 if (objAESCryptKey == nullptr) return (Node *) nullptr; 8045 8046 // now have the array, need to get the start address of the K array 8047 Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 8048 return k_start; 8049 } 8050 8051 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 8052 // Return node representing slow path of predicate check. 8053 // the pseudo code we want to emulate with this predicate is: 8054 // for encryption: 8055 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8056 // for decryption: 8057 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8058 // note cipher==plain is more conservative than the original java code but that's OK 8059 // 8060 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 8061 // The receiver was checked for null already. 8062 Node* objCBC = argument(0); 8063 8064 Node* src = argument(1); 8065 Node* dest = argument(4); 8066 8067 // Load embeddedCipher field of CipherBlockChaining object. 8068 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8069 8070 // get AESCrypt klass for instanceOf check 8071 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8072 // will have same classloader as CipherBlockChaining object 8073 const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 8074 assert(tinst != nullptr, "CBCobj is null"); 8075 assert(tinst->is_loaded(), "CBCobj is not loaded"); 8076 8077 // we want to do an instanceof comparison against the AESCrypt class 8078 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8079 if (!klass_AESCrypt->is_loaded()) { 8080 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8081 Node* ctrl = control(); 8082 set_control(top()); // no regular fast path 8083 return ctrl; 8084 } 8085 8086 src = must_be_not_null(src, true); 8087 dest = must_be_not_null(dest, true); 8088 8089 // Resolve oops to stable for CmpP below. 8090 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8091 8092 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 8093 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 8094 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8095 8096 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8097 8098 // for encryption, we are done 8099 if (!decrypting) 8100 return instof_false; // even if it is null 8101 8102 // for decryption, we need to add a further check to avoid 8103 // taking the intrinsic path when cipher and plain are the same 8104 // see the original java code for why. 8105 RegionNode* region = new RegionNode(3); 8106 region->init_req(1, instof_false); 8107 8108 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 8109 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 8110 Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN); 8111 region->init_req(2, src_dest_conjoint); 8112 8113 record_for_igvn(region); 8114 return _gvn.transform(region); 8115 } 8116 8117 //----------------------------inline_electronicCodeBook_AESCrypt_predicate---------------------------- 8118 // Return node representing slow path of predicate check. 8119 // the pseudo code we want to emulate with this predicate is: 8120 // for encryption: 8121 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8122 // for decryption: 8123 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8124 // note cipher==plain is more conservative than the original java code but that's OK 8125 // 8126 Node* LibraryCallKit::inline_electronicCodeBook_AESCrypt_predicate(bool decrypting) { 8127 // The receiver was checked for null already. 8128 Node* objECB = argument(0); 8129 8130 // Load embeddedCipher field of ElectronicCodeBook object. 8131 Node* embeddedCipherObj = load_field_from_object(objECB, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8132 8133 // get AESCrypt klass for instanceOf check 8134 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8135 // will have same classloader as ElectronicCodeBook object 8136 const TypeInstPtr* tinst = _gvn.type(objECB)->isa_instptr(); 8137 assert(tinst != nullptr, "ECBobj is null"); 8138 assert(tinst->is_loaded(), "ECBobj is not loaded"); 8139 8140 // we want to do an instanceof comparison against the AESCrypt class 8141 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8142 if (!klass_AESCrypt->is_loaded()) { 8143 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8144 Node* ctrl = control(); 8145 set_control(top()); // no regular fast path 8146 return ctrl; 8147 } 8148 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 8149 8150 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 8151 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 8152 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8153 8154 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8155 8156 // for encryption, we are done 8157 if (!decrypting) 8158 return instof_false; // even if it is null 8159 8160 // for decryption, we need to add a further check to avoid 8161 // taking the intrinsic path when cipher and plain are the same 8162 // see the original java code for why. 8163 RegionNode* region = new RegionNode(3); 8164 region->init_req(1, instof_false); 8165 Node* src = argument(1); 8166 Node* dest = argument(4); 8167 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 8168 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 8169 Node* src_dest_conjoint = generate_guard(bool_src_dest, nullptr, PROB_MIN); 8170 region->init_req(2, src_dest_conjoint); 8171 8172 record_for_igvn(region); 8173 return _gvn.transform(region); 8174 } 8175 8176 //----------------------------inline_counterMode_AESCrypt_predicate---------------------------- 8177 // Return node representing slow path of predicate check. 8178 // the pseudo code we want to emulate with this predicate is: 8179 // for encryption: 8180 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 8181 // for decryption: 8182 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 8183 // note cipher==plain is more conservative than the original java code but that's OK 8184 // 8185 8186 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() { 8187 // The receiver was checked for null already. 8188 Node* objCTR = argument(0); 8189 8190 // Load embeddedCipher field of CipherBlockChaining object. 8191 Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 8192 8193 // get AESCrypt klass for instanceOf check 8194 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 8195 // will have same classloader as CipherBlockChaining object 8196 const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr(); 8197 assert(tinst != nullptr, "CTRobj is null"); 8198 assert(tinst->is_loaded(), "CTRobj is not loaded"); 8199 8200 // we want to do an instanceof comparison against the AESCrypt class 8201 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 8202 if (!klass_AESCrypt->is_loaded()) { 8203 // if AESCrypt is not even loaded, we never take the intrinsic fast path 8204 Node* ctrl = control(); 8205 set_control(top()); // no regular fast path 8206 return ctrl; 8207 } 8208 8209 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 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 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 8214 8215 return instof_false; // even if it is null 8216 } 8217 8218 //------------------------------inline_ghash_processBlocks 8219 bool LibraryCallKit::inline_ghash_processBlocks() { 8220 address stubAddr; 8221 const char *stubName; 8222 assert(UseGHASHIntrinsics, "need GHASH intrinsics support"); 8223 8224 stubAddr = StubRoutines::ghash_processBlocks(); 8225 stubName = "ghash_processBlocks"; 8226 8227 Node* data = argument(0); 8228 Node* offset = argument(1); 8229 Node* len = argument(2); 8230 Node* state = argument(3); 8231 Node* subkeyH = argument(4); 8232 8233 state = must_be_not_null(state, true); 8234 subkeyH = must_be_not_null(subkeyH, true); 8235 data = must_be_not_null(data, true); 8236 8237 Node* state_start = array_element_address(state, intcon(0), T_LONG); 8238 assert(state_start, "state is null"); 8239 Node* subkeyH_start = array_element_address(subkeyH, intcon(0), T_LONG); 8240 assert(subkeyH_start, "subkeyH is null"); 8241 Node* data_start = array_element_address(data, offset, T_BYTE); 8242 assert(data_start, "data is null"); 8243 8244 Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP, 8245 OptoRuntime::ghash_processBlocks_Type(), 8246 stubAddr, stubName, TypePtr::BOTTOM, 8247 state_start, subkeyH_start, data_start, len); 8248 return true; 8249 } 8250 8251 //------------------------------inline_chacha20Block 8252 bool LibraryCallKit::inline_chacha20Block() { 8253 address stubAddr; 8254 const char *stubName; 8255 assert(UseChaCha20Intrinsics, "need ChaCha20 intrinsics support"); 8256 8257 stubAddr = StubRoutines::chacha20Block(); 8258 stubName = "chacha20Block"; 8259 8260 Node* state = argument(0); 8261 Node* result = argument(1); 8262 8263 state = must_be_not_null(state, true); 8264 result = must_be_not_null(result, true); 8265 8266 Node* state_start = array_element_address(state, intcon(0), T_INT); 8267 assert(state_start, "state is null"); 8268 Node* result_start = array_element_address(result, intcon(0), T_BYTE); 8269 assert(result_start, "result is null"); 8270 8271 Node* cc20Blk = make_runtime_call(RC_LEAF|RC_NO_FP, 8272 OptoRuntime::chacha20Block_Type(), 8273 stubAddr, stubName, TypePtr::BOTTOM, 8274 state_start, result_start); 8275 // return key stream length (int) 8276 Node* retvalue = _gvn.transform(new ProjNode(cc20Blk, TypeFunc::Parms)); 8277 set_result(retvalue); 8278 return true; 8279 } 8280 8281 //------------------------------inline_kyberNtt 8282 bool LibraryCallKit::inline_kyberNtt() { 8283 address stubAddr; 8284 const char *stubName; 8285 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8286 assert(callee()->signature()->size() == 2, "kyberNtt has 2 parameters"); 8287 8288 stubAddr = StubRoutines::kyberNtt(); 8289 stubName = "kyberNtt"; 8290 if (!stubAddr) return false; 8291 8292 Node* coeffs = argument(0); 8293 Node* ntt_zetas = argument(1); 8294 8295 coeffs = must_be_not_null(coeffs, true); 8296 ntt_zetas = must_be_not_null(ntt_zetas, true); 8297 8298 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8299 assert(coeffs_start, "coeffs is null"); 8300 Node* ntt_zetas_start = array_element_address(ntt_zetas, intcon(0), T_SHORT); 8301 assert(ntt_zetas_start, "ntt_zetas is null"); 8302 Node* kyberNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8303 OptoRuntime::kyberNtt_Type(), 8304 stubAddr, stubName, TypePtr::BOTTOM, 8305 coeffs_start, ntt_zetas_start); 8306 // return an int 8307 Node* retvalue = _gvn.transform(new ProjNode(kyberNtt, TypeFunc::Parms)); 8308 set_result(retvalue); 8309 return true; 8310 } 8311 8312 //------------------------------inline_kyberInverseNtt 8313 bool LibraryCallKit::inline_kyberInverseNtt() { 8314 address stubAddr; 8315 const char *stubName; 8316 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8317 assert(callee()->signature()->size() == 2, "kyberInverseNtt has 2 parameters"); 8318 8319 stubAddr = StubRoutines::kyberInverseNtt(); 8320 stubName = "kyberInverseNtt"; 8321 if (!stubAddr) return false; 8322 8323 Node* coeffs = argument(0); 8324 Node* zetas = argument(1); 8325 8326 coeffs = must_be_not_null(coeffs, true); 8327 zetas = must_be_not_null(zetas, true); 8328 8329 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8330 assert(coeffs_start, "coeffs is null"); 8331 Node* zetas_start = array_element_address(zetas, intcon(0), T_SHORT); 8332 assert(zetas_start, "inverseNtt_zetas is null"); 8333 Node* kyberInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8334 OptoRuntime::kyberInverseNtt_Type(), 8335 stubAddr, stubName, TypePtr::BOTTOM, 8336 coeffs_start, zetas_start); 8337 8338 // return an int 8339 Node* retvalue = _gvn.transform(new ProjNode(kyberInverseNtt, TypeFunc::Parms)); 8340 set_result(retvalue); 8341 return true; 8342 } 8343 8344 //------------------------------inline_kyberNttMult 8345 bool LibraryCallKit::inline_kyberNttMult() { 8346 address stubAddr; 8347 const char *stubName; 8348 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8349 assert(callee()->signature()->size() == 4, "kyberNttMult has 4 parameters"); 8350 8351 stubAddr = StubRoutines::kyberNttMult(); 8352 stubName = "kyberNttMult"; 8353 if (!stubAddr) return false; 8354 8355 Node* result = argument(0); 8356 Node* ntta = argument(1); 8357 Node* nttb = argument(2); 8358 Node* zetas = argument(3); 8359 8360 result = must_be_not_null(result, true); 8361 ntta = must_be_not_null(ntta, true); 8362 nttb = must_be_not_null(nttb, true); 8363 zetas = must_be_not_null(zetas, true); 8364 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8365 assert(result_start, "result is null"); 8366 Node* ntta_start = array_element_address(ntta, intcon(0), T_SHORT); 8367 assert(ntta_start, "ntta is null"); 8368 Node* nttb_start = array_element_address(nttb, intcon(0), T_SHORT); 8369 assert(nttb_start, "nttb is null"); 8370 Node* zetas_start = array_element_address(zetas, intcon(0), T_SHORT); 8371 assert(zetas_start, "nttMult_zetas is null"); 8372 Node* kyberNttMult = make_runtime_call(RC_LEAF|RC_NO_FP, 8373 OptoRuntime::kyberNttMult_Type(), 8374 stubAddr, stubName, TypePtr::BOTTOM, 8375 result_start, ntta_start, nttb_start, 8376 zetas_start); 8377 8378 // return an int 8379 Node* retvalue = _gvn.transform(new ProjNode(kyberNttMult, TypeFunc::Parms)); 8380 set_result(retvalue); 8381 8382 return true; 8383 } 8384 8385 //------------------------------inline_kyberAddPoly_2 8386 bool LibraryCallKit::inline_kyberAddPoly_2() { 8387 address stubAddr; 8388 const char *stubName; 8389 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8390 assert(callee()->signature()->size() == 3, "kyberAddPoly_2 has 3 parameters"); 8391 8392 stubAddr = StubRoutines::kyberAddPoly_2(); 8393 stubName = "kyberAddPoly_2"; 8394 if (!stubAddr) return false; 8395 8396 Node* result = argument(0); 8397 Node* a = argument(1); 8398 Node* b = argument(2); 8399 8400 result = must_be_not_null(result, true); 8401 a = must_be_not_null(a, true); 8402 b = must_be_not_null(b, true); 8403 8404 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8405 assert(result_start, "result is null"); 8406 Node* a_start = array_element_address(a, intcon(0), T_SHORT); 8407 assert(a_start, "a is null"); 8408 Node* b_start = array_element_address(b, intcon(0), T_SHORT); 8409 assert(b_start, "b is null"); 8410 Node* kyberAddPoly_2 = make_runtime_call(RC_LEAF|RC_NO_FP, 8411 OptoRuntime::kyberAddPoly_2_Type(), 8412 stubAddr, stubName, TypePtr::BOTTOM, 8413 result_start, a_start, b_start); 8414 // return an int 8415 Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_2, TypeFunc::Parms)); 8416 set_result(retvalue); 8417 return true; 8418 } 8419 8420 //------------------------------inline_kyberAddPoly_3 8421 bool LibraryCallKit::inline_kyberAddPoly_3() { 8422 address stubAddr; 8423 const char *stubName; 8424 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8425 assert(callee()->signature()->size() == 4, "kyberAddPoly_3 has 4 parameters"); 8426 8427 stubAddr = StubRoutines::kyberAddPoly_3(); 8428 stubName = "kyberAddPoly_3"; 8429 if (!stubAddr) return false; 8430 8431 Node* result = argument(0); 8432 Node* a = argument(1); 8433 Node* b = argument(2); 8434 Node* c = argument(3); 8435 8436 result = must_be_not_null(result, true); 8437 a = must_be_not_null(a, true); 8438 b = must_be_not_null(b, true); 8439 c = must_be_not_null(c, true); 8440 8441 Node* result_start = array_element_address(result, intcon(0), T_SHORT); 8442 assert(result_start, "result is null"); 8443 Node* a_start = array_element_address(a, intcon(0), T_SHORT); 8444 assert(a_start, "a is null"); 8445 Node* b_start = array_element_address(b, intcon(0), T_SHORT); 8446 assert(b_start, "b is null"); 8447 Node* c_start = array_element_address(c, intcon(0), T_SHORT); 8448 assert(c_start, "c is null"); 8449 Node* kyberAddPoly_3 = make_runtime_call(RC_LEAF|RC_NO_FP, 8450 OptoRuntime::kyberAddPoly_3_Type(), 8451 stubAddr, stubName, TypePtr::BOTTOM, 8452 result_start, a_start, b_start, c_start); 8453 // return an int 8454 Node* retvalue = _gvn.transform(new ProjNode(kyberAddPoly_3, TypeFunc::Parms)); 8455 set_result(retvalue); 8456 return true; 8457 } 8458 8459 //------------------------------inline_kyber12To16 8460 bool LibraryCallKit::inline_kyber12To16() { 8461 address stubAddr; 8462 const char *stubName; 8463 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8464 assert(callee()->signature()->size() == 4, "kyber12To16 has 4 parameters"); 8465 8466 stubAddr = StubRoutines::kyber12To16(); 8467 stubName = "kyber12To16"; 8468 if (!stubAddr) return false; 8469 8470 Node* condensed = argument(0); 8471 Node* condensedOffs = argument(1); 8472 Node* parsed = argument(2); 8473 Node* parsedLength = argument(3); 8474 8475 condensed = must_be_not_null(condensed, true); 8476 parsed = must_be_not_null(parsed, true); 8477 8478 Node* condensed_start = array_element_address(condensed, intcon(0), T_BYTE); 8479 assert(condensed_start, "condensed is null"); 8480 Node* parsed_start = array_element_address(parsed, intcon(0), T_SHORT); 8481 assert(parsed_start, "parsed is null"); 8482 Node* kyber12To16 = make_runtime_call(RC_LEAF|RC_NO_FP, 8483 OptoRuntime::kyber12To16_Type(), 8484 stubAddr, stubName, TypePtr::BOTTOM, 8485 condensed_start, condensedOffs, parsed_start, parsedLength); 8486 // return an int 8487 Node* retvalue = _gvn.transform(new ProjNode(kyber12To16, TypeFunc::Parms)); 8488 set_result(retvalue); 8489 return true; 8490 8491 } 8492 8493 //------------------------------inline_kyberBarrettReduce 8494 bool LibraryCallKit::inline_kyberBarrettReduce() { 8495 address stubAddr; 8496 const char *stubName; 8497 assert(UseKyberIntrinsics, "need Kyber intrinsics support"); 8498 assert(callee()->signature()->size() == 1, "kyberBarrettReduce has 1 parameters"); 8499 8500 stubAddr = StubRoutines::kyberBarrettReduce(); 8501 stubName = "kyberBarrettReduce"; 8502 if (!stubAddr) return false; 8503 8504 Node* coeffs = argument(0); 8505 8506 coeffs = must_be_not_null(coeffs, true); 8507 8508 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_SHORT); 8509 assert(coeffs_start, "coeffs is null"); 8510 Node* kyberBarrettReduce = make_runtime_call(RC_LEAF|RC_NO_FP, 8511 OptoRuntime::kyberBarrettReduce_Type(), 8512 stubAddr, stubName, TypePtr::BOTTOM, 8513 coeffs_start); 8514 // return an int 8515 Node* retvalue = _gvn.transform(new ProjNode(kyberBarrettReduce, TypeFunc::Parms)); 8516 set_result(retvalue); 8517 return true; 8518 } 8519 8520 //------------------------------inline_dilithiumAlmostNtt 8521 bool LibraryCallKit::inline_dilithiumAlmostNtt() { 8522 address stubAddr; 8523 const char *stubName; 8524 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8525 assert(callee()->signature()->size() == 2, "dilithiumAlmostNtt has 2 parameters"); 8526 8527 stubAddr = StubRoutines::dilithiumAlmostNtt(); 8528 stubName = "dilithiumAlmostNtt"; 8529 if (!stubAddr) return false; 8530 8531 Node* coeffs = argument(0); 8532 Node* ntt_zetas = argument(1); 8533 8534 coeffs = must_be_not_null(coeffs, true); 8535 ntt_zetas = must_be_not_null(ntt_zetas, true); 8536 8537 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8538 assert(coeffs_start, "coeffs is null"); 8539 Node* ntt_zetas_start = array_element_address(ntt_zetas, intcon(0), T_INT); 8540 assert(ntt_zetas_start, "ntt_zetas is null"); 8541 Node* dilithiumAlmostNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8542 OptoRuntime::dilithiumAlmostNtt_Type(), 8543 stubAddr, stubName, TypePtr::BOTTOM, 8544 coeffs_start, ntt_zetas_start); 8545 // return an int 8546 Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostNtt, TypeFunc::Parms)); 8547 set_result(retvalue); 8548 return true; 8549 } 8550 8551 //------------------------------inline_dilithiumAlmostInverseNtt 8552 bool LibraryCallKit::inline_dilithiumAlmostInverseNtt() { 8553 address stubAddr; 8554 const char *stubName; 8555 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8556 assert(callee()->signature()->size() == 2, "dilithiumAlmostInverseNtt has 2 parameters"); 8557 8558 stubAddr = StubRoutines::dilithiumAlmostInverseNtt(); 8559 stubName = "dilithiumAlmostInverseNtt"; 8560 if (!stubAddr) return false; 8561 8562 Node* coeffs = argument(0); 8563 Node* zetas = argument(1); 8564 8565 coeffs = must_be_not_null(coeffs, true); 8566 zetas = must_be_not_null(zetas, true); 8567 8568 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8569 assert(coeffs_start, "coeffs is null"); 8570 Node* zetas_start = array_element_address(zetas, intcon(0), T_INT); 8571 assert(zetas_start, "inverseNtt_zetas is null"); 8572 Node* dilithiumAlmostInverseNtt = make_runtime_call(RC_LEAF|RC_NO_FP, 8573 OptoRuntime::dilithiumAlmostInverseNtt_Type(), 8574 stubAddr, stubName, TypePtr::BOTTOM, 8575 coeffs_start, zetas_start); 8576 // return an int 8577 Node* retvalue = _gvn.transform(new ProjNode(dilithiumAlmostInverseNtt, TypeFunc::Parms)); 8578 set_result(retvalue); 8579 return true; 8580 } 8581 8582 //------------------------------inline_dilithiumNttMult 8583 bool LibraryCallKit::inline_dilithiumNttMult() { 8584 address stubAddr; 8585 const char *stubName; 8586 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8587 assert(callee()->signature()->size() == 3, "dilithiumNttMult has 3 parameters"); 8588 8589 stubAddr = StubRoutines::dilithiumNttMult(); 8590 stubName = "dilithiumNttMult"; 8591 if (!stubAddr) return false; 8592 8593 Node* result = argument(0); 8594 Node* ntta = argument(1); 8595 Node* nttb = argument(2); 8596 Node* zetas = argument(3); 8597 8598 result = must_be_not_null(result, true); 8599 ntta = must_be_not_null(ntta, true); 8600 nttb = must_be_not_null(nttb, true); 8601 zetas = must_be_not_null(zetas, true); 8602 8603 Node* result_start = array_element_address(result, intcon(0), T_INT); 8604 assert(result_start, "result is null"); 8605 Node* ntta_start = array_element_address(ntta, intcon(0), T_INT); 8606 assert(ntta_start, "ntta is null"); 8607 Node* nttb_start = array_element_address(nttb, intcon(0), T_INT); 8608 assert(nttb_start, "nttb is null"); 8609 Node* dilithiumNttMult = make_runtime_call(RC_LEAF|RC_NO_FP, 8610 OptoRuntime::dilithiumNttMult_Type(), 8611 stubAddr, stubName, TypePtr::BOTTOM, 8612 result_start, ntta_start, nttb_start); 8613 8614 // return an int 8615 Node* retvalue = _gvn.transform(new ProjNode(dilithiumNttMult, TypeFunc::Parms)); 8616 set_result(retvalue); 8617 8618 return true; 8619 } 8620 8621 //------------------------------inline_dilithiumMontMulByConstant 8622 bool LibraryCallKit::inline_dilithiumMontMulByConstant() { 8623 address stubAddr; 8624 const char *stubName; 8625 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8626 assert(callee()->signature()->size() == 2, "dilithiumMontMulByConstant has 2 parameters"); 8627 8628 stubAddr = StubRoutines::dilithiumMontMulByConstant(); 8629 stubName = "dilithiumMontMulByConstant"; 8630 if (!stubAddr) return false; 8631 8632 Node* coeffs = argument(0); 8633 Node* constant = argument(1); 8634 8635 coeffs = must_be_not_null(coeffs, true); 8636 8637 Node* coeffs_start = array_element_address(coeffs, intcon(0), T_INT); 8638 assert(coeffs_start, "coeffs is null"); 8639 Node* dilithiumMontMulByConstant = make_runtime_call(RC_LEAF|RC_NO_FP, 8640 OptoRuntime::dilithiumMontMulByConstant_Type(), 8641 stubAddr, stubName, TypePtr::BOTTOM, 8642 coeffs_start, constant); 8643 8644 // return an int 8645 Node* retvalue = _gvn.transform(new ProjNode(dilithiumMontMulByConstant, TypeFunc::Parms)); 8646 set_result(retvalue); 8647 return true; 8648 } 8649 8650 8651 //------------------------------inline_dilithiumDecomposePoly 8652 bool LibraryCallKit::inline_dilithiumDecomposePoly() { 8653 address stubAddr; 8654 const char *stubName; 8655 assert(UseDilithiumIntrinsics, "need Dilithium intrinsics support"); 8656 assert(callee()->signature()->size() == 5, "dilithiumDecomposePoly has 5 parameters"); 8657 8658 stubAddr = StubRoutines::dilithiumDecomposePoly(); 8659 stubName = "dilithiumDecomposePoly"; 8660 if (!stubAddr) return false; 8661 8662 Node* input = argument(0); 8663 Node* lowPart = argument(1); 8664 Node* highPart = argument(2); 8665 Node* twoGamma2 = argument(3); 8666 Node* multiplier = argument(4); 8667 8668 input = must_be_not_null(input, true); 8669 lowPart = must_be_not_null(lowPart, true); 8670 highPart = must_be_not_null(highPart, true); 8671 8672 Node* input_start = array_element_address(input, intcon(0), T_INT); 8673 assert(input_start, "input is null"); 8674 Node* lowPart_start = array_element_address(lowPart, intcon(0), T_INT); 8675 assert(lowPart_start, "lowPart is null"); 8676 Node* highPart_start = array_element_address(highPart, intcon(0), T_INT); 8677 assert(highPart_start, "highPart is null"); 8678 8679 Node* dilithiumDecomposePoly = make_runtime_call(RC_LEAF|RC_NO_FP, 8680 OptoRuntime::dilithiumDecomposePoly_Type(), 8681 stubAddr, stubName, TypePtr::BOTTOM, 8682 input_start, lowPart_start, highPart_start, 8683 twoGamma2, multiplier); 8684 8685 // return an int 8686 Node* retvalue = _gvn.transform(new ProjNode(dilithiumDecomposePoly, TypeFunc::Parms)); 8687 set_result(retvalue); 8688 return true; 8689 } 8690 8691 bool LibraryCallKit::inline_base64_encodeBlock() { 8692 address stubAddr; 8693 const char *stubName; 8694 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 8695 assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters"); 8696 stubAddr = StubRoutines::base64_encodeBlock(); 8697 stubName = "encodeBlock"; 8698 8699 if (!stubAddr) return false; 8700 Node* base64obj = argument(0); 8701 Node* src = argument(1); 8702 Node* offset = argument(2); 8703 Node* len = argument(3); 8704 Node* dest = argument(4); 8705 Node* dp = argument(5); 8706 Node* isURL = argument(6); 8707 8708 src = must_be_not_null(src, true); 8709 dest = must_be_not_null(dest, true); 8710 8711 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 8712 assert(src_start, "source array is null"); 8713 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 8714 assert(dest_start, "destination array is null"); 8715 8716 Node* base64 = make_runtime_call(RC_LEAF, 8717 OptoRuntime::base64_encodeBlock_Type(), 8718 stubAddr, stubName, TypePtr::BOTTOM, 8719 src_start, offset, len, dest_start, dp, isURL); 8720 return true; 8721 } 8722 8723 bool LibraryCallKit::inline_base64_decodeBlock() { 8724 address stubAddr; 8725 const char *stubName; 8726 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 8727 assert(callee()->signature()->size() == 7, "base64_decodeBlock has 7 parameters"); 8728 stubAddr = StubRoutines::base64_decodeBlock(); 8729 stubName = "decodeBlock"; 8730 8731 if (!stubAddr) return false; 8732 Node* base64obj = argument(0); 8733 Node* src = argument(1); 8734 Node* src_offset = argument(2); 8735 Node* len = argument(3); 8736 Node* dest = argument(4); 8737 Node* dest_offset = argument(5); 8738 Node* isURL = argument(6); 8739 Node* isMIME = argument(7); 8740 8741 src = must_be_not_null(src, true); 8742 dest = must_be_not_null(dest, true); 8743 8744 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 8745 assert(src_start, "source array is null"); 8746 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 8747 assert(dest_start, "destination array is null"); 8748 8749 Node* call = make_runtime_call(RC_LEAF, 8750 OptoRuntime::base64_decodeBlock_Type(), 8751 stubAddr, stubName, TypePtr::BOTTOM, 8752 src_start, src_offset, len, dest_start, dest_offset, isURL, isMIME); 8753 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 8754 set_result(result); 8755 return true; 8756 } 8757 8758 bool LibraryCallKit::inline_poly1305_processBlocks() { 8759 address stubAddr; 8760 const char *stubName; 8761 assert(UsePoly1305Intrinsics, "need Poly intrinsics support"); 8762 assert(callee()->signature()->size() == 5, "poly1305_processBlocks has %d parameters", callee()->signature()->size()); 8763 stubAddr = StubRoutines::poly1305_processBlocks(); 8764 stubName = "poly1305_processBlocks"; 8765 8766 if (!stubAddr) return false; 8767 null_check_receiver(); // null-check receiver 8768 if (stopped()) return true; 8769 8770 Node* input = argument(1); 8771 Node* input_offset = argument(2); 8772 Node* len = argument(3); 8773 Node* alimbs = argument(4); 8774 Node* rlimbs = argument(5); 8775 8776 input = must_be_not_null(input, true); 8777 alimbs = must_be_not_null(alimbs, true); 8778 rlimbs = must_be_not_null(rlimbs, true); 8779 8780 Node* input_start = array_element_address(input, input_offset, T_BYTE); 8781 assert(input_start, "input array is null"); 8782 Node* acc_start = array_element_address(alimbs, intcon(0), T_LONG); 8783 assert(acc_start, "acc array is null"); 8784 Node* r_start = array_element_address(rlimbs, intcon(0), T_LONG); 8785 assert(r_start, "r array is null"); 8786 8787 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8788 OptoRuntime::poly1305_processBlocks_Type(), 8789 stubAddr, stubName, TypePtr::BOTTOM, 8790 input_start, len, acc_start, r_start); 8791 return true; 8792 } 8793 8794 bool LibraryCallKit::inline_intpoly_montgomeryMult_P256() { 8795 address stubAddr; 8796 const char *stubName; 8797 assert(UseIntPolyIntrinsics, "need intpoly intrinsics support"); 8798 assert(callee()->signature()->size() == 3, "intpoly_montgomeryMult_P256 has %d parameters", callee()->signature()->size()); 8799 stubAddr = StubRoutines::intpoly_montgomeryMult_P256(); 8800 stubName = "intpoly_montgomeryMult_P256"; 8801 8802 if (!stubAddr) return false; 8803 null_check_receiver(); // null-check receiver 8804 if (stopped()) return true; 8805 8806 Node* a = argument(1); 8807 Node* b = argument(2); 8808 Node* r = argument(3); 8809 8810 a = must_be_not_null(a, true); 8811 b = must_be_not_null(b, true); 8812 r = must_be_not_null(r, true); 8813 8814 Node* a_start = array_element_address(a, intcon(0), T_LONG); 8815 assert(a_start, "a array is null"); 8816 Node* b_start = array_element_address(b, intcon(0), T_LONG); 8817 assert(b_start, "b array is null"); 8818 Node* r_start = array_element_address(r, intcon(0), T_LONG); 8819 assert(r_start, "r array is null"); 8820 8821 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8822 OptoRuntime::intpoly_montgomeryMult_P256_Type(), 8823 stubAddr, stubName, TypePtr::BOTTOM, 8824 a_start, b_start, r_start); 8825 return true; 8826 } 8827 8828 bool LibraryCallKit::inline_intpoly_assign() { 8829 assert(UseIntPolyIntrinsics, "need intpoly intrinsics support"); 8830 assert(callee()->signature()->size() == 3, "intpoly_assign has %d parameters", callee()->signature()->size()); 8831 const char *stubName = "intpoly_assign"; 8832 address stubAddr = StubRoutines::intpoly_assign(); 8833 if (!stubAddr) return false; 8834 8835 Node* set = argument(0); 8836 Node* a = argument(1); 8837 Node* b = argument(2); 8838 Node* arr_length = load_array_length(a); 8839 8840 a = must_be_not_null(a, true); 8841 b = must_be_not_null(b, true); 8842 8843 Node* a_start = array_element_address(a, intcon(0), T_LONG); 8844 assert(a_start, "a array is null"); 8845 Node* b_start = array_element_address(b, intcon(0), T_LONG); 8846 assert(b_start, "b array is null"); 8847 8848 Node* call = make_runtime_call(RC_LEAF | RC_NO_FP, 8849 OptoRuntime::intpoly_assign_Type(), 8850 stubAddr, stubName, TypePtr::BOTTOM, 8851 set, a_start, b_start, arr_length); 8852 return true; 8853 } 8854 8855 //------------------------------inline_digestBase_implCompress----------------------- 8856 // 8857 // Calculate MD5 for single-block byte[] array. 8858 // void com.sun.security.provider.MD5.implCompress(byte[] buf, int ofs) 8859 // 8860 // Calculate SHA (i.e., SHA-1) for single-block byte[] array. 8861 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs) 8862 // 8863 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array. 8864 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs) 8865 // 8866 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array. 8867 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs) 8868 // 8869 // Calculate SHA3 (i.e., SHA3-224 or SHA3-256 or SHA3-384 or SHA3-512) for single-block byte[] array. 8870 // void com.sun.security.provider.SHA3.implCompress(byte[] buf, int ofs) 8871 // 8872 bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) { 8873 assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters"); 8874 8875 Node* digestBase_obj = argument(0); 8876 Node* src = argument(1); // type oop 8877 Node* ofs = argument(2); // type int 8878 8879 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 8880 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 8881 // failed array check 8882 return false; 8883 } 8884 // Figure out the size and type of the elements we will be copying. 8885 BasicType src_elem = src_type->elem()->array_element_basic_type(); 8886 if (src_elem != T_BYTE) { 8887 return false; 8888 } 8889 // 'src_start' points to src array + offset 8890 src = must_be_not_null(src, true); 8891 Node* src_start = array_element_address(src, ofs, src_elem); 8892 Node* state = nullptr; 8893 Node* block_size = nullptr; 8894 address stubAddr; 8895 const char *stubName; 8896 8897 switch(id) { 8898 case vmIntrinsics::_md5_implCompress: 8899 assert(UseMD5Intrinsics, "need MD5 instruction support"); 8900 state = get_state_from_digest_object(digestBase_obj, T_INT); 8901 stubAddr = StubRoutines::md5_implCompress(); 8902 stubName = "md5_implCompress"; 8903 break; 8904 case vmIntrinsics::_sha_implCompress: 8905 assert(UseSHA1Intrinsics, "need SHA1 instruction support"); 8906 state = get_state_from_digest_object(digestBase_obj, T_INT); 8907 stubAddr = StubRoutines::sha1_implCompress(); 8908 stubName = "sha1_implCompress"; 8909 break; 8910 case vmIntrinsics::_sha2_implCompress: 8911 assert(UseSHA256Intrinsics, "need SHA256 instruction support"); 8912 state = get_state_from_digest_object(digestBase_obj, T_INT); 8913 stubAddr = StubRoutines::sha256_implCompress(); 8914 stubName = "sha256_implCompress"; 8915 break; 8916 case vmIntrinsics::_sha5_implCompress: 8917 assert(UseSHA512Intrinsics, "need SHA512 instruction support"); 8918 state = get_state_from_digest_object(digestBase_obj, T_LONG); 8919 stubAddr = StubRoutines::sha512_implCompress(); 8920 stubName = "sha512_implCompress"; 8921 break; 8922 case vmIntrinsics::_sha3_implCompress: 8923 assert(UseSHA3Intrinsics, "need SHA3 instruction support"); 8924 state = get_state_from_digest_object(digestBase_obj, T_LONG); 8925 stubAddr = StubRoutines::sha3_implCompress(); 8926 stubName = "sha3_implCompress"; 8927 block_size = get_block_size_from_digest_object(digestBase_obj); 8928 if (block_size == nullptr) return false; 8929 break; 8930 default: 8931 fatal_unexpected_iid(id); 8932 return false; 8933 } 8934 if (state == nullptr) return false; 8935 8936 assert(stubAddr != nullptr, "Stub %s is not generated", stubName); 8937 if (stubAddr == nullptr) return false; 8938 8939 // Call the stub. 8940 Node* call; 8941 if (block_size == nullptr) { 8942 call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(false), 8943 stubAddr, stubName, TypePtr::BOTTOM, 8944 src_start, state); 8945 } else { 8946 call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::digestBase_implCompress_Type(true), 8947 stubAddr, stubName, TypePtr::BOTTOM, 8948 src_start, state, block_size); 8949 } 8950 8951 return true; 8952 } 8953 8954 //------------------------------inline_double_keccak 8955 bool LibraryCallKit::inline_double_keccak() { 8956 address stubAddr; 8957 const char *stubName; 8958 assert(UseSHA3Intrinsics, "need SHA3 intrinsics support"); 8959 assert(callee()->signature()->size() == 2, "double_keccak has 2 parameters"); 8960 8961 stubAddr = StubRoutines::double_keccak(); 8962 stubName = "double_keccak"; 8963 if (!stubAddr) return false; 8964 8965 Node* status0 = argument(0); 8966 Node* status1 = argument(1); 8967 8968 status0 = must_be_not_null(status0, true); 8969 status1 = must_be_not_null(status1, true); 8970 8971 Node* status0_start = array_element_address(status0, intcon(0), T_LONG); 8972 assert(status0_start, "status0 is null"); 8973 Node* status1_start = array_element_address(status1, intcon(0), T_LONG); 8974 assert(status1_start, "status1 is null"); 8975 Node* double_keccak = make_runtime_call(RC_LEAF|RC_NO_FP, 8976 OptoRuntime::double_keccak_Type(), 8977 stubAddr, stubName, TypePtr::BOTTOM, 8978 status0_start, status1_start); 8979 // return an int 8980 Node* retvalue = _gvn.transform(new ProjNode(double_keccak, TypeFunc::Parms)); 8981 set_result(retvalue); 8982 return true; 8983 } 8984 8985 8986 //------------------------------inline_digestBase_implCompressMB----------------------- 8987 // 8988 // Calculate MD5/SHA/SHA2/SHA5/SHA3 for multi-block byte[] array. 8989 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 8990 // 8991 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) { 8992 assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics, 8993 "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support"); 8994 assert((uint)predicate < 5, "sanity"); 8995 assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters"); 8996 8997 Node* digestBase_obj = argument(0); // The receiver was checked for null already. 8998 Node* src = argument(1); // byte[] array 8999 Node* ofs = argument(2); // type int 9000 Node* limit = argument(3); // type int 9001 9002 const TypeAryPtr* src_type = src->Value(&_gvn)->isa_aryptr(); 9003 if (src_type == nullptr || src_type->elem() == Type::BOTTOM) { 9004 // failed array check 9005 return false; 9006 } 9007 // Figure out the size and type of the elements we will be copying. 9008 BasicType src_elem = src_type->elem()->array_element_basic_type(); 9009 if (src_elem != T_BYTE) { 9010 return false; 9011 } 9012 // 'src_start' points to src array + offset 9013 src = must_be_not_null(src, false); 9014 Node* src_start = array_element_address(src, ofs, src_elem); 9015 9016 const char* klass_digestBase_name = nullptr; 9017 const char* stub_name = nullptr; 9018 address stub_addr = nullptr; 9019 BasicType elem_type = T_INT; 9020 9021 switch (predicate) { 9022 case 0: 9023 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_md5_implCompress)) { 9024 klass_digestBase_name = "sun/security/provider/MD5"; 9025 stub_name = "md5_implCompressMB"; 9026 stub_addr = StubRoutines::md5_implCompressMB(); 9027 } 9028 break; 9029 case 1: 9030 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha_implCompress)) { 9031 klass_digestBase_name = "sun/security/provider/SHA"; 9032 stub_name = "sha1_implCompressMB"; 9033 stub_addr = StubRoutines::sha1_implCompressMB(); 9034 } 9035 break; 9036 case 2: 9037 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha2_implCompress)) { 9038 klass_digestBase_name = "sun/security/provider/SHA2"; 9039 stub_name = "sha256_implCompressMB"; 9040 stub_addr = StubRoutines::sha256_implCompressMB(); 9041 } 9042 break; 9043 case 3: 9044 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha5_implCompress)) { 9045 klass_digestBase_name = "sun/security/provider/SHA5"; 9046 stub_name = "sha512_implCompressMB"; 9047 stub_addr = StubRoutines::sha512_implCompressMB(); 9048 elem_type = T_LONG; 9049 } 9050 break; 9051 case 4: 9052 if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha3_implCompress)) { 9053 klass_digestBase_name = "sun/security/provider/SHA3"; 9054 stub_name = "sha3_implCompressMB"; 9055 stub_addr = StubRoutines::sha3_implCompressMB(); 9056 elem_type = T_LONG; 9057 } 9058 break; 9059 default: 9060 fatal("unknown DigestBase intrinsic predicate: %d", predicate); 9061 } 9062 if (klass_digestBase_name != nullptr) { 9063 assert(stub_addr != nullptr, "Stub is generated"); 9064 if (stub_addr == nullptr) return false; 9065 9066 // get DigestBase klass to lookup for SHA klass 9067 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr(); 9068 assert(tinst != nullptr, "digestBase_obj is not instance???"); 9069 assert(tinst->is_loaded(), "DigestBase is not loaded"); 9070 9071 ciKlass* klass_digestBase = tinst->instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name)); 9072 assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded"); 9073 ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass(); 9074 return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit); 9075 } 9076 return false; 9077 } 9078 9079 //------------------------------inline_digestBase_implCompressMB----------------------- 9080 bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase, 9081 BasicType elem_type, address stubAddr, const char *stubName, 9082 Node* src_start, Node* ofs, Node* limit) { 9083 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase); 9084 const TypeOopPtr* xtype = aklass->cast_to_exactness(false)->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); 9085 Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype); 9086 digest_obj = _gvn.transform(digest_obj); 9087 9088 Node* state = get_state_from_digest_object(digest_obj, elem_type); 9089 if (state == nullptr) return false; 9090 9091 Node* block_size = nullptr; 9092 if (strcmp("sha3_implCompressMB", stubName) == 0) { 9093 block_size = get_block_size_from_digest_object(digest_obj); 9094 if (block_size == nullptr) return false; 9095 } 9096 9097 // Call the stub. 9098 Node* call; 9099 if (block_size == nullptr) { 9100 call = make_runtime_call(RC_LEAF|RC_NO_FP, 9101 OptoRuntime::digestBase_implCompressMB_Type(false), 9102 stubAddr, stubName, TypePtr::BOTTOM, 9103 src_start, state, ofs, limit); 9104 } else { 9105 call = make_runtime_call(RC_LEAF|RC_NO_FP, 9106 OptoRuntime::digestBase_implCompressMB_Type(true), 9107 stubAddr, stubName, TypePtr::BOTTOM, 9108 src_start, state, block_size, ofs, limit); 9109 } 9110 9111 // return ofs (int) 9112 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 9113 set_result(result); 9114 9115 return true; 9116 } 9117 9118 //------------------------------inline_galoisCounterMode_AESCrypt----------------------- 9119 bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() { 9120 assert(UseAES, "need AES instruction support"); 9121 address stubAddr = nullptr; 9122 const char *stubName = nullptr; 9123 stubAddr = StubRoutines::galoisCounterMode_AESCrypt(); 9124 stubName = "galoisCounterMode_AESCrypt"; 9125 9126 if (stubAddr == nullptr) return false; 9127 9128 Node* in = argument(0); 9129 Node* inOfs = argument(1); 9130 Node* len = argument(2); 9131 Node* ct = argument(3); 9132 Node* ctOfs = argument(4); 9133 Node* out = argument(5); 9134 Node* outOfs = argument(6); 9135 Node* gctr_object = argument(7); 9136 Node* ghash_object = argument(8); 9137 9138 // (1) in, ct and out are arrays. 9139 const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr(); 9140 const TypeAryPtr* ct_type = ct->Value(&_gvn)->isa_aryptr(); 9141 const TypeAryPtr* out_type = out->Value(&_gvn)->isa_aryptr(); 9142 assert( in_type != nullptr && in_type->elem() != Type::BOTTOM && 9143 ct_type != nullptr && ct_type->elem() != Type::BOTTOM && 9144 out_type != nullptr && out_type->elem() != Type::BOTTOM, "args are strange"); 9145 9146 // checks are the responsibility of the caller 9147 Node* in_start = in; 9148 Node* ct_start = ct; 9149 Node* out_start = out; 9150 if (inOfs != nullptr || ctOfs != nullptr || outOfs != nullptr) { 9151 assert(inOfs != nullptr && ctOfs != nullptr && outOfs != nullptr, ""); 9152 in_start = array_element_address(in, inOfs, T_BYTE); 9153 ct_start = array_element_address(ct, ctOfs, T_BYTE); 9154 out_start = array_element_address(out, outOfs, T_BYTE); 9155 } 9156 9157 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 9158 // (because of the predicated logic executed earlier). 9159 // so we cast it here safely. 9160 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 9161 Node* embeddedCipherObj = load_field_from_object(gctr_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 9162 Node* counter = load_field_from_object(gctr_object, "counter", "[B"); 9163 Node* subkeyHtbl = load_field_from_object(ghash_object, "subkeyHtbl", "[J"); 9164 Node* state = load_field_from_object(ghash_object, "state", "[J"); 9165 9166 if (embeddedCipherObj == nullptr || counter == nullptr || subkeyHtbl == nullptr || state == nullptr) { 9167 return false; 9168 } 9169 // cast it to what we know it will be at runtime 9170 const TypeInstPtr* tinst = _gvn.type(gctr_object)->isa_instptr(); 9171 assert(tinst != nullptr, "GCTR obj is null"); 9172 assert(tinst->is_loaded(), "GCTR obj is not loaded"); 9173 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 9174 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 9175 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 9176 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 9177 const TypeOopPtr* xtype = aklass->as_instance_type(); 9178 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 9179 aescrypt_object = _gvn.transform(aescrypt_object); 9180 // we need to get the start of the aescrypt_object's expanded key array 9181 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 9182 if (k_start == nullptr) return false; 9183 // similarly, get the start address of the r vector 9184 Node* cnt_start = array_element_address(counter, intcon(0), T_BYTE); 9185 Node* state_start = array_element_address(state, intcon(0), T_LONG); 9186 Node* subkeyHtbl_start = array_element_address(subkeyHtbl, intcon(0), T_LONG); 9187 9188 9189 // Call the stub, passing params 9190 Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 9191 OptoRuntime::galoisCounterMode_aescrypt_Type(), 9192 stubAddr, stubName, TypePtr::BOTTOM, 9193 in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start); 9194 9195 // return cipher length (int) 9196 Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms)); 9197 set_result(retvalue); 9198 9199 return true; 9200 } 9201 9202 //----------------------------inline_galoisCounterMode_AESCrypt_predicate---------------------------- 9203 // Return node representing slow path of predicate check. 9204 // the pseudo code we want to emulate with this predicate is: 9205 // for encryption: 9206 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 9207 // for decryption: 9208 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 9209 // note cipher==plain is more conservative than the original java code but that's OK 9210 // 9211 9212 Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() { 9213 // The receiver was checked for null already. 9214 Node* objGCTR = argument(7); 9215 // Load embeddedCipher field of GCTR object. 9216 Node* embeddedCipherObj = load_field_from_object(objGCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;"); 9217 assert(embeddedCipherObj != nullptr, "embeddedCipherObj is null"); 9218 9219 // get AESCrypt klass for instanceOf check 9220 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 9221 // will have same classloader as CipherBlockChaining object 9222 const TypeInstPtr* tinst = _gvn.type(objGCTR)->isa_instptr(); 9223 assert(tinst != nullptr, "GCTR obj is null"); 9224 assert(tinst->is_loaded(), "GCTR obj is not loaded"); 9225 9226 // we want to do an instanceof comparison against the AESCrypt class 9227 ciKlass* klass_AESCrypt = tinst->instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 9228 if (!klass_AESCrypt->is_loaded()) { 9229 // if AESCrypt is not even loaded, we never take the intrinsic fast path 9230 Node* ctrl = control(); 9231 set_control(top()); // no regular fast path 9232 return ctrl; 9233 } 9234 9235 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 9236 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 9237 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 9238 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 9239 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 9240 9241 return instof_false; // even if it is null 9242 } 9243 9244 //------------------------------get_state_from_digest_object----------------------- 9245 Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) { 9246 const char* state_type; 9247 switch (elem_type) { 9248 case T_BYTE: state_type = "[B"; break; 9249 case T_INT: state_type = "[I"; break; 9250 case T_LONG: state_type = "[J"; break; 9251 default: ShouldNotReachHere(); 9252 } 9253 Node* digest_state = load_field_from_object(digest_object, "state", state_type); 9254 assert (digest_state != nullptr, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3"); 9255 if (digest_state == nullptr) return (Node *) nullptr; 9256 9257 // now have the array, need to get the start address of the state array 9258 Node* state = array_element_address(digest_state, intcon(0), elem_type); 9259 return state; 9260 } 9261 9262 //------------------------------get_block_size_from_sha3_object---------------------------------- 9263 Node * LibraryCallKit::get_block_size_from_digest_object(Node *digest_object) { 9264 Node* block_size = load_field_from_object(digest_object, "blockSize", "I"); 9265 assert (block_size != nullptr, "sanity"); 9266 return block_size; 9267 } 9268 9269 //----------------------------inline_digestBase_implCompressMB_predicate---------------------------- 9270 // Return node representing slow path of predicate check. 9271 // the pseudo code we want to emulate with this predicate is: 9272 // if (digestBaseObj instanceof MD5/SHA/SHA2/SHA5/SHA3) do_intrinsic, else do_javapath 9273 // 9274 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) { 9275 assert(UseMD5Intrinsics || UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics || UseSHA3Intrinsics, 9276 "need MD5/SHA1/SHA256/SHA512/SHA3 instruction support"); 9277 assert((uint)predicate < 5, "sanity"); 9278 9279 // The receiver was checked for null already. 9280 Node* digestBaseObj = argument(0); 9281 9282 // get DigestBase klass for instanceOf check 9283 const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr(); 9284 assert(tinst != nullptr, "digestBaseObj is null"); 9285 assert(tinst->is_loaded(), "DigestBase is not loaded"); 9286 9287 const char* klass_name = nullptr; 9288 switch (predicate) { 9289 case 0: 9290 if (UseMD5Intrinsics) { 9291 // we want to do an instanceof comparison against the MD5 class 9292 klass_name = "sun/security/provider/MD5"; 9293 } 9294 break; 9295 case 1: 9296 if (UseSHA1Intrinsics) { 9297 // we want to do an instanceof comparison against the SHA class 9298 klass_name = "sun/security/provider/SHA"; 9299 } 9300 break; 9301 case 2: 9302 if (UseSHA256Intrinsics) { 9303 // we want to do an instanceof comparison against the SHA2 class 9304 klass_name = "sun/security/provider/SHA2"; 9305 } 9306 break; 9307 case 3: 9308 if (UseSHA512Intrinsics) { 9309 // we want to do an instanceof comparison against the SHA5 class 9310 klass_name = "sun/security/provider/SHA5"; 9311 } 9312 break; 9313 case 4: 9314 if (UseSHA3Intrinsics) { 9315 // we want to do an instanceof comparison against the SHA3 class 9316 klass_name = "sun/security/provider/SHA3"; 9317 } 9318 break; 9319 default: 9320 fatal("unknown SHA intrinsic predicate: %d", predicate); 9321 } 9322 9323 ciKlass* klass = nullptr; 9324 if (klass_name != nullptr) { 9325 klass = tinst->instance_klass()->find_klass(ciSymbol::make(klass_name)); 9326 } 9327 if ((klass == nullptr) || !klass->is_loaded()) { 9328 // if none of MD5/SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path 9329 Node* ctrl = control(); 9330 set_control(top()); // no intrinsic path 9331 return ctrl; 9332 } 9333 ciInstanceKlass* instklass = klass->as_instance_klass(); 9334 9335 Node* instof = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass))); 9336 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 9337 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 9338 Node* instof_false = generate_guard(bool_instof, nullptr, PROB_MIN); 9339 9340 return instof_false; // even if it is null 9341 } 9342 9343 //-------------inline_fma----------------------------------- 9344 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) { 9345 Node *a = nullptr; 9346 Node *b = nullptr; 9347 Node *c = nullptr; 9348 Node* result = nullptr; 9349 switch (id) { 9350 case vmIntrinsics::_fmaD: 9351 assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each."); 9352 // no receiver since it is static method 9353 a = argument(0); 9354 b = argument(2); 9355 c = argument(4); 9356 result = _gvn.transform(new FmaDNode(a, b, c)); 9357 break; 9358 case vmIntrinsics::_fmaF: 9359 assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each."); 9360 a = argument(0); 9361 b = argument(1); 9362 c = argument(2); 9363 result = _gvn.transform(new FmaFNode(a, b, c)); 9364 break; 9365 default: 9366 fatal_unexpected_iid(id); break; 9367 } 9368 set_result(result); 9369 return true; 9370 } 9371 9372 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) { 9373 // argument(0) is receiver 9374 Node* codePoint = argument(1); 9375 Node* n = nullptr; 9376 9377 switch (id) { 9378 case vmIntrinsics::_isDigit : 9379 n = new DigitNode(control(), codePoint); 9380 break; 9381 case vmIntrinsics::_isLowerCase : 9382 n = new LowerCaseNode(control(), codePoint); 9383 break; 9384 case vmIntrinsics::_isUpperCase : 9385 n = new UpperCaseNode(control(), codePoint); 9386 break; 9387 case vmIntrinsics::_isWhitespace : 9388 n = new WhitespaceNode(control(), codePoint); 9389 break; 9390 default: 9391 fatal_unexpected_iid(id); 9392 } 9393 9394 set_result(_gvn.transform(n)); 9395 return true; 9396 } 9397 9398 bool LibraryCallKit::inline_profileBoolean() { 9399 Node* counts = argument(1); 9400 const TypeAryPtr* ary = nullptr; 9401 ciArray* aobj = nullptr; 9402 if (counts->is_Con() 9403 && (ary = counts->bottom_type()->isa_aryptr()) != nullptr 9404 && (aobj = ary->const_oop()->as_array()) != nullptr 9405 && (aobj->length() == 2)) { 9406 // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively. 9407 jint false_cnt = aobj->element_value(0).as_int(); 9408 jint true_cnt = aobj->element_value(1).as_int(); 9409 9410 if (C->log() != nullptr) { 9411 C->log()->elem("observe source='profileBoolean' false='%d' true='%d'", 9412 false_cnt, true_cnt); 9413 } 9414 9415 if (false_cnt + true_cnt == 0) { 9416 // According to profile, never executed. 9417 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 9418 Deoptimization::Action_reinterpret); 9419 return true; 9420 } 9421 9422 // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt) 9423 // is a number of each value occurrences. 9424 Node* result = argument(0); 9425 if (false_cnt == 0 || true_cnt == 0) { 9426 // According to profile, one value has been never seen. 9427 int expected_val = (false_cnt == 0) ? 1 : 0; 9428 9429 Node* cmp = _gvn.transform(new CmpINode(result, intcon(expected_val))); 9430 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 9431 9432 IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN); 9433 Node* fast_path = _gvn.transform(new IfTrueNode(check)); 9434 Node* slow_path = _gvn.transform(new IfFalseNode(check)); 9435 9436 { // Slow path: uncommon trap for never seen value and then reexecute 9437 // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows 9438 // the value has been seen at least once. 9439 PreserveJVMState pjvms(this); 9440 PreserveReexecuteState preexecs(this); 9441 jvms()->set_should_reexecute(true); 9442 9443 set_control(slow_path); 9444 set_i_o(i_o()); 9445 9446 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 9447 Deoptimization::Action_reinterpret); 9448 } 9449 // The guard for never seen value enables sharpening of the result and 9450 // returning a constant. It allows to eliminate branches on the same value 9451 // later on. 9452 set_control(fast_path); 9453 result = intcon(expected_val); 9454 } 9455 // Stop profiling. 9456 // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode. 9457 // By replacing method body with profile data (represented as ProfileBooleanNode 9458 // on IR level) we effectively disable profiling. 9459 // It enables full speed execution once optimized code is generated. 9460 Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt)); 9461 C->record_for_igvn(profile); 9462 set_result(profile); 9463 return true; 9464 } else { 9465 // Continue profiling. 9466 // Profile data isn't available at the moment. So, execute method's bytecode version. 9467 // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod 9468 // is compiled and counters aren't available since corresponding MethodHandle 9469 // isn't a compile-time constant. 9470 return false; 9471 } 9472 } 9473 9474 bool LibraryCallKit::inline_isCompileConstant() { 9475 Node* n = argument(0); 9476 set_result(n->is_Con() ? intcon(1) : intcon(0)); 9477 return true; 9478 } 9479 9480 //------------------------------- inline_getObjectSize -------------------------------------- 9481 // 9482 // Calculate the runtime size of the object/array. 9483 // native long sun.instrument.InstrumentationImpl.getObjectSize0(long nativeAgent, Object objectToSize); 9484 // 9485 bool LibraryCallKit::inline_getObjectSize() { 9486 Node* obj = argument(3); 9487 Node* klass_node = load_object_klass(obj); 9488 9489 jint layout_con = Klass::_lh_neutral_value; 9490 Node* layout_val = get_layout_helper(klass_node, layout_con); 9491 int layout_is_con = (layout_val == nullptr); 9492 9493 if (layout_is_con) { 9494 // Layout helper is constant, can figure out things at compile time. 9495 9496 if (Klass::layout_helper_is_instance(layout_con)) { 9497 // Instance case: layout_con contains the size itself. 9498 Node *size = longcon(Klass::layout_helper_size_in_bytes(layout_con)); 9499 set_result(size); 9500 } else { 9501 // Array case: size is round(header + element_size*arraylength). 9502 // Since arraylength is different for every array instance, we have to 9503 // compute the whole thing at runtime. 9504 9505 Node* arr_length = load_array_length(obj); 9506 9507 int round_mask = MinObjAlignmentInBytes - 1; 9508 int hsize = Klass::layout_helper_header_size(layout_con); 9509 int eshift = Klass::layout_helper_log2_element_size(layout_con); 9510 9511 if ((round_mask & ~right_n_bits(eshift)) == 0) { 9512 round_mask = 0; // strength-reduce it if it goes away completely 9513 } 9514 assert((hsize & right_n_bits(eshift)) == 0, "hsize is pre-rounded"); 9515 Node* header_size = intcon(hsize + round_mask); 9516 9517 Node* lengthx = ConvI2X(arr_length); 9518 Node* headerx = ConvI2X(header_size); 9519 9520 Node* abody = lengthx; 9521 if (eshift != 0) { 9522 abody = _gvn.transform(new LShiftXNode(lengthx, intcon(eshift))); 9523 } 9524 Node* size = _gvn.transform( new AddXNode(headerx, abody) ); 9525 if (round_mask != 0) { 9526 size = _gvn.transform( new AndXNode(size, MakeConX(~round_mask)) ); 9527 } 9528 size = ConvX2L(size); 9529 set_result(size); 9530 } 9531 } else { 9532 // Layout helper is not constant, need to test for array-ness at runtime. 9533 9534 enum { _instance_path = 1, _array_path, PATH_LIMIT }; 9535 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 9536 PhiNode* result_val = new PhiNode(result_reg, TypeLong::LONG); 9537 record_for_igvn(result_reg); 9538 9539 Node* array_ctl = generate_array_guard(klass_node, nullptr, &obj); 9540 if (array_ctl != nullptr) { 9541 // Array case: size is round(header + element_size*arraylength). 9542 // Since arraylength is different for every array instance, we have to 9543 // compute the whole thing at runtime. 9544 9545 PreserveJVMState pjvms(this); 9546 set_control(array_ctl); 9547 Node* arr_length = load_array_length(obj); 9548 9549 int round_mask = MinObjAlignmentInBytes - 1; 9550 Node* mask = intcon(round_mask); 9551 9552 Node* hss = intcon(Klass::_lh_header_size_shift); 9553 Node* hsm = intcon(Klass::_lh_header_size_mask); 9554 Node* header_size = _gvn.transform(new URShiftINode(layout_val, hss)); 9555 header_size = _gvn.transform(new AndINode(header_size, hsm)); 9556 header_size = _gvn.transform(new AddINode(header_size, mask)); 9557 9558 // There is no need to mask or shift this value. 9559 // The semantics of LShiftINode include an implicit mask to 0x1F. 9560 assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place"); 9561 Node* elem_shift = layout_val; 9562 9563 Node* lengthx = ConvI2X(arr_length); 9564 Node* headerx = ConvI2X(header_size); 9565 9566 Node* abody = _gvn.transform(new LShiftXNode(lengthx, elem_shift)); 9567 Node* size = _gvn.transform(new AddXNode(headerx, abody)); 9568 if (round_mask != 0) { 9569 size = _gvn.transform(new AndXNode(size, MakeConX(~round_mask))); 9570 } 9571 size = ConvX2L(size); 9572 9573 result_reg->init_req(_array_path, control()); 9574 result_val->init_req(_array_path, size); 9575 } 9576 9577 if (!stopped()) { 9578 // Instance case: the layout helper gives us instance size almost directly, 9579 // but we need to mask out the _lh_instance_slow_path_bit. 9580 Node* size = ConvI2X(layout_val); 9581 assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit"); 9582 Node* mask = MakeConX(~(intptr_t) right_n_bits(LogBytesPerLong)); 9583 size = _gvn.transform(new AndXNode(size, mask)); 9584 size = ConvX2L(size); 9585 9586 result_reg->init_req(_instance_path, control()); 9587 result_val->init_req(_instance_path, size); 9588 } 9589 9590 set_result(result_reg, result_val); 9591 } 9592 9593 return true; 9594 } 9595 9596 //------------------------------- inline_blackhole -------------------------------------- 9597 // 9598 // Make sure all arguments to this node are alive. 9599 // This matches methods that were requested to be blackholed through compile commands. 9600 // 9601 bool LibraryCallKit::inline_blackhole() { 9602 assert(callee()->is_static(), "Should have been checked before: only static methods here"); 9603 assert(callee()->is_empty(), "Should have been checked before: only empty methods here"); 9604 assert(callee()->holder()->is_loaded(), "Should have been checked before: only methods for loaded classes here"); 9605 9606 // Blackhole node pinches only the control, not memory. This allows 9607 // the blackhole to be pinned in the loop that computes blackholed 9608 // values, but have no other side effects, like breaking the optimizations 9609 // across the blackhole. 9610 9611 Node* bh = _gvn.transform(new BlackholeNode(control())); 9612 set_control(_gvn.transform(new ProjNode(bh, TypeFunc::Control))); 9613 9614 // Bind call arguments as blackhole arguments to keep them alive 9615 uint nargs = callee()->arg_size(); 9616 for (uint i = 0; i < nargs; i++) { 9617 bh->add_req(argument(i)); 9618 } 9619 9620 return true; 9621 } 9622 9623 Node* LibraryCallKit::unbox_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* box) { 9624 const TypeInstPtr* box_type = _gvn.type(box)->isa_instptr(); 9625 if (box_type == nullptr || box_type->instance_klass() != float16_box_type->instance_klass()) { 9626 return nullptr; // box klass is not Float16 9627 } 9628 9629 // Null check; get notnull casted pointer 9630 Node* null_ctl = top(); 9631 Node* not_null_box = null_check_oop(box, &null_ctl, true); 9632 // If not_null_box is dead, only null-path is taken 9633 if (stopped()) { 9634 set_control(null_ctl); 9635 return nullptr; 9636 } 9637 assert(not_null_box->bottom_type()->is_instptr()->maybe_null() == false, ""); 9638 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 9639 Node* adr = basic_plus_adr(not_null_box, field->offset_in_bytes()); 9640 return access_load_at(not_null_box, adr, adr_type, TypeInt::SHORT, T_SHORT, IN_HEAP); 9641 } 9642 9643 Node* LibraryCallKit::box_fp16_value(const TypeInstPtr* float16_box_type, ciField* field, Node* value) { 9644 PreserveReexecuteState preexecs(this); 9645 jvms()->set_should_reexecute(true); 9646 9647 const TypeKlassPtr* klass_type = float16_box_type->as_klass_type(); 9648 Node* klass_node = makecon(klass_type); 9649 Node* box = new_instance(klass_node); 9650 9651 Node* value_field = basic_plus_adr(box, field->offset_in_bytes()); 9652 const TypePtr* value_adr_type = value_field->bottom_type()->is_ptr(); 9653 9654 Node* field_store = _gvn.transform(access_store_at(box, 9655 value_field, 9656 value_adr_type, 9657 value, 9658 TypeInt::SHORT, 9659 T_SHORT, 9660 IN_HEAP)); 9661 set_memory(field_store, value_adr_type); 9662 return box; 9663 } 9664 9665 bool LibraryCallKit::inline_fp16_operations(vmIntrinsics::ID id, int num_args) { 9666 if (!Matcher::match_rule_supported(Op_ReinterpretS2HF) || 9667 !Matcher::match_rule_supported(Op_ReinterpretHF2S)) { 9668 return false; 9669 } 9670 9671 const TypeInstPtr* box_type = _gvn.type(argument(0))->isa_instptr(); 9672 if (box_type == nullptr || box_type->const_oop() == nullptr) { 9673 return false; 9674 } 9675 9676 ciInstanceKlass* float16_klass = box_type->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass(); 9677 const TypeInstPtr* float16_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, float16_klass); 9678 ciField* field = float16_klass->get_field_by_name(ciSymbols::value_name(), 9679 ciSymbols::short_signature(), 9680 false); 9681 assert(field != nullptr, ""); 9682 9683 // Transformed nodes 9684 Node* fld1 = nullptr; 9685 Node* fld2 = nullptr; 9686 Node* fld3 = nullptr; 9687 switch(num_args) { 9688 case 3: 9689 fld3 = unbox_fp16_value(float16_box_type, field, argument(3)); 9690 if (fld3 == nullptr) { 9691 return false; 9692 } 9693 fld3 = _gvn.transform(new ReinterpretS2HFNode(fld3)); 9694 // fall-through 9695 case 2: 9696 fld2 = unbox_fp16_value(float16_box_type, field, argument(2)); 9697 if (fld2 == nullptr) { 9698 return false; 9699 } 9700 fld2 = _gvn.transform(new ReinterpretS2HFNode(fld2)); 9701 // fall-through 9702 case 1: 9703 fld1 = unbox_fp16_value(float16_box_type, field, argument(1)); 9704 if (fld1 == nullptr) { 9705 return false; 9706 } 9707 fld1 = _gvn.transform(new ReinterpretS2HFNode(fld1)); 9708 break; 9709 default: fatal("Unsupported number of arguments %d", num_args); 9710 } 9711 9712 Node* result = nullptr; 9713 switch (id) { 9714 // Unary operations 9715 case vmIntrinsics::_sqrt_float16: 9716 result = _gvn.transform(new SqrtHFNode(C, control(), fld1)); 9717 break; 9718 // Ternary operations 9719 case vmIntrinsics::_fma_float16: 9720 result = _gvn.transform(new FmaHFNode(fld1, fld2, fld3)); 9721 break; 9722 default: 9723 fatal_unexpected_iid(id); 9724 break; 9725 } 9726 result = _gvn.transform(new ReinterpretHF2SNode(result)); 9727 set_result(box_fp16_value(float16_box_type, field, result)); 9728 return true; 9729 } 9730