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