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