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