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