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