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