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