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