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