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