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