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