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