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 int LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) { 1956 const TypePtr* base_type = TypePtr::NULL_PTR; 1957 if (base != NULL) base_type = _gvn.type(base)->isa_ptr(); 1958 if (base_type == NULL) { 1959 // Unknown type. 1960 return Type::AnyPtr; 1961 } else if (base_type == TypePtr::NULL_PTR) { 1962 // Since this is a NULL+long form, we have to switch to a rawptr. 1963 base = _gvn.transform(new CastX2PNode(offset)); 1964 offset = MakeConX(0); 1965 return Type::RawPtr; 1966 } else if (base_type->base() == Type::RawPtr) { 1967 return Type::RawPtr; 1968 } else if (base_type->isa_oopptr()) { 1969 // Base is never null => always a heap address. 1970 if (!TypePtr::NULL_PTR->higher_equal(base_type)) { 1971 return Type::OopPtr; 1972 } 1973 // Offset is small => always a heap address. 1974 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 1975 if (offset_type != NULL && 1976 base_type->offset() == 0 && // (should always be?) 1977 offset_type->_lo >= 0 && 1978 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 1979 return Type::OopPtr; 1980 } else if (type == T_OBJECT) { 1981 // off heap access to an oop doesn't make any sense. Has to be on 1982 // heap. 1983 return Type::OopPtr; 1984 } 1985 // Otherwise, it might either be oop+off or NULL+addr. 1986 return Type::AnyPtr; 1987 } else { 1988 // No information: 1989 return Type::AnyPtr; 1990 } 1991 } 1992 1993 Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, DecoratorSet decorators, BasicType type, bool can_cast) { 1994 Node* uncasted_base = base; 1995 int kind = classify_unsafe_addr(uncasted_base, offset, type); 1996 if (kind == Type::RawPtr) { 1997 return basic_plus_adr(top(), uncasted_base, offset); 1998 } else if (kind == Type::AnyPtr) { 1999 assert(base == uncasted_base, "unexpected base change"); 2000 if (can_cast) { 2001 if (!_gvn.type(base)->speculative_maybe_null() && 2002 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2003 // According to profiling, this access is always on 2004 // heap. Casting the base to not null and thus avoiding membars 2005 // around the access should allow better optimizations 2006 Node* null_ctl = top(); 2007 base = null_check_oop(base, &null_ctl, true, true, true); 2008 assert(null_ctl->is_top(), "no null control here"); 2009 return basic_plus_adr(base, offset); 2010 } else if (_gvn.type(base)->speculative_always_null() && 2011 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) { 2012 // According to profiling, this access is always off 2013 // heap. 2014 base = null_assert(base); 2015 Node* raw_base = _gvn.transform(new CastX2PNode(offset)); 2016 offset = MakeConX(0); 2017 return basic_plus_adr(top(), raw_base, offset); 2018 } 2019 } 2020 // We don't know if it's an on heap or off heap access. Fall back 2021 // to raw memory access. 2022 Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM)); 2023 return basic_plus_adr(top(), raw, offset); 2024 } else { 2025 assert(base == uncasted_base, "unexpected base change"); 2026 // We know it's an on heap access so base can't be null 2027 if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) { 2028 base = must_be_not_null(base, true); 2029 } 2030 return basic_plus_adr(base, offset); 2031 } 2032 } 2033 2034 //--------------------------inline_number_methods----------------------------- 2035 // inline int Integer.numberOfLeadingZeros(int) 2036 // inline int Long.numberOfLeadingZeros(long) 2037 // 2038 // inline int Integer.numberOfTrailingZeros(int) 2039 // inline int Long.numberOfTrailingZeros(long) 2040 // 2041 // inline int Integer.bitCount(int) 2042 // inline int Long.bitCount(long) 2043 // 2044 // inline char Character.reverseBytes(char) 2045 // inline short Short.reverseBytes(short) 2046 // inline int Integer.reverseBytes(int) 2047 // inline long Long.reverseBytes(long) 2048 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 2049 Node* arg = argument(0); 2050 Node* n = NULL; 2051 switch (id) { 2052 case vmIntrinsics::_numberOfLeadingZeros_i: n = new CountLeadingZerosINode( arg); break; 2053 case vmIntrinsics::_numberOfLeadingZeros_l: n = new CountLeadingZerosLNode( arg); break; 2054 case vmIntrinsics::_numberOfTrailingZeros_i: n = new CountTrailingZerosINode(arg); break; 2055 case vmIntrinsics::_numberOfTrailingZeros_l: n = new CountTrailingZerosLNode(arg); break; 2056 case vmIntrinsics::_bitCount_i: n = new PopCountINode( arg); break; 2057 case vmIntrinsics::_bitCount_l: n = new PopCountLNode( arg); break; 2058 case vmIntrinsics::_reverseBytes_c: n = new ReverseBytesUSNode(0, arg); break; 2059 case vmIntrinsics::_reverseBytes_s: n = new ReverseBytesSNode( 0, arg); break; 2060 case vmIntrinsics::_reverseBytes_i: n = new ReverseBytesINode( 0, arg); break; 2061 case vmIntrinsics::_reverseBytes_l: n = new ReverseBytesLNode( 0, arg); break; 2062 default: fatal_unexpected_iid(id); break; 2063 } 2064 set_result(_gvn.transform(n)); 2065 return true; 2066 } 2067 2068 //----------------------------inline_unsafe_access---------------------------- 2069 2070 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { 2071 // Attempt to infer a sharper value type from the offset and base type. 2072 ciKlass* sharpened_klass = NULL; 2073 2074 // See if it is an instance field, with an object type. 2075 if (alias_type->field() != NULL) { 2076 if (alias_type->field()->type()->is_klass()) { 2077 sharpened_klass = alias_type->field()->type()->as_klass(); 2078 } 2079 } 2080 2081 // See if it is a narrow oop array. 2082 if (adr_type->isa_aryptr()) { 2083 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) { 2084 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr(); 2085 if (elem_type != NULL) { 2086 sharpened_klass = elem_type->klass(); 2087 } 2088 } 2089 } 2090 2091 // The sharpened class might be unloaded if there is no class loader 2092 // contraint in place. 2093 if (sharpened_klass != NULL && sharpened_klass->is_loaded()) { 2094 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass); 2095 2096 #ifndef PRODUCT 2097 if (C->print_intrinsics() || C->print_inlining()) { 2098 tty->print(" from base type: "); adr_type->dump(); tty->cr(); 2099 tty->print(" sharpened value: "); tjp->dump(); tty->cr(); 2100 } 2101 #endif 2102 // Sharpen the value type. 2103 return tjp; 2104 } 2105 return NULL; 2106 } 2107 2108 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) { 2109 switch (kind) { 2110 case Relaxed: 2111 return MO_UNORDERED; 2112 case Opaque: 2113 return MO_RELAXED; 2114 case Acquire: 2115 return MO_ACQUIRE; 2116 case Release: 2117 return MO_RELEASE; 2118 case Volatile: 2119 return MO_SEQ_CST; 2120 default: 2121 ShouldNotReachHere(); 2122 return 0; 2123 } 2124 } 2125 2126 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) { 2127 if (callee()->is_static()) return false; // caller must have the capability! 2128 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2129 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); 2130 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); 2131 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); 2132 2133 if (is_reference_type(type)) { 2134 decorators |= ON_UNKNOWN_OOP_REF; 2135 } 2136 2137 if (unaligned) { 2138 decorators |= C2_UNALIGNED; 2139 } 2140 2141 #ifndef PRODUCT 2142 { 2143 ResourceMark rm; 2144 // Check the signatures. 2145 ciSignature* sig = callee()->signature(); 2146 #ifdef ASSERT 2147 if (!is_store) { 2148 // Object getReference(Object base, int/long offset), etc. 2149 BasicType rtype = sig->return_type()->basic_type(); 2150 assert(rtype == type, "getter must return the expected value"); 2151 assert(sig->count() == 2, "oop getter has 2 arguments"); 2152 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 2153 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 2154 } else { 2155 // void putReference(Object base, int/long offset, Object x), etc. 2156 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 2157 assert(sig->count() == 3, "oop putter has 3 arguments"); 2158 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 2159 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 2160 BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 2161 assert(vtype == type, "putter must accept the expected value"); 2162 } 2163 #endif // ASSERT 2164 } 2165 #endif //PRODUCT 2166 2167 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2168 2169 Node* receiver = argument(0); // type: oop 2170 2171 // Build address expression. 2172 Node* adr; 2173 Node* heap_base_oop = top(); 2174 Node* offset = top(); 2175 Node* val; 2176 2177 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2178 Node* base = argument(1); // type: oop 2179 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2180 offset = argument(2); // type: long 2181 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2182 // to be plain byte offsets, which are also the same as those accepted 2183 // by oopDesc::field_addr. 2184 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2185 "fieldOffset must be byte-scaled"); 2186 // 32-bit machines ignore the high half! 2187 offset = ConvL2X(offset); 2188 adr = make_unsafe_address(base, offset, is_store ? ACCESS_WRITE : ACCESS_READ, type, kind == Relaxed); 2189 2190 if (_gvn.type(base)->isa_ptr() == TypePtr::NULL_PTR) { 2191 if (type != T_OBJECT) { 2192 decorators |= IN_NATIVE; // off-heap primitive access 2193 } else { 2194 return false; // off-heap oop accesses are not supported 2195 } 2196 } else { 2197 heap_base_oop = base; // on-heap or mixed access 2198 } 2199 2200 // Can base be NULL? Otherwise, always on-heap access. 2201 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base)); 2202 2203 if (!can_access_non_heap) { 2204 decorators |= IN_HEAP; 2205 } 2206 2207 val = is_store ? argument(4) : NULL; 2208 2209 const TypePtr* adr_type = _gvn.type(adr)->isa_ptr(); 2210 if (adr_type == TypePtr::NULL_PTR) { 2211 return false; // off-heap access with zero address 2212 } 2213 2214 // Try to categorize the address. 2215 Compile::AliasType* alias_type = C->alias_type(adr_type); 2216 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2217 2218 if (alias_type->adr_type() == TypeInstPtr::KLASS || 2219 alias_type->adr_type() == TypeAryPtr::RANGE) { 2220 return false; // not supported 2221 } 2222 2223 bool mismatched = false; 2224 BasicType bt = alias_type->basic_type(); 2225 if (bt != T_ILLEGAL) { 2226 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access"); 2227 if (bt == T_BYTE && adr_type->isa_aryptr()) { 2228 // Alias type doesn't differentiate between byte[] and boolean[]). 2229 // Use address type to get the element type. 2230 bt = adr_type->is_aryptr()->elem()->array_element_basic_type(); 2231 } 2232 if (bt == T_ARRAY || bt == T_NARROWOOP) { 2233 // accessing an array field with getReference is not a mismatch 2234 bt = T_OBJECT; 2235 } 2236 if ((bt == T_OBJECT) != (type == T_OBJECT)) { 2237 // Don't intrinsify mismatched object accesses 2238 return false; 2239 } 2240 mismatched = (bt != type); 2241 } else if (alias_type->adr_type()->isa_oopptr()) { 2242 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched 2243 } 2244 2245 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); 2246 2247 if (mismatched) { 2248 decorators |= C2_MISMATCHED; 2249 } 2250 2251 // First guess at the value type. 2252 const Type *value_type = Type::get_const_basic_type(type); 2253 2254 // Figure out the memory ordering. 2255 decorators |= mo_decorator_for_access_kind(kind); 2256 2257 if (!is_store && type == T_OBJECT) { 2258 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2259 if (tjp != NULL) { 2260 value_type = tjp; 2261 } 2262 } 2263 2264 receiver = null_check(receiver); 2265 if (stopped()) { 2266 return true; 2267 } 2268 // Heap pointers get a null-check from the interpreter, 2269 // as a courtesy. However, this is not guaranteed by Unsafe, 2270 // and it is not possible to fully distinguish unintended nulls 2271 // from intended ones in this API. 2272 2273 if (!is_store) { 2274 Node* p = NULL; 2275 // Try to constant fold a load from a constant field 2276 ciField* field = alias_type->field(); 2277 if (heap_base_oop != top() && field != NULL && field->is_constant() && !mismatched) { 2278 // final or stable field 2279 p = make_constant_from_field(field, heap_base_oop); 2280 } 2281 2282 if (p == NULL) { // Could not constant fold the load 2283 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators); 2284 // Normalize the value returned by getBoolean in the following cases 2285 if (type == T_BOOLEAN && 2286 (mismatched || 2287 heap_base_oop == top() || // - heap_base_oop is NULL or 2288 (can_access_non_heap && field == NULL)) // - heap_base_oop is potentially NULL 2289 // and the unsafe access is made to large offset 2290 // (i.e., larger than the maximum offset necessary for any 2291 // field access) 2292 ) { 2293 IdealKit ideal = IdealKit(this); 2294 #define __ ideal. 2295 IdealVariable normalized_result(ideal); 2296 __ declarations_done(); 2297 __ set(normalized_result, p); 2298 __ if_then(p, BoolTest::ne, ideal.ConI(0)); 2299 __ set(normalized_result, ideal.ConI(1)); 2300 ideal.end_if(); 2301 final_sync(ideal); 2302 p = __ value(normalized_result); 2303 #undef __ 2304 } 2305 } 2306 if (type == T_ADDRESS) { 2307 p = gvn().transform(new CastP2XNode(NULL, p)); 2308 p = ConvX2UL(p); 2309 } 2310 // The load node has the control of the preceding MemBarCPUOrder. All 2311 // following nodes will have the control of the MemBarCPUOrder inserted at 2312 // the end of this method. So, pushing the load onto the stack at a later 2313 // point is fine. 2314 set_result(p); 2315 } else { 2316 if (bt == T_ADDRESS) { 2317 // Repackage the long as a pointer. 2318 val = ConvL2X(val); 2319 val = gvn().transform(new CastX2PNode(val)); 2320 } 2321 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators); 2322 } 2323 2324 return true; 2325 } 2326 2327 //----------------------------inline_unsafe_load_store---------------------------- 2328 // This method serves a couple of different customers (depending on LoadStoreKind): 2329 // 2330 // LS_cmp_swap: 2331 // 2332 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x); 2333 // boolean compareAndSetInt( Object o, long offset, int expected, int x); 2334 // boolean compareAndSetLong( Object o, long offset, long expected, long x); 2335 // 2336 // LS_cmp_swap_weak: 2337 // 2338 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x); 2339 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x); 2340 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x); 2341 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x); 2342 // 2343 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x); 2344 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x); 2345 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x); 2346 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x); 2347 // 2348 // boolean weakCompareAndSetLong( Object o, long offset, long expected, long x); 2349 // boolean weakCompareAndSetLongPlain( Object o, long offset, long expected, long x); 2350 // boolean weakCompareAndSetLongAcquire( Object o, long offset, long expected, long x); 2351 // boolean weakCompareAndSetLongRelease( Object o, long offset, long expected, long x); 2352 // 2353 // LS_cmp_exchange: 2354 // 2355 // Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x); 2356 // Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x); 2357 // Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x); 2358 // 2359 // Object compareAndExchangeIntVolatile( Object o, long offset, Object expected, Object x); 2360 // Object compareAndExchangeIntAcquire( Object o, long offset, Object expected, Object x); 2361 // Object compareAndExchangeIntRelease( Object o, long offset, Object expected, Object x); 2362 // 2363 // Object compareAndExchangeLongVolatile( Object o, long offset, Object expected, Object x); 2364 // Object compareAndExchangeLongAcquire( Object o, long offset, Object expected, Object x); 2365 // Object compareAndExchangeLongRelease( Object o, long offset, Object expected, Object x); 2366 // 2367 // LS_get_add: 2368 // 2369 // int getAndAddInt( Object o, long offset, int delta) 2370 // long getAndAddLong(Object o, long offset, long delta) 2371 // 2372 // LS_get_set: 2373 // 2374 // int getAndSet(Object o, long offset, int newValue) 2375 // long getAndSet(Object o, long offset, long newValue) 2376 // Object getAndSet(Object o, long offset, Object newValue) 2377 // 2378 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) { 2379 // This basic scheme here is the same as inline_unsafe_access, but 2380 // differs in enough details that combining them would make the code 2381 // overly confusing. (This is a true fact! I originally combined 2382 // them, but even I was confused by it!) As much code/comments as 2383 // possible are retained from inline_unsafe_access though to make 2384 // the correspondences clearer. - dl 2385 2386 if (callee()->is_static()) return false; // caller must have the capability! 2387 2388 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2389 decorators |= mo_decorator_for_access_kind(access_kind); 2390 2391 #ifndef PRODUCT 2392 BasicType rtype; 2393 { 2394 ResourceMark rm; 2395 // Check the signatures. 2396 ciSignature* sig = callee()->signature(); 2397 rtype = sig->return_type()->basic_type(); 2398 switch(kind) { 2399 case LS_get_add: 2400 case LS_get_set: { 2401 // Check the signatures. 2402 #ifdef ASSERT 2403 assert(rtype == type, "get and set must return the expected type"); 2404 assert(sig->count() == 3, "get and set has 3 arguments"); 2405 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 2406 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 2407 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 2408 assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation"); 2409 #endif // ASSERT 2410 break; 2411 } 2412 case LS_cmp_swap: 2413 case LS_cmp_swap_weak: { 2414 // Check the signatures. 2415 #ifdef ASSERT 2416 assert(rtype == T_BOOLEAN, "CAS must return boolean"); 2417 assert(sig->count() == 4, "CAS has 4 arguments"); 2418 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 2419 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 2420 #endif // ASSERT 2421 break; 2422 } 2423 case LS_cmp_exchange: { 2424 // Check the signatures. 2425 #ifdef ASSERT 2426 assert(rtype == type, "CAS must return the expected type"); 2427 assert(sig->count() == 4, "CAS has 4 arguments"); 2428 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 2429 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 2430 #endif // ASSERT 2431 break; 2432 } 2433 default: 2434 ShouldNotReachHere(); 2435 } 2436 } 2437 #endif //PRODUCT 2438 2439 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2440 2441 // Get arguments: 2442 Node* receiver = NULL; 2443 Node* base = NULL; 2444 Node* offset = NULL; 2445 Node* oldval = NULL; 2446 Node* newval = NULL; 2447 switch(kind) { 2448 case LS_cmp_swap: 2449 case LS_cmp_swap_weak: 2450 case LS_cmp_exchange: { 2451 const bool two_slot_type = type2size[type] == 2; 2452 receiver = argument(0); // type: oop 2453 base = argument(1); // type: oop 2454 offset = argument(2); // type: long 2455 oldval = argument(4); // type: oop, int, or long 2456 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 2457 break; 2458 } 2459 case LS_get_add: 2460 case LS_get_set: { 2461 receiver = argument(0); // type: oop 2462 base = argument(1); // type: oop 2463 offset = argument(2); // type: long 2464 oldval = NULL; 2465 newval = argument(4); // type: oop, int, or long 2466 break; 2467 } 2468 default: 2469 ShouldNotReachHere(); 2470 } 2471 2472 // Build field offset expression. 2473 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2474 // to be plain byte offsets, which are also the same as those accepted 2475 // by oopDesc::field_addr. 2476 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 2477 // 32-bit machines ignore the high half of long offsets 2478 offset = ConvL2X(offset); 2479 Node* adr = make_unsafe_address(base, offset, ACCESS_WRITE | ACCESS_READ, type, false); 2480 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 2481 2482 Compile::AliasType* alias_type = C->alias_type(adr_type); 2483 BasicType bt = alias_type->basic_type(); 2484 if (bt != T_ILLEGAL && 2485 (is_reference_type(bt) != (type == T_OBJECT))) { 2486 // Don't intrinsify mismatched object accesses. 2487 return false; 2488 } 2489 2490 // For CAS, unlike inline_unsafe_access, there seems no point in 2491 // trying to refine types. Just use the coarse types here. 2492 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2493 const Type *value_type = Type::get_const_basic_type(type); 2494 2495 switch (kind) { 2496 case LS_get_set: 2497 case LS_cmp_exchange: { 2498 if (type == T_OBJECT) { 2499 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2500 if (tjp != NULL) { 2501 value_type = tjp; 2502 } 2503 } 2504 break; 2505 } 2506 case LS_cmp_swap: 2507 case LS_cmp_swap_weak: 2508 case LS_get_add: 2509 break; 2510 default: 2511 ShouldNotReachHere(); 2512 } 2513 2514 // Null check receiver. 2515 receiver = null_check(receiver); 2516 if (stopped()) { 2517 return true; 2518 } 2519 2520 int alias_idx = C->get_alias_index(adr_type); 2521 2522 if (is_reference_type(type)) { 2523 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF; 2524 2525 // Transformation of a value which could be NULL pointer (CastPP #NULL) 2526 // could be delayed during Parse (for example, in adjust_map_after_if()). 2527 // Execute transformation here to avoid barrier generation in such case. 2528 if (_gvn.type(newval) == TypePtr::NULL_PTR) 2529 newval = _gvn.makecon(TypePtr::NULL_PTR); 2530 2531 if (oldval != NULL && _gvn.type(oldval) == TypePtr::NULL_PTR) { 2532 // Refine the value to a null constant, when it is known to be null 2533 oldval = _gvn.makecon(TypePtr::NULL_PTR); 2534 } 2535 } 2536 2537 Node* result = NULL; 2538 switch (kind) { 2539 case LS_cmp_exchange: { 2540 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx, 2541 oldval, newval, value_type, type, decorators); 2542 break; 2543 } 2544 case LS_cmp_swap_weak: 2545 decorators |= C2_WEAK_CMPXCHG; 2546 case LS_cmp_swap: { 2547 result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx, 2548 oldval, newval, value_type, type, decorators); 2549 break; 2550 } 2551 case LS_get_set: { 2552 result = access_atomic_xchg_at(base, adr, adr_type, alias_idx, 2553 newval, value_type, type, decorators); 2554 break; 2555 } 2556 case LS_get_add: { 2557 result = access_atomic_add_at(base, adr, adr_type, alias_idx, 2558 newval, value_type, type, decorators); 2559 break; 2560 } 2561 default: 2562 ShouldNotReachHere(); 2563 } 2564 2565 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 2566 set_result(result); 2567 return true; 2568 } 2569 2570 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 2571 // Regardless of form, don't allow previous ld/st to move down, 2572 // then issue acquire, release, or volatile mem_bar. 2573 insert_mem_bar(Op_MemBarCPUOrder); 2574 switch(id) { 2575 case vmIntrinsics::_loadFence: 2576 insert_mem_bar(Op_LoadFence); 2577 return true; 2578 case vmIntrinsics::_storeFence: 2579 insert_mem_bar(Op_StoreFence); 2580 return true; 2581 case vmIntrinsics::_fullFence: 2582 insert_mem_bar(Op_MemBarVolatile); 2583 return true; 2584 default: 2585 fatal_unexpected_iid(id); 2586 return false; 2587 } 2588 } 2589 2590 bool LibraryCallKit::inline_onspinwait() { 2591 insert_mem_bar(Op_OnSpinWait); 2592 return true; 2593 } 2594 2595 bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 2596 if (!kls->is_Con()) { 2597 return true; 2598 } 2599 const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr(); 2600 if (klsptr == NULL) { 2601 return true; 2602 } 2603 ciInstanceKlass* ik = klsptr->klass()->as_instance_klass(); 2604 // don't need a guard for a klass that is already initialized 2605 return !ik->is_initialized(); 2606 } 2607 2608 //----------------------------inline_unsafe_writeback0------------------------- 2609 // public native void Unsafe.writeback0(long address) 2610 bool LibraryCallKit::inline_unsafe_writeback0() { 2611 if (!Matcher::has_match_rule(Op_CacheWB)) { 2612 return false; 2613 } 2614 #ifndef PRODUCT 2615 assert(Matcher::has_match_rule(Op_CacheWBPreSync), "found match rule for CacheWB but not CacheWBPreSync"); 2616 assert(Matcher::has_match_rule(Op_CacheWBPostSync), "found match rule for CacheWB but not CacheWBPostSync"); 2617 ciSignature* sig = callee()->signature(); 2618 assert(sig->type_at(0)->basic_type() == T_LONG, "Unsafe_writeback0 address is long!"); 2619 #endif 2620 null_check_receiver(); // null-check, then ignore 2621 Node *addr = argument(1); 2622 addr = new CastX2PNode(addr); 2623 addr = _gvn.transform(addr); 2624 Node *flush = new CacheWBNode(control(), memory(TypeRawPtr::BOTTOM), addr); 2625 flush = _gvn.transform(flush); 2626 set_memory(flush, TypeRawPtr::BOTTOM); 2627 return true; 2628 } 2629 2630 //----------------------------inline_unsafe_writeback0------------------------- 2631 // public native void Unsafe.writeback0(long address) 2632 bool LibraryCallKit::inline_unsafe_writebackSync0(bool is_pre) { 2633 if (is_pre && !Matcher::has_match_rule(Op_CacheWBPreSync)) { 2634 return false; 2635 } 2636 if (!is_pre && !Matcher::has_match_rule(Op_CacheWBPostSync)) { 2637 return false; 2638 } 2639 #ifndef PRODUCT 2640 assert(Matcher::has_match_rule(Op_CacheWB), 2641 (is_pre ? "found match rule for CacheWBPreSync but not CacheWB" 2642 : "found match rule for CacheWBPostSync but not CacheWB")); 2643 2644 #endif 2645 null_check_receiver(); // null-check, then ignore 2646 Node *sync; 2647 if (is_pre) { 2648 sync = new CacheWBPreSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 2649 } else { 2650 sync = new CacheWBPostSyncNode(control(), memory(TypeRawPtr::BOTTOM)); 2651 } 2652 sync = _gvn.transform(sync); 2653 set_memory(sync, TypeRawPtr::BOTTOM); 2654 return true; 2655 } 2656 2657 //----------------------------inline_unsafe_allocate--------------------------- 2658 // public native Object Unsafe.allocateInstance(Class<?> cls); 2659 bool LibraryCallKit::inline_unsafe_allocate() { 2660 if (callee()->is_static()) return false; // caller must have the capability! 2661 2662 null_check_receiver(); // null-check, then ignore 2663 Node* cls = null_check(argument(1)); 2664 if (stopped()) return true; 2665 2666 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 2667 kls = null_check(kls); 2668 if (stopped()) return true; // argument was like int.class 2669 2670 Node* test = NULL; 2671 if (LibraryCallKit::klass_needs_init_guard(kls)) { 2672 // Note: The argument might still be an illegal value like 2673 // Serializable.class or Object[].class. The runtime will handle it. 2674 // But we must make an explicit check for initialization. 2675 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 2676 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 2677 // can generate code to load it as unsigned byte. 2678 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); 2679 Node* bits = intcon(InstanceKlass::fully_initialized); 2680 test = _gvn.transform(new SubINode(inst, bits)); 2681 // The 'test' is non-zero if we need to take a slow path. 2682 } 2683 2684 Node* obj = new_instance(kls, test); 2685 set_result(obj); 2686 return true; 2687 } 2688 2689 //------------------------inline_native_time_funcs-------------- 2690 // inline code for System.currentTimeMillis() and System.nanoTime() 2691 // these have the same type and signature 2692 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 2693 const TypeFunc* tf = OptoRuntime::void_long_Type(); 2694 const TypePtr* no_memory_effects = NULL; 2695 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 2696 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0)); 2697 #ifdef ASSERT 2698 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1)); 2699 assert(value_top == top(), "second value must be top"); 2700 #endif 2701 set_result(value); 2702 return true; 2703 } 2704 2705 #ifdef JFR_HAVE_INTRINSICS 2706 2707 /* 2708 * oop -> myklass 2709 * myklass->trace_id |= USED 2710 * return myklass->trace_id & ~0x3 2711 */ 2712 bool LibraryCallKit::inline_native_classID() { 2713 Node* cls = null_check(argument(0), T_OBJECT); 2714 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 2715 kls = null_check(kls, T_OBJECT); 2716 2717 ByteSize offset = KLASS_TRACE_ID_OFFSET; 2718 Node* insp = basic_plus_adr(kls, in_bytes(offset)); 2719 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered); 2720 2721 Node* clsused = longcon(0x01l); // set the class bit 2722 Node* orl = _gvn.transform(new OrLNode(tvalue, clsused)); 2723 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr(); 2724 store_to_memory(control(), insp, orl, T_LONG, adr_type, MemNode::unordered); 2725 2726 #ifdef TRACE_ID_META_BITS 2727 Node* mbits = longcon(~TRACE_ID_META_BITS); 2728 tvalue = _gvn.transform(new AndLNode(tvalue, mbits)); 2729 #endif 2730 #ifdef TRACE_ID_SHIFT 2731 Node* cbits = intcon(TRACE_ID_SHIFT); 2732 tvalue = _gvn.transform(new URShiftLNode(tvalue, cbits)); 2733 #endif 2734 2735 set_result(tvalue); 2736 return true; 2737 2738 } 2739 2740 bool LibraryCallKit::inline_native_getEventWriter() { 2741 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 2742 2743 Node* jobj_ptr = basic_plus_adr(top(), tls_ptr, 2744 in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR)); 2745 2746 Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); 2747 2748 Node* jobj_cmp_null = _gvn.transform( new CmpPNode(jobj, null()) ); 2749 Node* test_jobj_eq_null = _gvn.transform( new BoolNode(jobj_cmp_null, BoolTest::eq) ); 2750 2751 IfNode* iff_jobj_null = 2752 create_and_map_if(control(), test_jobj_eq_null, PROB_MIN, COUNT_UNKNOWN); 2753 2754 enum { _normal_path = 1, 2755 _null_path = 2, 2756 PATH_LIMIT }; 2757 2758 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 2759 PhiNode* result_val = new PhiNode(result_rgn, TypeInstPtr::BOTTOM); 2760 2761 Node* jobj_is_null = _gvn.transform(new IfTrueNode(iff_jobj_null)); 2762 result_rgn->init_req(_null_path, jobj_is_null); 2763 result_val->init_req(_null_path, null()); 2764 2765 Node* jobj_is_not_null = _gvn.transform(new IfFalseNode(iff_jobj_null)); 2766 set_control(jobj_is_not_null); 2767 Node* res = access_load(jobj, TypeInstPtr::NOTNULL, T_OBJECT, 2768 IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD); 2769 result_rgn->init_req(_normal_path, control()); 2770 result_val->init_req(_normal_path, res); 2771 2772 set_result(result_rgn, result_val); 2773 2774 return true; 2775 } 2776 2777 #endif // JFR_HAVE_INTRINSICS 2778 2779 //------------------------inline_native_currentThread------------------ 2780 bool LibraryCallKit::inline_native_currentThread() { 2781 Node* junk = NULL; 2782 set_result(generate_current_thread(junk)); 2783 return true; 2784 } 2785 2786 //---------------------------load_mirror_from_klass---------------------------- 2787 // Given a klass oop, load its java mirror (a java.lang.Class oop). 2788 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) { 2789 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset())); 2790 Node* load = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 2791 // mirror = ((OopHandle)mirror)->resolve(); 2792 return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE); 2793 } 2794 2795 //-----------------------load_klass_from_mirror_common------------------------- 2796 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 2797 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 2798 // and branch to the given path on the region. 2799 // If never_see_null, take an uncommon trap on null, so we can optimistically 2800 // compile for the non-null case. 2801 // If the region is NULL, force never_see_null = true. 2802 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 2803 bool never_see_null, 2804 RegionNode* region, 2805 int null_path, 2806 int offset) { 2807 if (region == NULL) never_see_null = true; 2808 Node* p = basic_plus_adr(mirror, offset); 2809 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 2810 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 2811 Node* null_ctl = top(); 2812 kls = null_check_oop(kls, &null_ctl, never_see_null); 2813 if (region != NULL) { 2814 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 2815 region->init_req(null_path, null_ctl); 2816 } else { 2817 assert(null_ctl == top(), "no loose ends"); 2818 } 2819 return kls; 2820 } 2821 2822 //--------------------(inline_native_Class_query helpers)--------------------- 2823 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE_FAST, JVM_ACC_HAS_FINALIZER. 2824 // Fall through if (mods & mask) == bits, take the guard otherwise. 2825 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 2826 // Branch around if the given klass has the given modifier bit set. 2827 // Like generate_guard, adds a new path onto the region. 2828 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 2829 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered); 2830 Node* mask = intcon(modifier_mask); 2831 Node* bits = intcon(modifier_bits); 2832 Node* mbit = _gvn.transform(new AndINode(mods, mask)); 2833 Node* cmp = _gvn.transform(new CmpINode(mbit, bits)); 2834 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 2835 return generate_fair_guard(bol, region); 2836 } 2837 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 2838 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region); 2839 } 2840 Node* LibraryCallKit::generate_hidden_class_guard(Node* kls, RegionNode* region) { 2841 return generate_access_flags_guard(kls, JVM_ACC_IS_HIDDEN_CLASS, 0, region); 2842 } 2843 2844 //-------------------------inline_native_Class_query------------------- 2845 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 2846 const Type* return_type = TypeInt::BOOL; 2847 Node* prim_return_value = top(); // what happens if it's a primitive class? 2848 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 2849 bool expect_prim = false; // most of these guys expect to work on refs 2850 2851 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 2852 2853 Node* mirror = argument(0); 2854 Node* obj = top(); 2855 2856 switch (id) { 2857 case vmIntrinsics::_isInstance: 2858 // nothing is an instance of a primitive type 2859 prim_return_value = intcon(0); 2860 obj = argument(1); 2861 break; 2862 case vmIntrinsics::_getModifiers: 2863 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 2864 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line"); 2865 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin); 2866 break; 2867 case vmIntrinsics::_isInterface: 2868 prim_return_value = intcon(0); 2869 break; 2870 case vmIntrinsics::_isArray: 2871 prim_return_value = intcon(0); 2872 expect_prim = true; // cf. ObjectStreamClass.getClassSignature 2873 break; 2874 case vmIntrinsics::_isPrimitive: 2875 prim_return_value = intcon(1); 2876 expect_prim = true; // obviously 2877 break; 2878 case vmIntrinsics::_isHidden: 2879 prim_return_value = intcon(0); 2880 break; 2881 case vmIntrinsics::_getSuperclass: 2882 prim_return_value = null(); 2883 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 2884 break; 2885 case vmIntrinsics::_getClassAccessFlags: 2886 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 2887 return_type = TypeInt::INT; // not bool! 6297094 2888 break; 2889 default: 2890 fatal_unexpected_iid(id); 2891 break; 2892 } 2893 2894 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 2895 if (mirror_con == NULL) return false; // cannot happen? 2896 2897 #ifndef PRODUCT 2898 if (C->print_intrinsics() || C->print_inlining()) { 2899 ciType* k = mirror_con->java_mirror_type(); 2900 if (k) { 2901 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 2902 k->print_name(); 2903 tty->cr(); 2904 } 2905 } 2906 #endif 2907 2908 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 2909 RegionNode* region = new RegionNode(PATH_LIMIT); 2910 record_for_igvn(region); 2911 PhiNode* phi = new PhiNode(region, return_type); 2912 2913 // The mirror will never be null of Reflection.getClassAccessFlags, however 2914 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 2915 // if it is. See bug 4774291. 2916 2917 // For Reflection.getClassAccessFlags(), the null check occurs in 2918 // the wrong place; see inline_unsafe_access(), above, for a similar 2919 // situation. 2920 mirror = null_check(mirror); 2921 // If mirror or obj is dead, only null-path is taken. 2922 if (stopped()) return true; 2923 2924 if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 2925 2926 // Now load the mirror's klass metaobject, and null-check it. 2927 // Side-effects region with the control path if the klass is null. 2928 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 2929 // If kls is null, we have a primitive mirror. 2930 phi->init_req(_prim_path, prim_return_value); 2931 if (stopped()) { set_result(region, phi); return true; } 2932 bool safe_for_replace = (region->in(_prim_path) == top()); 2933 2934 Node* p; // handy temp 2935 Node* null_ctl; 2936 2937 // Now that we have the non-null klass, we can perform the real query. 2938 // For constant classes, the query will constant-fold in LoadNode::Value. 2939 Node* query_value = top(); 2940 switch (id) { 2941 case vmIntrinsics::_isInstance: 2942 // nothing is an instance of a primitive type 2943 query_value = gen_instanceof(obj, kls, safe_for_replace); 2944 break; 2945 2946 case vmIntrinsics::_getModifiers: 2947 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset())); 2948 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 2949 break; 2950 2951 case vmIntrinsics::_isInterface: 2952 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 2953 if (generate_interface_guard(kls, region) != NULL) 2954 // A guard was added. If the guard is taken, it was an interface. 2955 phi->add_req(intcon(1)); 2956 // If we fall through, it's a plain class. 2957 query_value = intcon(0); 2958 break; 2959 2960 case vmIntrinsics::_isArray: 2961 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.) 2962 if (generate_array_guard(kls, region) != NULL) 2963 // A guard was added. If the guard is taken, it was an array. 2964 phi->add_req(intcon(1)); 2965 // If we fall through, it's a plain class. 2966 query_value = intcon(0); 2967 break; 2968 2969 case vmIntrinsics::_isPrimitive: 2970 query_value = intcon(0); // "normal" path produces false 2971 break; 2972 2973 case vmIntrinsics::_isHidden: 2974 // (To verify this code sequence, check the asserts in JVM_IsHiddenClass.) 2975 if (generate_hidden_class_guard(kls, region) != NULL) 2976 // A guard was added. If the guard is taken, it was an hidden class. 2977 phi->add_req(intcon(1)); 2978 // If we fall through, it's a plain class. 2979 query_value = intcon(0); 2980 break; 2981 2982 2983 case vmIntrinsics::_getSuperclass: 2984 // The rules here are somewhat unfortunate, but we can still do better 2985 // with random logic than with a JNI call. 2986 // Interfaces store null or Object as _super, but must report null. 2987 // Arrays store an intermediate super as _super, but must report Object. 2988 // Other types can report the actual _super. 2989 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 2990 if (generate_interface_guard(kls, region) != NULL) 2991 // A guard was added. If the guard is taken, it was an interface. 2992 phi->add_req(null()); 2993 if (generate_array_guard(kls, region) != NULL) 2994 // A guard was added. If the guard is taken, it was an array. 2995 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 2996 // If we fall through, it's a plain class. Get its _super. 2997 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 2998 kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 2999 null_ctl = top(); 3000 kls = null_check_oop(kls, &null_ctl); 3001 if (null_ctl != top()) { 3002 // If the guard is taken, Object.superClass is null (both klass and mirror). 3003 region->add_req(null_ctl); 3004 phi ->add_req(null()); 3005 } 3006 if (!stopped()) { 3007 query_value = load_mirror_from_klass(kls); 3008 } 3009 break; 3010 3011 case vmIntrinsics::_getClassAccessFlags: 3012 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 3013 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 3014 break; 3015 3016 default: 3017 fatal_unexpected_iid(id); 3018 break; 3019 } 3020 3021 // Fall-through is the normal case of a query to a real class. 3022 phi->init_req(1, query_value); 3023 region->init_req(1, control()); 3024 3025 C->set_has_split_ifs(true); // Has chance for split-if optimization 3026 set_result(region, phi); 3027 return true; 3028 } 3029 3030 //-------------------------inline_Class_cast------------------- 3031 bool LibraryCallKit::inline_Class_cast() { 3032 Node* mirror = argument(0); // Class 3033 Node* obj = argument(1); 3034 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 3035 if (mirror_con == NULL) { 3036 return false; // dead path (mirror->is_top()). 3037 } 3038 if (obj == NULL || obj->is_top()) { 3039 return false; // dead path 3040 } 3041 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr(); 3042 3043 // First, see if Class.cast() can be folded statically. 3044 // java_mirror_type() returns non-null for compile-time Class constants. 3045 ciType* tm = mirror_con->java_mirror_type(); 3046 if (tm != NULL && tm->is_klass() && 3047 tp != NULL && tp->klass() != NULL) { 3048 if (!tp->klass()->is_loaded()) { 3049 // Don't use intrinsic when class is not loaded. 3050 return false; 3051 } else { 3052 int static_res = C->static_subtype_check(tm->as_klass(), tp->klass()); 3053 if (static_res == Compile::SSC_always_true) { 3054 // isInstance() is true - fold the code. 3055 set_result(obj); 3056 return true; 3057 } else if (static_res == Compile::SSC_always_false) { 3058 // Don't use intrinsic, have to throw ClassCastException. 3059 // If the reference is null, the non-intrinsic bytecode will 3060 // be optimized appropriately. 3061 return false; 3062 } 3063 } 3064 } 3065 3066 // Bailout intrinsic and do normal inlining if exception path is frequent. 3067 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 3068 return false; 3069 } 3070 3071 // Generate dynamic checks. 3072 // Class.cast() is java implementation of _checkcast bytecode. 3073 // Do checkcast (Parse::do_checkcast()) optimizations here. 3074 3075 mirror = null_check(mirror); 3076 // If mirror is dead, only null-path is taken. 3077 if (stopped()) { 3078 return true; 3079 } 3080 3081 // Not-subtype or the mirror's klass ptr is NULL (in case it is a primitive). 3082 enum { _bad_type_path = 1, _prim_path = 2, PATH_LIMIT }; 3083 RegionNode* region = new RegionNode(PATH_LIMIT); 3084 record_for_igvn(region); 3085 3086 // Now load the mirror's klass metaobject, and null-check it. 3087 // If kls is null, we have a primitive mirror and 3088 // nothing is an instance of a primitive type. 3089 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path); 3090 3091 Node* res = top(); 3092 if (!stopped()) { 3093 Node* bad_type_ctrl = top(); 3094 // Do checkcast optimizations. 3095 res = gen_checkcast(obj, kls, &bad_type_ctrl); 3096 region->init_req(_bad_type_path, bad_type_ctrl); 3097 } 3098 if (region->in(_prim_path) != top() || 3099 region->in(_bad_type_path) != top()) { 3100 // Let Interpreter throw ClassCastException. 3101 PreserveJVMState pjvms(this); 3102 set_control(_gvn.transform(region)); 3103 uncommon_trap(Deoptimization::Reason_intrinsic, 3104 Deoptimization::Action_maybe_recompile); 3105 } 3106 if (!stopped()) { 3107 set_result(res); 3108 } 3109 return true; 3110 } 3111 3112 3113 //--------------------------inline_native_subtype_check------------------------ 3114 // This intrinsic takes the JNI calls out of the heart of 3115 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 3116 bool LibraryCallKit::inline_native_subtype_check() { 3117 // Pull both arguments off the stack. 3118 Node* args[2]; // two java.lang.Class mirrors: superc, subc 3119 args[0] = argument(0); 3120 args[1] = argument(1); 3121 Node* klasses[2]; // corresponding Klasses: superk, subk 3122 klasses[0] = klasses[1] = top(); 3123 3124 enum { 3125 // A full decision tree on {superc is prim, subc is prim}: 3126 _prim_0_path = 1, // {P,N} => false 3127 // {P,P} & superc!=subc => false 3128 _prim_same_path, // {P,P} & superc==subc => true 3129 _prim_1_path, // {N,P} => false 3130 _ref_subtype_path, // {N,N} & subtype check wins => true 3131 _both_ref_path, // {N,N} & subtype check loses => false 3132 PATH_LIMIT 3133 }; 3134 3135 RegionNode* region = new RegionNode(PATH_LIMIT); 3136 Node* phi = new PhiNode(region, TypeInt::BOOL); 3137 record_for_igvn(region); 3138 3139 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 3140 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3141 int class_klass_offset = java_lang_Class::klass_offset_in_bytes(); 3142 3143 // First null-check both mirrors and load each mirror's klass metaobject. 3144 int which_arg; 3145 for (which_arg = 0; which_arg <= 1; which_arg++) { 3146 Node* arg = args[which_arg]; 3147 arg = null_check(arg); 3148 if (stopped()) break; 3149 args[which_arg] = arg; 3150 3151 Node* p = basic_plus_adr(arg, class_klass_offset); 3152 Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type); 3153 klasses[which_arg] = _gvn.transform(kls); 3154 } 3155 3156 // Having loaded both klasses, test each for null. 3157 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3158 for (which_arg = 0; which_arg <= 1; which_arg++) { 3159 Node* kls = klasses[which_arg]; 3160 Node* null_ctl = top(); 3161 kls = null_check_oop(kls, &null_ctl, never_see_null); 3162 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path); 3163 region->init_req(prim_path, null_ctl); 3164 if (stopped()) break; 3165 klasses[which_arg] = kls; 3166 } 3167 3168 if (!stopped()) { 3169 // now we have two reference types, in klasses[0..1] 3170 Node* subk = klasses[1]; // the argument to isAssignableFrom 3171 Node* superk = klasses[0]; // the receiver 3172 region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 3173 // now we have a successful reference subtype check 3174 region->set_req(_ref_subtype_path, control()); 3175 } 3176 3177 // If both operands are primitive (both klasses null), then 3178 // we must return true when they are identical primitives. 3179 // It is convenient to test this after the first null klass check. 3180 set_control(region->in(_prim_0_path)); // go back to first null check 3181 if (!stopped()) { 3182 // Since superc is primitive, make a guard for the superc==subc case. 3183 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1])); 3184 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq)); 3185 generate_guard(bol_eq, region, PROB_FAIR); 3186 if (region->req() == PATH_LIMIT+1) { 3187 // A guard was added. If the added guard is taken, superc==subc. 3188 region->swap_edges(PATH_LIMIT, _prim_same_path); 3189 region->del_req(PATH_LIMIT); 3190 } 3191 region->set_req(_prim_0_path, control()); // Not equal after all. 3192 } 3193 3194 // these are the only paths that produce 'true': 3195 phi->set_req(_prim_same_path, intcon(1)); 3196 phi->set_req(_ref_subtype_path, intcon(1)); 3197 3198 // pull together the cases: 3199 assert(region->req() == PATH_LIMIT, "sane region"); 3200 for (uint i = 1; i < region->req(); i++) { 3201 Node* ctl = region->in(i); 3202 if (ctl == NULL || ctl == top()) { 3203 region->set_req(i, top()); 3204 phi ->set_req(i, top()); 3205 } else if (phi->in(i) == NULL) { 3206 phi->set_req(i, intcon(0)); // all other paths produce 'false' 3207 } 3208 } 3209 3210 set_control(_gvn.transform(region)); 3211 set_result(_gvn.transform(phi)); 3212 return true; 3213 } 3214 3215 //---------------------generate_array_guard_common------------------------ 3216 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, 3217 bool obj_array, bool not_array) { 3218 3219 if (stopped()) { 3220 return NULL; 3221 } 3222 3223 // If obj_array/non_array==false/false: 3224 // Branch around if the given klass is in fact an array (either obj or prim). 3225 // If obj_array/non_array==false/true: 3226 // Branch around if the given klass is not an array klass of any kind. 3227 // If obj_array/non_array==true/true: 3228 // Branch around if the kls is not an oop array (kls is int[], String, etc.) 3229 // If obj_array/non_array==true/false: 3230 // Branch around if the kls is an oop array (Object[] or subtype) 3231 // 3232 // Like generate_guard, adds a new path onto the region. 3233 jint layout_con = 0; 3234 Node* layout_val = get_layout_helper(kls, layout_con); 3235 if (layout_val == NULL) { 3236 bool query = (obj_array 3237 ? Klass::layout_helper_is_objArray(layout_con) 3238 : Klass::layout_helper_is_array(layout_con)); 3239 if (query == not_array) { 3240 return NULL; // never a branch 3241 } else { // always a branch 3242 Node* always_branch = control(); 3243 if (region != NULL) 3244 region->add_req(always_branch); 3245 set_control(top()); 3246 return always_branch; 3247 } 3248 } 3249 // Now test the correct condition. 3250 jint nval = (obj_array 3251 ? (jint)(Klass::_lh_array_tag_type_value 3252 << Klass::_lh_array_tag_shift) 3253 : Klass::_lh_neutral_value); 3254 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval))); 3255 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array 3256 // invert the test if we are looking for a non-array 3257 if (not_array) btest = BoolTest(btest).negate(); 3258 Node* bol = _gvn.transform(new BoolNode(cmp, btest)); 3259 return generate_fair_guard(bol, region); 3260 } 3261 3262 3263 //-----------------------inline_native_newArray-------------------------- 3264 // private static native Object java.lang.reflect.newArray(Class<?> componentType, int length); 3265 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size); 3266 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) { 3267 Node* mirror; 3268 Node* count_val; 3269 if (uninitialized) { 3270 mirror = argument(1); 3271 count_val = argument(2); 3272 } else { 3273 mirror = argument(0); 3274 count_val = argument(1); 3275 } 3276 3277 mirror = null_check(mirror); 3278 // If mirror or obj is dead, only null-path is taken. 3279 if (stopped()) return true; 3280 3281 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 3282 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 3283 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 3284 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 3285 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 3286 3287 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3288 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 3289 result_reg, _slow_path); 3290 Node* normal_ctl = control(); 3291 Node* no_array_ctl = result_reg->in(_slow_path); 3292 3293 // Generate code for the slow case. We make a call to newArray(). 3294 set_control(no_array_ctl); 3295 if (!stopped()) { 3296 // Either the input type is void.class, or else the 3297 // array klass has not yet been cached. Either the 3298 // ensuing call will throw an exception, or else it 3299 // will cache the array klass for next time. 3300 PreserveJVMState pjvms(this); 3301 CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray); 3302 Node* slow_result = set_results_for_java_call(slow_call); 3303 // this->control() comes from set_results_for_java_call 3304 result_reg->set_req(_slow_path, control()); 3305 result_val->set_req(_slow_path, slow_result); 3306 result_io ->set_req(_slow_path, i_o()); 3307 result_mem->set_req(_slow_path, reset_memory()); 3308 } 3309 3310 set_control(normal_ctl); 3311 if (!stopped()) { 3312 // Normal case: The array type has been cached in the java.lang.Class. 3313 // The following call works fine even if the array type is polymorphic. 3314 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3315 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 3316 result_reg->init_req(_normal_path, control()); 3317 result_val->init_req(_normal_path, obj); 3318 result_io ->init_req(_normal_path, i_o()); 3319 result_mem->init_req(_normal_path, reset_memory()); 3320 3321 if (uninitialized) { 3322 // Mark the allocation so that zeroing is skipped 3323 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj, &_gvn); 3324 alloc->maybe_set_complete(&_gvn); 3325 } 3326 } 3327 3328 // Return the combined state. 3329 set_i_o( _gvn.transform(result_io) ); 3330 set_all_memory( _gvn.transform(result_mem)); 3331 3332 C->set_has_split_ifs(true); // Has chance for split-if optimization 3333 set_result(result_reg, result_val); 3334 return true; 3335 } 3336 3337 //----------------------inline_native_getLength-------------------------- 3338 // public static native int java.lang.reflect.Array.getLength(Object array); 3339 bool LibraryCallKit::inline_native_getLength() { 3340 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3341 3342 Node* array = null_check(argument(0)); 3343 // If array is dead, only null-path is taken. 3344 if (stopped()) return true; 3345 3346 // Deoptimize if it is a non-array. 3347 Node* non_array = generate_non_array_guard(load_object_klass(array), NULL); 3348 3349 if (non_array != NULL) { 3350 PreserveJVMState pjvms(this); 3351 set_control(non_array); 3352 uncommon_trap(Deoptimization::Reason_intrinsic, 3353 Deoptimization::Action_maybe_recompile); 3354 } 3355 3356 // If control is dead, only non-array-path is taken. 3357 if (stopped()) return true; 3358 3359 // The works fine even if the array type is polymorphic. 3360 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3361 Node* result = load_array_length(array); 3362 3363 C->set_has_split_ifs(true); // Has chance for split-if optimization 3364 set_result(result); 3365 return true; 3366 } 3367 3368 //------------------------inline_array_copyOf---------------------------- 3369 // public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 3370 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 3371 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 3372 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3373 3374 // Get the arguments. 3375 Node* original = argument(0); 3376 Node* start = is_copyOfRange? argument(1): intcon(0); 3377 Node* end = is_copyOfRange? argument(2): argument(1); 3378 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 3379 3380 Node* newcopy = NULL; 3381 3382 // Set the original stack and the reexecute bit for the interpreter to reexecute 3383 // the bytecode that invokes Arrays.copyOf if deoptimization happens. 3384 { PreserveReexecuteState preexecs(this); 3385 jvms()->set_should_reexecute(true); 3386 3387 array_type_mirror = null_check(array_type_mirror); 3388 original = null_check(original); 3389 3390 // Check if a null path was taken unconditionally. 3391 if (stopped()) return true; 3392 3393 Node* orig_length = load_array_length(original); 3394 3395 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, NULL, 0); 3396 klass_node = null_check(klass_node); 3397 3398 RegionNode* bailout = new RegionNode(1); 3399 record_for_igvn(bailout); 3400 3401 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 3402 // Bail out if that is so. 3403 Node* not_objArray = generate_non_objArray_guard(klass_node, bailout); 3404 if (not_objArray != NULL) { 3405 // Improve the klass node's type from the new optimistic assumption: 3406 ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 3407 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); 3408 Node* cast = new CastPPNode(klass_node, akls); 3409 cast->init_req(0, control()); 3410 klass_node = _gvn.transform(cast); 3411 } 3412 3413 // Bail out if either start or end is negative. 3414 generate_negative_guard(start, bailout, &start); 3415 generate_negative_guard(end, bailout, &end); 3416 3417 Node* length = end; 3418 if (_gvn.type(start) != TypeInt::ZERO) { 3419 length = _gvn.transform(new SubINode(end, start)); 3420 } 3421 3422 // Bail out if length is negative. 3423 // Without this the new_array would throw 3424 // NegativeArraySizeException but IllegalArgumentException is what 3425 // should be thrown 3426 generate_negative_guard(length, bailout, &length); 3427 3428 if (bailout->req() > 1) { 3429 PreserveJVMState pjvms(this); 3430 set_control(_gvn.transform(bailout)); 3431 uncommon_trap(Deoptimization::Reason_intrinsic, 3432 Deoptimization::Action_maybe_recompile); 3433 } 3434 3435 if (!stopped()) { 3436 // How many elements will we copy from the original? 3437 // The answer is MinI(orig_length - start, length). 3438 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start)); 3439 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); 3440 3441 // Generate a direct call to the right arraycopy function(s). 3442 // We know the copy is disjoint but we might not know if the 3443 // oop stores need checking. 3444 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 3445 // This will fail a store-check if x contains any non-nulls. 3446 3447 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to 3448 // loads/stores but it is legal only if we're sure the 3449 // Arrays.copyOf would succeed. So we need all input arguments 3450 // to the copyOf to be validated, including that the copy to the 3451 // new array won't trigger an ArrayStoreException. That subtype 3452 // check can be optimized if we know something on the type of 3453 // the input array from type speculation. 3454 if (_gvn.type(klass_node)->singleton()) { 3455 ciKlass* subk = _gvn.type(load_object_klass(original))->is_klassptr()->klass(); 3456 ciKlass* superk = _gvn.type(klass_node)->is_klassptr()->klass(); 3457 3458 int test = C->static_subtype_check(superk, subk); 3459 if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) { 3460 const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr(); 3461 if (t_original->speculative_type() != NULL) { 3462 original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true); 3463 } 3464 } 3465 } 3466 3467 bool validated = false; 3468 // Reason_class_check rather than Reason_intrinsic because we 3469 // want to intrinsify even if this traps. 3470 if (!too_many_traps(Deoptimization::Reason_class_check)) { 3471 Node* not_subtype_ctrl = gen_subtype_check(original, klass_node); 3472 3473 if (not_subtype_ctrl != top()) { 3474 PreserveJVMState pjvms(this); 3475 set_control(not_subtype_ctrl); 3476 uncommon_trap(Deoptimization::Reason_class_check, 3477 Deoptimization::Action_make_not_entrant); 3478 assert(stopped(), "Should be stopped"); 3479 } 3480 validated = true; 3481 } 3482 3483 if (!stopped()) { 3484 newcopy = new_array(klass_node, length, 0); // no arguments to push 3485 3486 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false, 3487 load_object_klass(original), klass_node); 3488 if (!is_copyOfRange) { 3489 ac->set_copyof(validated); 3490 } else { 3491 ac->set_copyofrange(validated); 3492 } 3493 Node* n = _gvn.transform(ac); 3494 if (n == ac) { 3495 ac->connect_outputs(this); 3496 } else { 3497 assert(validated, "shouldn't transform if all arguments not validated"); 3498 set_all_memory(n); 3499 } 3500 } 3501 } 3502 } // original reexecute is set back here 3503 3504 C->set_has_split_ifs(true); // Has chance for split-if optimization 3505 if (!stopped()) { 3506 set_result(newcopy); 3507 } 3508 return true; 3509 } 3510 3511 3512 //----------------------generate_virtual_guard--------------------------- 3513 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 3514 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 3515 RegionNode* slow_region) { 3516 ciMethod* method = callee(); 3517 int vtable_index = method->vtable_index(); 3518 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3519 "bad index %d", vtable_index); 3520 // Get the Method* out of the appropriate vtable entry. 3521 int entry_offset = in_bytes(Klass::vtable_start_offset()) + 3522 vtable_index*vtableEntry::size_in_bytes() + 3523 vtableEntry::method_offset_in_bytes(); 3524 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 3525 Node* target_call = make_load(NULL, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3526 3527 // Compare the target method with the expected method (e.g., Object.hashCode). 3528 const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 3529 3530 Node* native_call = makecon(native_call_addr); 3531 Node* chk_native = _gvn.transform(new CmpPNode(target_call, native_call)); 3532 Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne)); 3533 3534 return generate_slow_guard(test_native, slow_region); 3535 } 3536 3537 //-----------------------generate_method_call---------------------------- 3538 // Use generate_method_call to make a slow-call to the real 3539 // method if the fast path fails. An alternative would be to 3540 // use a stub like OptoRuntime::slow_arraycopy_Java. 3541 // This only works for expanding the current library call, 3542 // not another intrinsic. (E.g., don't use this for making an 3543 // arraycopy call inside of the copyOf intrinsic.) 3544 CallJavaNode* 3545 LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) { 3546 // When compiling the intrinsic method itself, do not use this technique. 3547 guarantee(callee() != C->method(), "cannot make slow-call to self"); 3548 3549 ciMethod* method = callee(); 3550 // ensure the JVMS we have will be correct for this call 3551 guarantee(method_id == method->intrinsic_id(), "must match"); 3552 3553 const TypeFunc* tf = TypeFunc::make(method); 3554 CallJavaNode* slow_call; 3555 if (is_static) { 3556 assert(!is_virtual, ""); 3557 slow_call = new CallStaticJavaNode(C, tf, 3558 SharedRuntime::get_resolve_static_call_stub(), 3559 method, bci()); 3560 } else if (is_virtual) { 3561 null_check_receiver(); 3562 int vtable_index = Method::invalid_vtable_index; 3563 if (UseInlineCaches) { 3564 // Suppress the vtable call 3565 } else { 3566 // hashCode and clone are not a miranda methods, 3567 // so the vtable index is fixed. 3568 // No need to use the linkResolver to get it. 3569 vtable_index = method->vtable_index(); 3570 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3571 "bad index %d", vtable_index); 3572 } 3573 slow_call = new CallDynamicJavaNode(tf, 3574 SharedRuntime::get_resolve_virtual_call_stub(), 3575 method, vtable_index, bci()); 3576 } else { // neither virtual nor static: opt_virtual 3577 null_check_receiver(); 3578 slow_call = new CallStaticJavaNode(C, tf, 3579 SharedRuntime::get_resolve_opt_virtual_call_stub(), 3580 method, bci()); 3581 slow_call->set_optimized_virtual(true); 3582 } 3583 if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) { 3584 // To be able to issue a direct call (optimized virtual or virtual) 3585 // and skip a call to MH.linkTo*/invokeBasic adapter, additional information 3586 // about the method being invoked should be attached to the call site to 3587 // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C). 3588 slow_call->set_override_symbolic_info(true); 3589 } 3590 set_arguments_for_java_call(slow_call); 3591 set_edges_for_java_call(slow_call); 3592 return slow_call; 3593 } 3594 3595 3596 /** 3597 * Build special case code for calls to hashCode on an object. This call may 3598 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate 3599 * slightly different code. 3600 */ 3601 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 3602 assert(is_static == callee()->is_static(), "correct intrinsic selection"); 3603 assert(!(is_virtual && is_static), "either virtual, special, or static"); 3604 3605 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 3606 3607 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 3608 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT); 3609 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 3610 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 3611 Node* obj = NULL; 3612 if (!is_static) { 3613 // Check for hashing null object 3614 obj = null_check_receiver(); 3615 if (stopped()) return true; // unconditionally null 3616 result_reg->init_req(_null_path, top()); 3617 result_val->init_req(_null_path, top()); 3618 } else { 3619 // Do a null check, and return zero if null. 3620 // System.identityHashCode(null) == 0 3621 obj = argument(0); 3622 Node* null_ctl = top(); 3623 obj = null_check_oop(obj, &null_ctl); 3624 result_reg->init_req(_null_path, null_ctl); 3625 result_val->init_req(_null_path, _gvn.intcon(0)); 3626 } 3627 3628 // Unconditionally null? Then return right away. 3629 if (stopped()) { 3630 set_control( result_reg->in(_null_path)); 3631 if (!stopped()) 3632 set_result(result_val->in(_null_path)); 3633 return true; 3634 } 3635 3636 // We only go to the fast case code if we pass a number of guards. The 3637 // paths which do not pass are accumulated in the slow_region. 3638 RegionNode* slow_region = new RegionNode(1); 3639 record_for_igvn(slow_region); 3640 3641 // If this is a virtual call, we generate a funny guard. We pull out 3642 // the vtable entry corresponding to hashCode() from the target object. 3643 // If the target method which we are calling happens to be the native 3644 // Object hashCode() method, we pass the guard. We do not need this 3645 // guard for non-virtual calls -- the caller is known to be the native 3646 // Object hashCode(). 3647 if (is_virtual) { 3648 // After null check, get the object's klass. 3649 Node* obj_klass = load_object_klass(obj); 3650 generate_virtual_guard(obj_klass, slow_region); 3651 } 3652 3653 // Get the header out of the object, use LoadMarkNode when available 3654 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 3655 // The control of the load must be NULL. Otherwise, the load can move before 3656 // the null check after castPP removal. 3657 Node* no_ctrl = NULL; 3658 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 3659 3660 // Test the header to see if it is unlocked. 3661 Node *lock_mask = _gvn.MakeConX(markWord::biased_lock_mask_in_place); 3662 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask)); 3663 Node *unlocked_val = _gvn.MakeConX(markWord::unlocked_value); 3664 Node *chk_unlocked = _gvn.transform(new CmpXNode( lmasked_header, unlocked_val)); 3665 Node *test_unlocked = _gvn.transform(new BoolNode( chk_unlocked, BoolTest::ne)); 3666 3667 generate_slow_guard(test_unlocked, slow_region); 3668 3669 // Get the hash value and check to see that it has been properly assigned. 3670 // We depend on hash_mask being at most 32 bits and avoid the use of 3671 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 3672 // vm: see markWord.hpp. 3673 Node *hash_mask = _gvn.intcon(markWord::hash_mask); 3674 Node *hash_shift = _gvn.intcon(markWord::hash_shift); 3675 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift)); 3676 // This hack lets the hash bits live anywhere in the mark object now, as long 3677 // as the shift drops the relevant bits into the low 32 bits. Note that 3678 // Java spec says that HashCode is an int so there's no point in capturing 3679 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 3680 hshifted_header = ConvX2I(hshifted_header); 3681 Node *hash_val = _gvn.transform(new AndINode(hshifted_header, hash_mask)); 3682 3683 Node *no_hash_val = _gvn.intcon(markWord::no_hash); 3684 Node *chk_assigned = _gvn.transform(new CmpINode( hash_val, no_hash_val)); 3685 Node *test_assigned = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq)); 3686 3687 generate_slow_guard(test_assigned, slow_region); 3688 3689 Node* init_mem = reset_memory(); 3690 // fill in the rest of the null path: 3691 result_io ->init_req(_null_path, i_o()); 3692 result_mem->init_req(_null_path, init_mem); 3693 3694 result_val->init_req(_fast_path, hash_val); 3695 result_reg->init_req(_fast_path, control()); 3696 result_io ->init_req(_fast_path, i_o()); 3697 result_mem->init_req(_fast_path, init_mem); 3698 3699 // Generate code for the slow case. We make a call to hashCode(). 3700 set_control(_gvn.transform(slow_region)); 3701 if (!stopped()) { 3702 // No need for PreserveJVMState, because we're using up the present state. 3703 set_all_memory(init_mem); 3704 vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 3705 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static); 3706 Node* slow_result = set_results_for_java_call(slow_call); 3707 // this->control() comes from set_results_for_java_call 3708 result_reg->init_req(_slow_path, control()); 3709 result_val->init_req(_slow_path, slow_result); 3710 result_io ->set_req(_slow_path, i_o()); 3711 result_mem ->set_req(_slow_path, reset_memory()); 3712 } 3713 3714 // Return the combined state. 3715 set_i_o( _gvn.transform(result_io) ); 3716 set_all_memory( _gvn.transform(result_mem)); 3717 3718 set_result(result_reg, result_val); 3719 return true; 3720 } 3721 3722 //---------------------------inline_native_getClass---------------------------- 3723 // public final native Class<?> java.lang.Object.getClass(); 3724 // 3725 // Build special case code for calls to getClass on an object. 3726 bool LibraryCallKit::inline_native_getClass() { 3727 Node* obj = null_check_receiver(); 3728 if (stopped()) return true; 3729 set_result(load_mirror_from_klass(load_object_klass(obj))); 3730 return true; 3731 } 3732 3733 //-----------------inline_native_Reflection_getCallerClass--------------------- 3734 // public static native Class<?> sun.reflect.Reflection.getCallerClass(); 3735 // 3736 // In the presence of deep enough inlining, getCallerClass() becomes a no-op. 3737 // 3738 // NOTE: This code must perform the same logic as JVM_GetCallerClass 3739 // in that it must skip particular security frames and checks for 3740 // caller sensitive methods. 3741 bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 3742 #ifndef PRODUCT 3743 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 3744 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 3745 } 3746 #endif 3747 3748 if (!jvms()->has_method()) { 3749 #ifndef PRODUCT 3750 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 3751 tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 3752 } 3753 #endif 3754 return false; 3755 } 3756 3757 // Walk back up the JVM state to find the caller at the required 3758 // depth. 3759 JVMState* caller_jvms = jvms(); 3760 3761 // Cf. JVM_GetCallerClass 3762 // NOTE: Start the loop at depth 1 because the current JVM state does 3763 // not include the Reflection.getCallerClass() frame. 3764 for (int n = 1; caller_jvms != NULL; caller_jvms = caller_jvms->caller(), n++) { 3765 ciMethod* m = caller_jvms->method(); 3766 switch (n) { 3767 case 0: 3768 fatal("current JVM state does not include the Reflection.getCallerClass frame"); 3769 break; 3770 case 1: 3771 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 3772 if (!m->caller_sensitive()) { 3773 #ifndef PRODUCT 3774 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 3775 tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 3776 } 3777 #endif 3778 return false; // bail-out; let JVM_GetCallerClass do the work 3779 } 3780 break; 3781 default: 3782 if (!m->is_ignored_by_security_stack_walk()) { 3783 // We have reached the desired frame; return the holder class. 3784 // Acquire method holder as java.lang.Class and push as constant. 3785 ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 3786 ciInstance* caller_mirror = caller_klass->java_mirror(); 3787 set_result(makecon(TypeInstPtr::make(caller_mirror))); 3788 3789 #ifndef PRODUCT 3790 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 3791 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()); 3792 tty->print_cr(" JVM state at this point:"); 3793 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 3794 ciMethod* m = jvms()->of_depth(i)->method(); 3795 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 3796 } 3797 } 3798 #endif 3799 return true; 3800 } 3801 break; 3802 } 3803 } 3804 3805 #ifndef PRODUCT 3806 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 3807 tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 3808 tty->print_cr(" JVM state at this point:"); 3809 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 3810 ciMethod* m = jvms()->of_depth(i)->method(); 3811 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 3812 } 3813 } 3814 #endif 3815 3816 return false; // bail-out; let JVM_GetCallerClass do the work 3817 } 3818 3819 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 3820 Node* arg = argument(0); 3821 Node* result = NULL; 3822 3823 switch (id) { 3824 case vmIntrinsics::_floatToRawIntBits: result = new MoveF2INode(arg); break; 3825 case vmIntrinsics::_intBitsToFloat: result = new MoveI2FNode(arg); break; 3826 case vmIntrinsics::_doubleToRawLongBits: result = new MoveD2LNode(arg); break; 3827 case vmIntrinsics::_longBitsToDouble: result = new MoveL2DNode(arg); break; 3828 3829 case vmIntrinsics::_doubleToLongBits: { 3830 // two paths (plus control) merge in a wood 3831 RegionNode *r = new RegionNode(3); 3832 Node *phi = new PhiNode(r, TypeLong::LONG); 3833 3834 Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg)); 3835 // Build the boolean node 3836 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 3837 3838 // Branch either way. 3839 // NaN case is less traveled, which makes all the difference. 3840 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 3841 Node *opt_isnan = _gvn.transform(ifisnan); 3842 assert( opt_isnan->is_If(), "Expect an IfNode"); 3843 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 3844 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 3845 3846 set_control(iftrue); 3847 3848 static const jlong nan_bits = CONST64(0x7ff8000000000000); 3849 Node *slow_result = longcon(nan_bits); // return NaN 3850 phi->init_req(1, _gvn.transform( slow_result )); 3851 r->init_req(1, iftrue); 3852 3853 // Else fall through 3854 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 3855 set_control(iffalse); 3856 3857 phi->init_req(2, _gvn.transform(new MoveD2LNode(arg))); 3858 r->init_req(2, iffalse); 3859 3860 // Post merge 3861 set_control(_gvn.transform(r)); 3862 record_for_igvn(r); 3863 3864 C->set_has_split_ifs(true); // Has chance for split-if optimization 3865 result = phi; 3866 assert(result->bottom_type()->isa_long(), "must be"); 3867 break; 3868 } 3869 3870 case vmIntrinsics::_floatToIntBits: { 3871 // two paths (plus control) merge in a wood 3872 RegionNode *r = new RegionNode(3); 3873 Node *phi = new PhiNode(r, TypeInt::INT); 3874 3875 Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg)); 3876 // Build the boolean node 3877 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 3878 3879 // Branch either way. 3880 // NaN case is less traveled, which makes all the difference. 3881 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 3882 Node *opt_isnan = _gvn.transform(ifisnan); 3883 assert( opt_isnan->is_If(), "Expect an IfNode"); 3884 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 3885 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 3886 3887 set_control(iftrue); 3888 3889 static const jint nan_bits = 0x7fc00000; 3890 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 3891 phi->init_req(1, _gvn.transform( slow_result )); 3892 r->init_req(1, iftrue); 3893 3894 // Else fall through 3895 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 3896 set_control(iffalse); 3897 3898 phi->init_req(2, _gvn.transform(new MoveF2INode(arg))); 3899 r->init_req(2, iffalse); 3900 3901 // Post merge 3902 set_control(_gvn.transform(r)); 3903 record_for_igvn(r); 3904 3905 C->set_has_split_ifs(true); // Has chance for split-if optimization 3906 result = phi; 3907 assert(result->bottom_type()->isa_int(), "must be"); 3908 break; 3909 } 3910 3911 default: 3912 fatal_unexpected_iid(id); 3913 break; 3914 } 3915 set_result(_gvn.transform(result)); 3916 return true; 3917 } 3918 3919 //----------------------inline_unsafe_copyMemory------------------------- 3920 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 3921 bool LibraryCallKit::inline_unsafe_copyMemory() { 3922 if (callee()->is_static()) return false; // caller must have the capability! 3923 null_check_receiver(); // null-check receiver 3924 if (stopped()) return true; 3925 3926 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 3927 3928 Node* src_ptr = argument(1); // type: oop 3929 Node* src_off = ConvL2X(argument(2)); // type: long 3930 Node* dst_ptr = argument(4); // type: oop 3931 Node* dst_off = ConvL2X(argument(5)); // type: long 3932 Node* size = ConvL2X(argument(7)); // type: long 3933 3934 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 3935 "fieldOffset must be byte-scaled"); 3936 3937 Node* src = make_unsafe_address(src_ptr, src_off, ACCESS_READ); 3938 Node* dst = make_unsafe_address(dst_ptr, dst_off, ACCESS_WRITE); 3939 3940 // Conservatively insert a memory barrier on all memory slices. 3941 // Do not let writes of the copy source or destination float below the copy. 3942 insert_mem_bar(Op_MemBarCPUOrder); 3943 3944 Node* thread = _gvn.transform(new ThreadLocalNode()); 3945 Node* doing_unsafe_access_addr = basic_plus_adr(top(), thread, in_bytes(JavaThread::doing_unsafe_access_offset())); 3946 BasicType doing_unsafe_access_bt = T_BYTE; 3947 assert((sizeof(bool) * CHAR_BIT) == 8, "not implemented"); 3948 3949 // update volatile field 3950 store_to_memory(control(), doing_unsafe_access_addr, intcon(1), doing_unsafe_access_bt, Compile::AliasIdxRaw, MemNode::unordered); 3951 3952 // Call it. Note that the length argument is not scaled. 3953 make_runtime_call(RC_LEAF|RC_NO_FP, 3954 OptoRuntime::fast_arraycopy_Type(), 3955 StubRoutines::unsafe_arraycopy(), 3956 "unsafe_arraycopy", 3957 TypeRawPtr::BOTTOM, 3958 src, dst, size XTOP); 3959 3960 store_to_memory(control(), doing_unsafe_access_addr, intcon(0), doing_unsafe_access_bt, Compile::AliasIdxRaw, MemNode::unordered); 3961 3962 // Do not let reads of the copy destination float above the copy. 3963 insert_mem_bar(Op_MemBarCPUOrder); 3964 3965 return true; 3966 } 3967 3968 //------------------------clone_coping----------------------------------- 3969 // Helper function for inline_native_clone. 3970 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) { 3971 assert(obj_size != NULL, ""); 3972 Node* raw_obj = alloc_obj->in(1); 3973 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 3974 3975 AllocateNode* alloc = NULL; 3976 if (ReduceBulkZeroing) { 3977 // We will be completely responsible for initializing this object - 3978 // mark Initialize node as complete. 3979 alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 3980 // The object was just allocated - there should be no any stores! 3981 guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), ""); 3982 // Mark as complete_with_arraycopy so that on AllocateNode 3983 // expansion, we know this AllocateNode is initialized by an array 3984 // copy and a StoreStore barrier exists after the array copy. 3985 alloc->initialization()->set_complete_with_arraycopy(); 3986 } 3987 3988 Node* size = _gvn.transform(obj_size); 3989 access_clone(obj, alloc_obj, size, is_array); 3990 3991 // Do not let reads from the cloned object float above the arraycopy. 3992 if (alloc != NULL) { 3993 // Do not let stores that initialize this object be reordered with 3994 // a subsequent store that would make this object accessible by 3995 // other threads. 3996 // Record what AllocateNode this StoreStore protects so that 3997 // escape analysis can go from the MemBarStoreStoreNode to the 3998 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 3999 // based on the escape status of the AllocateNode. 4000 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 4001 } else { 4002 insert_mem_bar(Op_MemBarCPUOrder); 4003 } 4004 } 4005 4006 //------------------------inline_native_clone---------------------------- 4007 // protected native Object java.lang.Object.clone(); 4008 // 4009 // Here are the simple edge cases: 4010 // null receiver => normal trap 4011 // virtual and clone was overridden => slow path to out-of-line clone 4012 // not cloneable or finalizer => slow path to out-of-line Object.clone 4013 // 4014 // The general case has two steps, allocation and copying. 4015 // Allocation has two cases, and uses GraphKit::new_instance or new_array. 4016 // 4017 // Copying also has two cases, oop arrays and everything else. 4018 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 4019 // Everything else uses the tight inline loop supplied by CopyArrayNode. 4020 // 4021 // These steps fold up nicely if and when the cloned object's klass 4022 // can be sharply typed as an object array, a type array, or an instance. 4023 // 4024 bool LibraryCallKit::inline_native_clone(bool is_virtual) { 4025 PhiNode* result_val; 4026 4027 // Set the reexecute bit for the interpreter to reexecute 4028 // the bytecode that invokes Object.clone if deoptimization happens. 4029 { PreserveReexecuteState preexecs(this); 4030 jvms()->set_should_reexecute(true); 4031 4032 Node* obj = null_check_receiver(); 4033 if (stopped()) return true; 4034 4035 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 4036 4037 // If we are going to clone an instance, we need its exact type to 4038 // know the number and types of fields to convert the clone to 4039 // loads/stores. Maybe a speculative type can help us. 4040 if (!obj_type->klass_is_exact() && 4041 obj_type->speculative_type() != NULL && 4042 obj_type->speculative_type()->is_instance_klass()) { 4043 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass(); 4044 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem && 4045 !spec_ik->has_injected_fields()) { 4046 ciKlass* k = obj_type->klass(); 4047 if (!k->is_instance_klass() || 4048 k->as_instance_klass()->is_interface() || 4049 k->as_instance_klass()->has_subklass()) { 4050 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false); 4051 } 4052 } 4053 } 4054 4055 // Conservatively insert a memory barrier on all memory slices. 4056 // Do not let writes into the original float below the clone. 4057 insert_mem_bar(Op_MemBarCPUOrder); 4058 4059 // paths into result_reg: 4060 enum { 4061 _slow_path = 1, // out-of-line call to clone method (virtual or not) 4062 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 4063 _array_path, // plain array allocation, plus arrayof_long_arraycopy 4064 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 4065 PATH_LIMIT 4066 }; 4067 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 4068 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 4069 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); 4070 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 4071 record_for_igvn(result_reg); 4072 4073 Node* obj_klass = load_object_klass(obj); 4074 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); 4075 if (array_ctl != NULL) { 4076 // It's an array. 4077 PreserveJVMState pjvms(this); 4078 set_control(array_ctl); 4079 Node* obj_length = load_array_length(obj); 4080 Node* obj_size = NULL; 4081 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push 4082 4083 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 4084 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Parsing)) { 4085 // If it is an oop array, it requires very special treatment, 4086 // because gc barriers are required when accessing the array. 4087 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); 4088 if (is_obja != NULL) { 4089 PreserveJVMState pjvms2(this); 4090 set_control(is_obja); 4091 // Generate a direct call to the right arraycopy function(s). 4092 Node* alloc = tightly_coupled_allocation(alloc_obj, NULL); 4093 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false); 4094 ac->set_clone_oop_array(); 4095 Node* n = _gvn.transform(ac); 4096 assert(n == ac, "cannot disappear"); 4097 ac->connect_outputs(this); 4098 4099 result_reg->init_req(_objArray_path, control()); 4100 result_val->init_req(_objArray_path, alloc_obj); 4101 result_i_o ->set_req(_objArray_path, i_o()); 4102 result_mem ->set_req(_objArray_path, reset_memory()); 4103 } 4104 } 4105 // Otherwise, there are no barriers to worry about. 4106 // (We can dispense with card marks if we know the allocation 4107 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 4108 // causes the non-eden paths to take compensating steps to 4109 // simulate a fresh allocation, so that no further 4110 // card marks are required in compiled code to initialize 4111 // the object.) 4112 4113 if (!stopped()) { 4114 copy_to_clone(obj, alloc_obj, obj_size, true); 4115 4116 // Present the results of the copy. 4117 result_reg->init_req(_array_path, control()); 4118 result_val->init_req(_array_path, alloc_obj); 4119 result_i_o ->set_req(_array_path, i_o()); 4120 result_mem ->set_req(_array_path, reset_memory()); 4121 } 4122 } 4123 4124 // We only go to the instance fast case code if we pass a number of guards. 4125 // The paths which do not pass are accumulated in the slow_region. 4126 RegionNode* slow_region = new RegionNode(1); 4127 record_for_igvn(slow_region); 4128 if (!stopped()) { 4129 // It's an instance (we did array above). Make the slow-path tests. 4130 // If this is a virtual call, we generate a funny guard. We grab 4131 // the vtable entry corresponding to clone() from the target object. 4132 // If the target method which we are calling happens to be the 4133 // Object clone() method, we pass the guard. We do not need this 4134 // guard for non-virtual calls; the caller is known to be the native 4135 // Object clone(). 4136 if (is_virtual) { 4137 generate_virtual_guard(obj_klass, slow_region); 4138 } 4139 4140 // The object must be easily cloneable and must not have a finalizer. 4141 // Both of these conditions may be checked in a single test. 4142 // We could optimize the test further, but we don't care. 4143 generate_access_flags_guard(obj_klass, 4144 // Test both conditions: 4145 JVM_ACC_IS_CLONEABLE_FAST | JVM_ACC_HAS_FINALIZER, 4146 // Must be cloneable but not finalizer: 4147 JVM_ACC_IS_CLONEABLE_FAST, 4148 slow_region); 4149 } 4150 4151 if (!stopped()) { 4152 // It's an instance, and it passed the slow-path tests. 4153 PreserveJVMState pjvms(this); 4154 Node* obj_size = NULL; 4155 // Need to deoptimize on exception from allocation since Object.clone intrinsic 4156 // is reexecuted if deoptimization occurs and there could be problems when merging 4157 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). 4158 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); 4159 4160 copy_to_clone(obj, alloc_obj, obj_size, false); 4161 4162 // Present the results of the slow call. 4163 result_reg->init_req(_instance_path, control()); 4164 result_val->init_req(_instance_path, alloc_obj); 4165 result_i_o ->set_req(_instance_path, i_o()); 4166 result_mem ->set_req(_instance_path, reset_memory()); 4167 } 4168 4169 // Generate code for the slow case. We make a call to clone(). 4170 set_control(_gvn.transform(slow_region)); 4171 if (!stopped()) { 4172 PreserveJVMState pjvms(this); 4173 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); 4174 // We need to deoptimize on exception (see comment above) 4175 Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true); 4176 // this->control() comes from set_results_for_java_call 4177 result_reg->init_req(_slow_path, control()); 4178 result_val->init_req(_slow_path, slow_result); 4179 result_i_o ->set_req(_slow_path, i_o()); 4180 result_mem ->set_req(_slow_path, reset_memory()); 4181 } 4182 4183 // Return the combined state. 4184 set_control( _gvn.transform(result_reg)); 4185 set_i_o( _gvn.transform(result_i_o)); 4186 set_all_memory( _gvn.transform(result_mem)); 4187 } // original reexecute is set back here 4188 4189 set_result(_gvn.transform(result_val)); 4190 return true; 4191 } 4192 4193 // If we have a tightly coupled allocation, the arraycopy may take care 4194 // of the array initialization. If one of the guards we insert between 4195 // the allocation and the arraycopy causes a deoptimization, an 4196 // unitialized array will escape the compiled method. To prevent that 4197 // we set the JVM state for uncommon traps between the allocation and 4198 // the arraycopy to the state before the allocation so, in case of 4199 // deoptimization, we'll reexecute the allocation and the 4200 // initialization. 4201 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) { 4202 if (alloc != NULL) { 4203 ciMethod* trap_method = alloc->jvms()->method(); 4204 int trap_bci = alloc->jvms()->bci(); 4205 4206 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 4207 !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) { 4208 // Make sure there's no store between the allocation and the 4209 // arraycopy otherwise visible side effects could be rexecuted 4210 // in case of deoptimization and cause incorrect execution. 4211 bool no_interfering_store = true; 4212 Node* mem = alloc->in(TypeFunc::Memory); 4213 if (mem->is_MergeMem()) { 4214 for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) { 4215 Node* n = mms.memory(); 4216 if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 4217 assert(n->is_Store(), "what else?"); 4218 no_interfering_store = false; 4219 break; 4220 } 4221 } 4222 } else { 4223 for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { 4224 Node* n = mms.memory(); 4225 if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 4226 assert(n->is_Store(), "what else?"); 4227 no_interfering_store = false; 4228 break; 4229 } 4230 } 4231 } 4232 4233 if (no_interfering_store) { 4234 JVMState* old_jvms = alloc->jvms()->clone_shallow(C); 4235 uint size = alloc->req(); 4236 SafePointNode* sfpt = new SafePointNode(size, old_jvms); 4237 old_jvms->set_map(sfpt); 4238 for (uint i = 0; i < size; i++) { 4239 sfpt->init_req(i, alloc->in(i)); 4240 } 4241 // re-push array length for deoptimization 4242 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), alloc->in(AllocateNode::ALength)); 4243 old_jvms->set_sp(old_jvms->sp()+1); 4244 old_jvms->set_monoff(old_jvms->monoff()+1); 4245 old_jvms->set_scloff(old_jvms->scloff()+1); 4246 old_jvms->set_endoff(old_jvms->endoff()+1); 4247 old_jvms->set_should_reexecute(true); 4248 4249 sfpt->set_i_o(map()->i_o()); 4250 sfpt->set_memory(map()->memory()); 4251 sfpt->set_control(map()->control()); 4252 4253 JVMState* saved_jvms = jvms(); 4254 saved_reexecute_sp = _reexecute_sp; 4255 4256 set_jvms(sfpt->jvms()); 4257 _reexecute_sp = jvms()->sp(); 4258 4259 return saved_jvms; 4260 } 4261 } 4262 } 4263 return NULL; 4264 } 4265 4266 // In case of a deoptimization, we restart execution at the 4267 // allocation, allocating a new array. We would leave an uninitialized 4268 // array in the heap that GCs wouldn't expect. Move the allocation 4269 // after the traps so we don't allocate the array if we 4270 // deoptimize. This is possible because tightly_coupled_allocation() 4271 // guarantees there's no observer of the allocated array at this point 4272 // and the control flow is simple enough. 4273 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, 4274 int saved_reexecute_sp, uint new_idx) { 4275 if (saved_jvms != NULL && !stopped()) { 4276 assert(alloc != NULL, "only with a tightly coupled allocation"); 4277 // restore JVM state to the state at the arraycopy 4278 saved_jvms->map()->set_control(map()->control()); 4279 assert(saved_jvms->map()->memory() == map()->memory(), "memory state changed?"); 4280 assert(saved_jvms->map()->i_o() == map()->i_o(), "IO state changed?"); 4281 // If we've improved the types of some nodes (null check) while 4282 // emitting the guards, propagate them to the current state 4283 map()->replaced_nodes().apply(saved_jvms->map(), new_idx); 4284 set_jvms(saved_jvms); 4285 _reexecute_sp = saved_reexecute_sp; 4286 4287 // Remove the allocation from above the guards 4288 CallProjections callprojs; 4289 alloc->extract_projections(&callprojs, true); 4290 InitializeNode* init = alloc->initialization(); 4291 Node* alloc_mem = alloc->in(TypeFunc::Memory); 4292 C->gvn_replace_by(callprojs.fallthrough_ioproj, alloc->in(TypeFunc::I_O)); 4293 C->gvn_replace_by(init->proj_out(TypeFunc::Memory), alloc_mem); 4294 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0)); 4295 4296 // move the allocation here (after the guards) 4297 _gvn.hash_delete(alloc); 4298 alloc->set_req(TypeFunc::Control, control()); 4299 alloc->set_req(TypeFunc::I_O, i_o()); 4300 Node *mem = reset_memory(); 4301 set_all_memory(mem); 4302 alloc->set_req(TypeFunc::Memory, mem); 4303 set_control(init->proj_out_or_null(TypeFunc::Control)); 4304 set_i_o(callprojs.fallthrough_ioproj); 4305 4306 // Update memory as done in GraphKit::set_output_for_allocation() 4307 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength)); 4308 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type(); 4309 if (ary_type->isa_aryptr() && length_type != NULL) { 4310 ary_type = ary_type->is_aryptr()->cast_to_size(length_type); 4311 } 4312 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot); 4313 int elemidx = C->get_alias_index(telemref); 4314 set_memory(init->proj_out_or_null(TypeFunc::Memory), Compile::AliasIdxRaw); 4315 set_memory(init->proj_out_or_null(TypeFunc::Memory), elemidx); 4316 4317 Node* allocx = _gvn.transform(alloc); 4318 assert(allocx == alloc, "where has the allocation gone?"); 4319 assert(dest->is_CheckCastPP(), "not an allocation result?"); 4320 4321 _gvn.hash_delete(dest); 4322 dest->set_req(0, control()); 4323 Node* destx = _gvn.transform(dest); 4324 assert(destx == dest, "where has the allocation result gone?"); 4325 } 4326 } 4327 4328 4329 //------------------------------inline_arraycopy----------------------- 4330 // public static native void java.lang.System.arraycopy(Object src, int srcPos, 4331 // Object dest, int destPos, 4332 // int length); 4333 bool LibraryCallKit::inline_arraycopy() { 4334 // Get the arguments. 4335 Node* src = argument(0); // type: oop 4336 Node* src_offset = argument(1); // type: int 4337 Node* dest = argument(2); // type: oop 4338 Node* dest_offset = argument(3); // type: int 4339 Node* length = argument(4); // type: int 4340 4341 uint new_idx = C->unique(); 4342 4343 // Check for allocation before we add nodes that would confuse 4344 // tightly_coupled_allocation() 4345 AllocateArrayNode* alloc = tightly_coupled_allocation(dest, NULL); 4346 4347 int saved_reexecute_sp = -1; 4348 JVMState* saved_jvms = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp); 4349 // See arraycopy_restore_alloc_state() comment 4350 // if alloc == NULL we don't have to worry about a tightly coupled allocation so we can emit all needed guards 4351 // if saved_jvms != NULL (then alloc != NULL) then we can handle guards and a tightly coupled allocation 4352 // if saved_jvms == NULL and alloc != NULL, we can't emit any guards 4353 bool can_emit_guards = (alloc == NULL || saved_jvms != NULL); 4354 4355 // The following tests must be performed 4356 // (1) src and dest are arrays. 4357 // (2) src and dest arrays must have elements of the same BasicType 4358 // (3) src and dest must not be null. 4359 // (4) src_offset must not be negative. 4360 // (5) dest_offset must not be negative. 4361 // (6) length must not be negative. 4362 // (7) src_offset + length must not exceed length of src. 4363 // (8) dest_offset + length must not exceed length of dest. 4364 // (9) each element of an oop array must be assignable 4365 4366 // (3) src and dest must not be null. 4367 // always do this here because we need the JVM state for uncommon traps 4368 Node* null_ctl = top(); 4369 src = saved_jvms != NULL ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY); 4370 assert(null_ctl->is_top(), "no null control here"); 4371 dest = null_check(dest, T_ARRAY); 4372 4373 if (!can_emit_guards) { 4374 // if saved_jvms == NULL and alloc != NULL, we don't emit any 4375 // guards but the arraycopy node could still take advantage of a 4376 // tightly allocated allocation. tightly_coupled_allocation() is 4377 // called again to make sure it takes the null check above into 4378 // account: the null check is mandatory and if it caused an 4379 // uncommon trap to be emitted then the allocation can't be 4380 // considered tightly coupled in this context. 4381 alloc = tightly_coupled_allocation(dest, NULL); 4382 } 4383 4384 bool validated = false; 4385 4386 const Type* src_type = _gvn.type(src); 4387 const Type* dest_type = _gvn.type(dest); 4388 const TypeAryPtr* top_src = src_type->isa_aryptr(); 4389 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 4390 4391 // Do we have the type of src? 4392 bool has_src = (top_src != NULL && top_src->klass() != NULL); 4393 // Do we have the type of dest? 4394 bool has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4395 // Is the type for src from speculation? 4396 bool src_spec = false; 4397 // Is the type for dest from speculation? 4398 bool dest_spec = false; 4399 4400 if ((!has_src || !has_dest) && can_emit_guards) { 4401 // We don't have sufficient type information, let's see if 4402 // speculative types can help. We need to have types for both src 4403 // and dest so that it pays off. 4404 4405 // Do we already have or could we have type information for src 4406 bool could_have_src = has_src; 4407 // Do we already have or could we have type information for dest 4408 bool could_have_dest = has_dest; 4409 4410 ciKlass* src_k = NULL; 4411 if (!has_src) { 4412 src_k = src_type->speculative_type_not_null(); 4413 if (src_k != NULL && src_k->is_array_klass()) { 4414 could_have_src = true; 4415 } 4416 } 4417 4418 ciKlass* dest_k = NULL; 4419 if (!has_dest) { 4420 dest_k = dest_type->speculative_type_not_null(); 4421 if (dest_k != NULL && dest_k->is_array_klass()) { 4422 could_have_dest = true; 4423 } 4424 } 4425 4426 if (could_have_src && could_have_dest) { 4427 // This is going to pay off so emit the required guards 4428 if (!has_src) { 4429 src = maybe_cast_profiled_obj(src, src_k, true); 4430 src_type = _gvn.type(src); 4431 top_src = src_type->isa_aryptr(); 4432 has_src = (top_src != NULL && top_src->klass() != NULL); 4433 src_spec = true; 4434 } 4435 if (!has_dest) { 4436 dest = maybe_cast_profiled_obj(dest, dest_k, true); 4437 dest_type = _gvn.type(dest); 4438 top_dest = dest_type->isa_aryptr(); 4439 has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4440 dest_spec = true; 4441 } 4442 } 4443 } 4444 4445 if (has_src && has_dest && can_emit_guards) { 4446 BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type(); 4447 BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type(); 4448 if (is_reference_type(src_elem)) src_elem = T_OBJECT; 4449 if (is_reference_type(dest_elem)) dest_elem = T_OBJECT; 4450 4451 if (src_elem == dest_elem && src_elem == T_OBJECT) { 4452 // If both arrays are object arrays then having the exact types 4453 // for both will remove the need for a subtype check at runtime 4454 // before the call and may make it possible to pick a faster copy 4455 // routine (without a subtype check on every element) 4456 // Do we have the exact type of src? 4457 bool could_have_src = src_spec; 4458 // Do we have the exact type of dest? 4459 bool could_have_dest = dest_spec; 4460 ciKlass* src_k = top_src->klass(); 4461 ciKlass* dest_k = top_dest->klass(); 4462 if (!src_spec) { 4463 src_k = src_type->speculative_type_not_null(); 4464 if (src_k != NULL && src_k->is_array_klass()) { 4465 could_have_src = true; 4466 } 4467 } 4468 if (!dest_spec) { 4469 dest_k = dest_type->speculative_type_not_null(); 4470 if (dest_k != NULL && dest_k->is_array_klass()) { 4471 could_have_dest = true; 4472 } 4473 } 4474 if (could_have_src && could_have_dest) { 4475 // If we can have both exact types, emit the missing guards 4476 if (could_have_src && !src_spec) { 4477 src = maybe_cast_profiled_obj(src, src_k, true); 4478 } 4479 if (could_have_dest && !dest_spec) { 4480 dest = maybe_cast_profiled_obj(dest, dest_k, true); 4481 } 4482 } 4483 } 4484 } 4485 4486 ciMethod* trap_method = method(); 4487 int trap_bci = bci(); 4488 if (saved_jvms != NULL) { 4489 trap_method = alloc->jvms()->method(); 4490 trap_bci = alloc->jvms()->bci(); 4491 } 4492 4493 bool negative_length_guard_generated = false; 4494 4495 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 4496 can_emit_guards && 4497 !src->is_top() && !dest->is_top()) { 4498 // validate arguments: enables transformation the ArrayCopyNode 4499 validated = true; 4500 4501 RegionNode* slow_region = new RegionNode(1); 4502 record_for_igvn(slow_region); 4503 4504 // (1) src and dest are arrays. 4505 generate_non_array_guard(load_object_klass(src), slow_region); 4506 generate_non_array_guard(load_object_klass(dest), slow_region); 4507 4508 // (2) src and dest arrays must have elements of the same BasicType 4509 // done at macro expansion or at Ideal transformation time 4510 4511 // (4) src_offset must not be negative. 4512 generate_negative_guard(src_offset, slow_region); 4513 4514 // (5) dest_offset must not be negative. 4515 generate_negative_guard(dest_offset, slow_region); 4516 4517 // (7) src_offset + length must not exceed length of src. 4518 generate_limit_guard(src_offset, length, 4519 load_array_length(src), 4520 slow_region); 4521 4522 // (8) dest_offset + length must not exceed length of dest. 4523 generate_limit_guard(dest_offset, length, 4524 load_array_length(dest), 4525 slow_region); 4526 4527 // (6) length must not be negative. 4528 // This is also checked in generate_arraycopy() during macro expansion, but 4529 // we also have to check it here for the case where the ArrayCopyNode will 4530 // be eliminated by Escape Analysis. 4531 if (EliminateAllocations) { 4532 generate_negative_guard(length, slow_region); 4533 negative_length_guard_generated = true; 4534 } 4535 4536 // (9) each element of an oop array must be assignable 4537 Node* dest_klass = load_object_klass(dest); 4538 if (src != dest) { 4539 Node* not_subtype_ctrl = gen_subtype_check(src, dest_klass); 4540 4541 if (not_subtype_ctrl != top()) { 4542 PreserveJVMState pjvms(this); 4543 set_control(not_subtype_ctrl); 4544 uncommon_trap(Deoptimization::Reason_intrinsic, 4545 Deoptimization::Action_make_not_entrant); 4546 assert(stopped(), "Should be stopped"); 4547 } 4548 } 4549 { 4550 PreserveJVMState pjvms(this); 4551 set_control(_gvn.transform(slow_region)); 4552 uncommon_trap(Deoptimization::Reason_intrinsic, 4553 Deoptimization::Action_make_not_entrant); 4554 assert(stopped(), "Should be stopped"); 4555 } 4556 4557 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr(); 4558 const Type *toop = TypeOopPtr::make_from_klass(dest_klass_t->klass()); 4559 src = _gvn.transform(new CheckCastPPNode(control(), src, toop)); 4560 } 4561 4562 arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx); 4563 4564 if (stopped()) { 4565 return true; 4566 } 4567 4568 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, src, src_offset, dest, dest_offset, length, alloc != NULL, negative_length_guard_generated, 4569 // Create LoadRange and LoadKlass nodes for use during macro expansion here 4570 // so the compiler has a chance to eliminate them: during macro expansion, 4571 // we have to set their control (CastPP nodes are eliminated). 4572 load_object_klass(src), load_object_klass(dest), 4573 load_array_length(src), load_array_length(dest)); 4574 4575 ac->set_arraycopy(validated); 4576 4577 Node* n = _gvn.transform(ac); 4578 if (n == ac) { 4579 ac->connect_outputs(this); 4580 } else { 4581 assert(validated, "shouldn't transform if all arguments not validated"); 4582 set_all_memory(n); 4583 } 4584 clear_upper_avx(); 4585 4586 4587 return true; 4588 } 4589 4590 4591 // Helper function which determines if an arraycopy immediately follows 4592 // an allocation, with no intervening tests or other escapes for the object. 4593 AllocateArrayNode* 4594 LibraryCallKit::tightly_coupled_allocation(Node* ptr, 4595 RegionNode* slow_region) { 4596 if (stopped()) return NULL; // no fast path 4597 if (C->AliasLevel() == 0) return NULL; // no MergeMems around 4598 4599 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn); 4600 if (alloc == NULL) return NULL; 4601 4602 Node* rawmem = memory(Compile::AliasIdxRaw); 4603 // Is the allocation's memory state untouched? 4604 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 4605 // Bail out if there have been raw-memory effects since the allocation. 4606 // (Example: There might have been a call or safepoint.) 4607 return NULL; 4608 } 4609 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 4610 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 4611 return NULL; 4612 } 4613 4614 // There must be no unexpected observers of this allocation. 4615 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 4616 Node* obs = ptr->fast_out(i); 4617 if (obs != this->map()) { 4618 return NULL; 4619 } 4620 } 4621 4622 // This arraycopy must unconditionally follow the allocation of the ptr. 4623 Node* alloc_ctl = ptr->in(0); 4624 Node* ctl = control(); 4625 while (ctl != alloc_ctl) { 4626 // There may be guards which feed into the slow_region. 4627 // Any other control flow means that we might not get a chance 4628 // to finish initializing the allocated object. 4629 if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) { 4630 IfNode* iff = ctl->in(0)->as_If(); 4631 Node* not_ctl = iff->proj_out_or_null(1 - ctl->as_Proj()->_con); 4632 assert(not_ctl != NULL && not_ctl != ctl, "found alternate"); 4633 if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) { 4634 ctl = iff->in(0); // This test feeds the known slow_region. 4635 continue; 4636 } 4637 // One more try: Various low-level checks bottom out in 4638 // uncommon traps. If the debug-info of the trap omits 4639 // any reference to the allocation, as we've already 4640 // observed, then there can be no objection to the trap. 4641 bool found_trap = false; 4642 for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) { 4643 Node* obs = not_ctl->fast_out(j); 4644 if (obs->in(0) == not_ctl && obs->is_Call() && 4645 (obs->as_Call()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point())) { 4646 found_trap = true; break; 4647 } 4648 } 4649 if (found_trap) { 4650 ctl = iff->in(0); // This test feeds a harmless uncommon trap. 4651 continue; 4652 } 4653 } 4654 return NULL; 4655 } 4656 4657 // If we get this far, we have an allocation which immediately 4658 // precedes the arraycopy, and we can take over zeroing the new object. 4659 // The arraycopy will finish the initialization, and provide 4660 // a new control state to which we will anchor the destination pointer. 4661 4662 return alloc; 4663 } 4664 4665 //-------------inline_encodeISOArray----------------------------------- 4666 // encode char[] to byte[] in ISO_8859_1 4667 bool LibraryCallKit::inline_encodeISOArray() { 4668 assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 4669 // no receiver since it is static method 4670 Node *src = argument(0); 4671 Node *src_offset = argument(1); 4672 Node *dst = argument(2); 4673 Node *dst_offset = argument(3); 4674 Node *length = argument(4); 4675 4676 src = must_be_not_null(src, true); 4677 dst = must_be_not_null(dst, true); 4678 4679 const Type* src_type = src->Value(&_gvn); 4680 const Type* dst_type = dst->Value(&_gvn); 4681 const TypeAryPtr* top_src = src_type->isa_aryptr(); 4682 const TypeAryPtr* top_dest = dst_type->isa_aryptr(); 4683 if (top_src == NULL || top_src->klass() == NULL || 4684 top_dest == NULL || top_dest->klass() == NULL) { 4685 // failed array check 4686 return false; 4687 } 4688 4689 // Figure out the size and type of the elements we will be copying. 4690 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4691 BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4692 if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) { 4693 return false; 4694 } 4695 4696 Node* src_start = array_element_address(src, src_offset, T_CHAR); 4697 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 4698 // 'src_start' points to src array + scaled offset 4699 // 'dst_start' points to dst array + scaled offset 4700 4701 const TypeAryPtr* mtype = TypeAryPtr::BYTES; 4702 Node* enc = new EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length); 4703 enc = _gvn.transform(enc); 4704 Node* res_mem = _gvn.transform(new SCMemProjNode(enc)); 4705 set_memory(res_mem, mtype); 4706 set_result(enc); 4707 clear_upper_avx(); 4708 4709 return true; 4710 } 4711 4712 //-------------inline_multiplyToLen----------------------------------- 4713 bool LibraryCallKit::inline_multiplyToLen() { 4714 assert(UseMultiplyToLenIntrinsic, "not implemented on this platform"); 4715 4716 address stubAddr = StubRoutines::multiplyToLen(); 4717 if (stubAddr == NULL) { 4718 return false; // Intrinsic's stub is not implemented on this platform 4719 } 4720 const char* stubName = "multiplyToLen"; 4721 4722 assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters"); 4723 4724 // no receiver because it is a static method 4725 Node* x = argument(0); 4726 Node* xlen = argument(1); 4727 Node* y = argument(2); 4728 Node* ylen = argument(3); 4729 Node* z = argument(4); 4730 4731 x = must_be_not_null(x, true); 4732 y = must_be_not_null(y, true); 4733 4734 const Type* x_type = x->Value(&_gvn); 4735 const Type* y_type = y->Value(&_gvn); 4736 const TypeAryPtr* top_x = x_type->isa_aryptr(); 4737 const TypeAryPtr* top_y = y_type->isa_aryptr(); 4738 if (top_x == NULL || top_x->klass() == NULL || 4739 top_y == NULL || top_y->klass() == NULL) { 4740 // failed array check 4741 return false; 4742 } 4743 4744 BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4745 BasicType y_elem = y_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4746 if (x_elem != T_INT || y_elem != T_INT) { 4747 return false; 4748 } 4749 4750 // Set the original stack and the reexecute bit for the interpreter to reexecute 4751 // the bytecode that invokes BigInteger.multiplyToLen() if deoptimization happens 4752 // on the return from z array allocation in runtime. 4753 { PreserveReexecuteState preexecs(this); 4754 jvms()->set_should_reexecute(true); 4755 4756 Node* x_start = array_element_address(x, intcon(0), x_elem); 4757 Node* y_start = array_element_address(y, intcon(0), y_elem); 4758 // 'x_start' points to x array + scaled xlen 4759 // 'y_start' points to y array + scaled ylen 4760 4761 // Allocate the result array 4762 Node* zlen = _gvn.transform(new AddINode(xlen, ylen)); 4763 ciKlass* klass = ciTypeArrayKlass::make(T_INT); 4764 Node* klass_node = makecon(TypeKlassPtr::make(klass)); 4765 4766 IdealKit ideal(this); 4767 4768 #define __ ideal. 4769 Node* one = __ ConI(1); 4770 Node* zero = __ ConI(0); 4771 IdealVariable need_alloc(ideal), z_alloc(ideal); __ declarations_done(); 4772 __ set(need_alloc, zero); 4773 __ set(z_alloc, z); 4774 __ if_then(z, BoolTest::eq, null()); { 4775 __ increment (need_alloc, one); 4776 } __ else_(); { 4777 // Update graphKit memory and control from IdealKit. 4778 sync_kit(ideal); 4779 Node *cast = new CastPPNode(z, TypePtr::NOTNULL); 4780 cast->init_req(0, control()); 4781 _gvn.set_type(cast, cast->bottom_type()); 4782 C->record_for_igvn(cast); 4783 4784 Node* zlen_arg = load_array_length(cast); 4785 // Update IdealKit memory and control from graphKit. 4786 __ sync_kit(this); 4787 __ if_then(zlen_arg, BoolTest::lt, zlen); { 4788 __ increment (need_alloc, one); 4789 } __ end_if(); 4790 } __ end_if(); 4791 4792 __ if_then(__ value(need_alloc), BoolTest::ne, zero); { 4793 // Update graphKit memory and control from IdealKit. 4794 sync_kit(ideal); 4795 Node * narr = new_array(klass_node, zlen, 1); 4796 // Update IdealKit memory and control from graphKit. 4797 __ sync_kit(this); 4798 __ set(z_alloc, narr); 4799 } __ end_if(); 4800 4801 sync_kit(ideal); 4802 z = __ value(z_alloc); 4803 // Can't use TypeAryPtr::INTS which uses Bottom offset. 4804 _gvn.set_type(z, TypeOopPtr::make_from_klass(klass)); 4805 // Final sync IdealKit and GraphKit. 4806 final_sync(ideal); 4807 #undef __ 4808 4809 Node* z_start = array_element_address(z, intcon(0), T_INT); 4810 4811 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 4812 OptoRuntime::multiplyToLen_Type(), 4813 stubAddr, stubName, TypePtr::BOTTOM, 4814 x_start, xlen, y_start, ylen, z_start, zlen); 4815 } // original reexecute is set back here 4816 4817 C->set_has_split_ifs(true); // Has chance for split-if optimization 4818 set_result(z); 4819 return true; 4820 } 4821 4822 //-------------inline_squareToLen------------------------------------ 4823 bool LibraryCallKit::inline_squareToLen() { 4824 assert(UseSquareToLenIntrinsic, "not implemented on this platform"); 4825 4826 address stubAddr = StubRoutines::squareToLen(); 4827 if (stubAddr == NULL) { 4828 return false; // Intrinsic's stub is not implemented on this platform 4829 } 4830 const char* stubName = "squareToLen"; 4831 4832 assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters"); 4833 4834 Node* x = argument(0); 4835 Node* len = argument(1); 4836 Node* z = argument(2); 4837 Node* zlen = argument(3); 4838 4839 x = must_be_not_null(x, true); 4840 z = must_be_not_null(z, true); 4841 4842 const Type* x_type = x->Value(&_gvn); 4843 const Type* z_type = z->Value(&_gvn); 4844 const TypeAryPtr* top_x = x_type->isa_aryptr(); 4845 const TypeAryPtr* top_z = z_type->isa_aryptr(); 4846 if (top_x == NULL || top_x->klass() == NULL || 4847 top_z == NULL || top_z->klass() == NULL) { 4848 // failed array check 4849 return false; 4850 } 4851 4852 BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4853 BasicType z_elem = z_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4854 if (x_elem != T_INT || z_elem != T_INT) { 4855 return false; 4856 } 4857 4858 4859 Node* x_start = array_element_address(x, intcon(0), x_elem); 4860 Node* z_start = array_element_address(z, intcon(0), z_elem); 4861 4862 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 4863 OptoRuntime::squareToLen_Type(), 4864 stubAddr, stubName, TypePtr::BOTTOM, 4865 x_start, len, z_start, zlen); 4866 4867 set_result(z); 4868 return true; 4869 } 4870 4871 //-------------inline_mulAdd------------------------------------------ 4872 bool LibraryCallKit::inline_mulAdd() { 4873 assert(UseMulAddIntrinsic, "not implemented on this platform"); 4874 4875 address stubAddr = StubRoutines::mulAdd(); 4876 if (stubAddr == NULL) { 4877 return false; // Intrinsic's stub is not implemented on this platform 4878 } 4879 const char* stubName = "mulAdd"; 4880 4881 assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters"); 4882 4883 Node* out = argument(0); 4884 Node* in = argument(1); 4885 Node* offset = argument(2); 4886 Node* len = argument(3); 4887 Node* k = argument(4); 4888 4889 out = must_be_not_null(out, true); 4890 4891 const Type* out_type = out->Value(&_gvn); 4892 const Type* in_type = in->Value(&_gvn); 4893 const TypeAryPtr* top_out = out_type->isa_aryptr(); 4894 const TypeAryPtr* top_in = in_type->isa_aryptr(); 4895 if (top_out == NULL || top_out->klass() == NULL || 4896 top_in == NULL || top_in->klass() == NULL) { 4897 // failed array check 4898 return false; 4899 } 4900 4901 BasicType out_elem = out_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4902 BasicType in_elem = in_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4903 if (out_elem != T_INT || in_elem != T_INT) { 4904 return false; 4905 } 4906 4907 Node* outlen = load_array_length(out); 4908 Node* new_offset = _gvn.transform(new SubINode(outlen, offset)); 4909 Node* out_start = array_element_address(out, intcon(0), out_elem); 4910 Node* in_start = array_element_address(in, intcon(0), in_elem); 4911 4912 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 4913 OptoRuntime::mulAdd_Type(), 4914 stubAddr, stubName, TypePtr::BOTTOM, 4915 out_start,in_start, new_offset, len, k); 4916 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 4917 set_result(result); 4918 return true; 4919 } 4920 4921 //-------------inline_montgomeryMultiply----------------------------------- 4922 bool LibraryCallKit::inline_montgomeryMultiply() { 4923 address stubAddr = StubRoutines::montgomeryMultiply(); 4924 if (stubAddr == NULL) { 4925 return false; // Intrinsic's stub is not implemented on this platform 4926 } 4927 4928 assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform"); 4929 const char* stubName = "montgomery_multiply"; 4930 4931 assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters"); 4932 4933 Node* a = argument(0); 4934 Node* b = argument(1); 4935 Node* n = argument(2); 4936 Node* len = argument(3); 4937 Node* inv = argument(4); 4938 Node* m = argument(6); 4939 4940 const Type* a_type = a->Value(&_gvn); 4941 const TypeAryPtr* top_a = a_type->isa_aryptr(); 4942 const Type* b_type = b->Value(&_gvn); 4943 const TypeAryPtr* top_b = b_type->isa_aryptr(); 4944 const Type* n_type = a->Value(&_gvn); 4945 const TypeAryPtr* top_n = n_type->isa_aryptr(); 4946 const Type* m_type = a->Value(&_gvn); 4947 const TypeAryPtr* top_m = m_type->isa_aryptr(); 4948 if (top_a == NULL || top_a->klass() == NULL || 4949 top_b == NULL || top_b->klass() == NULL || 4950 top_n == NULL || top_n->klass() == NULL || 4951 top_m == NULL || top_m->klass() == NULL) { 4952 // failed array check 4953 return false; 4954 } 4955 4956 BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4957 BasicType b_elem = b_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4958 BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4959 BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 4960 if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 4961 return false; 4962 } 4963 4964 // Make the call 4965 { 4966 Node* a_start = array_element_address(a, intcon(0), a_elem); 4967 Node* b_start = array_element_address(b, intcon(0), b_elem); 4968 Node* n_start = array_element_address(n, intcon(0), n_elem); 4969 Node* m_start = array_element_address(m, intcon(0), m_elem); 4970 4971 Node* call = make_runtime_call(RC_LEAF, 4972 OptoRuntime::montgomeryMultiply_Type(), 4973 stubAddr, stubName, TypePtr::BOTTOM, 4974 a_start, b_start, n_start, len, inv, top(), 4975 m_start); 4976 set_result(m); 4977 } 4978 4979 return true; 4980 } 4981 4982 bool LibraryCallKit::inline_montgomerySquare() { 4983 address stubAddr = StubRoutines::montgomerySquare(); 4984 if (stubAddr == NULL) { 4985 return false; // Intrinsic's stub is not implemented on this platform 4986 } 4987 4988 assert(UseMontgomerySquareIntrinsic, "not implemented on this platform"); 4989 const char* stubName = "montgomery_square"; 4990 4991 assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters"); 4992 4993 Node* a = argument(0); 4994 Node* n = argument(1); 4995 Node* len = argument(2); 4996 Node* inv = argument(3); 4997 Node* m = argument(5); 4998 4999 const Type* a_type = a->Value(&_gvn); 5000 const TypeAryPtr* top_a = a_type->isa_aryptr(); 5001 const Type* n_type = a->Value(&_gvn); 5002 const TypeAryPtr* top_n = n_type->isa_aryptr(); 5003 const Type* m_type = a->Value(&_gvn); 5004 const TypeAryPtr* top_m = m_type->isa_aryptr(); 5005 if (top_a == NULL || top_a->klass() == NULL || 5006 top_n == NULL || top_n->klass() == NULL || 5007 top_m == NULL || top_m->klass() == NULL) { 5008 // failed array check 5009 return false; 5010 } 5011 5012 BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5013 BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5014 BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5015 if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 5016 return false; 5017 } 5018 5019 // Make the call 5020 { 5021 Node* a_start = array_element_address(a, intcon(0), a_elem); 5022 Node* n_start = array_element_address(n, intcon(0), n_elem); 5023 Node* m_start = array_element_address(m, intcon(0), m_elem); 5024 5025 Node* call = make_runtime_call(RC_LEAF, 5026 OptoRuntime::montgomerySquare_Type(), 5027 stubAddr, stubName, TypePtr::BOTTOM, 5028 a_start, n_start, len, inv, top(), 5029 m_start); 5030 set_result(m); 5031 } 5032 5033 return true; 5034 } 5035 5036 bool LibraryCallKit::inline_bigIntegerShift(bool isRightShift) { 5037 address stubAddr = NULL; 5038 const char* stubName = NULL; 5039 5040 stubAddr = isRightShift? StubRoutines::bigIntegerRightShift(): StubRoutines::bigIntegerLeftShift(); 5041 if (stubAddr == NULL) { 5042 return false; // Intrinsic's stub is not implemented on this platform 5043 } 5044 5045 stubName = isRightShift? "bigIntegerRightShiftWorker" : "bigIntegerLeftShiftWorker"; 5046 5047 assert(callee()->signature()->size() == 5, "expected 5 arguments"); 5048 5049 Node* newArr = argument(0); 5050 Node* oldArr = argument(1); 5051 Node* newIdx = argument(2); 5052 Node* shiftCount = argument(3); 5053 Node* numIter = argument(4); 5054 5055 const Type* newArr_type = newArr->Value(&_gvn); 5056 const TypeAryPtr* top_newArr = newArr_type->isa_aryptr(); 5057 const Type* oldArr_type = oldArr->Value(&_gvn); 5058 const TypeAryPtr* top_oldArr = oldArr_type->isa_aryptr(); 5059 if (top_newArr == NULL || top_newArr->klass() == NULL || top_oldArr == NULL 5060 || top_oldArr->klass() == NULL) { 5061 return false; 5062 } 5063 5064 BasicType newArr_elem = newArr_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5065 BasicType oldArr_elem = oldArr_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5066 if (newArr_elem != T_INT || oldArr_elem != T_INT) { 5067 return false; 5068 } 5069 5070 // Make the call 5071 { 5072 Node* newArr_start = array_element_address(newArr, intcon(0), newArr_elem); 5073 Node* oldArr_start = array_element_address(oldArr, intcon(0), oldArr_elem); 5074 5075 Node* call = make_runtime_call(RC_LEAF, 5076 OptoRuntime::bigIntegerShift_Type(), 5077 stubAddr, 5078 stubName, 5079 TypePtr::BOTTOM, 5080 newArr_start, 5081 oldArr_start, 5082 newIdx, 5083 shiftCount, 5084 numIter); 5085 } 5086 5087 return true; 5088 } 5089 5090 //-------------inline_vectorizedMismatch------------------------------ 5091 bool LibraryCallKit::inline_vectorizedMismatch() { 5092 assert(UseVectorizedMismatchIntrinsic, "not implementated on this platform"); 5093 5094 address stubAddr = StubRoutines::vectorizedMismatch(); 5095 if (stubAddr == NULL) { 5096 return false; // Intrinsic's stub is not implemented on this platform 5097 } 5098 const char* stubName = "vectorizedMismatch"; 5099 int size_l = callee()->signature()->size(); 5100 assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters"); 5101 5102 Node* obja = argument(0); 5103 Node* aoffset = argument(1); 5104 Node* objb = argument(3); 5105 Node* boffset = argument(4); 5106 Node* length = argument(6); 5107 Node* scale = argument(7); 5108 5109 const Type* a_type = obja->Value(&_gvn); 5110 const Type* b_type = objb->Value(&_gvn); 5111 const TypeAryPtr* top_a = a_type->isa_aryptr(); 5112 const TypeAryPtr* top_b = b_type->isa_aryptr(); 5113 if (top_a == NULL || top_a->klass() == NULL || 5114 top_b == NULL || top_b->klass() == NULL) { 5115 // failed array check 5116 return false; 5117 } 5118 5119 Node* call; 5120 jvms()->set_should_reexecute(true); 5121 5122 Node* obja_adr = make_unsafe_address(obja, aoffset, ACCESS_READ); 5123 Node* objb_adr = make_unsafe_address(objb, boffset, ACCESS_READ); 5124 5125 call = make_runtime_call(RC_LEAF, 5126 OptoRuntime::vectorizedMismatch_Type(), 5127 stubAddr, stubName, TypePtr::BOTTOM, 5128 obja_adr, objb_adr, length, scale); 5129 5130 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5131 set_result(result); 5132 return true; 5133 } 5134 5135 /** 5136 * Calculate CRC32 for byte. 5137 * int java.util.zip.CRC32.update(int crc, int b) 5138 */ 5139 bool LibraryCallKit::inline_updateCRC32() { 5140 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5141 assert(callee()->signature()->size() == 2, "update has 2 parameters"); 5142 // no receiver since it is static method 5143 Node* crc = argument(0); // type: int 5144 Node* b = argument(1); // type: int 5145 5146 /* 5147 * int c = ~ crc; 5148 * b = timesXtoThe32[(b ^ c) & 0xFF]; 5149 * b = b ^ (c >>> 8); 5150 * crc = ~b; 5151 */ 5152 5153 Node* M1 = intcon(-1); 5154 crc = _gvn.transform(new XorINode(crc, M1)); 5155 Node* result = _gvn.transform(new XorINode(crc, b)); 5156 result = _gvn.transform(new AndINode(result, intcon(0xFF))); 5157 5158 Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 5159 Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2))); 5160 Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 5161 result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 5162 5163 crc = _gvn.transform(new URShiftINode(crc, intcon(8))); 5164 result = _gvn.transform(new XorINode(crc, result)); 5165 result = _gvn.transform(new XorINode(result, M1)); 5166 set_result(result); 5167 return true; 5168 } 5169 5170 /** 5171 * Calculate CRC32 for byte[] array. 5172 * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 5173 */ 5174 bool LibraryCallKit::inline_updateBytesCRC32() { 5175 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5176 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5177 // no receiver since it is static method 5178 Node* crc = argument(0); // type: int 5179 Node* src = argument(1); // type: oop 5180 Node* offset = argument(2); // type: int 5181 Node* length = argument(3); // type: int 5182 5183 const Type* src_type = src->Value(&_gvn); 5184 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5185 if (top_src == NULL || top_src->klass() == NULL) { 5186 // failed array check 5187 return false; 5188 } 5189 5190 // Figure out the size and type of the elements we will be copying. 5191 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5192 if (src_elem != T_BYTE) { 5193 return false; 5194 } 5195 5196 // 'src_start' points to src array + scaled offset 5197 src = must_be_not_null(src, true); 5198 Node* src_start = array_element_address(src, offset, src_elem); 5199 5200 // We assume that range check is done by caller. 5201 // TODO: generate range check (offset+length < src.length) in debug VM. 5202 5203 // Call the stub. 5204 address stubAddr = StubRoutines::updateBytesCRC32(); 5205 const char *stubName = "updateBytesCRC32"; 5206 5207 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5208 stubAddr, stubName, TypePtr::BOTTOM, 5209 crc, src_start, length); 5210 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5211 set_result(result); 5212 return true; 5213 } 5214 5215 /** 5216 * Calculate CRC32 for ByteBuffer. 5217 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 5218 */ 5219 bool LibraryCallKit::inline_updateByteBufferCRC32() { 5220 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5221 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 5222 // no receiver since it is static method 5223 Node* crc = argument(0); // type: int 5224 Node* src = argument(1); // type: long 5225 Node* offset = argument(3); // type: int 5226 Node* length = argument(4); // type: int 5227 5228 src = ConvL2X(src); // adjust Java long to machine word 5229 Node* base = _gvn.transform(new CastX2PNode(src)); 5230 offset = ConvI2X(offset); 5231 5232 // 'src_start' points to src array + scaled offset 5233 Node* src_start = basic_plus_adr(top(), base, offset); 5234 5235 // Call the stub. 5236 address stubAddr = StubRoutines::updateBytesCRC32(); 5237 const char *stubName = "updateBytesCRC32"; 5238 5239 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5240 stubAddr, stubName, TypePtr::BOTTOM, 5241 crc, src_start, length); 5242 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5243 set_result(result); 5244 return true; 5245 } 5246 5247 //------------------------------get_table_from_crc32c_class----------------------- 5248 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) { 5249 Node* table = load_field_from_object(NULL, "byteTable", "[I", /*is_exact*/ false, /*is_static*/ true, crc32c_class); 5250 assert (table != NULL, "wrong version of java.util.zip.CRC32C"); 5251 5252 return table; 5253 } 5254 5255 //------------------------------inline_updateBytesCRC32C----------------------- 5256 // 5257 // Calculate CRC32C for byte[] array. 5258 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end) 5259 // 5260 bool LibraryCallKit::inline_updateBytesCRC32C() { 5261 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 5262 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5263 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 5264 // no receiver since it is a static method 5265 Node* crc = argument(0); // type: int 5266 Node* src = argument(1); // type: oop 5267 Node* offset = argument(2); // type: int 5268 Node* end = argument(3); // type: int 5269 5270 Node* length = _gvn.transform(new SubINode(end, offset)); 5271 5272 const Type* src_type = src->Value(&_gvn); 5273 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5274 if (top_src == NULL || top_src->klass() == NULL) { 5275 // failed array check 5276 return false; 5277 } 5278 5279 // Figure out the size and type of the elements we will be copying. 5280 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5281 if (src_elem != T_BYTE) { 5282 return false; 5283 } 5284 5285 // 'src_start' points to src array + scaled offset 5286 src = must_be_not_null(src, true); 5287 Node* src_start = array_element_address(src, offset, src_elem); 5288 5289 // static final int[] byteTable in class CRC32C 5290 Node* table = get_table_from_crc32c_class(callee()->holder()); 5291 table = must_be_not_null(table, true); 5292 Node* table_start = array_element_address(table, intcon(0), T_INT); 5293 5294 // We assume that range check is done by caller. 5295 // TODO: generate range check (offset+length < src.length) in debug VM. 5296 5297 // Call the stub. 5298 address stubAddr = StubRoutines::updateBytesCRC32C(); 5299 const char *stubName = "updateBytesCRC32C"; 5300 5301 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 5302 stubAddr, stubName, TypePtr::BOTTOM, 5303 crc, src_start, length, table_start); 5304 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5305 set_result(result); 5306 return true; 5307 } 5308 5309 //------------------------------inline_updateDirectByteBufferCRC32C----------------------- 5310 // 5311 // Calculate CRC32C for DirectByteBuffer. 5312 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end) 5313 // 5314 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() { 5315 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 5316 assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long"); 5317 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 5318 // no receiver since it is a static method 5319 Node* crc = argument(0); // type: int 5320 Node* src = argument(1); // type: long 5321 Node* offset = argument(3); // type: int 5322 Node* end = argument(4); // type: int 5323 5324 Node* length = _gvn.transform(new SubINode(end, offset)); 5325 5326 src = ConvL2X(src); // adjust Java long to machine word 5327 Node* base = _gvn.transform(new CastX2PNode(src)); 5328 offset = ConvI2X(offset); 5329 5330 // 'src_start' points to src array + scaled offset 5331 Node* src_start = basic_plus_adr(top(), base, offset); 5332 5333 // static final int[] byteTable in class CRC32C 5334 Node* table = get_table_from_crc32c_class(callee()->holder()); 5335 table = must_be_not_null(table, true); 5336 Node* table_start = array_element_address(table, intcon(0), T_INT); 5337 5338 // Call the stub. 5339 address stubAddr = StubRoutines::updateBytesCRC32C(); 5340 const char *stubName = "updateBytesCRC32C"; 5341 5342 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 5343 stubAddr, stubName, TypePtr::BOTTOM, 5344 crc, src_start, length, table_start); 5345 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5346 set_result(result); 5347 return true; 5348 } 5349 5350 //------------------------------inline_updateBytesAdler32---------------------- 5351 // 5352 // Calculate Adler32 checksum for byte[] array. 5353 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len) 5354 // 5355 bool LibraryCallKit::inline_updateBytesAdler32() { 5356 assert(UseAdler32Intrinsics, "Adler32 Instrinsic support need"); // check if we actually need to check this flag or check a different one 5357 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5358 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 5359 // no receiver since it is static method 5360 Node* crc = argument(0); // type: int 5361 Node* src = argument(1); // type: oop 5362 Node* offset = argument(2); // type: int 5363 Node* length = argument(3); // type: int 5364 5365 const Type* src_type = src->Value(&_gvn); 5366 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5367 if (top_src == NULL || top_src->klass() == NULL) { 5368 // failed array check 5369 return false; 5370 } 5371 5372 // Figure out the size and type of the elements we will be copying. 5373 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5374 if (src_elem != T_BYTE) { 5375 return false; 5376 } 5377 5378 // 'src_start' points to src array + scaled offset 5379 Node* src_start = array_element_address(src, offset, src_elem); 5380 5381 // We assume that range check is done by caller. 5382 // TODO: generate range check (offset+length < src.length) in debug VM. 5383 5384 // Call the stub. 5385 address stubAddr = StubRoutines::updateBytesAdler32(); 5386 const char *stubName = "updateBytesAdler32"; 5387 5388 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 5389 stubAddr, stubName, TypePtr::BOTTOM, 5390 crc, src_start, length); 5391 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5392 set_result(result); 5393 return true; 5394 } 5395 5396 //------------------------------inline_updateByteBufferAdler32--------------- 5397 // 5398 // Calculate Adler32 checksum for DirectByteBuffer. 5399 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len) 5400 // 5401 bool LibraryCallKit::inline_updateByteBufferAdler32() { 5402 assert(UseAdler32Intrinsics, "Adler32 Instrinsic support need"); // check if we actually need to check this flag or check a different one 5403 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 5404 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 5405 // no receiver since it is static method 5406 Node* crc = argument(0); // type: int 5407 Node* src = argument(1); // type: long 5408 Node* offset = argument(3); // type: int 5409 Node* length = argument(4); // type: int 5410 5411 src = ConvL2X(src); // adjust Java long to machine word 5412 Node* base = _gvn.transform(new CastX2PNode(src)); 5413 offset = ConvI2X(offset); 5414 5415 // 'src_start' points to src array + scaled offset 5416 Node* src_start = basic_plus_adr(top(), base, offset); 5417 5418 // Call the stub. 5419 address stubAddr = StubRoutines::updateBytesAdler32(); 5420 const char *stubName = "updateBytesAdler32"; 5421 5422 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 5423 stubAddr, stubName, TypePtr::BOTTOM, 5424 crc, src_start, length); 5425 5426 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5427 set_result(result); 5428 return true; 5429 } 5430 5431 //----------------------------inline_reference_get---------------------------- 5432 // public T java.lang.ref.Reference.get(); 5433 bool LibraryCallKit::inline_reference_get() { 5434 const int referent_offset = java_lang_ref_Reference::referent_offset; 5435 guarantee(referent_offset > 0, "should have already been set"); 5436 5437 // Get the argument: 5438 Node* reference_obj = null_check_receiver(); 5439 if (stopped()) return true; 5440 5441 const TypeInstPtr* tinst = _gvn.type(reference_obj)->isa_instptr(); 5442 assert(tinst != NULL, "obj is null"); 5443 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5444 ciInstanceKlass* referenceKlass = tinst->klass()->as_instance_klass(); 5445 ciField* field = referenceKlass->get_field_by_name(ciSymbol::make("referent"), 5446 ciSymbol::make("Ljava/lang/Object;"), 5447 false); 5448 assert (field != NULL, "undefined field"); 5449 5450 Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); 5451 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 5452 5453 ciInstanceKlass* klass = env()->Object_klass(); 5454 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); 5455 5456 DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF; 5457 Node* result = access_load_at(reference_obj, adr, adr_type, object_type, T_OBJECT, decorators); 5458 // Add memory barrier to prevent commoning reads from this field 5459 // across safepoint since GC can change its value. 5460 insert_mem_bar(Op_MemBarCPUOrder); 5461 5462 set_result(result); 5463 return true; 5464 } 5465 5466 5467 Node * LibraryCallKit::load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 5468 bool is_exact=true, bool is_static=false, 5469 ciInstanceKlass * fromKls=NULL) { 5470 if (fromKls == NULL) { 5471 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 5472 assert(tinst != NULL, "obj is null"); 5473 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5474 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 5475 fromKls = tinst->klass()->as_instance_klass(); 5476 } else { 5477 assert(is_static, "only for static field access"); 5478 } 5479 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 5480 ciSymbol::make(fieldTypeString), 5481 is_static); 5482 5483 assert (field != NULL, "undefined field"); 5484 if (field == NULL) return (Node *) NULL; 5485 5486 if (is_static) { 5487 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 5488 fromObj = makecon(tip); 5489 } 5490 5491 // Next code copied from Parse::do_get_xxx(): 5492 5493 // Compute address and memory type. 5494 int offset = field->offset_in_bytes(); 5495 bool is_vol = field->is_volatile(); 5496 ciType* field_klass = field->type(); 5497 assert(field_klass->is_loaded(), "should be loaded"); 5498 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 5499 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 5500 BasicType bt = field->layout_type(); 5501 5502 // Build the resultant type of the load 5503 const Type *type; 5504 if (bt == T_OBJECT) { 5505 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 5506 } else { 5507 type = Type::get_const_basic_type(bt); 5508 } 5509 5510 DecoratorSet decorators = IN_HEAP; 5511 5512 if (is_vol) { 5513 decorators |= MO_SEQ_CST; 5514 } 5515 5516 return access_load_at(fromObj, adr, adr_type, type, bt, decorators); 5517 } 5518 5519 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 5520 bool is_exact = true, bool is_static = false, 5521 ciInstanceKlass * fromKls = NULL) { 5522 if (fromKls == NULL) { 5523 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 5524 assert(tinst != NULL, "obj is null"); 5525 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5526 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 5527 fromKls = tinst->klass()->as_instance_klass(); 5528 } 5529 else { 5530 assert(is_static, "only for static field access"); 5531 } 5532 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 5533 ciSymbol::make(fieldTypeString), 5534 is_static); 5535 5536 assert(field != NULL, "undefined field"); 5537 assert(!field->is_volatile(), "not defined for volatile fields"); 5538 5539 if (is_static) { 5540 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 5541 fromObj = makecon(tip); 5542 } 5543 5544 // Next code copied from Parse::do_get_xxx(): 5545 5546 // Compute address and memory type. 5547 int offset = field->offset_in_bytes(); 5548 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 5549 5550 return adr; 5551 } 5552 5553 //------------------------------inline_aescrypt_Block----------------------- 5554 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 5555 address stubAddr = NULL; 5556 const char *stubName; 5557 assert(UseAES, "need AES instruction support"); 5558 5559 switch(id) { 5560 case vmIntrinsics::_aescrypt_encryptBlock: 5561 stubAddr = StubRoutines::aescrypt_encryptBlock(); 5562 stubName = "aescrypt_encryptBlock"; 5563 break; 5564 case vmIntrinsics::_aescrypt_decryptBlock: 5565 stubAddr = StubRoutines::aescrypt_decryptBlock(); 5566 stubName = "aescrypt_decryptBlock"; 5567 break; 5568 default: 5569 break; 5570 } 5571 if (stubAddr == NULL) return false; 5572 5573 Node* aescrypt_object = argument(0); 5574 Node* src = argument(1); 5575 Node* src_offset = argument(2); 5576 Node* dest = argument(3); 5577 Node* dest_offset = argument(4); 5578 5579 src = must_be_not_null(src, true); 5580 dest = must_be_not_null(dest, true); 5581 5582 // (1) src and dest are arrays. 5583 const Type* src_type = src->Value(&_gvn); 5584 const Type* dest_type = dest->Value(&_gvn); 5585 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5586 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5587 assert (top_src != NULL && top_src->klass() != NULL && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5588 5589 // for the quick and dirty code we will skip all the checks. 5590 // we are just trying to get the call to be generated. 5591 Node* src_start = src; 5592 Node* dest_start = dest; 5593 if (src_offset != NULL || dest_offset != NULL) { 5594 assert(src_offset != NULL && dest_offset != NULL, ""); 5595 src_start = array_element_address(src, src_offset, T_BYTE); 5596 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5597 } 5598 5599 // now need to get the start of its expanded key array 5600 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5601 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5602 if (k_start == NULL) return false; 5603 5604 if (Matcher::pass_original_key_for_aes()) { 5605 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 5606 // compatibility issues between Java key expansion and SPARC crypto instructions 5607 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 5608 if (original_k_start == NULL) return false; 5609 5610 // Call the stub. 5611 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5612 stubAddr, stubName, TypePtr::BOTTOM, 5613 src_start, dest_start, k_start, original_k_start); 5614 } else { 5615 // Call the stub. 5616 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5617 stubAddr, stubName, TypePtr::BOTTOM, 5618 src_start, dest_start, k_start); 5619 } 5620 5621 return true; 5622 } 5623 5624 //------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 5625 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 5626 address stubAddr = NULL; 5627 const char *stubName = NULL; 5628 5629 assert(UseAES, "need AES instruction support"); 5630 5631 switch(id) { 5632 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 5633 stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 5634 stubName = "cipherBlockChaining_encryptAESCrypt"; 5635 break; 5636 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 5637 stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 5638 stubName = "cipherBlockChaining_decryptAESCrypt"; 5639 break; 5640 default: 5641 break; 5642 } 5643 if (stubAddr == NULL) return false; 5644 5645 Node* cipherBlockChaining_object = argument(0); 5646 Node* src = argument(1); 5647 Node* src_offset = argument(2); 5648 Node* len = argument(3); 5649 Node* dest = argument(4); 5650 Node* dest_offset = argument(5); 5651 5652 src = must_be_not_null(src, false); 5653 dest = must_be_not_null(dest, false); 5654 5655 // (1) src and dest are arrays. 5656 const Type* src_type = src->Value(&_gvn); 5657 const Type* dest_type = dest->Value(&_gvn); 5658 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5659 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5660 assert (top_src != NULL && top_src->klass() != NULL 5661 && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5662 5663 // checks are the responsibility of the caller 5664 Node* src_start = src; 5665 Node* dest_start = dest; 5666 if (src_offset != NULL || dest_offset != NULL) { 5667 assert(src_offset != NULL && dest_offset != NULL, ""); 5668 src_start = array_element_address(src, src_offset, T_BYTE); 5669 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5670 } 5671 5672 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 5673 // (because of the predicated logic executed earlier). 5674 // so we cast it here safely. 5675 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5676 5677 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5678 if (embeddedCipherObj == NULL) return false; 5679 5680 // cast it to what we know it will be at runtime 5681 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 5682 assert(tinst != NULL, "CBC obj is null"); 5683 assert(tinst->klass()->is_loaded(), "CBC obj is not loaded"); 5684 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 5685 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 5686 5687 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 5688 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 5689 const TypeOopPtr* xtype = aklass->as_instance_type(); 5690 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 5691 aescrypt_object = _gvn.transform(aescrypt_object); 5692 5693 // we need to get the start of the aescrypt_object's expanded key array 5694 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5695 if (k_start == NULL) return false; 5696 5697 // similarly, get the start address of the r vector 5698 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false); 5699 if (objRvec == NULL) return false; 5700 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 5701 5702 Node* cbcCrypt; 5703 if (Matcher::pass_original_key_for_aes()) { 5704 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 5705 // compatibility issues between Java key expansion and SPARC crypto instructions 5706 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 5707 if (original_k_start == NULL) return false; 5708 5709 // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start 5710 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 5711 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 5712 stubAddr, stubName, TypePtr::BOTTOM, 5713 src_start, dest_start, k_start, r_start, len, original_k_start); 5714 } else { 5715 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 5716 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 5717 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 5718 stubAddr, stubName, TypePtr::BOTTOM, 5719 src_start, dest_start, k_start, r_start, len); 5720 } 5721 5722 // return cipher length (int) 5723 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms)); 5724 set_result(retvalue); 5725 return true; 5726 } 5727 5728 //------------------------------inline_electronicCodeBook_AESCrypt----------------------- 5729 bool LibraryCallKit::inline_electronicCodeBook_AESCrypt(vmIntrinsics::ID id) { 5730 address stubAddr = NULL; 5731 const char *stubName = NULL; 5732 5733 assert(UseAES, "need AES instruction support"); 5734 5735 switch (id) { 5736 case vmIntrinsics::_electronicCodeBook_encryptAESCrypt: 5737 stubAddr = StubRoutines::electronicCodeBook_encryptAESCrypt(); 5738 stubName = "electronicCodeBook_encryptAESCrypt"; 5739 break; 5740 case vmIntrinsics::_electronicCodeBook_decryptAESCrypt: 5741 stubAddr = StubRoutines::electronicCodeBook_decryptAESCrypt(); 5742 stubName = "electronicCodeBook_decryptAESCrypt"; 5743 break; 5744 default: 5745 break; 5746 } 5747 5748 if (stubAddr == NULL) return false; 5749 5750 Node* electronicCodeBook_object = argument(0); 5751 Node* src = argument(1); 5752 Node* src_offset = argument(2); 5753 Node* len = argument(3); 5754 Node* dest = argument(4); 5755 Node* dest_offset = argument(5); 5756 5757 // (1) src and dest are arrays. 5758 const Type* src_type = src->Value(&_gvn); 5759 const Type* dest_type = dest->Value(&_gvn); 5760 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5761 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5762 assert(top_src != NULL && top_src->klass() != NULL 5763 && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5764 5765 // checks are the responsibility of the caller 5766 Node* src_start = src; 5767 Node* dest_start = dest; 5768 if (src_offset != NULL || dest_offset != NULL) { 5769 assert(src_offset != NULL && dest_offset != NULL, ""); 5770 src_start = array_element_address(src, src_offset, T_BYTE); 5771 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5772 } 5773 5774 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 5775 // (because of the predicated logic executed earlier). 5776 // so we cast it here safely. 5777 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5778 5779 Node* embeddedCipherObj = load_field_from_object(electronicCodeBook_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5780 if (embeddedCipherObj == NULL) return false; 5781 5782 // cast it to what we know it will be at runtime 5783 const TypeInstPtr* tinst = _gvn.type(electronicCodeBook_object)->isa_instptr(); 5784 assert(tinst != NULL, "ECB obj is null"); 5785 assert(tinst->klass()->is_loaded(), "ECB obj is not loaded"); 5786 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 5787 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 5788 5789 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 5790 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 5791 const TypeOopPtr* xtype = aklass->as_instance_type(); 5792 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 5793 aescrypt_object = _gvn.transform(aescrypt_object); 5794 5795 // we need to get the start of the aescrypt_object's expanded key array 5796 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5797 if (k_start == NULL) return false; 5798 5799 Node* ecbCrypt; 5800 if (Matcher::pass_original_key_for_aes()) { 5801 // no SPARC version for AES/ECB intrinsics now. 5802 return false; 5803 } 5804 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 5805 ecbCrypt = make_runtime_call(RC_LEAF | RC_NO_FP, 5806 OptoRuntime::electronicCodeBook_aescrypt_Type(), 5807 stubAddr, stubName, TypePtr::BOTTOM, 5808 src_start, dest_start, k_start, len); 5809 5810 // return cipher length (int) 5811 Node* retvalue = _gvn.transform(new ProjNode(ecbCrypt, TypeFunc::Parms)); 5812 set_result(retvalue); 5813 return true; 5814 } 5815 5816 //------------------------------inline_counterMode_AESCrypt----------------------- 5817 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) { 5818 assert(UseAES, "need AES instruction support"); 5819 if (!UseAESCTRIntrinsics) return false; 5820 5821 address stubAddr = NULL; 5822 const char *stubName = NULL; 5823 if (id == vmIntrinsics::_counterMode_AESCrypt) { 5824 stubAddr = StubRoutines::counterMode_AESCrypt(); 5825 stubName = "counterMode_AESCrypt"; 5826 } 5827 if (stubAddr == NULL) return false; 5828 5829 Node* counterMode_object = argument(0); 5830 Node* src = argument(1); 5831 Node* src_offset = argument(2); 5832 Node* len = argument(3); 5833 Node* dest = argument(4); 5834 Node* dest_offset = argument(5); 5835 5836 // (1) src and dest are arrays. 5837 const Type* src_type = src->Value(&_gvn); 5838 const Type* dest_type = dest->Value(&_gvn); 5839 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5840 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5841 assert(top_src != NULL && top_src->klass() != NULL && 5842 top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5843 5844 // checks are the responsibility of the caller 5845 Node* src_start = src; 5846 Node* dest_start = dest; 5847 if (src_offset != NULL || dest_offset != NULL) { 5848 assert(src_offset != NULL && dest_offset != NULL, ""); 5849 src_start = array_element_address(src, src_offset, T_BYTE); 5850 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5851 } 5852 5853 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 5854 // (because of the predicated logic executed earlier). 5855 // so we cast it here safely. 5856 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5857 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5858 if (embeddedCipherObj == NULL) return false; 5859 // cast it to what we know it will be at runtime 5860 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr(); 5861 assert(tinst != NULL, "CTR obj is null"); 5862 assert(tinst->klass()->is_loaded(), "CTR obj is not loaded"); 5863 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 5864 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 5865 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 5866 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 5867 const TypeOopPtr* xtype = aklass->as_instance_type(); 5868 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 5869 aescrypt_object = _gvn.transform(aescrypt_object); 5870 // we need to get the start of the aescrypt_object's expanded key array 5871 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5872 if (k_start == NULL) return false; 5873 // similarly, get the start address of the r vector 5874 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B", /*is_exact*/ false); 5875 if (obj_counter == NULL) return false; 5876 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE); 5877 5878 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B", /*is_exact*/ false); 5879 if (saved_encCounter == NULL) return false; 5880 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE); 5881 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false); 5882 5883 Node* ctrCrypt; 5884 if (Matcher::pass_original_key_for_aes()) { 5885 // no SPARC version for AES/CTR intrinsics now. 5886 return false; 5887 } 5888 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 5889 ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 5890 OptoRuntime::counterMode_aescrypt_Type(), 5891 stubAddr, stubName, TypePtr::BOTTOM, 5892 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used); 5893 5894 // return cipher length (int) 5895 Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms)); 5896 set_result(retvalue); 5897 return true; 5898 } 5899 5900 //------------------------------get_key_start_from_aescrypt_object----------------------- 5901 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 5902 #if defined(PPC64) || defined(S390) 5903 // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys. 5904 // Intel's extention is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns. 5905 // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption. 5906 // The ppc64 stubs of encryption and decryption use the same round keys (sessionK[0]). 5907 Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I", /*is_exact*/ false); 5908 assert (objSessionK != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 5909 if (objSessionK == NULL) { 5910 return (Node *) NULL; 5911 } 5912 Node* objAESCryptKey = load_array_element(control(), objSessionK, intcon(0), TypeAryPtr::OOPS); 5913 #else 5914 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false); 5915 #endif // PPC64 5916 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 5917 if (objAESCryptKey == NULL) return (Node *) NULL; 5918 5919 // now have the array, need to get the start address of the K array 5920 Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 5921 return k_start; 5922 } 5923 5924 //------------------------------get_original_key_start_from_aescrypt_object----------------------- 5925 Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) { 5926 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false); 5927 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 5928 if (objAESCryptKey == NULL) return (Node *) NULL; 5929 5930 // now have the array, need to get the start address of the lastKey array 5931 Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE); 5932 return original_k_start; 5933 } 5934 5935 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 5936 // Return node representing slow path of predicate check. 5937 // the pseudo code we want to emulate with this predicate is: 5938 // for encryption: 5939 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 5940 // for decryption: 5941 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 5942 // note cipher==plain is more conservative than the original java code but that's OK 5943 // 5944 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 5945 // The receiver was checked for NULL already. 5946 Node* objCBC = argument(0); 5947 5948 Node* src = argument(1); 5949 Node* dest = argument(4); 5950 5951 // Load embeddedCipher field of CipherBlockChaining object. 5952 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5953 5954 // get AESCrypt klass for instanceOf check 5955 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 5956 // will have same classloader as CipherBlockChaining object 5957 const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 5958 assert(tinst != NULL, "CBCobj is null"); 5959 assert(tinst->klass()->is_loaded(), "CBCobj is not loaded"); 5960 5961 // we want to do an instanceof comparison against the AESCrypt class 5962 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 5963 if (!klass_AESCrypt->is_loaded()) { 5964 // if AESCrypt is not even loaded, we never take the intrinsic fast path 5965 Node* ctrl = control(); 5966 set_control(top()); // no regular fast path 5967 return ctrl; 5968 } 5969 5970 src = must_be_not_null(src, true); 5971 dest = must_be_not_null(dest, true); 5972 5973 // Resolve oops to stable for CmpP below. 5974 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 5975 5976 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 5977 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 5978 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 5979 5980 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 5981 5982 // for encryption, we are done 5983 if (!decrypting) 5984 return instof_false; // even if it is NULL 5985 5986 // for decryption, we need to add a further check to avoid 5987 // taking the intrinsic path when cipher and plain are the same 5988 // see the original java code for why. 5989 RegionNode* region = new RegionNode(3); 5990 region->init_req(1, instof_false); 5991 5992 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 5993 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 5994 Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN); 5995 region->init_req(2, src_dest_conjoint); 5996 5997 record_for_igvn(region); 5998 return _gvn.transform(region); 5999 } 6000 6001 //----------------------------inline_electronicCodeBook_AESCrypt_predicate---------------------------- 6002 // Return node representing slow path of predicate check. 6003 // the pseudo code we want to emulate with this predicate is: 6004 // for encryption: 6005 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 6006 // for decryption: 6007 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6008 // note cipher==plain is more conservative than the original java code but that's OK 6009 // 6010 Node* LibraryCallKit::inline_electronicCodeBook_AESCrypt_predicate(bool decrypting) { 6011 // The receiver was checked for NULL already. 6012 Node* objECB = argument(0); 6013 6014 // Load embeddedCipher field of ElectronicCodeBook object. 6015 Node* embeddedCipherObj = load_field_from_object(objECB, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6016 6017 // get AESCrypt klass for instanceOf check 6018 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 6019 // will have same classloader as ElectronicCodeBook object 6020 const TypeInstPtr* tinst = _gvn.type(objECB)->isa_instptr(); 6021 assert(tinst != NULL, "ECBobj is null"); 6022 assert(tinst->klass()->is_loaded(), "ECBobj is not loaded"); 6023 6024 // we want to do an instanceof comparison against the AESCrypt class 6025 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6026 if (!klass_AESCrypt->is_loaded()) { 6027 // if AESCrypt is not even loaded, we never take the intrinsic fast path 6028 Node* ctrl = control(); 6029 set_control(top()); // no regular fast path 6030 return ctrl; 6031 } 6032 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6033 6034 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 6035 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 6036 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 6037 6038 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6039 6040 // for encryption, we are done 6041 if (!decrypting) 6042 return instof_false; // even if it is NULL 6043 6044 // for decryption, we need to add a further check to avoid 6045 // taking the intrinsic path when cipher and plain are the same 6046 // see the original java code for why. 6047 RegionNode* region = new RegionNode(3); 6048 region->init_req(1, instof_false); 6049 Node* src = argument(1); 6050 Node* dest = argument(4); 6051 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 6052 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 6053 Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN); 6054 region->init_req(2, src_dest_conjoint); 6055 6056 record_for_igvn(region); 6057 return _gvn.transform(region); 6058 } 6059 6060 //----------------------------inline_counterMode_AESCrypt_predicate---------------------------- 6061 // Return node representing slow path of predicate check. 6062 // the pseudo code we want to emulate with this predicate is: 6063 // for encryption: 6064 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 6065 // for decryption: 6066 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6067 // note cipher==plain is more conservative than the original java code but that's OK 6068 // 6069 6070 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() { 6071 // The receiver was checked for NULL already. 6072 Node* objCTR = argument(0); 6073 6074 // Load embeddedCipher field of CipherBlockChaining object. 6075 Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6076 6077 // get AESCrypt klass for instanceOf check 6078 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 6079 // will have same classloader as CipherBlockChaining object 6080 const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr(); 6081 assert(tinst != NULL, "CTRobj is null"); 6082 assert(tinst->klass()->is_loaded(), "CTRobj is not loaded"); 6083 6084 // we want to do an instanceof comparison against the AESCrypt class 6085 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6086 if (!klass_AESCrypt->is_loaded()) { 6087 // if AESCrypt is not even loaded, we never take the intrinsic fast path 6088 Node* ctrl = control(); 6089 set_control(top()); // no regular fast path 6090 return ctrl; 6091 } 6092 6093 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6094 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 6095 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 6096 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 6097 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6098 6099 return instof_false; // even if it is NULL 6100 } 6101 6102 //------------------------------inline_ghash_processBlocks 6103 bool LibraryCallKit::inline_ghash_processBlocks() { 6104 address stubAddr; 6105 const char *stubName; 6106 assert(UseGHASHIntrinsics, "need GHASH intrinsics support"); 6107 6108 stubAddr = StubRoutines::ghash_processBlocks(); 6109 stubName = "ghash_processBlocks"; 6110 6111 Node* data = argument(0); 6112 Node* offset = argument(1); 6113 Node* len = argument(2); 6114 Node* state = argument(3); 6115 Node* subkeyH = argument(4); 6116 6117 state = must_be_not_null(state, true); 6118 subkeyH = must_be_not_null(subkeyH, true); 6119 data = must_be_not_null(data, true); 6120 6121 Node* state_start = array_element_address(state, intcon(0), T_LONG); 6122 assert(state_start, "state is NULL"); 6123 Node* subkeyH_start = array_element_address(subkeyH, intcon(0), T_LONG); 6124 assert(subkeyH_start, "subkeyH is NULL"); 6125 Node* data_start = array_element_address(data, offset, T_BYTE); 6126 assert(data_start, "data is NULL"); 6127 6128 Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP, 6129 OptoRuntime::ghash_processBlocks_Type(), 6130 stubAddr, stubName, TypePtr::BOTTOM, 6131 state_start, subkeyH_start, data_start, len); 6132 return true; 6133 } 6134 6135 bool LibraryCallKit::inline_base64_encodeBlock() { 6136 address stubAddr; 6137 const char *stubName; 6138 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 6139 assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters"); 6140 stubAddr = StubRoutines::base64_encodeBlock(); 6141 stubName = "encodeBlock"; 6142 6143 if (!stubAddr) return false; 6144 Node* base64obj = argument(0); 6145 Node* src = argument(1); 6146 Node* offset = argument(2); 6147 Node* len = argument(3); 6148 Node* dest = argument(4); 6149 Node* dp = argument(5); 6150 Node* isURL = argument(6); 6151 6152 src = must_be_not_null(src, true); 6153 dest = must_be_not_null(dest, true); 6154 6155 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 6156 assert(src_start, "source array is NULL"); 6157 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 6158 assert(dest_start, "destination array is NULL"); 6159 6160 Node* base64 = make_runtime_call(RC_LEAF, 6161 OptoRuntime::base64_encodeBlock_Type(), 6162 stubAddr, stubName, TypePtr::BOTTOM, 6163 src_start, offset, len, dest_start, dp, isURL); 6164 return true; 6165 } 6166 6167 //------------------------------inline_sha_implCompress----------------------- 6168 // 6169 // Calculate SHA (i.e., SHA-1) for single-block byte[] array. 6170 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs) 6171 // 6172 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array. 6173 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs) 6174 // 6175 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array. 6176 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs) 6177 // 6178 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) { 6179 assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters"); 6180 6181 Node* sha_obj = argument(0); 6182 Node* src = argument(1); // type oop 6183 Node* ofs = argument(2); // type int 6184 6185 const Type* src_type = src->Value(&_gvn); 6186 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6187 if (top_src == NULL || top_src->klass() == NULL) { 6188 // failed array check 6189 return false; 6190 } 6191 // Figure out the size and type of the elements we will be copying. 6192 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 6193 if (src_elem != T_BYTE) { 6194 return false; 6195 } 6196 // 'src_start' points to src array + offset 6197 src = must_be_not_null(src, true); 6198 Node* src_start = array_element_address(src, ofs, src_elem); 6199 Node* state = NULL; 6200 address stubAddr; 6201 const char *stubName; 6202 6203 switch(id) { 6204 case vmIntrinsics::_sha_implCompress: 6205 assert(UseSHA1Intrinsics, "need SHA1 instruction support"); 6206 state = get_state_from_sha_object(sha_obj); 6207 stubAddr = StubRoutines::sha1_implCompress(); 6208 stubName = "sha1_implCompress"; 6209 break; 6210 case vmIntrinsics::_sha2_implCompress: 6211 assert(UseSHA256Intrinsics, "need SHA256 instruction support"); 6212 state = get_state_from_sha_object(sha_obj); 6213 stubAddr = StubRoutines::sha256_implCompress(); 6214 stubName = "sha256_implCompress"; 6215 break; 6216 case vmIntrinsics::_sha5_implCompress: 6217 assert(UseSHA512Intrinsics, "need SHA512 instruction support"); 6218 state = get_state_from_sha5_object(sha_obj); 6219 stubAddr = StubRoutines::sha512_implCompress(); 6220 stubName = "sha512_implCompress"; 6221 break; 6222 default: 6223 fatal_unexpected_iid(id); 6224 return false; 6225 } 6226 if (state == NULL) return false; 6227 6228 assert(stubAddr != NULL, "Stub is generated"); 6229 if (stubAddr == NULL) return false; 6230 6231 // Call the stub. 6232 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::sha_implCompress_Type(), 6233 stubAddr, stubName, TypePtr::BOTTOM, 6234 src_start, state); 6235 6236 return true; 6237 } 6238 6239 //------------------------------inline_digestBase_implCompressMB----------------------- 6240 // 6241 // Calculate SHA/SHA2/SHA5 for multi-block byte[] array. 6242 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 6243 // 6244 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) { 6245 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics, 6246 "need SHA1/SHA256/SHA512 instruction support"); 6247 assert((uint)predicate < 3, "sanity"); 6248 assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters"); 6249 6250 Node* digestBase_obj = argument(0); // The receiver was checked for NULL already. 6251 Node* src = argument(1); // byte[] array 6252 Node* ofs = argument(2); // type int 6253 Node* limit = argument(3); // type int 6254 6255 const Type* src_type = src->Value(&_gvn); 6256 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6257 if (top_src == NULL || top_src->klass() == NULL) { 6258 // failed array check 6259 return false; 6260 } 6261 // Figure out the size and type of the elements we will be copying. 6262 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 6263 if (src_elem != T_BYTE) { 6264 return false; 6265 } 6266 // 'src_start' points to src array + offset 6267 src = must_be_not_null(src, false); 6268 Node* src_start = array_element_address(src, ofs, src_elem); 6269 6270 const char* klass_SHA_name = NULL; 6271 const char* stub_name = NULL; 6272 address stub_addr = NULL; 6273 bool long_state = false; 6274 6275 switch (predicate) { 6276 case 0: 6277 if (UseSHA1Intrinsics) { 6278 klass_SHA_name = "sun/security/provider/SHA"; 6279 stub_name = "sha1_implCompressMB"; 6280 stub_addr = StubRoutines::sha1_implCompressMB(); 6281 } 6282 break; 6283 case 1: 6284 if (UseSHA256Intrinsics) { 6285 klass_SHA_name = "sun/security/provider/SHA2"; 6286 stub_name = "sha256_implCompressMB"; 6287 stub_addr = StubRoutines::sha256_implCompressMB(); 6288 } 6289 break; 6290 case 2: 6291 if (UseSHA512Intrinsics) { 6292 klass_SHA_name = "sun/security/provider/SHA5"; 6293 stub_name = "sha512_implCompressMB"; 6294 stub_addr = StubRoutines::sha512_implCompressMB(); 6295 long_state = true; 6296 } 6297 break; 6298 default: 6299 fatal("unknown SHA intrinsic predicate: %d", predicate); 6300 } 6301 if (klass_SHA_name != NULL) { 6302 assert(stub_addr != NULL, "Stub is generated"); 6303 if (stub_addr == NULL) return false; 6304 6305 // get DigestBase klass to lookup for SHA klass 6306 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr(); 6307 assert(tinst != NULL, "digestBase_obj is not instance???"); 6308 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded"); 6309 6310 ciKlass* klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name)); 6311 assert(klass_SHA->is_loaded(), "predicate checks that this class is loaded"); 6312 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass(); 6313 return inline_sha_implCompressMB(digestBase_obj, instklass_SHA, long_state, stub_addr, stub_name, src_start, ofs, limit); 6314 } 6315 return false; 6316 } 6317 //------------------------------inline_sha_implCompressMB----------------------- 6318 bool LibraryCallKit::inline_sha_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_SHA, 6319 bool long_state, address stubAddr, const char *stubName, 6320 Node* src_start, Node* ofs, Node* limit) { 6321 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_SHA); 6322 const TypeOopPtr* xtype = aklass->as_instance_type(); 6323 Node* sha_obj = new CheckCastPPNode(control(), digestBase_obj, xtype); 6324 sha_obj = _gvn.transform(sha_obj); 6325 6326 Node* state; 6327 if (long_state) { 6328 state = get_state_from_sha5_object(sha_obj); 6329 } else { 6330 state = get_state_from_sha_object(sha_obj); 6331 } 6332 if (state == NULL) return false; 6333 6334 // Call the stub. 6335 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6336 OptoRuntime::digestBase_implCompressMB_Type(), 6337 stubAddr, stubName, TypePtr::BOTTOM, 6338 src_start, state, ofs, limit); 6339 // return ofs (int) 6340 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 6341 set_result(result); 6342 6343 return true; 6344 } 6345 6346 //------------------------------get_state_from_sha_object----------------------- 6347 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) { 6348 Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false); 6349 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2"); 6350 if (sha_state == NULL) return (Node *) NULL; 6351 6352 // now have the array, need to get the start address of the state array 6353 Node* state = array_element_address(sha_state, intcon(0), T_INT); 6354 return state; 6355 } 6356 6357 //------------------------------get_state_from_sha5_object----------------------- 6358 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) { 6359 Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false); 6360 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5"); 6361 if (sha_state == NULL) return (Node *) NULL; 6362 6363 // now have the array, need to get the start address of the state array 6364 Node* state = array_element_address(sha_state, intcon(0), T_LONG); 6365 return state; 6366 } 6367 6368 //----------------------------inline_digestBase_implCompressMB_predicate---------------------------- 6369 // Return node representing slow path of predicate check. 6370 // the pseudo code we want to emulate with this predicate is: 6371 // if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath 6372 // 6373 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) { 6374 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics, 6375 "need SHA1/SHA256/SHA512 instruction support"); 6376 assert((uint)predicate < 3, "sanity"); 6377 6378 // The receiver was checked for NULL already. 6379 Node* digestBaseObj = argument(0); 6380 6381 // get DigestBase klass for instanceOf check 6382 const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr(); 6383 assert(tinst != NULL, "digestBaseObj is null"); 6384 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded"); 6385 6386 const char* klass_SHA_name = NULL; 6387 switch (predicate) { 6388 case 0: 6389 if (UseSHA1Intrinsics) { 6390 // we want to do an instanceof comparison against the SHA class 6391 klass_SHA_name = "sun/security/provider/SHA"; 6392 } 6393 break; 6394 case 1: 6395 if (UseSHA256Intrinsics) { 6396 // we want to do an instanceof comparison against the SHA2 class 6397 klass_SHA_name = "sun/security/provider/SHA2"; 6398 } 6399 break; 6400 case 2: 6401 if (UseSHA512Intrinsics) { 6402 // we want to do an instanceof comparison against the SHA5 class 6403 klass_SHA_name = "sun/security/provider/SHA5"; 6404 } 6405 break; 6406 default: 6407 fatal("unknown SHA intrinsic predicate: %d", predicate); 6408 } 6409 6410 ciKlass* klass_SHA = NULL; 6411 if (klass_SHA_name != NULL) { 6412 klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name)); 6413 } 6414 if ((klass_SHA == NULL) || !klass_SHA->is_loaded()) { 6415 // if none of SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path 6416 Node* ctrl = control(); 6417 set_control(top()); // no intrinsic path 6418 return ctrl; 6419 } 6420 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass(); 6421 6422 Node* instofSHA = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass_SHA))); 6423 Node* cmp_instof = _gvn.transform(new CmpINode(instofSHA, intcon(1))); 6424 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 6425 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6426 6427 return instof_false; // even if it is NULL 6428 } 6429 6430 //-------------inline_fma----------------------------------- 6431 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) { 6432 Node *a = NULL; 6433 Node *b = NULL; 6434 Node *c = NULL; 6435 Node* result = NULL; 6436 switch (id) { 6437 case vmIntrinsics::_fmaD: 6438 assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each."); 6439 // no receiver since it is static method 6440 a = round_double_node(argument(0)); 6441 b = round_double_node(argument(2)); 6442 c = round_double_node(argument(4)); 6443 result = _gvn.transform(new FmaDNode(control(), a, b, c)); 6444 break; 6445 case vmIntrinsics::_fmaF: 6446 assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each."); 6447 a = argument(0); 6448 b = argument(1); 6449 c = argument(2); 6450 result = _gvn.transform(new FmaFNode(control(), a, b, c)); 6451 break; 6452 default: 6453 fatal_unexpected_iid(id); break; 6454 } 6455 set_result(result); 6456 return true; 6457 } 6458 6459 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) { 6460 // argument(0) is receiver 6461 Node* codePoint = argument(1); 6462 Node* n = NULL; 6463 6464 switch (id) { 6465 case vmIntrinsics::_isDigit : 6466 n = new DigitNode(control(), codePoint); 6467 break; 6468 case vmIntrinsics::_isLowerCase : 6469 n = new LowerCaseNode(control(), codePoint); 6470 break; 6471 case vmIntrinsics::_isUpperCase : 6472 n = new UpperCaseNode(control(), codePoint); 6473 break; 6474 case vmIntrinsics::_isWhitespace : 6475 n = new WhitespaceNode(control(), codePoint); 6476 break; 6477 default: 6478 fatal_unexpected_iid(id); 6479 } 6480 6481 set_result(_gvn.transform(n)); 6482 return true; 6483 } 6484 6485 //------------------------------inline_fp_min_max------------------------------ 6486 bool LibraryCallKit::inline_fp_min_max(vmIntrinsics::ID id) { 6487 /* DISABLED BECAUSE METHOD DATA ISN'T COLLECTED PER CALL-SITE, SEE JDK-8015416. 6488 6489 // The intrinsic should be used only when the API branches aren't predictable, 6490 // the last one performing the most important comparison. The following heuristic 6491 // uses the branch statistics to eventually bail out if necessary. 6492 6493 ciMethodData *md = callee()->method_data(); 6494 6495 if ( md != NULL && md->is_mature() && md->invocation_count() > 0 ) { 6496 ciCallProfile cp = caller()->call_profile_at_bci(bci()); 6497 6498 if ( ((double)cp.count()) / ((double)md->invocation_count()) < 0.8 ) { 6499 // Bail out if the call-site didn't contribute enough to the statistics. 6500 return false; 6501 } 6502 6503 uint taken = 0, not_taken = 0; 6504 6505 for (ciProfileData *p = md->first_data(); md->is_valid(p); p = md->next_data(p)) { 6506 if (p->is_BranchData()) { 6507 taken = ((ciBranchData*)p)->taken(); 6508 not_taken = ((ciBranchData*)p)->not_taken(); 6509 } 6510 } 6511 6512 double balance = (((double)taken) - ((double)not_taken)) / ((double)md->invocation_count()); 6513 balance = balance < 0 ? -balance : balance; 6514 if ( balance > 0.2 ) { 6515 // Bail out if the most important branch is predictable enough. 6516 return false; 6517 } 6518 } 6519 */ 6520 6521 Node *a = NULL; 6522 Node *b = NULL; 6523 Node *n = NULL; 6524 switch (id) { 6525 case vmIntrinsics::_maxF: 6526 case vmIntrinsics::_minF: 6527 assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each."); 6528 a = argument(0); 6529 b = argument(1); 6530 break; 6531 case vmIntrinsics::_maxD: 6532 case vmIntrinsics::_minD: 6533 assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each."); 6534 a = round_double_node(argument(0)); 6535 b = round_double_node(argument(2)); 6536 break; 6537 default: 6538 fatal_unexpected_iid(id); 6539 break; 6540 } 6541 switch (id) { 6542 case vmIntrinsics::_maxF: n = new MaxFNode(a, b); break; 6543 case vmIntrinsics::_minF: n = new MinFNode(a, b); break; 6544 case vmIntrinsics::_maxD: n = new MaxDNode(a, b); break; 6545 case vmIntrinsics::_minD: n = new MinDNode(a, b); break; 6546 default: fatal_unexpected_iid(id); break; 6547 } 6548 set_result(_gvn.transform(n)); 6549 return true; 6550 } 6551 6552 bool LibraryCallKit::inline_profileBoolean() { 6553 Node* counts = argument(1); 6554 const TypeAryPtr* ary = NULL; 6555 ciArray* aobj = NULL; 6556 if (counts->is_Con() 6557 && (ary = counts->bottom_type()->isa_aryptr()) != NULL 6558 && (aobj = ary->const_oop()->as_array()) != NULL 6559 && (aobj->length() == 2)) { 6560 // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively. 6561 jint false_cnt = aobj->element_value(0).as_int(); 6562 jint true_cnt = aobj->element_value(1).as_int(); 6563 6564 if (C->log() != NULL) { 6565 C->log()->elem("observe source='profileBoolean' false='%d' true='%d'", 6566 false_cnt, true_cnt); 6567 } 6568 6569 if (false_cnt + true_cnt == 0) { 6570 // According to profile, never executed. 6571 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 6572 Deoptimization::Action_reinterpret); 6573 return true; 6574 } 6575 6576 // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt) 6577 // is a number of each value occurrences. 6578 Node* result = argument(0); 6579 if (false_cnt == 0 || true_cnt == 0) { 6580 // According to profile, one value has been never seen. 6581 int expected_val = (false_cnt == 0) ? 1 : 0; 6582 6583 Node* cmp = _gvn.transform(new CmpINode(result, intcon(expected_val))); 6584 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 6585 6586 IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN); 6587 Node* fast_path = _gvn.transform(new IfTrueNode(check)); 6588 Node* slow_path = _gvn.transform(new IfFalseNode(check)); 6589 6590 { // Slow path: uncommon trap for never seen value and then reexecute 6591 // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows 6592 // the value has been seen at least once. 6593 PreserveJVMState pjvms(this); 6594 PreserveReexecuteState preexecs(this); 6595 jvms()->set_should_reexecute(true); 6596 6597 set_control(slow_path); 6598 set_i_o(i_o()); 6599 6600 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 6601 Deoptimization::Action_reinterpret); 6602 } 6603 // The guard for never seen value enables sharpening of the result and 6604 // returning a constant. It allows to eliminate branches on the same value 6605 // later on. 6606 set_control(fast_path); 6607 result = intcon(expected_val); 6608 } 6609 // Stop profiling. 6610 // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode. 6611 // By replacing method body with profile data (represented as ProfileBooleanNode 6612 // on IR level) we effectively disable profiling. 6613 // It enables full speed execution once optimized code is generated. 6614 Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt)); 6615 C->record_for_igvn(profile); 6616 set_result(profile); 6617 return true; 6618 } else { 6619 // Continue profiling. 6620 // Profile data isn't available at the moment. So, execute method's bytecode version. 6621 // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod 6622 // is compiled and counters aren't available since corresponding MethodHandle 6623 // isn't a compile-time constant. 6624 return false; 6625 } 6626 } 6627 6628 bool LibraryCallKit::inline_isCompileConstant() { 6629 Node* n = argument(0); 6630 set_result(n->is_Con() ? intcon(1) : intcon(0)); 6631 return true; 6632 }