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