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