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