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