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