1 /* 2 * Copyright (c) 1999, 2013, 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 "classfile/systemDictionary.hpp" 27 #include "classfile/vmSymbols.hpp" 28 #include "compiler/compileBroker.hpp" 29 #include "compiler/compileLog.hpp" 30 #include "oops/objArrayKlass.hpp" 31 #include "opto/addnode.hpp" 32 #include "opto/callGenerator.hpp" 33 #include "opto/castnode.hpp" 34 #include "opto/cfgnode.hpp" 35 #include "opto/convertnode.hpp" 36 #include "opto/countbitsnode.hpp" 37 #include "opto/intrinsicnode.hpp" 38 #include "opto/idealKit.hpp" 39 #include "opto/mathexactnode.hpp" 40 #include "opto/movenode.hpp" 41 #include "opto/mulnode.hpp" 42 #include "opto/narrowptrnode.hpp" 43 #include "opto/parse.hpp" 44 #include "opto/runtime.hpp" 45 #include "opto/subnode.hpp" 46 #include "prims/nativeLookup.hpp" 47 #include "runtime/sharedRuntime.hpp" 48 #include "trace/traceMacros.hpp" 49 50 class LibraryIntrinsic : public InlineCallGenerator { 51 // Extend the set of intrinsics known to the runtime: 52 public: 53 private: 54 bool _is_virtual; 55 bool _is_predicted; 56 bool _does_virtual_dispatch; 57 vmIntrinsics::ID _intrinsic_id; 58 59 public: 60 LibraryIntrinsic(ciMethod* m, bool is_virtual, bool is_predicted, bool does_virtual_dispatch, vmIntrinsics::ID id) 61 : InlineCallGenerator(m), 62 _is_virtual(is_virtual), 63 _is_predicted(is_predicted), 64 _does_virtual_dispatch(does_virtual_dispatch), 65 _intrinsic_id(id) 66 { 67 } 68 virtual bool is_intrinsic() const { return true; } 69 virtual bool is_virtual() const { return _is_virtual; } 70 virtual bool is_predicted() const { return _is_predicted; } 71 virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; } 72 virtual JVMState* generate(JVMState* jvms, Parse* parent_parser); 73 virtual Node* generate_predicate(JVMState* jvms); 74 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; } 75 }; 76 77 78 // Local helper class for LibraryIntrinsic: 79 class LibraryCallKit : public GraphKit { 80 private: 81 LibraryIntrinsic* _intrinsic; // the library intrinsic being called 82 Node* _result; // the result node, if any 83 int _reexecute_sp; // the stack pointer when bytecode needs to be reexecuted 84 85 const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr = false); 86 87 public: 88 LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic) 89 : GraphKit(jvms), 90 _intrinsic(intrinsic), 91 _result(NULL) 92 { 93 // Check if this is a root compile. In that case we don't have a caller. 94 if (!jvms->has_method()) { 95 _reexecute_sp = sp(); 96 } else { 97 // Find out how many arguments the interpreter needs when deoptimizing 98 // and save the stack pointer value so it can used by uncommon_trap. 99 // We find the argument count by looking at the declared signature. 100 bool ignored_will_link; 101 ciSignature* declared_signature = NULL; 102 ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature); 103 const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci())); 104 _reexecute_sp = sp() + nargs; // "push" arguments back on stack 105 } 106 } 107 108 virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; } 109 110 ciMethod* caller() const { return jvms()->method(); } 111 int bci() const { return jvms()->bci(); } 112 LibraryIntrinsic* intrinsic() const { return _intrinsic; } 113 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); } 114 ciMethod* callee() const { return _intrinsic->method(); } 115 116 bool try_to_inline(); 117 Node* try_to_predicate(); 118 119 void push_result() { 120 // Push the result onto the stack. 121 if (!stopped() && result() != NULL) { 122 BasicType bt = result()->bottom_type()->basic_type(); 123 push_node(bt, result()); 124 } 125 } 126 127 private: 128 void fatal_unexpected_iid(vmIntrinsics::ID iid) { 129 fatal(err_msg_res("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid))); 130 } 131 132 void set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; } 133 void set_result(RegionNode* region, PhiNode* value); 134 Node* result() { return _result; } 135 136 virtual int reexecute_sp() { return _reexecute_sp; } 137 138 // Helper functions to inline natives 139 Node* generate_guard(Node* test, RegionNode* region, float true_prob); 140 Node* generate_slow_guard(Node* test, RegionNode* region); 141 Node* generate_fair_guard(Node* test, RegionNode* region); 142 Node* generate_negative_guard(Node* index, RegionNode* region, 143 // resulting CastII of index: 144 Node* *pos_index = NULL); 145 Node* generate_nonpositive_guard(Node* index, bool never_negative, 146 // resulting CastII of index: 147 Node* *pos_index = NULL); 148 Node* generate_limit_guard(Node* offset, Node* subseq_length, 149 Node* array_length, 150 RegionNode* region); 151 Node* generate_current_thread(Node* &tls_output); 152 address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset, 153 bool disjoint_bases, const char* &name, bool dest_uninitialized); 154 Node* load_mirror_from_klass(Node* klass); 155 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null, 156 RegionNode* region, int null_path, 157 int offset); 158 Node* load_klass_from_mirror(Node* mirror, bool never_see_null, 159 RegionNode* region, int null_path) { 160 int offset = java_lang_Class::klass_offset_in_bytes(); 161 return load_klass_from_mirror_common(mirror, never_see_null, 162 region, null_path, 163 offset); 164 } 165 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null, 166 RegionNode* region, int null_path) { 167 int offset = java_lang_Class::array_klass_offset_in_bytes(); 168 return load_klass_from_mirror_common(mirror, never_see_null, 169 region, null_path, 170 offset); 171 } 172 Node* generate_access_flags_guard(Node* kls, 173 int modifier_mask, int modifier_bits, 174 RegionNode* region); 175 Node* generate_interface_guard(Node* kls, RegionNode* region); 176 Node* generate_array_guard(Node* kls, RegionNode* region) { 177 return generate_array_guard_common(kls, region, false, false); 178 } 179 Node* generate_non_array_guard(Node* kls, RegionNode* region) { 180 return generate_array_guard_common(kls, region, false, true); 181 } 182 Node* generate_objArray_guard(Node* kls, RegionNode* region) { 183 return generate_array_guard_common(kls, region, true, false); 184 } 185 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) { 186 return generate_array_guard_common(kls, region, true, true); 187 } 188 Node* generate_array_guard_common(Node* kls, RegionNode* region, 189 bool obj_array, bool not_array); 190 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region); 191 CallJavaNode* generate_method_call(vmIntrinsics::ID method_id, 192 bool is_virtual = false, bool is_static = false); 193 CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) { 194 return generate_method_call(method_id, false, true); 195 } 196 CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) { 197 return generate_method_call(method_id, true, false); 198 } 199 Node * load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static); 200 201 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2); 202 Node* make_string_method_node(int opcode, Node* str1, Node* str2); 203 bool inline_string_compareTo(); 204 bool inline_string_indexOf(); 205 Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i); 206 bool inline_string_equals(); 207 Node* round_double_node(Node* n); 208 bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName); 209 bool inline_math_native(vmIntrinsics::ID id); 210 bool inline_trig(vmIntrinsics::ID id); 211 bool inline_math(vmIntrinsics::ID id); 212 template <typename OverflowOp> 213 bool inline_math_overflow(Node* arg1, Node* arg2); 214 void inline_math_mathExact(Node* math, Node* test); 215 bool inline_math_addExactI(bool is_increment); 216 bool inline_math_addExactL(bool is_increment); 217 bool inline_math_multiplyExactI(); 218 bool inline_math_multiplyExactL(); 219 bool inline_math_negateExactI(); 220 bool inline_math_negateExactL(); 221 bool inline_math_subtractExactI(bool is_decrement); 222 bool inline_math_subtractExactL(bool is_decrement); 223 bool inline_exp(); 224 bool inline_pow(); 225 Node* finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName); 226 bool inline_min_max(vmIntrinsics::ID id); 227 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); 228 // This returns Type::AnyPtr, RawPtr, or OopPtr. 229 int classify_unsafe_addr(Node* &base, Node* &offset); 230 Node* make_unsafe_address(Node* base, Node* offset); 231 // Helper for inline_unsafe_access. 232 // Generates the guards that check whether the result of 233 // Unsafe.getObject should be recorded in an SATB log buffer. 234 void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar); 235 bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile); 236 bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static); 237 static bool klass_needs_init_guard(Node* kls); 238 bool inline_unsafe_allocate(); 239 bool inline_unsafe_copyMemory(); 240 bool inline_native_currentThread(); 241 #ifdef TRACE_HAVE_INTRINSICS 242 bool inline_native_classID(); 243 bool inline_native_threadID(); 244 #endif 245 bool inline_native_time_funcs(address method, const char* funcName); 246 bool inline_native_isInterrupted(); 247 bool inline_native_Class_query(vmIntrinsics::ID id); 248 bool inline_native_subtype_check(); 249 250 bool inline_native_newArray(); 251 bool inline_native_getLength(); 252 bool inline_array_copyOf(bool is_copyOfRange); 253 bool inline_array_equals(); 254 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark); 255 bool inline_native_clone(bool is_virtual); 256 bool inline_native_Reflection_getCallerClass(); 257 // Helper function for inlining native object hash method 258 bool inline_native_hashcode(bool is_virtual, bool is_static); 259 bool inline_native_getClass(); 260 261 // Helper functions for inlining arraycopy 262 bool inline_arraycopy(); 263 void generate_arraycopy(const TypePtr* adr_type, 264 BasicType basic_elem_type, 265 Node* src, Node* src_offset, 266 Node* dest, Node* dest_offset, 267 Node* copy_length, 268 bool disjoint_bases = false, 269 bool length_never_negative = false, 270 RegionNode* slow_region = NULL); 271 AllocateArrayNode* tightly_coupled_allocation(Node* ptr, 272 RegionNode* slow_region); 273 void generate_clear_array(const TypePtr* adr_type, 274 Node* dest, 275 BasicType basic_elem_type, 276 Node* slice_off, 277 Node* slice_len, 278 Node* slice_end); 279 bool generate_block_arraycopy(const TypePtr* adr_type, 280 BasicType basic_elem_type, 281 AllocateNode* alloc, 282 Node* src, Node* src_offset, 283 Node* dest, Node* dest_offset, 284 Node* dest_size, bool dest_uninitialized); 285 void generate_slow_arraycopy(const TypePtr* adr_type, 286 Node* src, Node* src_offset, 287 Node* dest, Node* dest_offset, 288 Node* copy_length, bool dest_uninitialized); 289 Node* generate_checkcast_arraycopy(const TypePtr* adr_type, 290 Node* dest_elem_klass, 291 Node* src, Node* src_offset, 292 Node* dest, Node* dest_offset, 293 Node* copy_length, bool dest_uninitialized); 294 Node* generate_generic_arraycopy(const TypePtr* adr_type, 295 Node* src, Node* src_offset, 296 Node* dest, Node* dest_offset, 297 Node* copy_length, bool dest_uninitialized); 298 void generate_unchecked_arraycopy(const TypePtr* adr_type, 299 BasicType basic_elem_type, 300 bool disjoint_bases, 301 Node* src, Node* src_offset, 302 Node* dest, Node* dest_offset, 303 Node* copy_length, bool dest_uninitialized); 304 typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind; 305 bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind); 306 bool inline_unsafe_ordered_store(BasicType type); 307 bool inline_unsafe_fence(vmIntrinsics::ID id); 308 bool inline_fp_conversions(vmIntrinsics::ID id); 309 bool inline_number_methods(vmIntrinsics::ID id); 310 bool inline_reference_get(); 311 bool inline_aescrypt_Block(vmIntrinsics::ID id); 312 bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id); 313 Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting); 314 Node* get_key_start_from_aescrypt_object(Node* aescrypt_object); 315 Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object); 316 bool inline_encodeISOArray(); 317 bool inline_updateCRC32(); 318 bool inline_updateBytesCRC32(); 319 bool inline_updateByteBufferCRC32(); 320 }; 321 322 323 //---------------------------make_vm_intrinsic---------------------------- 324 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 325 vmIntrinsics::ID id = m->intrinsic_id(); 326 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 327 328 if (DisableIntrinsic[0] != '\0' 329 && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) { 330 // disabled by a user request on the command line: 331 // example: -XX:DisableIntrinsic=_hashCode,_getClass 332 return NULL; 333 } 334 335 if (!m->is_loaded()) { 336 // do not attempt to inline unloaded methods 337 return NULL; 338 } 339 340 // Only a few intrinsics implement a virtual dispatch. 341 // They are expensive calls which are also frequently overridden. 342 if (is_virtual) { 343 switch (id) { 344 case vmIntrinsics::_hashCode: 345 case vmIntrinsics::_clone: 346 // OK, Object.hashCode and Object.clone intrinsics come in both flavors 347 break; 348 default: 349 return NULL; 350 } 351 } 352 353 // -XX:-InlineNatives disables nearly all intrinsics: 354 if (!InlineNatives) { 355 switch (id) { 356 case vmIntrinsics::_indexOf: 357 case vmIntrinsics::_compareTo: 358 case vmIntrinsics::_equals: 359 case vmIntrinsics::_equalsC: 360 case vmIntrinsics::_getAndAddInt: 361 case vmIntrinsics::_getAndAddLong: 362 case vmIntrinsics::_getAndSetInt: 363 case vmIntrinsics::_getAndSetLong: 364 case vmIntrinsics::_getAndSetObject: 365 case vmIntrinsics::_loadFence: 366 case vmIntrinsics::_storeFence: 367 case vmIntrinsics::_fullFence: 368 break; // InlineNatives does not control String.compareTo 369 case vmIntrinsics::_Reference_get: 370 break; // InlineNatives does not control Reference.get 371 default: 372 return NULL; 373 } 374 } 375 376 bool is_predicted = false; 377 bool does_virtual_dispatch = false; 378 379 switch (id) { 380 case vmIntrinsics::_compareTo: 381 if (!SpecialStringCompareTo) return NULL; 382 if (!Matcher::match_rule_supported(Op_StrComp)) return NULL; 383 break; 384 case vmIntrinsics::_indexOf: 385 if (!SpecialStringIndexOf) return NULL; 386 break; 387 case vmIntrinsics::_equals: 388 if (!SpecialStringEquals) return NULL; 389 if (!Matcher::match_rule_supported(Op_StrEquals)) return NULL; 390 break; 391 case vmIntrinsics::_equalsC: 392 if (!SpecialArraysEquals) return NULL; 393 if (!Matcher::match_rule_supported(Op_AryEq)) return NULL; 394 break; 395 case vmIntrinsics::_arraycopy: 396 if (!InlineArrayCopy) return NULL; 397 break; 398 case vmIntrinsics::_copyMemory: 399 if (StubRoutines::unsafe_arraycopy() == NULL) return NULL; 400 if (!InlineArrayCopy) return NULL; 401 break; 402 case vmIntrinsics::_hashCode: 403 if (!InlineObjectHash) return NULL; 404 does_virtual_dispatch = true; 405 break; 406 case vmIntrinsics::_clone: 407 does_virtual_dispatch = true; 408 case vmIntrinsics::_copyOf: 409 case vmIntrinsics::_copyOfRange: 410 if (!InlineObjectCopy) return NULL; 411 // These also use the arraycopy intrinsic mechanism: 412 if (!InlineArrayCopy) return NULL; 413 break; 414 case vmIntrinsics::_encodeISOArray: 415 if (!SpecialEncodeISOArray) return NULL; 416 if (!Matcher::match_rule_supported(Op_EncodeISOArray)) return NULL; 417 break; 418 case vmIntrinsics::_checkIndex: 419 // We do not intrinsify this. The optimizer does fine with it. 420 return NULL; 421 422 case vmIntrinsics::_getCallerClass: 423 if (!UseNewReflection) return NULL; 424 if (!InlineReflectionGetCallerClass) return NULL; 425 if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) return NULL; 426 break; 427 428 case vmIntrinsics::_bitCount_i: 429 if (!Matcher::match_rule_supported(Op_PopCountI)) return NULL; 430 break; 431 432 case vmIntrinsics::_bitCount_l: 433 if (!Matcher::match_rule_supported(Op_PopCountL)) return NULL; 434 break; 435 436 case vmIntrinsics::_numberOfLeadingZeros_i: 437 if (!Matcher::match_rule_supported(Op_CountLeadingZerosI)) return NULL; 438 break; 439 440 case vmIntrinsics::_numberOfLeadingZeros_l: 441 if (!Matcher::match_rule_supported(Op_CountLeadingZerosL)) return NULL; 442 break; 443 444 case vmIntrinsics::_numberOfTrailingZeros_i: 445 if (!Matcher::match_rule_supported(Op_CountTrailingZerosI)) return NULL; 446 break; 447 448 case vmIntrinsics::_numberOfTrailingZeros_l: 449 if (!Matcher::match_rule_supported(Op_CountTrailingZerosL)) return NULL; 450 break; 451 452 case vmIntrinsics::_reverseBytes_c: 453 if (!Matcher::match_rule_supported(Op_ReverseBytesUS)) return NULL; 454 break; 455 case vmIntrinsics::_reverseBytes_s: 456 if (!Matcher::match_rule_supported(Op_ReverseBytesS)) return NULL; 457 break; 458 case vmIntrinsics::_reverseBytes_i: 459 if (!Matcher::match_rule_supported(Op_ReverseBytesI)) return NULL; 460 break; 461 case vmIntrinsics::_reverseBytes_l: 462 if (!Matcher::match_rule_supported(Op_ReverseBytesL)) return NULL; 463 break; 464 465 case vmIntrinsics::_Reference_get: 466 // Use the intrinsic version of Reference.get() so that the value in 467 // the referent field can be registered by the G1 pre-barrier code. 468 // Also add memory barrier to prevent commoning reads from this field 469 // across safepoint since GC can change it value. 470 break; 471 472 case vmIntrinsics::_compareAndSwapObject: 473 #ifdef _LP64 474 if (!UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndSwapP)) return NULL; 475 #endif 476 break; 477 478 case vmIntrinsics::_compareAndSwapLong: 479 if (!Matcher::match_rule_supported(Op_CompareAndSwapL)) return NULL; 480 break; 481 482 case vmIntrinsics::_getAndAddInt: 483 if (!Matcher::match_rule_supported(Op_GetAndAddI)) return NULL; 484 break; 485 486 case vmIntrinsics::_getAndAddLong: 487 if (!Matcher::match_rule_supported(Op_GetAndAddL)) return NULL; 488 break; 489 490 case vmIntrinsics::_getAndSetInt: 491 if (!Matcher::match_rule_supported(Op_GetAndSetI)) return NULL; 492 break; 493 494 case vmIntrinsics::_getAndSetLong: 495 if (!Matcher::match_rule_supported(Op_GetAndSetL)) return NULL; 496 break; 497 498 case vmIntrinsics::_getAndSetObject: 499 #ifdef _LP64 500 if (!UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetP)) return NULL; 501 if (UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetN)) return NULL; 502 break; 503 #else 504 if (!Matcher::match_rule_supported(Op_GetAndSetP)) return NULL; 505 break; 506 #endif 507 508 case vmIntrinsics::_aescrypt_encryptBlock: 509 case vmIntrinsics::_aescrypt_decryptBlock: 510 if (!UseAESIntrinsics) return NULL; 511 break; 512 513 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 514 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 515 if (!UseAESIntrinsics) return NULL; 516 // these two require the predicated logic 517 is_predicted = true; 518 break; 519 520 case vmIntrinsics::_updateCRC32: 521 case vmIntrinsics::_updateBytesCRC32: 522 case vmIntrinsics::_updateByteBufferCRC32: 523 if (!UseCRC32Intrinsics) return NULL; 524 break; 525 526 case vmIntrinsics::_incrementExactI: 527 case vmIntrinsics::_addExactI: 528 if (!Matcher::match_rule_supported(Op_OverflowAddI) || !UseMathExactIntrinsics) return NULL; 529 break; 530 case vmIntrinsics::_incrementExactL: 531 case vmIntrinsics::_addExactL: 532 if (!Matcher::match_rule_supported(Op_OverflowAddL) || !UseMathExactIntrinsics) return NULL; 533 break; 534 case vmIntrinsics::_decrementExactI: 535 case vmIntrinsics::_subtractExactI: 536 if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL; 537 break; 538 case vmIntrinsics::_decrementExactL: 539 case vmIntrinsics::_subtractExactL: 540 if (!Matcher::match_rule_supported(Op_OverflowSubL) || !UseMathExactIntrinsics) return NULL; 541 break; 542 case vmIntrinsics::_negateExactI: 543 if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL; 544 break; 545 case vmIntrinsics::_negateExactL: 546 if (!Matcher::match_rule_supported(Op_OverflowSubL) || !UseMathExactIntrinsics) return NULL; 547 break; 548 case vmIntrinsics::_multiplyExactI: 549 if (!Matcher::match_rule_supported(Op_OverflowMulI) || !UseMathExactIntrinsics) return NULL; 550 break; 551 case vmIntrinsics::_multiplyExactL: 552 if (!Matcher::match_rule_supported(Op_OverflowMulL) || !UseMathExactIntrinsics) return NULL; 553 break; 554 555 default: 556 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility"); 557 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?"); 558 break; 559 } 560 561 // -XX:-InlineClassNatives disables natives from the Class class. 562 // The flag applies to all reflective calls, notably Array.newArray 563 // (visible to Java programmers as Array.newInstance). 564 if (m->holder()->name() == ciSymbol::java_lang_Class() || 565 m->holder()->name() == ciSymbol::java_lang_reflect_Array()) { 566 if (!InlineClassNatives) return NULL; 567 } 568 569 // -XX:-InlineThreadNatives disables natives from the Thread class. 570 if (m->holder()->name() == ciSymbol::java_lang_Thread()) { 571 if (!InlineThreadNatives) return NULL; 572 } 573 574 // -XX:-InlineMathNatives disables natives from the Math,Float and Double classes. 575 if (m->holder()->name() == ciSymbol::java_lang_Math() || 576 m->holder()->name() == ciSymbol::java_lang_Float() || 577 m->holder()->name() == ciSymbol::java_lang_Double()) { 578 if (!InlineMathNatives) return NULL; 579 } 580 581 // -XX:-InlineUnsafeOps disables natives from the Unsafe class. 582 if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) { 583 if (!InlineUnsafeOps) return NULL; 584 } 585 586 return new LibraryIntrinsic(m, is_virtual, is_predicted, does_virtual_dispatch, (vmIntrinsics::ID) id); 587 } 588 589 //----------------------register_library_intrinsics----------------------- 590 // Initialize this file's data structures, for each Compile instance. 591 void Compile::register_library_intrinsics() { 592 // Nothing to do here. 593 } 594 595 JVMState* LibraryIntrinsic::generate(JVMState* jvms, Parse* parent_parser) { 596 LibraryCallKit kit(jvms, this); 597 Compile* C = kit.C; 598 int nodes = C->unique(); 599 #ifndef PRODUCT 600 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 601 char buf[1000]; 602 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 603 tty->print_cr("Intrinsic %s", str); 604 } 605 #endif 606 ciMethod* callee = kit.callee(); 607 const int bci = kit.bci(); 608 609 // Try to inline the intrinsic. 610 if (kit.try_to_inline()) { 611 if (C->print_intrinsics() || C->print_inlining()) { 612 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 613 } 614 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 615 if (C->log()) { 616 C->log()->elem("intrinsic id='%s'%s nodes='%d'", 617 vmIntrinsics::name_at(intrinsic_id()), 618 (is_virtual() ? " virtual='1'" : ""), 619 C->unique() - nodes); 620 } 621 // Push the result from the inlined method onto the stack. 622 kit.push_result(); 623 C->print_inlining_update(this); 624 return kit.transfer_exceptions_into_jvms(); 625 } 626 627 // The intrinsic bailed out 628 if (C->print_intrinsics() || C->print_inlining()) { 629 if (jvms->has_method()) { 630 // Not a root compile. 631 const char* msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)"; 632 C->print_inlining(callee, jvms->depth() - 1, bci, msg); 633 } else { 634 // Root compile 635 tty->print("Did not generate intrinsic %s%s at bci:%d in", 636 vmIntrinsics::name_at(intrinsic_id()), 637 (is_virtual() ? " (virtual)" : ""), bci); 638 } 639 } 640 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 641 C->print_inlining_update(this); 642 return NULL; 643 } 644 645 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms) { 646 LibraryCallKit kit(jvms, this); 647 Compile* C = kit.C; 648 int nodes = C->unique(); 649 #ifndef PRODUCT 650 assert(is_predicted(), "sanity"); 651 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 652 char buf[1000]; 653 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 654 tty->print_cr("Predicate for intrinsic %s", str); 655 } 656 #endif 657 ciMethod* callee = kit.callee(); 658 const int bci = kit.bci(); 659 660 Node* slow_ctl = kit.try_to_predicate(); 661 if (!kit.failing()) { 662 if (C->print_intrinsics() || C->print_inlining()) { 663 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 664 } 665 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 666 if (C->log()) { 667 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 668 vmIntrinsics::name_at(intrinsic_id()), 669 (is_virtual() ? " virtual='1'" : ""), 670 C->unique() - nodes); 671 } 672 return slow_ctl; // Could be NULL if the check folds. 673 } 674 675 // The intrinsic bailed out 676 if (C->print_intrinsics() || C->print_inlining()) { 677 if (jvms->has_method()) { 678 // Not a root compile. 679 const char* msg = "failed to generate predicate for intrinsic"; 680 C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg); 681 } else { 682 // Root compile 683 C->print_inlining_stream()->print("Did not generate predicate for intrinsic %s%s at bci:%d in", 684 vmIntrinsics::name_at(intrinsic_id()), 685 (is_virtual() ? " (virtual)" : ""), bci); 686 } 687 } 688 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 689 return NULL; 690 } 691 692 bool LibraryCallKit::try_to_inline() { 693 // Handle symbolic names for otherwise undistinguished boolean switches: 694 const bool is_store = true; 695 const bool is_native_ptr = true; 696 const bool is_static = true; 697 const bool is_volatile = true; 698 699 if (!jvms()->has_method()) { 700 // Root JVMState has a null method. 701 assert(map()->memory()->Opcode() == Op_Parm, ""); 702 // Insert the memory aliasing node 703 set_all_memory(reset_memory()); 704 } 705 assert(merged_memory(), ""); 706 707 708 switch (intrinsic_id()) { 709 case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 710 case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static); 711 case vmIntrinsics::_getClass: return inline_native_getClass(); 712 713 case vmIntrinsics::_dsin: 714 case vmIntrinsics::_dcos: 715 case vmIntrinsics::_dtan: 716 case vmIntrinsics::_dabs: 717 case vmIntrinsics::_datan2: 718 case vmIntrinsics::_dsqrt: 719 case vmIntrinsics::_dexp: 720 case vmIntrinsics::_dlog: 721 case vmIntrinsics::_dlog10: 722 case vmIntrinsics::_dpow: return inline_math_native(intrinsic_id()); 723 724 case vmIntrinsics::_min: 725 case vmIntrinsics::_max: return inline_min_max(intrinsic_id()); 726 727 case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 728 case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 729 case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 730 case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 731 case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 732 case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 733 case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 734 case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 735 case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 736 case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 737 case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 738 case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 739 740 case vmIntrinsics::_arraycopy: return inline_arraycopy(); 741 742 case vmIntrinsics::_compareTo: return inline_string_compareTo(); 743 case vmIntrinsics::_indexOf: return inline_string_indexOf(); 744 case vmIntrinsics::_equals: return inline_string_equals(); 745 746 case vmIntrinsics::_getObject: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, !is_volatile); 747 case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, !is_volatile); 748 case vmIntrinsics::_getByte: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, !is_volatile); 749 case vmIntrinsics::_getShort: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, !is_volatile); 750 case vmIntrinsics::_getChar: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, !is_volatile); 751 case vmIntrinsics::_getInt: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, !is_volatile); 752 case vmIntrinsics::_getLong: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, !is_volatile); 753 case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, !is_volatile); 754 case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, !is_volatile); 755 756 case vmIntrinsics::_putObject: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, !is_volatile); 757 case vmIntrinsics::_putBoolean: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, !is_volatile); 758 case vmIntrinsics::_putByte: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, !is_volatile); 759 case vmIntrinsics::_putShort: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, !is_volatile); 760 case vmIntrinsics::_putChar: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, !is_volatile); 761 case vmIntrinsics::_putInt: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, !is_volatile); 762 case vmIntrinsics::_putLong: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, !is_volatile); 763 case vmIntrinsics::_putFloat: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, !is_volatile); 764 case vmIntrinsics::_putDouble: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, !is_volatile); 765 766 case vmIntrinsics::_getByte_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_BYTE, !is_volatile); 767 case vmIntrinsics::_getShort_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_SHORT, !is_volatile); 768 case vmIntrinsics::_getChar_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_CHAR, !is_volatile); 769 case vmIntrinsics::_getInt_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_INT, !is_volatile); 770 case vmIntrinsics::_getLong_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_LONG, !is_volatile); 771 case vmIntrinsics::_getFloat_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_FLOAT, !is_volatile); 772 case vmIntrinsics::_getDouble_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_DOUBLE, !is_volatile); 773 case vmIntrinsics::_getAddress_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_ADDRESS, !is_volatile); 774 775 case vmIntrinsics::_putByte_raw: return inline_unsafe_access( is_native_ptr, is_store, T_BYTE, !is_volatile); 776 case vmIntrinsics::_putShort_raw: return inline_unsafe_access( is_native_ptr, is_store, T_SHORT, !is_volatile); 777 case vmIntrinsics::_putChar_raw: return inline_unsafe_access( is_native_ptr, is_store, T_CHAR, !is_volatile); 778 case vmIntrinsics::_putInt_raw: return inline_unsafe_access( is_native_ptr, is_store, T_INT, !is_volatile); 779 case vmIntrinsics::_putLong_raw: return inline_unsafe_access( is_native_ptr, is_store, T_LONG, !is_volatile); 780 case vmIntrinsics::_putFloat_raw: return inline_unsafe_access( is_native_ptr, is_store, T_FLOAT, !is_volatile); 781 case vmIntrinsics::_putDouble_raw: return inline_unsafe_access( is_native_ptr, is_store, T_DOUBLE, !is_volatile); 782 case vmIntrinsics::_putAddress_raw: return inline_unsafe_access( is_native_ptr, is_store, T_ADDRESS, !is_volatile); 783 784 case vmIntrinsics::_getObjectVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, is_volatile); 785 case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, is_volatile); 786 case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, is_volatile); 787 case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, is_volatile); 788 case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, is_volatile); 789 case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, is_volatile); 790 case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, is_volatile); 791 case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, is_volatile); 792 case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, is_volatile); 793 794 case vmIntrinsics::_putObjectVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, is_volatile); 795 case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, is_volatile); 796 case vmIntrinsics::_putByteVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, is_volatile); 797 case vmIntrinsics::_putShortVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, is_volatile); 798 case vmIntrinsics::_putCharVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, is_volatile); 799 case vmIntrinsics::_putIntVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, is_volatile); 800 case vmIntrinsics::_putLongVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, is_volatile); 801 case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, is_volatile); 802 case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, is_volatile); 803 804 case vmIntrinsics::_prefetchRead: return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static); 805 case vmIntrinsics::_prefetchWrite: return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static); 806 case vmIntrinsics::_prefetchReadStatic: return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static); 807 case vmIntrinsics::_prefetchWriteStatic: return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static); 808 809 case vmIntrinsics::_compareAndSwapObject: return inline_unsafe_load_store(T_OBJECT, LS_cmpxchg); 810 case vmIntrinsics::_compareAndSwapInt: return inline_unsafe_load_store(T_INT, LS_cmpxchg); 811 case vmIntrinsics::_compareAndSwapLong: return inline_unsafe_load_store(T_LONG, LS_cmpxchg); 812 813 case vmIntrinsics::_putOrderedObject: return inline_unsafe_ordered_store(T_OBJECT); 814 case vmIntrinsics::_putOrderedInt: return inline_unsafe_ordered_store(T_INT); 815 case vmIntrinsics::_putOrderedLong: return inline_unsafe_ordered_store(T_LONG); 816 817 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_xadd); 818 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_xadd); 819 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_xchg); 820 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_xchg); 821 case vmIntrinsics::_getAndSetObject: return inline_unsafe_load_store(T_OBJECT, LS_xchg); 822 823 case vmIntrinsics::_loadFence: 824 case vmIntrinsics::_storeFence: 825 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id()); 826 827 case vmIntrinsics::_currentThread: return inline_native_currentThread(); 828 case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted(); 829 830 #ifdef TRACE_HAVE_INTRINSICS 831 case vmIntrinsics::_classID: return inline_native_classID(); 832 case vmIntrinsics::_threadID: return inline_native_threadID(); 833 case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), "counterTime"); 834 #endif 835 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis"); 836 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime"); 837 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate(); 838 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory(); 839 case vmIntrinsics::_newArray: return inline_native_newArray(); 840 case vmIntrinsics::_getLength: return inline_native_getLength(); 841 case vmIntrinsics::_copyOf: return inline_array_copyOf(false); 842 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true); 843 case vmIntrinsics::_equalsC: return inline_array_equals(); 844 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual()); 845 846 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check(); 847 848 case vmIntrinsics::_isInstance: 849 case vmIntrinsics::_getModifiers: 850 case vmIntrinsics::_isInterface: 851 case vmIntrinsics::_isArray: 852 case vmIntrinsics::_isPrimitive: 853 case vmIntrinsics::_getSuperclass: 854 case vmIntrinsics::_getComponentType: 855 case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id()); 856 857 case vmIntrinsics::_floatToRawIntBits: 858 case vmIntrinsics::_floatToIntBits: 859 case vmIntrinsics::_intBitsToFloat: 860 case vmIntrinsics::_doubleToRawLongBits: 861 case vmIntrinsics::_doubleToLongBits: 862 case vmIntrinsics::_longBitsToDouble: return inline_fp_conversions(intrinsic_id()); 863 864 case vmIntrinsics::_numberOfLeadingZeros_i: 865 case vmIntrinsics::_numberOfLeadingZeros_l: 866 case vmIntrinsics::_numberOfTrailingZeros_i: 867 case vmIntrinsics::_numberOfTrailingZeros_l: 868 case vmIntrinsics::_bitCount_i: 869 case vmIntrinsics::_bitCount_l: 870 case vmIntrinsics::_reverseBytes_i: 871 case vmIntrinsics::_reverseBytes_l: 872 case vmIntrinsics::_reverseBytes_s: 873 case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id()); 874 875 case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass(); 876 877 case vmIntrinsics::_Reference_get: return inline_reference_get(); 878 879 case vmIntrinsics::_aescrypt_encryptBlock: 880 case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id()); 881 882 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 883 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 884 return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 885 886 case vmIntrinsics::_encodeISOArray: 887 return inline_encodeISOArray(); 888 889 case vmIntrinsics::_updateCRC32: 890 return inline_updateCRC32(); 891 case vmIntrinsics::_updateBytesCRC32: 892 return inline_updateBytesCRC32(); 893 case vmIntrinsics::_updateByteBufferCRC32: 894 return inline_updateByteBufferCRC32(); 895 896 default: 897 // If you get here, it may be that someone has added a new intrinsic 898 // to the list in vmSymbols.hpp without implementing it here. 899 #ifndef PRODUCT 900 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 901 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 902 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 903 } 904 #endif 905 return false; 906 } 907 } 908 909 Node* LibraryCallKit::try_to_predicate() { 910 if (!jvms()->has_method()) { 911 // Root JVMState has a null method. 912 assert(map()->memory()->Opcode() == Op_Parm, ""); 913 // Insert the memory aliasing node 914 set_all_memory(reset_memory()); 915 } 916 assert(merged_memory(), ""); 917 918 switch (intrinsic_id()) { 919 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 920 return inline_cipherBlockChaining_AESCrypt_predicate(false); 921 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 922 return inline_cipherBlockChaining_AESCrypt_predicate(true); 923 924 default: 925 // If you get here, it may be that someone has added a new intrinsic 926 // to the list in vmSymbols.hpp without implementing it here. 927 #ifndef PRODUCT 928 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 929 tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)", 930 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 931 } 932 #endif 933 Node* slow_ctl = control(); 934 set_control(top()); // No fast path instrinsic 935 return slow_ctl; 936 } 937 } 938 939 //------------------------------set_result------------------------------- 940 // Helper function for finishing intrinsics. 941 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) { 942 record_for_igvn(region); 943 set_control(_gvn.transform(region)); 944 set_result( _gvn.transform(value)); 945 assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity"); 946 } 947 948 //------------------------------generate_guard--------------------------- 949 // Helper function for generating guarded fast-slow graph structures. 950 // The given 'test', if true, guards a slow path. If the test fails 951 // then a fast path can be taken. (We generally hope it fails.) 952 // In all cases, GraphKit::control() is updated to the fast path. 953 // The returned value represents the control for the slow path. 954 // The return value is never 'top'; it is either a valid control 955 // or NULL if it is obvious that the slow path can never be taken. 956 // Also, if region and the slow control are not NULL, the slow edge 957 // is appended to the region. 958 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 959 if (stopped()) { 960 // Already short circuited. 961 return NULL; 962 } 963 964 // Build an if node and its projections. 965 // If test is true we take the slow path, which we assume is uncommon. 966 if (_gvn.type(test) == TypeInt::ZERO) { 967 // The slow branch is never taken. No need to build this guard. 968 return NULL; 969 } 970 971 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 972 973 Node* if_slow = _gvn.transform(new (C) IfTrueNode(iff)); 974 if (if_slow == top()) { 975 // The slow branch is never taken. No need to build this guard. 976 return NULL; 977 } 978 979 if (region != NULL) 980 region->add_req(if_slow); 981 982 Node* if_fast = _gvn.transform(new (C) IfFalseNode(iff)); 983 set_control(if_fast); 984 985 return if_slow; 986 } 987 988 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 989 return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 990 } 991 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 992 return generate_guard(test, region, PROB_FAIR); 993 } 994 995 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 996 Node* *pos_index) { 997 if (stopped()) 998 return NULL; // already stopped 999 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 1000 return NULL; // index is already adequately typed 1001 Node* cmp_lt = _gvn.transform(new (C) CmpINode(index, intcon(0))); 1002 Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt)); 1003 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 1004 if (is_neg != NULL && pos_index != NULL) { 1005 // Emulate effect of Parse::adjust_map_after_if. 1006 Node* ccast = new (C) CastIINode(index, TypeInt::POS); 1007 ccast->set_req(0, control()); 1008 (*pos_index) = _gvn.transform(ccast); 1009 } 1010 return is_neg; 1011 } 1012 1013 inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_negative, 1014 Node* *pos_index) { 1015 if (stopped()) 1016 return NULL; // already stopped 1017 if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint] 1018 return NULL; // index is already adequately typed 1019 Node* cmp_le = _gvn.transform(new (C) CmpINode(index, intcon(0))); 1020 BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le); 1021 Node* bol_le = _gvn.transform(new (C) BoolNode(cmp_le, le_or_eq)); 1022 Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN); 1023 if (is_notp != NULL && pos_index != NULL) { 1024 // Emulate effect of Parse::adjust_map_after_if. 1025 Node* ccast = new (C) CastIINode(index, TypeInt::POS1); 1026 ccast->set_req(0, control()); 1027 (*pos_index) = _gvn.transform(ccast); 1028 } 1029 return is_notp; 1030 } 1031 1032 // Make sure that 'position' is a valid limit index, in [0..length]. 1033 // There are two equivalent plans for checking this: 1034 // A. (offset + copyLength) unsigned<= arrayLength 1035 // B. offset <= (arrayLength - copyLength) 1036 // We require that all of the values above, except for the sum and 1037 // difference, are already known to be non-negative. 1038 // Plan A is robust in the face of overflow, if offset and copyLength 1039 // are both hugely positive. 1040 // 1041 // Plan B is less direct and intuitive, but it does not overflow at 1042 // all, since the difference of two non-negatives is always 1043 // representable. Whenever Java methods must perform the equivalent 1044 // check they generally use Plan B instead of Plan A. 1045 // For the moment we use Plan A. 1046 inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 1047 Node* subseq_length, 1048 Node* array_length, 1049 RegionNode* region) { 1050 if (stopped()) 1051 return NULL; // already stopped 1052 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 1053 if (zero_offset && subseq_length->eqv_uncast(array_length)) 1054 return NULL; // common case of whole-array copy 1055 Node* last = subseq_length; 1056 if (!zero_offset) // last += offset 1057 last = _gvn.transform(new (C) AddINode(last, offset)); 1058 Node* cmp_lt = _gvn.transform(new (C) CmpUNode(array_length, last)); 1059 Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt)); 1060 Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 1061 return is_over; 1062 } 1063 1064 1065 //--------------------------generate_current_thread-------------------- 1066 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1067 ciKlass* thread_klass = env()->Thread_klass(); 1068 const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 1069 Node* thread = _gvn.transform(new (C) ThreadLocalNode()); 1070 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset())); 1071 Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT, MemNode::unordered); 1072 tls_output = thread; 1073 return threadObj; 1074 } 1075 1076 1077 //------------------------------make_string_method_node------------------------ 1078 // Helper method for String intrinsic functions. This version is called 1079 // with str1 and str2 pointing to String object nodes. 1080 // 1081 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* str2) { 1082 Node* no_ctrl = NULL; 1083 1084 // Get start addr of string 1085 Node* str1_value = load_String_value(no_ctrl, str1); 1086 Node* str1_offset = load_String_offset(no_ctrl, str1); 1087 Node* str1_start = array_element_address(str1_value, str1_offset, T_CHAR); 1088 1089 // Get length of string 1 1090 Node* str1_len = load_String_length(no_ctrl, str1); 1091 1092 Node* str2_value = load_String_value(no_ctrl, str2); 1093 Node* str2_offset = load_String_offset(no_ctrl, str2); 1094 Node* str2_start = array_element_address(str2_value, str2_offset, T_CHAR); 1095 1096 Node* str2_len = NULL; 1097 Node* result = NULL; 1098 1099 switch (opcode) { 1100 case Op_StrIndexOf: 1101 // Get length of string 2 1102 str2_len = load_String_length(no_ctrl, str2); 1103 1104 result = new (C) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), 1105 str1_start, str1_len, str2_start, str2_len); 1106 break; 1107 case Op_StrComp: 1108 // Get length of string 2 1109 str2_len = load_String_length(no_ctrl, str2); 1110 1111 result = new (C) StrCompNode(control(), memory(TypeAryPtr::CHARS), 1112 str1_start, str1_len, str2_start, str2_len); 1113 break; 1114 case Op_StrEquals: 1115 result = new (C) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), 1116 str1_start, str2_start, str1_len); 1117 break; 1118 default: 1119 ShouldNotReachHere(); 1120 return NULL; 1121 } 1122 1123 // All these intrinsics have checks. 1124 C->set_has_split_ifs(true); // Has chance for split-if optimization 1125 1126 return _gvn.transform(result); 1127 } 1128 1129 // Helper method for String intrinsic functions. This version is called 1130 // with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing 1131 // to Int nodes containing the lenghts of str1 and str2. 1132 // 1133 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) { 1134 Node* result = NULL; 1135 switch (opcode) { 1136 case Op_StrIndexOf: 1137 result = new (C) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), 1138 str1_start, cnt1, str2_start, cnt2); 1139 break; 1140 case Op_StrComp: 1141 result = new (C) StrCompNode(control(), memory(TypeAryPtr::CHARS), 1142 str1_start, cnt1, str2_start, cnt2); 1143 break; 1144 case Op_StrEquals: 1145 result = new (C) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), 1146 str1_start, str2_start, cnt1); 1147 break; 1148 default: 1149 ShouldNotReachHere(); 1150 return NULL; 1151 } 1152 1153 // All these intrinsics have checks. 1154 C->set_has_split_ifs(true); // Has chance for split-if optimization 1155 1156 return _gvn.transform(result); 1157 } 1158 1159 //------------------------------inline_string_compareTo------------------------ 1160 // public int java.lang.String.compareTo(String anotherString); 1161 bool LibraryCallKit::inline_string_compareTo() { 1162 Node* receiver = null_check(argument(0)); 1163 Node* arg = null_check(argument(1)); 1164 if (stopped()) { 1165 return true; 1166 } 1167 set_result(make_string_method_node(Op_StrComp, receiver, arg)); 1168 return true; 1169 } 1170 1171 //------------------------------inline_string_equals------------------------ 1172 bool LibraryCallKit::inline_string_equals() { 1173 Node* receiver = null_check_receiver(); 1174 // NOTE: Do not null check argument for String.equals() because spec 1175 // allows to specify NULL as argument. 1176 Node* argument = this->argument(1); 1177 if (stopped()) { 1178 return true; 1179 } 1180 1181 // paths (plus control) merge 1182 RegionNode* region = new (C) RegionNode(5); 1183 Node* phi = new (C) PhiNode(region, TypeInt::BOOL); 1184 1185 // does source == target string? 1186 Node* cmp = _gvn.transform(new (C) CmpPNode(receiver, argument)); 1187 Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::eq)); 1188 1189 Node* if_eq = generate_slow_guard(bol, NULL); 1190 if (if_eq != NULL) { 1191 // receiver == argument 1192 phi->init_req(2, intcon(1)); 1193 region->init_req(2, if_eq); 1194 } 1195 1196 // get String klass for instanceOf 1197 ciInstanceKlass* klass = env()->String_klass(); 1198 1199 if (!stopped()) { 1200 Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass))); 1201 Node* cmp = _gvn.transform(new (C) CmpINode(inst, intcon(1))); 1202 Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::ne)); 1203 1204 Node* inst_false = generate_guard(bol, NULL, PROB_MIN); 1205 //instanceOf == true, fallthrough 1206 1207 if (inst_false != NULL) { 1208 phi->init_req(3, intcon(0)); 1209 region->init_req(3, inst_false); 1210 } 1211 } 1212 1213 if (!stopped()) { 1214 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); 1215 1216 // Properly cast the argument to String 1217 argument = _gvn.transform(new (C) CheckCastPPNode(control(), argument, string_type)); 1218 // This path is taken only when argument's type is String:NotNull. 1219 argument = cast_not_null(argument, false); 1220 1221 Node* no_ctrl = NULL; 1222 1223 // Get start addr of receiver 1224 Node* receiver_val = load_String_value(no_ctrl, receiver); 1225 Node* receiver_offset = load_String_offset(no_ctrl, receiver); 1226 Node* receiver_start = array_element_address(receiver_val, receiver_offset, T_CHAR); 1227 1228 // Get length of receiver 1229 Node* receiver_cnt = load_String_length(no_ctrl, receiver); 1230 1231 // Get start addr of argument 1232 Node* argument_val = load_String_value(no_ctrl, argument); 1233 Node* argument_offset = load_String_offset(no_ctrl, argument); 1234 Node* argument_start = array_element_address(argument_val, argument_offset, T_CHAR); 1235 1236 // Get length of argument 1237 Node* argument_cnt = load_String_length(no_ctrl, argument); 1238 1239 // Check for receiver count != argument count 1240 Node* cmp = _gvn.transform(new(C) CmpINode(receiver_cnt, argument_cnt)); 1241 Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::ne)); 1242 Node* if_ne = generate_slow_guard(bol, NULL); 1243 if (if_ne != NULL) { 1244 phi->init_req(4, intcon(0)); 1245 region->init_req(4, if_ne); 1246 } 1247 1248 // Check for count == 0 is done by assembler code for StrEquals. 1249 1250 if (!stopped()) { 1251 Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt); 1252 phi->init_req(1, equals); 1253 region->init_req(1, control()); 1254 } 1255 } 1256 1257 // post merge 1258 set_control(_gvn.transform(region)); 1259 record_for_igvn(region); 1260 1261 set_result(_gvn.transform(phi)); 1262 return true; 1263 } 1264 1265 //------------------------------inline_array_equals---------------------------- 1266 bool LibraryCallKit::inline_array_equals() { 1267 Node* arg1 = argument(0); 1268 Node* arg2 = argument(1); 1269 set_result(_gvn.transform(new (C) AryEqNode(control(), memory(TypeAryPtr::CHARS), arg1, arg2))); 1270 return true; 1271 } 1272 1273 // Java version of String.indexOf(constant string) 1274 // class StringDecl { 1275 // StringDecl(char[] ca) { 1276 // offset = 0; 1277 // count = ca.length; 1278 // value = ca; 1279 // } 1280 // int offset; 1281 // int count; 1282 // char[] value; 1283 // } 1284 // 1285 // static int string_indexOf_J(StringDecl string_object, char[] target_object, 1286 // int targetOffset, int cache_i, int md2) { 1287 // int cache = cache_i; 1288 // int sourceOffset = string_object.offset; 1289 // int sourceCount = string_object.count; 1290 // int targetCount = target_object.length; 1291 // 1292 // int targetCountLess1 = targetCount - 1; 1293 // int sourceEnd = sourceOffset + sourceCount - targetCountLess1; 1294 // 1295 // char[] source = string_object.value; 1296 // char[] target = target_object; 1297 // int lastChar = target[targetCountLess1]; 1298 // 1299 // outer_loop: 1300 // for (int i = sourceOffset; i < sourceEnd; ) { 1301 // int src = source[i + targetCountLess1]; 1302 // if (src == lastChar) { 1303 // // With random strings and a 4-character alphabet, 1304 // // reverse matching at this point sets up 0.8% fewer 1305 // // frames, but (paradoxically) makes 0.3% more probes. 1306 // // Since those probes are nearer the lastChar probe, 1307 // // there is may be a net D$ win with reverse matching. 1308 // // But, reversing loop inhibits unroll of inner loop 1309 // // for unknown reason. So, does running outer loop from 1310 // // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) 1311 // for (int j = 0; j < targetCountLess1; j++) { 1312 // if (target[targetOffset + j] != source[i+j]) { 1313 // if ((cache & (1 << source[i+j])) == 0) { 1314 // if (md2 < j+1) { 1315 // i += j+1; 1316 // continue outer_loop; 1317 // } 1318 // } 1319 // i += md2; 1320 // continue outer_loop; 1321 // } 1322 // } 1323 // return i - sourceOffset; 1324 // } 1325 // if ((cache & (1 << src)) == 0) { 1326 // i += targetCountLess1; 1327 // } // using "i += targetCount;" and an "else i++;" causes a jump to jump. 1328 // i++; 1329 // } 1330 // return -1; 1331 // } 1332 1333 //------------------------------string_indexOf------------------------ 1334 Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i, 1335 jint cache_i, jint md2_i) { 1336 1337 Node* no_ctrl = NULL; 1338 float likely = PROB_LIKELY(0.9); 1339 float unlikely = PROB_UNLIKELY(0.9); 1340 1341 const int nargs = 0; // no arguments to push back for uncommon trap in predicate 1342 1343 Node* source = load_String_value(no_ctrl, string_object); 1344 Node* sourceOffset = load_String_offset(no_ctrl, string_object); 1345 Node* sourceCount = load_String_length(no_ctrl, string_object); 1346 1347 Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true))); 1348 jint target_length = target_array->length(); 1349 const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin)); 1350 const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot); 1351 1352 // String.value field is known to be @Stable. 1353 if (UseImplicitStableValues) { 1354 target = cast_array_to_stable(target, target_type); 1355 } 1356 1357 IdealKit kit(this, false, true); 1358 #define __ kit. 1359 Node* zero = __ ConI(0); 1360 Node* one = __ ConI(1); 1361 Node* cache = __ ConI(cache_i); 1362 Node* md2 = __ ConI(md2_i); 1363 Node* lastChar = __ ConI(target_array->char_at(target_length - 1)); 1364 Node* targetCount = __ ConI(target_length); 1365 Node* targetCountLess1 = __ ConI(target_length - 1); 1366 Node* targetOffset = __ ConI(targetOffset_i); 1367 Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1); 1368 1369 IdealVariable rtn(kit), i(kit), j(kit); __ declarations_done(); 1370 Node* outer_loop = __ make_label(2 /* goto */); 1371 Node* return_ = __ make_label(1); 1372 1373 __ set(rtn,__ ConI(-1)); 1374 __ loop(this, nargs, i, sourceOffset, BoolTest::lt, sourceEnd); { 1375 Node* i2 = __ AddI(__ value(i), targetCountLess1); 1376 // pin to prohibit loading of "next iteration" value which may SEGV (rare) 1377 Node* src = load_array_element(__ ctrl(), source, i2, TypeAryPtr::CHARS); 1378 __ if_then(src, BoolTest::eq, lastChar, unlikely); { 1379 __ loop(this, nargs, j, zero, BoolTest::lt, targetCountLess1); { 1380 Node* tpj = __ AddI(targetOffset, __ value(j)); 1381 Node* targ = load_array_element(no_ctrl, target, tpj, target_type); 1382 Node* ipj = __ AddI(__ value(i), __ value(j)); 1383 Node* src2 = load_array_element(no_ctrl, source, ipj, TypeAryPtr::CHARS); 1384 __ if_then(targ, BoolTest::ne, src2); { 1385 __ if_then(__ AndI(cache, __ LShiftI(one, src2)), BoolTest::eq, zero); { 1386 __ if_then(md2, BoolTest::lt, __ AddI(__ value(j), one)); { 1387 __ increment(i, __ AddI(__ value(j), one)); 1388 __ goto_(outer_loop); 1389 } __ end_if(); __ dead(j); 1390 }__ end_if(); __ dead(j); 1391 __ increment(i, md2); 1392 __ goto_(outer_loop); 1393 }__ end_if(); 1394 __ increment(j, one); 1395 }__ end_loop(); __ dead(j); 1396 __ set(rtn, __ SubI(__ value(i), sourceOffset)); __ dead(i); 1397 __ goto_(return_); 1398 }__ end_if(); 1399 __ if_then(__ AndI(cache, __ LShiftI(one, src)), BoolTest::eq, zero, likely); { 1400 __ increment(i, targetCountLess1); 1401 }__ end_if(); 1402 __ increment(i, one); 1403 __ bind(outer_loop); 1404 }__ end_loop(); __ dead(i); 1405 __ bind(return_); 1406 1407 // Final sync IdealKit and GraphKit. 1408 final_sync(kit); 1409 Node* result = __ value(rtn); 1410 #undef __ 1411 C->set_has_loops(true); 1412 return result; 1413 } 1414 1415 //------------------------------inline_string_indexOf------------------------ 1416 bool LibraryCallKit::inline_string_indexOf() { 1417 Node* receiver = argument(0); 1418 Node* arg = argument(1); 1419 1420 Node* result; 1421 // Disable the use of pcmpestri until it can be guaranteed that 1422 // the load doesn't cross into the uncommited space. 1423 if (Matcher::has_match_rule(Op_StrIndexOf) && 1424 UseSSE42Intrinsics) { 1425 // Generate SSE4.2 version of indexOf 1426 // We currently only have match rules that use SSE4.2 1427 1428 receiver = null_check(receiver); 1429 arg = null_check(arg); 1430 if (stopped()) { 1431 return true; 1432 } 1433 1434 ciInstanceKlass* str_klass = env()->String_klass(); 1435 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass); 1436 1437 // Make the merge point 1438 RegionNode* result_rgn = new (C) RegionNode(4); 1439 Node* result_phi = new (C) PhiNode(result_rgn, TypeInt::INT); 1440 Node* no_ctrl = NULL; 1441 1442 // Get start addr of source string 1443 Node* source = load_String_value(no_ctrl, receiver); 1444 Node* source_offset = load_String_offset(no_ctrl, receiver); 1445 Node* source_start = array_element_address(source, source_offset, T_CHAR); 1446 1447 // Get length of source string 1448 Node* source_cnt = load_String_length(no_ctrl, receiver); 1449 1450 // Get start addr of substring 1451 Node* substr = load_String_value(no_ctrl, arg); 1452 Node* substr_offset = load_String_offset(no_ctrl, arg); 1453 Node* substr_start = array_element_address(substr, substr_offset, T_CHAR); 1454 1455 // Get length of source string 1456 Node* substr_cnt = load_String_length(no_ctrl, arg); 1457 1458 // Check for substr count > string count 1459 Node* cmp = _gvn.transform(new(C) CmpINode(substr_cnt, source_cnt)); 1460 Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::gt)); 1461 Node* if_gt = generate_slow_guard(bol, NULL); 1462 if (if_gt != NULL) { 1463 result_phi->init_req(2, intcon(-1)); 1464 result_rgn->init_req(2, if_gt); 1465 } 1466 1467 if (!stopped()) { 1468 // Check for substr count == 0 1469 cmp = _gvn.transform(new(C) CmpINode(substr_cnt, intcon(0))); 1470 bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq)); 1471 Node* if_zero = generate_slow_guard(bol, NULL); 1472 if (if_zero != NULL) { 1473 result_phi->init_req(3, intcon(0)); 1474 result_rgn->init_req(3, if_zero); 1475 } 1476 } 1477 1478 if (!stopped()) { 1479 result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt); 1480 result_phi->init_req(1, result); 1481 result_rgn->init_req(1, control()); 1482 } 1483 set_control(_gvn.transform(result_rgn)); 1484 record_for_igvn(result_rgn); 1485 result = _gvn.transform(result_phi); 1486 1487 } else { // Use LibraryCallKit::string_indexOf 1488 // don't intrinsify if argument isn't a constant string. 1489 if (!arg->is_Con()) { 1490 return false; 1491 } 1492 const TypeOopPtr* str_type = _gvn.type(arg)->isa_oopptr(); 1493 if (str_type == NULL) { 1494 return false; 1495 } 1496 ciInstanceKlass* klass = env()->String_klass(); 1497 ciObject* str_const = str_type->const_oop(); 1498 if (str_const == NULL || str_const->klass() != klass) { 1499 return false; 1500 } 1501 ciInstance* str = str_const->as_instance(); 1502 assert(str != NULL, "must be instance"); 1503 1504 ciObject* v = str->field_value_by_offset(java_lang_String::value_offset_in_bytes()).as_object(); 1505 ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array 1506 1507 int o; 1508 int c; 1509 if (java_lang_String::has_offset_field()) { 1510 o = str->field_value_by_offset(java_lang_String::offset_offset_in_bytes()).as_int(); 1511 c = str->field_value_by_offset(java_lang_String::count_offset_in_bytes()).as_int(); 1512 } else { 1513 o = 0; 1514 c = pat->length(); 1515 } 1516 1517 // constant strings have no offset and count == length which 1518 // simplifies the resulting code somewhat so lets optimize for that. 1519 if (o != 0 || c != pat->length()) { 1520 return false; 1521 } 1522 1523 receiver = null_check(receiver, T_OBJECT); 1524 // NOTE: No null check on the argument is needed since it's a constant String oop. 1525 if (stopped()) { 1526 return true; 1527 } 1528 1529 // The null string as a pattern always returns 0 (match at beginning of string) 1530 if (c == 0) { 1531 set_result(intcon(0)); 1532 return true; 1533 } 1534 1535 // Generate default indexOf 1536 jchar lastChar = pat->char_at(o + (c - 1)); 1537 int cache = 0; 1538 int i; 1539 for (i = 0; i < c - 1; i++) { 1540 assert(i < pat->length(), "out of range"); 1541 cache |= (1 << (pat->char_at(o + i) & (sizeof(cache) * BitsPerByte - 1))); 1542 } 1543 1544 int md2 = c; 1545 for (i = 0; i < c - 1; i++) { 1546 assert(i < pat->length(), "out of range"); 1547 if (pat->char_at(o + i) == lastChar) { 1548 md2 = (c - 1) - i; 1549 } 1550 } 1551 1552 result = string_indexOf(receiver, pat, o, cache, md2); 1553 } 1554 set_result(result); 1555 return true; 1556 } 1557 1558 //--------------------------round_double_node-------------------------------- 1559 // Round a double node if necessary. 1560 Node* LibraryCallKit::round_double_node(Node* n) { 1561 if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1) 1562 n = _gvn.transform(new (C) RoundDoubleNode(0, n)); 1563 return n; 1564 } 1565 1566 //------------------------------inline_math----------------------------------- 1567 // public static double Math.abs(double) 1568 // public static double Math.sqrt(double) 1569 // public static double Math.log(double) 1570 // public static double Math.log10(double) 1571 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) { 1572 Node* arg = round_double_node(argument(0)); 1573 Node* n; 1574 switch (id) { 1575 case vmIntrinsics::_dabs: n = new (C) AbsDNode( arg); break; 1576 case vmIntrinsics::_dsqrt: n = new (C) SqrtDNode(C, control(), arg); break; 1577 case vmIntrinsics::_dlog: n = new (C) LogDNode(C, control(), arg); break; 1578 case vmIntrinsics::_dlog10: n = new (C) Log10DNode(C, control(), arg); break; 1579 default: fatal_unexpected_iid(id); break; 1580 } 1581 set_result(_gvn.transform(n)); 1582 return true; 1583 } 1584 1585 //------------------------------inline_trig---------------------------------- 1586 // Inline sin/cos/tan instructions, if possible. If rounding is required, do 1587 // argument reduction which will turn into a fast/slow diamond. 1588 bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) { 1589 Node* arg = round_double_node(argument(0)); 1590 Node* n = NULL; 1591 1592 switch (id) { 1593 case vmIntrinsics::_dsin: n = new (C) SinDNode(C, control(), arg); break; 1594 case vmIntrinsics::_dcos: n = new (C) CosDNode(C, control(), arg); break; 1595 case vmIntrinsics::_dtan: n = new (C) TanDNode(C, control(), arg); break; 1596 default: fatal_unexpected_iid(id); break; 1597 } 1598 n = _gvn.transform(n); 1599 1600 // Rounding required? Check for argument reduction! 1601 if (Matcher::strict_fp_requires_explicit_rounding) { 1602 static const double pi_4 = 0.7853981633974483; 1603 static const double neg_pi_4 = -0.7853981633974483; 1604 // pi/2 in 80-bit extended precision 1605 // static const unsigned char pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0x3f,0x00,0x00,0x00,0x00,0x00,0x00}; 1606 // -pi/2 in 80-bit extended precision 1607 // static const unsigned char neg_pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0xbf,0x00,0x00,0x00,0x00,0x00,0x00}; 1608 // Cutoff value for using this argument reduction technique 1609 //static const double pi_2_minus_epsilon = 1.564660403643354; 1610 //static const double neg_pi_2_plus_epsilon = -1.564660403643354; 1611 1612 // Pseudocode for sin: 1613 // if (x <= Math.PI / 4.0) { 1614 // if (x >= -Math.PI / 4.0) return fsin(x); 1615 // if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0); 1616 // } else { 1617 // if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0); 1618 // } 1619 // return StrictMath.sin(x); 1620 1621 // Pseudocode for cos: 1622 // if (x <= Math.PI / 4.0) { 1623 // if (x >= -Math.PI / 4.0) return fcos(x); 1624 // if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0); 1625 // } else { 1626 // if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0); 1627 // } 1628 // return StrictMath.cos(x); 1629 1630 // Actually, sticking in an 80-bit Intel value into C2 will be tough; it 1631 // requires a special machine instruction to load it. Instead we'll try 1632 // the 'easy' case. If we really need the extra range +/- PI/2 we'll 1633 // probably do the math inside the SIN encoding. 1634 1635 // Make the merge point 1636 RegionNode* r = new (C) RegionNode(3); 1637 Node* phi = new (C) PhiNode(r, Type::DOUBLE); 1638 1639 // Flatten arg so we need only 1 test 1640 Node *abs = _gvn.transform(new (C) AbsDNode(arg)); 1641 // Node for PI/4 constant 1642 Node *pi4 = makecon(TypeD::make(pi_4)); 1643 // Check PI/4 : abs(arg) 1644 Node *cmp = _gvn.transform(new (C) CmpDNode(pi4,abs)); 1645 // Check: If PI/4 < abs(arg) then go slow 1646 Node *bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::lt )); 1647 // Branch either way 1648 IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1649 set_control(opt_iff(r,iff)); 1650 1651 // Set fast path result 1652 phi->init_req(2, n); 1653 1654 // Slow path - non-blocking leaf call 1655 Node* call = NULL; 1656 switch (id) { 1657 case vmIntrinsics::_dsin: 1658 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1659 CAST_FROM_FN_PTR(address, SharedRuntime::dsin), 1660 "Sin", NULL, arg, top()); 1661 break; 1662 case vmIntrinsics::_dcos: 1663 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1664 CAST_FROM_FN_PTR(address, SharedRuntime::dcos), 1665 "Cos", NULL, arg, top()); 1666 break; 1667 case vmIntrinsics::_dtan: 1668 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1669 CAST_FROM_FN_PTR(address, SharedRuntime::dtan), 1670 "Tan", NULL, arg, top()); 1671 break; 1672 } 1673 assert(control()->in(0) == call, ""); 1674 Node* slow_result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1675 r->init_req(1, control()); 1676 phi->init_req(1, slow_result); 1677 1678 // Post-merge 1679 set_control(_gvn.transform(r)); 1680 record_for_igvn(r); 1681 n = _gvn.transform(phi); 1682 1683 C->set_has_split_ifs(true); // Has chance for split-if optimization 1684 } 1685 set_result(n); 1686 return true; 1687 } 1688 1689 Node* LibraryCallKit::finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName) { 1690 //------------------- 1691 //result=(result.isNaN())? funcAddr():result; 1692 // Check: If isNaN() by checking result!=result? then either trap 1693 // or go to runtime 1694 Node* cmpisnan = _gvn.transform(new (C) CmpDNode(result, result)); 1695 // Build the boolean node 1696 Node* bolisnum = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::eq)); 1697 1698 if (!too_many_traps(Deoptimization::Reason_intrinsic)) { 1699 { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT); 1700 // The pow or exp intrinsic returned a NaN, which requires a call 1701 // to the runtime. Recompile with the runtime call. 1702 uncommon_trap(Deoptimization::Reason_intrinsic, 1703 Deoptimization::Action_make_not_entrant); 1704 } 1705 return result; 1706 } else { 1707 // If this inlining ever returned NaN in the past, we compile a call 1708 // to the runtime to properly handle corner cases 1709 1710 IfNode* iff = create_and_xform_if(control(), bolisnum, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1711 Node* if_slow = _gvn.transform(new (C) IfFalseNode(iff)); 1712 Node* if_fast = _gvn.transform(new (C) IfTrueNode(iff)); 1713 1714 if (!if_slow->is_top()) { 1715 RegionNode* result_region = new (C) RegionNode(3); 1716 PhiNode* result_val = new (C) PhiNode(result_region, Type::DOUBLE); 1717 1718 result_region->init_req(1, if_fast); 1719 result_val->init_req(1, result); 1720 1721 set_control(if_slow); 1722 1723 const TypePtr* no_memory_effects = NULL; 1724 Node* rt = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1725 no_memory_effects, 1726 x, top(), y, y ? top() : NULL); 1727 Node* value = _gvn.transform(new (C) ProjNode(rt, TypeFunc::Parms+0)); 1728 #ifdef ASSERT 1729 Node* value_top = _gvn.transform(new (C) ProjNode(rt, TypeFunc::Parms+1)); 1730 assert(value_top == top(), "second value must be top"); 1731 #endif 1732 1733 result_region->init_req(2, control()); 1734 result_val->init_req(2, value); 1735 set_control(_gvn.transform(result_region)); 1736 // Make sure type of PhiNode is recorded 1737 _gvn.transform(result_val); 1738 return result_val; 1739 } else { 1740 return result; 1741 } 1742 } 1743 } 1744 1745 //------------------------------inline_exp------------------------------------- 1746 // Inline exp instructions, if possible. The Intel hardware only misses 1747 // really odd corner cases (+/- Infinity). Just uncommon-trap them. 1748 bool LibraryCallKit::inline_exp() { 1749 Node* arg = round_double_node(argument(0)); 1750 Node* n = _gvn.transform(new (C) ExpDNode(C, control(), arg)); 1751 1752 n = finish_pow_exp(n, arg, NULL, OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP"); 1753 set_result(n); 1754 1755 C->set_has_split_ifs(true); // Has chance for split-if optimization 1756 return true; 1757 } 1758 1759 //------------------------------inline_pow------------------------------------- 1760 // Inline power instructions, if possible. 1761 bool LibraryCallKit::inline_pow() { 1762 // Pseudocode for pow 1763 // if (y == 2) { 1764 // return x * x; 1765 // } else { 1766 // if (x <= 0.0) { 1767 // long longy = (long)y; 1768 // if ((double)longy == y) { // if y is long 1769 // if (y + 1 == y) longy = 0; // huge number: even 1770 // result = ((1&longy) == 0)?-DPow(abs(x), y):DPow(abs(x), y); 1771 // } else { 1772 // result = NaN; 1773 // } 1774 // } else { 1775 // result = DPow(x,y); 1776 // } 1777 // if (result != result)? { 1778 // result = uncommon_trap() or runtime_call(); 1779 // } 1780 // return result; 1781 // } 1782 1783 Node* x = round_double_node(argument(0)); 1784 Node* y = round_double_node(argument(2)); 1785 1786 Node* result = NULL; 1787 1788 Node* const_two_node = makecon(TypeD::make(2.0)); 1789 Node* cmp_node = _gvn.transform(new (C) CmpDNode(y, const_two_node)); 1790 Node* bool_node = _gvn.transform(new (C) BoolNode(cmp_node, BoolTest::eq)); 1791 IfNode* if_node = create_and_xform_if(control(), bool_node, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1792 Node* if_true = _gvn.transform(new (C) IfTrueNode(if_node)); 1793 Node* if_false = _gvn.transform(new (C) IfFalseNode(if_node)); 1794 1795 RegionNode* region_node = new (C) RegionNode(3); 1796 region_node->init_req(1, if_true); 1797 1798 Node* phi_node = new (C) PhiNode(region_node, Type::DOUBLE); 1799 // special case for x^y where y == 2, we can convert it to x * x 1800 phi_node->init_req(1, _gvn.transform(new (C) MulDNode(x, x))); 1801 1802 // set control to if_false since we will now process the false branch 1803 set_control(if_false); 1804 1805 if (!too_many_traps(Deoptimization::Reason_intrinsic)) { 1806 // Short form: skip the fancy tests and just check for NaN result. 1807 result = _gvn.transform(new (C) PowDNode(C, control(), x, y)); 1808 } else { 1809 // If this inlining ever returned NaN in the past, include all 1810 // checks + call to the runtime. 1811 1812 // Set the merge point for If node with condition of (x <= 0.0) 1813 // There are four possible paths to region node and phi node 1814 RegionNode *r = new (C) RegionNode(4); 1815 Node *phi = new (C) PhiNode(r, Type::DOUBLE); 1816 1817 // Build the first if node: if (x <= 0.0) 1818 // Node for 0 constant 1819 Node *zeronode = makecon(TypeD::ZERO); 1820 // Check x:0 1821 Node *cmp = _gvn.transform(new (C) CmpDNode(x, zeronode)); 1822 // Check: If (x<=0) then go complex path 1823 Node *bol1 = _gvn.transform(new (C) BoolNode( cmp, BoolTest::le )); 1824 // Branch either way 1825 IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1826 // Fast path taken; set region slot 3 1827 Node *fast_taken = _gvn.transform(new (C) IfFalseNode(if1)); 1828 r->init_req(3,fast_taken); // Capture fast-control 1829 1830 // Fast path not-taken, i.e. slow path 1831 Node *complex_path = _gvn.transform(new (C) IfTrueNode(if1)); 1832 1833 // Set fast path result 1834 Node *fast_result = _gvn.transform(new (C) PowDNode(C, control(), x, y)); 1835 phi->init_req(3, fast_result); 1836 1837 // Complex path 1838 // Build the second if node (if y is long) 1839 // Node for (long)y 1840 Node *longy = _gvn.transform(new (C) ConvD2LNode(y)); 1841 // Node for (double)((long) y) 1842 Node *doublelongy= _gvn.transform(new (C) ConvL2DNode(longy)); 1843 // Check (double)((long) y) : y 1844 Node *cmplongy= _gvn.transform(new (C) CmpDNode(doublelongy, y)); 1845 // Check if (y isn't long) then go to slow path 1846 1847 Node *bol2 = _gvn.transform(new (C) BoolNode( cmplongy, BoolTest::ne )); 1848 // Branch either way 1849 IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1850 Node* ylong_path = _gvn.transform(new (C) IfFalseNode(if2)); 1851 1852 Node *slow_path = _gvn.transform(new (C) IfTrueNode(if2)); 1853 1854 // Calculate DPow(abs(x), y)*(1 & (long)y) 1855 // Node for constant 1 1856 Node *conone = longcon(1); 1857 // 1& (long)y 1858 Node *signnode= _gvn.transform(new (C) AndLNode(conone, longy)); 1859 1860 // A huge number is always even. Detect a huge number by checking 1861 // if y + 1 == y and set integer to be tested for parity to 0. 1862 // Required for corner case: 1863 // (long)9.223372036854776E18 = max_jlong 1864 // (double)(long)9.223372036854776E18 = 9.223372036854776E18 1865 // max_jlong is odd but 9.223372036854776E18 is even 1866 Node* yplus1 = _gvn.transform(new (C) AddDNode(y, makecon(TypeD::make(1)))); 1867 Node *cmpyplus1= _gvn.transform(new (C) CmpDNode(yplus1, y)); 1868 Node *bolyplus1 = _gvn.transform(new (C) BoolNode( cmpyplus1, BoolTest::eq )); 1869 Node* correctedsign = NULL; 1870 if (ConditionalMoveLimit != 0) { 1871 correctedsign = _gvn.transform( CMoveNode::make(C, NULL, bolyplus1, signnode, longcon(0), TypeLong::LONG)); 1872 } else { 1873 IfNode *ifyplus1 = create_and_xform_if(ylong_path,bolyplus1, PROB_FAIR, COUNT_UNKNOWN); 1874 RegionNode *r = new (C) RegionNode(3); 1875 Node *phi = new (C) PhiNode(r, TypeLong::LONG); 1876 r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyplus1))); 1877 r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyplus1))); 1878 phi->init_req(1, signnode); 1879 phi->init_req(2, longcon(0)); 1880 correctedsign = _gvn.transform(phi); 1881 ylong_path = _gvn.transform(r); 1882 record_for_igvn(r); 1883 } 1884 1885 // zero node 1886 Node *conzero = longcon(0); 1887 // Check (1&(long)y)==0? 1888 Node *cmpeq1 = _gvn.transform(new (C) CmpLNode(correctedsign, conzero)); 1889 // Check if (1&(long)y)!=0?, if so the result is negative 1890 Node *bol3 = _gvn.transform(new (C) BoolNode( cmpeq1, BoolTest::ne )); 1891 // abs(x) 1892 Node *absx=_gvn.transform(new (C) AbsDNode(x)); 1893 // abs(x)^y 1894 Node *absxpowy = _gvn.transform(new (C) PowDNode(C, control(), absx, y)); 1895 // -abs(x)^y 1896 Node *negabsxpowy = _gvn.transform(new (C) NegDNode (absxpowy)); 1897 // (1&(long)y)==1?-DPow(abs(x), y):DPow(abs(x), y) 1898 Node *signresult = NULL; 1899 if (ConditionalMoveLimit != 0) { 1900 signresult = _gvn.transform( CMoveNode::make(C, NULL, bol3, absxpowy, negabsxpowy, Type::DOUBLE)); 1901 } else { 1902 IfNode *ifyeven = create_and_xform_if(ylong_path,bol3, PROB_FAIR, COUNT_UNKNOWN); 1903 RegionNode *r = new (C) RegionNode(3); 1904 Node *phi = new (C) PhiNode(r, Type::DOUBLE); 1905 r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyeven))); 1906 r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyeven))); 1907 phi->init_req(1, absxpowy); 1908 phi->init_req(2, negabsxpowy); 1909 signresult = _gvn.transform(phi); 1910 ylong_path = _gvn.transform(r); 1911 record_for_igvn(r); 1912 } 1913 // Set complex path fast result 1914 r->init_req(2, ylong_path); 1915 phi->init_req(2, signresult); 1916 1917 static const jlong nan_bits = CONST64(0x7ff8000000000000); 1918 Node *slow_result = makecon(TypeD::make(*(double*)&nan_bits)); // return NaN 1919 r->init_req(1,slow_path); 1920 phi->init_req(1,slow_result); 1921 1922 // Post merge 1923 set_control(_gvn.transform(r)); 1924 record_for_igvn(r); 1925 result = _gvn.transform(phi); 1926 } 1927 1928 result = finish_pow_exp(result, x, y, OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW"); 1929 1930 // control from finish_pow_exp is now input to the region node 1931 region_node->set_req(2, control()); 1932 // the result from finish_pow_exp is now input to the phi node 1933 phi_node->init_req(2, _gvn.transform(result)); 1934 set_control(_gvn.transform(region_node)); 1935 record_for_igvn(region_node); 1936 set_result(_gvn.transform(phi_node)); 1937 1938 C->set_has_split_ifs(true); // Has chance for split-if optimization 1939 return true; 1940 } 1941 1942 //------------------------------runtime_math----------------------------- 1943 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1944 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1945 "must be (DD)D or (D)D type"); 1946 1947 // Inputs 1948 Node* a = round_double_node(argument(0)); 1949 Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? round_double_node(argument(2)) : NULL; 1950 1951 const TypePtr* no_memory_effects = NULL; 1952 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1953 no_memory_effects, 1954 a, top(), b, b ? top() : NULL); 1955 Node* value = _gvn.transform(new (C) ProjNode(trig, TypeFunc::Parms+0)); 1956 #ifdef ASSERT 1957 Node* value_top = _gvn.transform(new (C) ProjNode(trig, TypeFunc::Parms+1)); 1958 assert(value_top == top(), "second value must be top"); 1959 #endif 1960 1961 set_result(value); 1962 return true; 1963 } 1964 1965 //------------------------------inline_math_native----------------------------- 1966 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1967 #define FN_PTR(f) CAST_FROM_FN_PTR(address, f) 1968 switch (id) { 1969 // These intrinsics are not properly supported on all hardware 1970 case vmIntrinsics::_dcos: return Matcher::has_match_rule(Op_CosD) ? inline_trig(id) : 1971 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dcos), "COS"); 1972 case vmIntrinsics::_dsin: return Matcher::has_match_rule(Op_SinD) ? inline_trig(id) : 1973 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dsin), "SIN"); 1974 case vmIntrinsics::_dtan: return Matcher::has_match_rule(Op_TanD) ? inline_trig(id) : 1975 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dtan), "TAN"); 1976 1977 case vmIntrinsics::_dlog: return Matcher::has_match_rule(Op_LogD) ? inline_math(id) : 1978 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog), "LOG"); 1979 case vmIntrinsics::_dlog10: return Matcher::has_match_rule(Op_Log10D) ? inline_math(id) : 1980 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog10), "LOG10"); 1981 1982 // These intrinsics are supported on all hardware 1983 case vmIntrinsics::_dsqrt: return Matcher::match_rule_supported(Op_SqrtD) ? inline_math(id) : false; 1984 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_math(id) : false; 1985 1986 case vmIntrinsics::_dexp: return Matcher::has_match_rule(Op_ExpD) ? inline_exp() : 1987 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dexp), "EXP"); 1988 case vmIntrinsics::_dpow: return Matcher::has_match_rule(Op_PowD) ? inline_pow() : 1989 runtime_math(OptoRuntime::Math_DD_D_Type(), FN_PTR(SharedRuntime::dpow), "POW"); 1990 #undef FN_PTR 1991 1992 // These intrinsics are not yet correctly implemented 1993 case vmIntrinsics::_datan2: 1994 return false; 1995 1996 default: 1997 fatal_unexpected_iid(id); 1998 return false; 1999 } 2000 } 2001 2002 static bool is_simple_name(Node* n) { 2003 return (n->req() == 1 // constant 2004 || (n->is_Type() && n->as_Type()->type()->singleton()) 2005 || n->is_Proj() // parameter or return value 2006 || n->is_Phi() // local of some sort 2007 ); 2008 } 2009 2010 //----------------------------inline_min_max----------------------------------- 2011 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 2012 set_result(generate_min_max(id, argument(0), argument(1))); 2013 return true; 2014 } 2015 2016 void LibraryCallKit::inline_math_mathExact(Node* math, Node *test) { 2017 Node* bol = _gvn.transform( new (C) BoolNode(test, BoolTest::overflow) ); 2018 IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 2019 Node* fast_path = _gvn.transform( new (C) IfFalseNode(check)); 2020 Node* slow_path = _gvn.transform( new (C) IfTrueNode(check) ); 2021 2022 { 2023 PreserveJVMState pjvms(this); 2024 PreserveReexecuteState preexecs(this); 2025 jvms()->set_should_reexecute(true); 2026 2027 set_control(slow_path); 2028 set_i_o(i_o()); 2029 2030 uncommon_trap(Deoptimization::Reason_intrinsic, 2031 Deoptimization::Action_none); 2032 } 2033 2034 set_control(fast_path); 2035 set_result(math); 2036 } 2037 2038 template <typename OverflowOp> 2039 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) { 2040 typedef typename OverflowOp::MathOp MathOp; 2041 2042 MathOp* mathOp = new(C) MathOp(arg1, arg2); 2043 Node* operation = _gvn.transform( mathOp ); 2044 Node* ofcheck = _gvn.transform( new(C) OverflowOp(arg1, arg2) ); 2045 inline_math_mathExact(operation, ofcheck); 2046 return true; 2047 } 2048 2049 bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 2050 return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1)); 2051 } 2052 2053 bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 2054 return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2)); 2055 } 2056 2057 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 2058 return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1)); 2059 } 2060 2061 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 2062 return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2)); 2063 } 2064 2065 bool LibraryCallKit::inline_math_negateExactI() { 2066 return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0)); 2067 } 2068 2069 bool LibraryCallKit::inline_math_negateExactL() { 2070 return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0)); 2071 } 2072 2073 bool LibraryCallKit::inline_math_multiplyExactI() { 2074 return inline_math_overflow<OverflowMulINode>(argument(0), argument(1)); 2075 } 2076 2077 bool LibraryCallKit::inline_math_multiplyExactL() { 2078 return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2)); 2079 } 2080 2081 Node* 2082 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) { 2083 // These are the candidate return value: 2084 Node* xvalue = x0; 2085 Node* yvalue = y0; 2086 2087 if (xvalue == yvalue) { 2088 return xvalue; 2089 } 2090 2091 bool want_max = (id == vmIntrinsics::_max); 2092 2093 const TypeInt* txvalue = _gvn.type(xvalue)->isa_int(); 2094 const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int(); 2095 if (txvalue == NULL || tyvalue == NULL) return top(); 2096 // This is not really necessary, but it is consistent with a 2097 // hypothetical MaxINode::Value method: 2098 int widen = MAX2(txvalue->_widen, tyvalue->_widen); 2099 2100 // %%% This folding logic should (ideally) be in a different place. 2101 // Some should be inside IfNode, and there to be a more reliable 2102 // transformation of ?: style patterns into cmoves. We also want 2103 // more powerful optimizations around cmove and min/max. 2104 2105 // Try to find a dominating comparison of these guys. 2106 // It can simplify the index computation for Arrays.copyOf 2107 // and similar uses of System.arraycopy. 2108 // First, compute the normalized version of CmpI(x, y). 2109 int cmp_op = Op_CmpI; 2110 Node* xkey = xvalue; 2111 Node* ykey = yvalue; 2112 Node* ideal_cmpxy = _gvn.transform(new(C) CmpINode(xkey, ykey)); 2113 if (ideal_cmpxy->is_Cmp()) { 2114 // E.g., if we have CmpI(length - offset, count), 2115 // it might idealize to CmpI(length, count + offset) 2116 cmp_op = ideal_cmpxy->Opcode(); 2117 xkey = ideal_cmpxy->in(1); 2118 ykey = ideal_cmpxy->in(2); 2119 } 2120 2121 // Start by locating any relevant comparisons. 2122 Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey; 2123 Node* cmpxy = NULL; 2124 Node* cmpyx = NULL; 2125 for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) { 2126 Node* cmp = start_from->fast_out(k); 2127 if (cmp->outcnt() > 0 && // must have prior uses 2128 cmp->in(0) == NULL && // must be context-independent 2129 cmp->Opcode() == cmp_op) { // right kind of compare 2130 if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp; 2131 if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp; 2132 } 2133 } 2134 2135 const int NCMPS = 2; 2136 Node* cmps[NCMPS] = { cmpxy, cmpyx }; 2137 int cmpn; 2138 for (cmpn = 0; cmpn < NCMPS; cmpn++) { 2139 if (cmps[cmpn] != NULL) break; // find a result 2140 } 2141 if (cmpn < NCMPS) { 2142 // Look for a dominating test that tells us the min and max. 2143 int depth = 0; // Limit search depth for speed 2144 Node* dom = control(); 2145 for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) { 2146 if (++depth >= 100) break; 2147 Node* ifproj = dom; 2148 if (!ifproj->is_Proj()) continue; 2149 Node* iff = ifproj->in(0); 2150 if (!iff->is_If()) continue; 2151 Node* bol = iff->in(1); 2152 if (!bol->is_Bool()) continue; 2153 Node* cmp = bol->in(1); 2154 if (cmp == NULL) continue; 2155 for (cmpn = 0; cmpn < NCMPS; cmpn++) 2156 if (cmps[cmpn] == cmp) break; 2157 if (cmpn == NCMPS) continue; 2158 BoolTest::mask btest = bol->as_Bool()->_test._test; 2159 if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate(); 2160 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 2161 // At this point, we know that 'x btest y' is true. 2162 switch (btest) { 2163 case BoolTest::eq: 2164 // They are proven equal, so we can collapse the min/max. 2165 // Either value is the answer. Choose the simpler. 2166 if (is_simple_name(yvalue) && !is_simple_name(xvalue)) 2167 return yvalue; 2168 return xvalue; 2169 case BoolTest::lt: // x < y 2170 case BoolTest::le: // x <= y 2171 return (want_max ? yvalue : xvalue); 2172 case BoolTest::gt: // x > y 2173 case BoolTest::ge: // x >= y 2174 return (want_max ? xvalue : yvalue); 2175 } 2176 } 2177 } 2178 2179 // We failed to find a dominating test. 2180 // Let's pick a test that might GVN with prior tests. 2181 Node* best_bol = NULL; 2182 BoolTest::mask best_btest = BoolTest::illegal; 2183 for (cmpn = 0; cmpn < NCMPS; cmpn++) { 2184 Node* cmp = cmps[cmpn]; 2185 if (cmp == NULL) continue; 2186 for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) { 2187 Node* bol = cmp->fast_out(j); 2188 if (!bol->is_Bool()) continue; 2189 BoolTest::mask btest = bol->as_Bool()->_test._test; 2190 if (btest == BoolTest::eq || btest == BoolTest::ne) continue; 2191 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 2192 if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) { 2193 best_bol = bol->as_Bool(); 2194 best_btest = btest; 2195 } 2196 } 2197 } 2198 2199 Node* answer_if_true = NULL; 2200 Node* answer_if_false = NULL; 2201 switch (best_btest) { 2202 default: 2203 if (cmpxy == NULL) 2204 cmpxy = ideal_cmpxy; 2205 best_bol = _gvn.transform(new(C) BoolNode(cmpxy, BoolTest::lt)); 2206 // and fall through: 2207 case BoolTest::lt: // x < y 2208 case BoolTest::le: // x <= y 2209 answer_if_true = (want_max ? yvalue : xvalue); 2210 answer_if_false = (want_max ? xvalue : yvalue); 2211 break; 2212 case BoolTest::gt: // x > y 2213 case BoolTest::ge: // x >= y 2214 answer_if_true = (want_max ? xvalue : yvalue); 2215 answer_if_false = (want_max ? yvalue : xvalue); 2216 break; 2217 } 2218 2219 jint hi, lo; 2220 if (want_max) { 2221 // We can sharpen the minimum. 2222 hi = MAX2(txvalue->_hi, tyvalue->_hi); 2223 lo = MAX2(txvalue->_lo, tyvalue->_lo); 2224 } else { 2225 // We can sharpen the maximum. 2226 hi = MIN2(txvalue->_hi, tyvalue->_hi); 2227 lo = MIN2(txvalue->_lo, tyvalue->_lo); 2228 } 2229 2230 // Use a flow-free graph structure, to avoid creating excess control edges 2231 // which could hinder other optimizations. 2232 // Since Math.min/max is often used with arraycopy, we want 2233 // tightly_coupled_allocation to be able to see beyond min/max expressions. 2234 Node* cmov = CMoveNode::make(C, NULL, best_bol, 2235 answer_if_false, answer_if_true, 2236 TypeInt::make(lo, hi, widen)); 2237 2238 return _gvn.transform(cmov); 2239 2240 /* 2241 // This is not as desirable as it may seem, since Min and Max 2242 // nodes do not have a full set of optimizations. 2243 // And they would interfere, anyway, with 'if' optimizations 2244 // and with CMoveI canonical forms. 2245 switch (id) { 2246 case vmIntrinsics::_min: 2247 result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break; 2248 case vmIntrinsics::_max: 2249 result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break; 2250 default: 2251 ShouldNotReachHere(); 2252 } 2253 */ 2254 } 2255 2256 inline int 2257 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) { 2258 const TypePtr* base_type = TypePtr::NULL_PTR; 2259 if (base != NULL) base_type = _gvn.type(base)->isa_ptr(); 2260 if (base_type == NULL) { 2261 // Unknown type. 2262 return Type::AnyPtr; 2263 } else if (base_type == TypePtr::NULL_PTR) { 2264 // Since this is a NULL+long form, we have to switch to a rawptr. 2265 base = _gvn.transform(new (C) CastX2PNode(offset)); 2266 offset = MakeConX(0); 2267 return Type::RawPtr; 2268 } else if (base_type->base() == Type::RawPtr) { 2269 return Type::RawPtr; 2270 } else if (base_type->isa_oopptr()) { 2271 // Base is never null => always a heap address. 2272 if (base_type->ptr() == TypePtr::NotNull) { 2273 return Type::OopPtr; 2274 } 2275 // Offset is small => always a heap address. 2276 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 2277 if (offset_type != NULL && 2278 base_type->offset() == 0 && // (should always be?) 2279 offset_type->_lo >= 0 && 2280 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 2281 return Type::OopPtr; 2282 } 2283 // Otherwise, it might either be oop+off or NULL+addr. 2284 return Type::AnyPtr; 2285 } else { 2286 // No information: 2287 return Type::AnyPtr; 2288 } 2289 } 2290 2291 inline Node* LibraryCallKit::make_unsafe_address(Node* base, Node* offset) { 2292 int kind = classify_unsafe_addr(base, offset); 2293 if (kind == Type::RawPtr) { 2294 return basic_plus_adr(top(), base, offset); 2295 } else { 2296 return basic_plus_adr(base, offset); 2297 } 2298 } 2299 2300 //--------------------------inline_number_methods----------------------------- 2301 // inline int Integer.numberOfLeadingZeros(int) 2302 // inline int Long.numberOfLeadingZeros(long) 2303 // 2304 // inline int Integer.numberOfTrailingZeros(int) 2305 // inline int Long.numberOfTrailingZeros(long) 2306 // 2307 // inline int Integer.bitCount(int) 2308 // inline int Long.bitCount(long) 2309 // 2310 // inline char Character.reverseBytes(char) 2311 // inline short Short.reverseBytes(short) 2312 // inline int Integer.reverseBytes(int) 2313 // inline long Long.reverseBytes(long) 2314 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 2315 Node* arg = argument(0); 2316 Node* n; 2317 switch (id) { 2318 case vmIntrinsics::_numberOfLeadingZeros_i: n = new (C) CountLeadingZerosINode( arg); break; 2319 case vmIntrinsics::_numberOfLeadingZeros_l: n = new (C) CountLeadingZerosLNode( arg); break; 2320 case vmIntrinsics::_numberOfTrailingZeros_i: n = new (C) CountTrailingZerosINode(arg); break; 2321 case vmIntrinsics::_numberOfTrailingZeros_l: n = new (C) CountTrailingZerosLNode(arg); break; 2322 case vmIntrinsics::_bitCount_i: n = new (C) PopCountINode( arg); break; 2323 case vmIntrinsics::_bitCount_l: n = new (C) PopCountLNode( arg); break; 2324 case vmIntrinsics::_reverseBytes_c: n = new (C) ReverseBytesUSNode(0, arg); break; 2325 case vmIntrinsics::_reverseBytes_s: n = new (C) ReverseBytesSNode( 0, arg); break; 2326 case vmIntrinsics::_reverseBytes_i: n = new (C) ReverseBytesINode( 0, arg); break; 2327 case vmIntrinsics::_reverseBytes_l: n = new (C) ReverseBytesLNode( 0, arg); break; 2328 default: fatal_unexpected_iid(id); break; 2329 } 2330 set_result(_gvn.transform(n)); 2331 return true; 2332 } 2333 2334 //----------------------------inline_unsafe_access---------------------------- 2335 2336 const static BasicType T_ADDRESS_HOLDER = T_LONG; 2337 2338 // Helper that guards and inserts a pre-barrier. 2339 void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset, 2340 Node* pre_val, bool need_mem_bar) { 2341 // We could be accessing the referent field of a reference object. If so, when G1 2342 // is enabled, we need to log the value in the referent field in an SATB buffer. 2343 // This routine performs some compile time filters and generates suitable 2344 // runtime filters that guard the pre-barrier code. 2345 // Also add memory barrier for non volatile load from the referent field 2346 // to prevent commoning of loads across safepoint. 2347 if (!UseG1GC && !need_mem_bar) 2348 return; 2349 2350 // Some compile time checks. 2351 2352 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset? 2353 const TypeX* otype = offset->find_intptr_t_type(); 2354 if (otype != NULL && otype->is_con() && 2355 otype->get_con() != java_lang_ref_Reference::referent_offset) { 2356 // Constant offset but not the reference_offset so just return 2357 return; 2358 } 2359 2360 // We only need to generate the runtime guards for instances. 2361 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr(); 2362 if (btype != NULL) { 2363 if (btype->isa_aryptr()) { 2364 // Array type so nothing to do 2365 return; 2366 } 2367 2368 const TypeInstPtr* itype = btype->isa_instptr(); 2369 if (itype != NULL) { 2370 // Can the klass of base_oop be statically determined to be 2371 // _not_ a sub-class of Reference and _not_ Object? 2372 ciKlass* klass = itype->klass(); 2373 if ( klass->is_loaded() && 2374 !klass->is_subtype_of(env()->Reference_klass()) && 2375 !env()->Object_klass()->is_subtype_of(klass)) { 2376 return; 2377 } 2378 } 2379 } 2380 2381 // The compile time filters did not reject base_oop/offset so 2382 // we need to generate the following runtime filters 2383 // 2384 // if (offset == java_lang_ref_Reference::_reference_offset) { 2385 // if (instance_of(base, java.lang.ref.Reference)) { 2386 // pre_barrier(_, pre_val, ...); 2387 // } 2388 // } 2389 2390 float likely = PROB_LIKELY( 0.999); 2391 float unlikely = PROB_UNLIKELY(0.999); 2392 2393 IdealKit ideal(this); 2394 #define __ ideal. 2395 2396 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset); 2397 2398 __ if_then(offset, BoolTest::eq, referent_off, unlikely); { 2399 // Update graphKit memory and control from IdealKit. 2400 sync_kit(ideal); 2401 2402 Node* ref_klass_con = makecon(TypeKlassPtr::make(env()->Reference_klass())); 2403 Node* is_instof = gen_instanceof(base_oop, ref_klass_con); 2404 2405 // Update IdealKit memory and control from graphKit. 2406 __ sync_kit(this); 2407 2408 Node* one = __ ConI(1); 2409 // is_instof == 0 if base_oop == NULL 2410 __ if_then(is_instof, BoolTest::eq, one, unlikely); { 2411 2412 // Update graphKit from IdeakKit. 2413 sync_kit(ideal); 2414 2415 // Use the pre-barrier to record the value in the referent field 2416 pre_barrier(false /* do_load */, 2417 __ ctrl(), 2418 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, 2419 pre_val /* pre_val */, 2420 T_OBJECT); 2421 if (need_mem_bar) { 2422 // Add memory barrier to prevent commoning reads from this field 2423 // across safepoint since GC can change its value. 2424 insert_mem_bar(Op_MemBarCPUOrder); 2425 } 2426 // Update IdealKit from graphKit. 2427 __ sync_kit(this); 2428 2429 } __ end_if(); // _ref_type != ref_none 2430 } __ end_if(); // offset == referent_offset 2431 2432 // Final sync IdealKit and GraphKit. 2433 final_sync(ideal); 2434 #undef __ 2435 } 2436 2437 2438 // Interpret Unsafe.fieldOffset cookies correctly: 2439 extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset); 2440 2441 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr) { 2442 // Attempt to infer a sharper value type from the offset and base type. 2443 ciKlass* sharpened_klass = NULL; 2444 2445 // See if it is an instance field, with an object type. 2446 if (alias_type->field() != NULL) { 2447 assert(!is_native_ptr, "native pointer op cannot use a java address"); 2448 if (alias_type->field()->type()->is_klass()) { 2449 sharpened_klass = alias_type->field()->type()->as_klass(); 2450 } 2451 } 2452 2453 // See if it is a narrow oop array. 2454 if (adr_type->isa_aryptr()) { 2455 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) { 2456 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr(); 2457 if (elem_type != NULL) { 2458 sharpened_klass = elem_type->klass(); 2459 } 2460 } 2461 } 2462 2463 // The sharpened class might be unloaded if there is no class loader 2464 // contraint in place. 2465 if (sharpened_klass != NULL && sharpened_klass->is_loaded()) { 2466 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass); 2467 2468 #ifndef PRODUCT 2469 if (C->print_intrinsics() || C->print_inlining()) { 2470 tty->print(" from base type: "); adr_type->dump(); 2471 tty->print(" sharpened value: "); tjp->dump(); 2472 } 2473 #endif 2474 // Sharpen the value type. 2475 return tjp; 2476 } 2477 return NULL; 2478 } 2479 2480 bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) { 2481 if (callee()->is_static()) return false; // caller must have the capability! 2482 2483 #ifndef PRODUCT 2484 { 2485 ResourceMark rm; 2486 // Check the signatures. 2487 ciSignature* sig = callee()->signature(); 2488 #ifdef ASSERT 2489 if (!is_store) { 2490 // Object getObject(Object base, int/long offset), etc. 2491 BasicType rtype = sig->return_type()->basic_type(); 2492 if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name()) 2493 rtype = T_ADDRESS; // it is really a C void* 2494 assert(rtype == type, "getter must return the expected value"); 2495 if (!is_native_ptr) { 2496 assert(sig->count() == 2, "oop getter has 2 arguments"); 2497 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 2498 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 2499 } else { 2500 assert(sig->count() == 1, "native getter has 1 argument"); 2501 assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long"); 2502 } 2503 } else { 2504 // void putObject(Object base, int/long offset, Object x), etc. 2505 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 2506 if (!is_native_ptr) { 2507 assert(sig->count() == 3, "oop putter has 3 arguments"); 2508 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 2509 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 2510 } else { 2511 assert(sig->count() == 2, "native putter has 2 arguments"); 2512 assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long"); 2513 } 2514 BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 2515 if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name()) 2516 vtype = T_ADDRESS; // it is really a C void* 2517 assert(vtype == type, "putter must accept the expected value"); 2518 } 2519 #endif // ASSERT 2520 } 2521 #endif //PRODUCT 2522 2523 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2524 2525 Node* receiver = argument(0); // type: oop 2526 2527 // Build address expression. See the code in inline_unsafe_prefetch. 2528 Node* adr; 2529 Node* heap_base_oop = top(); 2530 Node* offset = top(); 2531 Node* val; 2532 2533 if (!is_native_ptr) { 2534 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2535 Node* base = argument(1); // type: oop 2536 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2537 offset = argument(2); // type: long 2538 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2539 // to be plain byte offsets, which are also the same as those accepted 2540 // by oopDesc::field_base. 2541 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2542 "fieldOffset must be byte-scaled"); 2543 // 32-bit machines ignore the high half! 2544 offset = ConvL2X(offset); 2545 adr = make_unsafe_address(base, offset); 2546 heap_base_oop = base; 2547 val = is_store ? argument(4) : NULL; 2548 } else { 2549 Node* ptr = argument(1); // type: long 2550 ptr = ConvL2X(ptr); // adjust Java long to machine word 2551 adr = make_unsafe_address(NULL, ptr); 2552 val = is_store ? argument(3) : NULL; 2553 } 2554 2555 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 2556 2557 // First guess at the value type. 2558 const Type *value_type = Type::get_const_basic_type(type); 2559 2560 // Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM, 2561 // there was not enough information to nail it down. 2562 Compile::AliasType* alias_type = C->alias_type(adr_type); 2563 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2564 2565 // We will need memory barriers unless we can determine a unique 2566 // alias category for this reference. (Note: If for some reason 2567 // the barriers get omitted and the unsafe reference begins to "pollute" 2568 // the alias analysis of the rest of the graph, either Compile::can_alias 2569 // or Compile::must_alias will throw a diagnostic assert.) 2570 bool need_mem_bar = (alias_type->adr_type() == TypeOopPtr::BOTTOM); 2571 2572 // If we are reading the value of the referent field of a Reference 2573 // object (either by using Unsafe directly or through reflection) 2574 // then, if G1 is enabled, we need to record the referent in an 2575 // SATB log buffer using the pre-barrier mechanism. 2576 // Also we need to add memory barrier to prevent commoning reads 2577 // from this field across safepoint since GC can change its value. 2578 bool need_read_barrier = !is_native_ptr && !is_store && 2579 offset != top() && heap_base_oop != top(); 2580 2581 if (!is_store && type == T_OBJECT) { 2582 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type, is_native_ptr); 2583 if (tjp != NULL) { 2584 value_type = tjp; 2585 } 2586 } 2587 2588 receiver = null_check(receiver); 2589 if (stopped()) { 2590 return true; 2591 } 2592 // Heap pointers get a null-check from the interpreter, 2593 // as a courtesy. However, this is not guaranteed by Unsafe, 2594 // and it is not possible to fully distinguish unintended nulls 2595 // from intended ones in this API. 2596 2597 if (is_volatile) { 2598 // We need to emit leading and trailing CPU membars (see below) in 2599 // addition to memory membars when is_volatile. This is a little 2600 // too strong, but avoids the need to insert per-alias-type 2601 // volatile membars (for stores; compare Parse::do_put_xxx), which 2602 // we cannot do effectively here because we probably only have a 2603 // rough approximation of type. 2604 need_mem_bar = true; 2605 // For Stores, place a memory ordering barrier now. 2606 if (is_store) { 2607 insert_mem_bar(Op_MemBarRelease); 2608 } else { 2609 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 2610 insert_mem_bar(Op_MemBarVolatile); 2611 } 2612 } 2613 } 2614 2615 // Memory barrier to prevent normal and 'unsafe' accesses from 2616 // bypassing each other. Happens after null checks, so the 2617 // exception paths do not take memory state from the memory barrier, 2618 // so there's no problems making a strong assert about mixing users 2619 // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar 2620 // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl. 2621 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 2622 2623 if (!is_store) { 2624 Node* p = make_load(control(), adr, value_type, type, adr_type, MemNode::unordered, is_volatile); 2625 // load value 2626 switch (type) { 2627 case T_BOOLEAN: 2628 case T_CHAR: 2629 case T_BYTE: 2630 case T_SHORT: 2631 case T_INT: 2632 case T_LONG: 2633 case T_FLOAT: 2634 case T_DOUBLE: 2635 break; 2636 case T_OBJECT: 2637 if (need_read_barrier) { 2638 insert_pre_barrier(heap_base_oop, offset, p, !(is_volatile || need_mem_bar)); 2639 } 2640 break; 2641 case T_ADDRESS: 2642 // Cast to an int type. 2643 p = _gvn.transform(new (C) CastP2XNode(NULL, p)); 2644 p = ConvX2UL(p); 2645 break; 2646 default: 2647 fatal(err_msg_res("unexpected type %d: %s", type, type2name(type))); 2648 break; 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 (C) CastX2PNode(val)); 2665 break; 2666 } 2667 2668 MemNode::MemOrd mo = is_volatile ? MemNode::release : MemNode::unordered; 2669 if (type != T_OBJECT ) { 2670 (void) store_to_memory(control(), adr, val, type, adr_type, mo, is_volatile); 2671 } else { 2672 // Possibly an oop being stored to Java heap or native memory 2673 if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop))) { 2674 // oop to Java heap. 2675 (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo); 2676 } else { 2677 // We can't tell at compile time if we are storing in the Java heap or outside 2678 // of it. So we need to emit code to conditionally do the proper type of 2679 // store. 2680 2681 IdealKit ideal(this); 2682 #define __ ideal. 2683 // QQQ who knows what probability is here?? 2684 __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); { 2685 // Sync IdealKit and graphKit. 2686 sync_kit(ideal); 2687 Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo); 2688 // Update IdealKit memory. 2689 __ sync_kit(this); 2690 } __ else_(); { 2691 __ store(__ ctrl(), adr, val, type, alias_type->index(), mo, is_volatile); 2692 } __ end_if(); 2693 // Final sync IdealKit and GraphKit. 2694 final_sync(ideal); 2695 #undef __ 2696 } 2697 } 2698 } 2699 2700 if (is_volatile) { 2701 if (!is_store) { 2702 insert_mem_bar(Op_MemBarAcquire); 2703 } else { 2704 if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 2705 insert_mem_bar(Op_MemBarVolatile); 2706 } 2707 } 2708 } 2709 2710 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 2711 2712 return true; 2713 } 2714 2715 //----------------------------inline_unsafe_prefetch---------------------------- 2716 2717 bool LibraryCallKit::inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static) { 2718 #ifndef PRODUCT 2719 { 2720 ResourceMark rm; 2721 // Check the signatures. 2722 ciSignature* sig = callee()->signature(); 2723 #ifdef ASSERT 2724 // Object getObject(Object base, int/long offset), etc. 2725 BasicType rtype = sig->return_type()->basic_type(); 2726 if (!is_native_ptr) { 2727 assert(sig->count() == 2, "oop prefetch has 2 arguments"); 2728 assert(sig->type_at(0)->basic_type() == T_OBJECT, "prefetch base is object"); 2729 assert(sig->type_at(1)->basic_type() == T_LONG, "prefetcha offset is correct"); 2730 } else { 2731 assert(sig->count() == 1, "native prefetch has 1 argument"); 2732 assert(sig->type_at(0)->basic_type() == T_LONG, "prefetch base is long"); 2733 } 2734 #endif // ASSERT 2735 } 2736 #endif // !PRODUCT 2737 2738 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2739 2740 const int idx = is_static ? 0 : 1; 2741 if (!is_static) { 2742 null_check_receiver(); 2743 if (stopped()) { 2744 return true; 2745 } 2746 } 2747 2748 // Build address expression. See the code in inline_unsafe_access. 2749 Node *adr; 2750 if (!is_native_ptr) { 2751 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2752 Node* base = argument(idx + 0); // type: oop 2753 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2754 Node* offset = argument(idx + 1); // type: long 2755 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2756 // to be plain byte offsets, which are also the same as those accepted 2757 // by oopDesc::field_base. 2758 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2759 "fieldOffset must be byte-scaled"); 2760 // 32-bit machines ignore the high half! 2761 offset = ConvL2X(offset); 2762 adr = make_unsafe_address(base, offset); 2763 } else { 2764 Node* ptr = argument(idx + 0); // type: long 2765 ptr = ConvL2X(ptr); // adjust Java long to machine word 2766 adr = make_unsafe_address(NULL, ptr); 2767 } 2768 2769 // Generate the read or write prefetch 2770 Node *prefetch; 2771 if (is_store) { 2772 prefetch = new (C) PrefetchWriteNode(i_o(), adr); 2773 } else { 2774 prefetch = new (C) PrefetchReadNode(i_o(), adr); 2775 } 2776 prefetch->init_req(0, control()); 2777 set_i_o(_gvn.transform(prefetch)); 2778 2779 return true; 2780 } 2781 2782 //----------------------------inline_unsafe_load_store---------------------------- 2783 // This method serves a couple of different customers (depending on LoadStoreKind): 2784 // 2785 // LS_cmpxchg: 2786 // public final native boolean compareAndSwapObject(Object o, long offset, Object expected, Object x); 2787 // public final native boolean compareAndSwapInt( Object o, long offset, int expected, int x); 2788 // public final native boolean compareAndSwapLong( Object o, long offset, long expected, long x); 2789 // 2790 // LS_xadd: 2791 // public int getAndAddInt( Object o, long offset, int delta) 2792 // public long getAndAddLong(Object o, long offset, long delta) 2793 // 2794 // LS_xchg: 2795 // int getAndSet(Object o, long offset, int newValue) 2796 // long getAndSet(Object o, long offset, long newValue) 2797 // Object getAndSet(Object o, long offset, Object newValue) 2798 // 2799 bool LibraryCallKit::inline_unsafe_load_store(BasicType type, LoadStoreKind kind) { 2800 // This basic scheme here is the same as inline_unsafe_access, but 2801 // differs in enough details that combining them would make the code 2802 // overly confusing. (This is a true fact! I originally combined 2803 // them, but even I was confused by it!) As much code/comments as 2804 // possible are retained from inline_unsafe_access though to make 2805 // the correspondences clearer. - dl 2806 2807 if (callee()->is_static()) return false; // caller must have the capability! 2808 2809 #ifndef PRODUCT 2810 BasicType rtype; 2811 { 2812 ResourceMark rm; 2813 // Check the signatures. 2814 ciSignature* sig = callee()->signature(); 2815 rtype = sig->return_type()->basic_type(); 2816 if (kind == LS_xadd || kind == LS_xchg) { 2817 // Check the signatures. 2818 #ifdef ASSERT 2819 assert(rtype == type, "get and set must return the expected type"); 2820 assert(sig->count() == 3, "get and set has 3 arguments"); 2821 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 2822 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 2823 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 2824 #endif // ASSERT 2825 } else if (kind == LS_cmpxchg) { 2826 // Check the signatures. 2827 #ifdef ASSERT 2828 assert(rtype == T_BOOLEAN, "CAS must return boolean"); 2829 assert(sig->count() == 4, "CAS has 4 arguments"); 2830 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 2831 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 2832 #endif // ASSERT 2833 } else { 2834 ShouldNotReachHere(); 2835 } 2836 } 2837 #endif //PRODUCT 2838 2839 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2840 2841 // Get arguments: 2842 Node* receiver = NULL; 2843 Node* base = NULL; 2844 Node* offset = NULL; 2845 Node* oldval = NULL; 2846 Node* newval = NULL; 2847 if (kind == LS_cmpxchg) { 2848 const bool two_slot_type = type2size[type] == 2; 2849 receiver = argument(0); // type: oop 2850 base = argument(1); // type: oop 2851 offset = argument(2); // type: long 2852 oldval = argument(4); // type: oop, int, or long 2853 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 2854 } else if (kind == LS_xadd || kind == LS_xchg){ 2855 receiver = argument(0); // type: oop 2856 base = argument(1); // type: oop 2857 offset = argument(2); // type: long 2858 oldval = NULL; 2859 newval = argument(4); // type: oop, int, or long 2860 } 2861 2862 // Null check receiver. 2863 receiver = null_check(receiver); 2864 if (stopped()) { 2865 return true; 2866 } 2867 2868 // Build field offset expression. 2869 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2870 // to be plain byte offsets, which are also the same as those accepted 2871 // by oopDesc::field_base. 2872 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 2873 // 32-bit machines ignore the high half of long offsets 2874 offset = ConvL2X(offset); 2875 Node* adr = make_unsafe_address(base, offset); 2876 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 2877 2878 // For CAS, unlike inline_unsafe_access, there seems no point in 2879 // trying to refine types. Just use the coarse types here. 2880 const Type *value_type = Type::get_const_basic_type(type); 2881 Compile::AliasType* alias_type = C->alias_type(adr_type); 2882 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2883 2884 if (kind == LS_xchg && type == T_OBJECT) { 2885 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2886 if (tjp != NULL) { 2887 value_type = tjp; 2888 } 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 insert_mem_bar(Op_MemBarRelease); 2899 insert_mem_bar(Op_MemBarCPUOrder); 2900 2901 // 4984716: MemBars must be inserted before this 2902 // memory node in order to avoid a false 2903 // dependency which will confuse the scheduler. 2904 Node *mem = memory(alias_idx); 2905 2906 // For now, we handle only those cases that actually exist: ints, 2907 // longs, and Object. Adding others should be straightforward. 2908 Node* load_store; 2909 switch(type) { 2910 case T_INT: 2911 if (kind == LS_xadd) { 2912 load_store = _gvn.transform(new (C) GetAndAddINode(control(), mem, adr, newval, adr_type)); 2913 } else if (kind == LS_xchg) { 2914 load_store = _gvn.transform(new (C) GetAndSetINode(control(), mem, adr, newval, adr_type)); 2915 } else if (kind == LS_cmpxchg) { 2916 load_store = _gvn.transform(new (C) CompareAndSwapINode(control(), mem, adr, newval, oldval)); 2917 } else { 2918 ShouldNotReachHere(); 2919 } 2920 break; 2921 case T_LONG: 2922 if (kind == LS_xadd) { 2923 load_store = _gvn.transform(new (C) GetAndAddLNode(control(), mem, adr, newval, adr_type)); 2924 } else if (kind == LS_xchg) { 2925 load_store = _gvn.transform(new (C) GetAndSetLNode(control(), mem, adr, newval, adr_type)); 2926 } else if (kind == LS_cmpxchg) { 2927 load_store = _gvn.transform(new (C) CompareAndSwapLNode(control(), mem, adr, newval, oldval)); 2928 } else { 2929 ShouldNotReachHere(); 2930 } 2931 break; 2932 case T_OBJECT: 2933 // Transformation of a value which could be NULL pointer (CastPP #NULL) 2934 // could be delayed during Parse (for example, in adjust_map_after_if()). 2935 // Execute transformation here to avoid barrier generation in such case. 2936 if (_gvn.type(newval) == TypePtr::NULL_PTR) 2937 newval = _gvn.makecon(TypePtr::NULL_PTR); 2938 2939 // Reference stores need a store barrier. 2940 if (kind == LS_xchg) { 2941 // If pre-barrier must execute before the oop store, old value will require do_load here. 2942 if (!can_move_pre_barrier()) { 2943 pre_barrier(true /* do_load*/, 2944 control(), base, adr, alias_idx, newval, value_type->make_oopptr(), 2945 NULL /* pre_val*/, 2946 T_OBJECT); 2947 } // Else move pre_barrier to use load_store value, see below. 2948 } else if (kind == LS_cmpxchg) { 2949 // Same as for newval above: 2950 if (_gvn.type(oldval) == TypePtr::NULL_PTR) { 2951 oldval = _gvn.makecon(TypePtr::NULL_PTR); 2952 } 2953 // The only known value which might get overwritten is oldval. 2954 pre_barrier(false /* do_load */, 2955 control(), NULL, NULL, max_juint, NULL, NULL, 2956 oldval /* pre_val */, 2957 T_OBJECT); 2958 } else { 2959 ShouldNotReachHere(); 2960 } 2961 2962 #ifdef _LP64 2963 if (adr->bottom_type()->is_ptr_to_narrowoop()) { 2964 Node *newval_enc = _gvn.transform(new (C) EncodePNode(newval, newval->bottom_type()->make_narrowoop())); 2965 if (kind == LS_xchg) { 2966 load_store = _gvn.transform(new (C) GetAndSetNNode(control(), mem, adr, 2967 newval_enc, adr_type, value_type->make_narrowoop())); 2968 } else { 2969 assert(kind == LS_cmpxchg, "wrong LoadStore operation"); 2970 Node *oldval_enc = _gvn.transform(new (C) EncodePNode(oldval, oldval->bottom_type()->make_narrowoop())); 2971 load_store = _gvn.transform(new (C) CompareAndSwapNNode(control(), mem, adr, 2972 newval_enc, oldval_enc)); 2973 } 2974 } else 2975 #endif 2976 { 2977 if (kind == LS_xchg) { 2978 load_store = _gvn.transform(new (C) GetAndSetPNode(control(), mem, adr, newval, adr_type, value_type->is_oopptr())); 2979 } else { 2980 assert(kind == LS_cmpxchg, "wrong LoadStore operation"); 2981 load_store = _gvn.transform(new (C) CompareAndSwapPNode(control(), mem, adr, newval, oldval)); 2982 } 2983 } 2984 post_barrier(control(), load_store, base, adr, alias_idx, newval, T_OBJECT, true); 2985 break; 2986 default: 2987 fatal(err_msg_res("unexpected type %d: %s", type, type2name(type))); 2988 break; 2989 } 2990 2991 // SCMemProjNodes represent the memory state of a LoadStore. Their 2992 // main role is to prevent LoadStore nodes from being optimized away 2993 // when their results aren't used. 2994 Node* proj = _gvn.transform(new (C) SCMemProjNode(load_store)); 2995 set_memory(proj, alias_idx); 2996 2997 if (type == T_OBJECT && kind == LS_xchg) { 2998 #ifdef _LP64 2999 if (adr->bottom_type()->is_ptr_to_narrowoop()) { 3000 load_store = _gvn.transform(new (C) DecodeNNode(load_store, load_store->get_ptr_type())); 3001 } 3002 #endif 3003 if (can_move_pre_barrier()) { 3004 // Don't need to load pre_val. The old value is returned by load_store. 3005 // The pre_barrier can execute after the xchg as long as no safepoint 3006 // gets inserted between them. 3007 pre_barrier(false /* do_load */, 3008 control(), NULL, NULL, max_juint, NULL, NULL, 3009 load_store /* pre_val */, 3010 T_OBJECT); 3011 } 3012 } 3013 3014 // Add the trailing membar surrounding the access 3015 insert_mem_bar(Op_MemBarCPUOrder); 3016 insert_mem_bar(Op_MemBarAcquire); 3017 3018 assert(type2size[load_store->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 3019 set_result(load_store); 3020 return true; 3021 } 3022 3023 //----------------------------inline_unsafe_ordered_store---------------------- 3024 // public native void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x); 3025 // public native void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x); 3026 // public native void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x); 3027 bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) { 3028 // This is another variant of inline_unsafe_access, differing in 3029 // that it always issues store-store ("release") barrier and ensures 3030 // store-atomicity (which only matters for "long"). 3031 3032 if (callee()->is_static()) return false; // caller must have the capability! 3033 3034 #ifndef PRODUCT 3035 { 3036 ResourceMark rm; 3037 // Check the signatures. 3038 ciSignature* sig = callee()->signature(); 3039 #ifdef ASSERT 3040 BasicType rtype = sig->return_type()->basic_type(); 3041 assert(rtype == T_VOID, "must return void"); 3042 assert(sig->count() == 3, "has 3 arguments"); 3043 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base is object"); 3044 assert(sig->type_at(1)->basic_type() == T_LONG, "offset is long"); 3045 #endif // ASSERT 3046 } 3047 #endif //PRODUCT 3048 3049 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 3050 3051 // Get arguments: 3052 Node* receiver = argument(0); // type: oop 3053 Node* base = argument(1); // type: oop 3054 Node* offset = argument(2); // type: long 3055 Node* val = argument(4); // type: oop, int, or long 3056 3057 // Null check receiver. 3058 receiver = null_check(receiver); 3059 if (stopped()) { 3060 return true; 3061 } 3062 3063 // Build field offset expression. 3064 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 3065 // 32-bit machines ignore the high half of long offsets 3066 offset = ConvL2X(offset); 3067 Node* adr = make_unsafe_address(base, offset); 3068 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 3069 const Type *value_type = Type::get_const_basic_type(type); 3070 Compile::AliasType* alias_type = C->alias_type(adr_type); 3071 3072 insert_mem_bar(Op_MemBarRelease); 3073 insert_mem_bar(Op_MemBarCPUOrder); 3074 // Ensure that the store is atomic for longs: 3075 const bool require_atomic_access = true; 3076 Node* store; 3077 if (type == T_OBJECT) // reference stores need a store barrier. 3078 store = store_oop_to_unknown(control(), base, adr, adr_type, val, type, MemNode::release); 3079 else { 3080 store = store_to_memory(control(), adr, val, type, adr_type, MemNode::release, require_atomic_access); 3081 } 3082 insert_mem_bar(Op_MemBarCPUOrder); 3083 return true; 3084 } 3085 3086 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 3087 // Regardless of form, don't allow previous ld/st to move down, 3088 // then issue acquire, release, or volatile mem_bar. 3089 insert_mem_bar(Op_MemBarCPUOrder); 3090 switch(id) { 3091 case vmIntrinsics::_loadFence: 3092 insert_mem_bar(Op_LoadFence); 3093 return true; 3094 case vmIntrinsics::_storeFence: 3095 insert_mem_bar(Op_StoreFence); 3096 return true; 3097 case vmIntrinsics::_fullFence: 3098 insert_mem_bar(Op_MemBarVolatile); 3099 return true; 3100 default: 3101 fatal_unexpected_iid(id); 3102 return false; 3103 } 3104 } 3105 3106 bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 3107 if (!kls->is_Con()) { 3108 return true; 3109 } 3110 const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr(); 3111 if (klsptr == NULL) { 3112 return true; 3113 } 3114 ciInstanceKlass* ik = klsptr->klass()->as_instance_klass(); 3115 // don't need a guard for a klass that is already initialized 3116 return !ik->is_initialized(); 3117 } 3118 3119 //----------------------------inline_unsafe_allocate--------------------------- 3120 // public native Object sun.misc.Unsafe.allocateInstance(Class<?> cls); 3121 bool LibraryCallKit::inline_unsafe_allocate() { 3122 if (callee()->is_static()) return false; // caller must have the capability! 3123 3124 null_check_receiver(); // null-check, then ignore 3125 Node* cls = null_check(argument(1)); 3126 if (stopped()) return true; 3127 3128 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 3129 kls = null_check(kls); 3130 if (stopped()) return true; // argument was like int.class 3131 3132 Node* test = NULL; 3133 if (LibraryCallKit::klass_needs_init_guard(kls)) { 3134 // Note: The argument might still be an illegal value like 3135 // Serializable.class or Object[].class. The runtime will handle it. 3136 // But we must make an explicit check for initialization. 3137 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 3138 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 3139 // can generate code to load it as unsigned byte. 3140 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); 3141 Node* bits = intcon(InstanceKlass::fully_initialized); 3142 test = _gvn.transform(new (C) SubINode(inst, bits)); 3143 // The 'test' is non-zero if we need to take a slow path. 3144 } 3145 3146 Node* obj = new_instance(kls, test); 3147 set_result(obj); 3148 return true; 3149 } 3150 3151 #ifdef TRACE_HAVE_INTRINSICS 3152 /* 3153 * oop -> myklass 3154 * myklass->trace_id |= USED 3155 * return myklass->trace_id & ~0x3 3156 */ 3157 bool LibraryCallKit::inline_native_classID() { 3158 null_check_receiver(); // null-check, then ignore 3159 Node* cls = null_check(argument(1), T_OBJECT); 3160 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 3161 kls = null_check(kls, T_OBJECT); 3162 ByteSize offset = TRACE_ID_OFFSET; 3163 Node* insp = basic_plus_adr(kls, in_bytes(offset)); 3164 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered); 3165 Node* bits = longcon(~0x03l); // ignore bit 0 & 1 3166 Node* andl = _gvn.transform(new (C) AndLNode(tvalue, bits)); 3167 Node* clsused = longcon(0x01l); // set the class bit 3168 Node* orl = _gvn.transform(new (C) OrLNode(tvalue, clsused)); 3169 3170 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr(); 3171 store_to_memory(control(), insp, orl, T_LONG, adr_type, MemNode::unordered); 3172 set_result(andl); 3173 return true; 3174 } 3175 3176 bool LibraryCallKit::inline_native_threadID() { 3177 Node* tls_ptr = NULL; 3178 Node* cur_thr = generate_current_thread(tls_ptr); 3179 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 3180 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3181 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::thread_id_offset())); 3182 3183 Node* threadid = NULL; 3184 size_t thread_id_size = OSThread::thread_id_size(); 3185 if (thread_id_size == (size_t) BytesPerLong) { 3186 threadid = ConvL2I(make_load(control(), p, TypeLong::LONG, T_LONG, MemNode::unordered)); 3187 } else if (thread_id_size == (size_t) BytesPerInt) { 3188 threadid = make_load(control(), p, TypeInt::INT, T_INT, MemNode::unordered); 3189 } else { 3190 ShouldNotReachHere(); 3191 } 3192 set_result(threadid); 3193 return true; 3194 } 3195 #endif 3196 3197 //------------------------inline_native_time_funcs-------------- 3198 // inline code for System.currentTimeMillis() and System.nanoTime() 3199 // these have the same type and signature 3200 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 3201 const TypeFunc* tf = OptoRuntime::void_long_Type(); 3202 const TypePtr* no_memory_effects = NULL; 3203 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 3204 Node* value = _gvn.transform(new (C) ProjNode(time, TypeFunc::Parms+0)); 3205 #ifdef ASSERT 3206 Node* value_top = _gvn.transform(new (C) ProjNode(time, TypeFunc::Parms+1)); 3207 assert(value_top == top(), "second value must be top"); 3208 #endif 3209 set_result(value); 3210 return true; 3211 } 3212 3213 //------------------------inline_native_currentThread------------------ 3214 bool LibraryCallKit::inline_native_currentThread() { 3215 Node* junk = NULL; 3216 set_result(generate_current_thread(junk)); 3217 return true; 3218 } 3219 3220 //------------------------inline_native_isInterrupted------------------ 3221 // private native boolean java.lang.Thread.isInterrupted(boolean ClearInterrupted); 3222 bool LibraryCallKit::inline_native_isInterrupted() { 3223 // Add a fast path to t.isInterrupted(clear_int): 3224 // (t == Thread.current() && 3225 // (!TLS._osthread._interrupted || WINDOWS_ONLY(false) NOT_WINDOWS(!clear_int))) 3226 // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int) 3227 // So, in the common case that the interrupt bit is false, 3228 // we avoid making a call into the VM. Even if the interrupt bit 3229 // is true, if the clear_int argument is false, we avoid the VM call. 3230 // However, if the receiver is not currentThread, we must call the VM, 3231 // because there must be some locking done around the operation. 3232 3233 // We only go to the fast case code if we pass two guards. 3234 // Paths which do not pass are accumulated in the slow_region. 3235 3236 enum { 3237 no_int_result_path = 1, // t == Thread.current() && !TLS._osthread._interrupted 3238 no_clear_result_path = 2, // t == Thread.current() && TLS._osthread._interrupted && !clear_int 3239 slow_result_path = 3, // slow path: t.isInterrupted(clear_int) 3240 PATH_LIMIT 3241 }; 3242 3243 // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag 3244 // out of the function. 3245 insert_mem_bar(Op_MemBarCPUOrder); 3246 3247 RegionNode* result_rgn = new (C) RegionNode(PATH_LIMIT); 3248 PhiNode* result_val = new (C) PhiNode(result_rgn, TypeInt::BOOL); 3249 3250 RegionNode* slow_region = new (C) RegionNode(1); 3251 record_for_igvn(slow_region); 3252 3253 // (a) Receiving thread must be the current thread. 3254 Node* rec_thr = argument(0); 3255 Node* tls_ptr = NULL; 3256 Node* cur_thr = generate_current_thread(tls_ptr); 3257 Node* cmp_thr = _gvn.transform(new (C) CmpPNode(cur_thr, rec_thr)); 3258 Node* bol_thr = _gvn.transform(new (C) BoolNode(cmp_thr, BoolTest::ne)); 3259 3260 generate_slow_guard(bol_thr, slow_region); 3261 3262 // (b) Interrupt bit on TLS must be false. 3263 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 3264 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3265 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset())); 3266 3267 // Set the control input on the field _interrupted read to prevent it floating up. 3268 Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered); 3269 Node* cmp_bit = _gvn.transform(new (C) CmpINode(int_bit, intcon(0))); 3270 Node* bol_bit = _gvn.transform(new (C) BoolNode(cmp_bit, BoolTest::ne)); 3271 3272 IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 3273 3274 // First fast path: if (!TLS._interrupted) return false; 3275 Node* false_bit = _gvn.transform(new (C) IfFalseNode(iff_bit)); 3276 result_rgn->init_req(no_int_result_path, false_bit); 3277 result_val->init_req(no_int_result_path, intcon(0)); 3278 3279 // drop through to next case 3280 set_control( _gvn.transform(new (C) IfTrueNode(iff_bit))); 3281 3282 #ifndef TARGET_OS_FAMILY_windows 3283 // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path. 3284 Node* clr_arg = argument(1); 3285 Node* cmp_arg = _gvn.transform(new (C) CmpINode(clr_arg, intcon(0))); 3286 Node* bol_arg = _gvn.transform(new (C) BoolNode(cmp_arg, BoolTest::ne)); 3287 IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN); 3288 3289 // Second fast path: ... else if (!clear_int) return true; 3290 Node* false_arg = _gvn.transform(new (C) IfFalseNode(iff_arg)); 3291 result_rgn->init_req(no_clear_result_path, false_arg); 3292 result_val->init_req(no_clear_result_path, intcon(1)); 3293 3294 // drop through to next case 3295 set_control( _gvn.transform(new (C) IfTrueNode(iff_arg))); 3296 #else 3297 // To return true on Windows you must read the _interrupted field 3298 // and check the the event state i.e. take the slow path. 3299 #endif // TARGET_OS_FAMILY_windows 3300 3301 // (d) Otherwise, go to the slow path. 3302 slow_region->add_req(control()); 3303 set_control( _gvn.transform(slow_region)); 3304 3305 if (stopped()) { 3306 // There is no slow path. 3307 result_rgn->init_req(slow_result_path, top()); 3308 result_val->init_req(slow_result_path, top()); 3309 } else { 3310 // non-virtual because it is a private non-static 3311 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted); 3312 3313 Node* slow_val = set_results_for_java_call(slow_call); 3314 // this->control() comes from set_results_for_java_call 3315 3316 Node* fast_io = slow_call->in(TypeFunc::I_O); 3317 Node* fast_mem = slow_call->in(TypeFunc::Memory); 3318 3319 // These two phis are pre-filled with copies of of the fast IO and Memory 3320 PhiNode* result_mem = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); 3321 PhiNode* result_io = PhiNode::make(result_rgn, fast_io, Type::ABIO); 3322 3323 result_rgn->init_req(slow_result_path, control()); 3324 result_io ->init_req(slow_result_path, i_o()); 3325 result_mem->init_req(slow_result_path, reset_memory()); 3326 result_val->init_req(slow_result_path, slow_val); 3327 3328 set_all_memory(_gvn.transform(result_mem)); 3329 set_i_o( _gvn.transform(result_io)); 3330 } 3331 3332 C->set_has_split_ifs(true); // Has chance for split-if optimization 3333 set_result(result_rgn, result_val); 3334 return true; 3335 } 3336 3337 //---------------------------load_mirror_from_klass---------------------------- 3338 // Given a klass oop, load its java mirror (a java.lang.Class oop). 3339 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) { 3340 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset())); 3341 return make_load(NULL, p, TypeInstPtr::MIRROR, T_OBJECT, MemNode::unordered); 3342 } 3343 3344 //-----------------------load_klass_from_mirror_common------------------------- 3345 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 3346 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 3347 // and branch to the given path on the region. 3348 // If never_see_null, take an uncommon trap on null, so we can optimistically 3349 // compile for the non-null case. 3350 // If the region is NULL, force never_see_null = true. 3351 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 3352 bool never_see_null, 3353 RegionNode* region, 3354 int null_path, 3355 int offset) { 3356 if (region == NULL) never_see_null = true; 3357 Node* p = basic_plus_adr(mirror, offset); 3358 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3359 Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 3360 Node* null_ctl = top(); 3361 kls = null_check_oop(kls, &null_ctl, never_see_null); 3362 if (region != NULL) { 3363 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 3364 region->init_req(null_path, null_ctl); 3365 } else { 3366 assert(null_ctl == top(), "no loose ends"); 3367 } 3368 return kls; 3369 } 3370 3371 //--------------------(inline_native_Class_query helpers)--------------------- 3372 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER. 3373 // Fall through if (mods & mask) == bits, take the guard otherwise. 3374 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 3375 // Branch around if the given klass has the given modifier bit set. 3376 // Like generate_guard, adds a new path onto the region. 3377 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 3378 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered); 3379 Node* mask = intcon(modifier_mask); 3380 Node* bits = intcon(modifier_bits); 3381 Node* mbit = _gvn.transform(new (C) AndINode(mods, mask)); 3382 Node* cmp = _gvn.transform(new (C) CmpINode(mbit, bits)); 3383 Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::ne)); 3384 return generate_fair_guard(bol, region); 3385 } 3386 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 3387 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region); 3388 } 3389 3390 //-------------------------inline_native_Class_query------------------- 3391 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 3392 const Type* return_type = TypeInt::BOOL; 3393 Node* prim_return_value = top(); // what happens if it's a primitive class? 3394 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3395 bool expect_prim = false; // most of these guys expect to work on refs 3396 3397 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 3398 3399 Node* mirror = argument(0); 3400 Node* obj = top(); 3401 3402 switch (id) { 3403 case vmIntrinsics::_isInstance: 3404 // nothing is an instance of a primitive type 3405 prim_return_value = intcon(0); 3406 obj = argument(1); 3407 break; 3408 case vmIntrinsics::_getModifiers: 3409 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 3410 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line"); 3411 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin); 3412 break; 3413 case vmIntrinsics::_isInterface: 3414 prim_return_value = intcon(0); 3415 break; 3416 case vmIntrinsics::_isArray: 3417 prim_return_value = intcon(0); 3418 expect_prim = true; // cf. ObjectStreamClass.getClassSignature 3419 break; 3420 case vmIntrinsics::_isPrimitive: 3421 prim_return_value = intcon(1); 3422 expect_prim = true; // obviously 3423 break; 3424 case vmIntrinsics::_getSuperclass: 3425 prim_return_value = null(); 3426 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 3427 break; 3428 case vmIntrinsics::_getComponentType: 3429 prim_return_value = null(); 3430 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 3431 break; 3432 case vmIntrinsics::_getClassAccessFlags: 3433 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 3434 return_type = TypeInt::INT; // not bool! 6297094 3435 break; 3436 default: 3437 fatal_unexpected_iid(id); 3438 break; 3439 } 3440 3441 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 3442 if (mirror_con == NULL) return false; // cannot happen? 3443 3444 #ifndef PRODUCT 3445 if (C->print_intrinsics() || C->print_inlining()) { 3446 ciType* k = mirror_con->java_mirror_type(); 3447 if (k) { 3448 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 3449 k->print_name(); 3450 tty->cr(); 3451 } 3452 } 3453 #endif 3454 3455 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 3456 RegionNode* region = new (C) RegionNode(PATH_LIMIT); 3457 record_for_igvn(region); 3458 PhiNode* phi = new (C) PhiNode(region, return_type); 3459 3460 // The mirror will never be null of Reflection.getClassAccessFlags, however 3461 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 3462 // if it is. See bug 4774291. 3463 3464 // For Reflection.getClassAccessFlags(), the null check occurs in 3465 // the wrong place; see inline_unsafe_access(), above, for a similar 3466 // situation. 3467 mirror = null_check(mirror); 3468 // If mirror or obj is dead, only null-path is taken. 3469 if (stopped()) return true; 3470 3471 if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 3472 3473 // Now load the mirror's klass metaobject, and null-check it. 3474 // Side-effects region with the control path if the klass is null. 3475 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 3476 // If kls is null, we have a primitive mirror. 3477 phi->init_req(_prim_path, prim_return_value); 3478 if (stopped()) { set_result(region, phi); return true; } 3479 bool safe_for_replace = (region->in(_prim_path) == top()); 3480 3481 Node* p; // handy temp 3482 Node* null_ctl; 3483 3484 // Now that we have the non-null klass, we can perform the real query. 3485 // For constant classes, the query will constant-fold in LoadNode::Value. 3486 Node* query_value = top(); 3487 switch (id) { 3488 case vmIntrinsics::_isInstance: 3489 // nothing is an instance of a primitive type 3490 query_value = gen_instanceof(obj, kls, safe_for_replace); 3491 break; 3492 3493 case vmIntrinsics::_getModifiers: 3494 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset())); 3495 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 3496 break; 3497 3498 case vmIntrinsics::_isInterface: 3499 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 3500 if (generate_interface_guard(kls, region) != NULL) 3501 // A guard was added. If the guard is taken, it was an interface. 3502 phi->add_req(intcon(1)); 3503 // If we fall through, it's a plain class. 3504 query_value = intcon(0); 3505 break; 3506 3507 case vmIntrinsics::_isArray: 3508 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.) 3509 if (generate_array_guard(kls, region) != NULL) 3510 // A guard was added. If the guard is taken, it was an array. 3511 phi->add_req(intcon(1)); 3512 // If we fall through, it's a plain class. 3513 query_value = intcon(0); 3514 break; 3515 3516 case vmIntrinsics::_isPrimitive: 3517 query_value = intcon(0); // "normal" path produces false 3518 break; 3519 3520 case vmIntrinsics::_getSuperclass: 3521 // The rules here are somewhat unfortunate, but we can still do better 3522 // with random logic than with a JNI call. 3523 // Interfaces store null or Object as _super, but must report null. 3524 // Arrays store an intermediate super as _super, but must report Object. 3525 // Other types can report the actual _super. 3526 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 3527 if (generate_interface_guard(kls, region) != NULL) 3528 // A guard was added. If the guard is taken, it was an interface. 3529 phi->add_req(null()); 3530 if (generate_array_guard(kls, region) != NULL) 3531 // A guard was added. If the guard is taken, it was an array. 3532 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 3533 // If we fall through, it's a plain class. Get its _super. 3534 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 3535 kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 3536 null_ctl = top(); 3537 kls = null_check_oop(kls, &null_ctl); 3538 if (null_ctl != top()) { 3539 // If the guard is taken, Object.superClass is null (both klass and mirror). 3540 region->add_req(null_ctl); 3541 phi ->add_req(null()); 3542 } 3543 if (!stopped()) { 3544 query_value = load_mirror_from_klass(kls); 3545 } 3546 break; 3547 3548 case vmIntrinsics::_getComponentType: 3549 if (generate_array_guard(kls, region) != NULL) { 3550 // Be sure to pin the oop load to the guard edge just created: 3551 Node* is_array_ctrl = region->in(region->req()-1); 3552 Node* cma = basic_plus_adr(kls, in_bytes(ArrayKlass::component_mirror_offset())); 3553 Node* cmo = make_load(is_array_ctrl, cma, TypeInstPtr::MIRROR, T_OBJECT, MemNode::unordered); 3554 phi->add_req(cmo); 3555 } 3556 query_value = null(); // non-array case is null 3557 break; 3558 3559 case vmIntrinsics::_getClassAccessFlags: 3560 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 3561 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 3562 break; 3563 3564 default: 3565 fatal_unexpected_iid(id); 3566 break; 3567 } 3568 3569 // Fall-through is the normal case of a query to a real class. 3570 phi->init_req(1, query_value); 3571 region->init_req(1, control()); 3572 3573 C->set_has_split_ifs(true); // Has chance for split-if optimization 3574 set_result(region, phi); 3575 return true; 3576 } 3577 3578 //--------------------------inline_native_subtype_check------------------------ 3579 // This intrinsic takes the JNI calls out of the heart of 3580 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 3581 bool LibraryCallKit::inline_native_subtype_check() { 3582 // Pull both arguments off the stack. 3583 Node* args[2]; // two java.lang.Class mirrors: superc, subc 3584 args[0] = argument(0); 3585 args[1] = argument(1); 3586 Node* klasses[2]; // corresponding Klasses: superk, subk 3587 klasses[0] = klasses[1] = top(); 3588 3589 enum { 3590 // A full decision tree on {superc is prim, subc is prim}: 3591 _prim_0_path = 1, // {P,N} => false 3592 // {P,P} & superc!=subc => false 3593 _prim_same_path, // {P,P} & superc==subc => true 3594 _prim_1_path, // {N,P} => false 3595 _ref_subtype_path, // {N,N} & subtype check wins => true 3596 _both_ref_path, // {N,N} & subtype check loses => false 3597 PATH_LIMIT 3598 }; 3599 3600 RegionNode* region = new (C) RegionNode(PATH_LIMIT); 3601 Node* phi = new (C) PhiNode(region, TypeInt::BOOL); 3602 record_for_igvn(region); 3603 3604 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 3605 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3606 int class_klass_offset = java_lang_Class::klass_offset_in_bytes(); 3607 3608 // First null-check both mirrors and load each mirror's klass metaobject. 3609 int which_arg; 3610 for (which_arg = 0; which_arg <= 1; which_arg++) { 3611 Node* arg = args[which_arg]; 3612 arg = null_check(arg); 3613 if (stopped()) break; 3614 args[which_arg] = arg; 3615 3616 Node* p = basic_plus_adr(arg, class_klass_offset); 3617 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type); 3618 klasses[which_arg] = _gvn.transform(kls); 3619 } 3620 3621 // Having loaded both klasses, test each for null. 3622 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3623 for (which_arg = 0; which_arg <= 1; which_arg++) { 3624 Node* kls = klasses[which_arg]; 3625 Node* null_ctl = top(); 3626 kls = null_check_oop(kls, &null_ctl, never_see_null); 3627 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path); 3628 region->init_req(prim_path, null_ctl); 3629 if (stopped()) break; 3630 klasses[which_arg] = kls; 3631 } 3632 3633 if (!stopped()) { 3634 // now we have two reference types, in klasses[0..1] 3635 Node* subk = klasses[1]; // the argument to isAssignableFrom 3636 Node* superk = klasses[0]; // the receiver 3637 region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 3638 // now we have a successful reference subtype check 3639 region->set_req(_ref_subtype_path, control()); 3640 } 3641 3642 // If both operands are primitive (both klasses null), then 3643 // we must return true when they are identical primitives. 3644 // It is convenient to test this after the first null klass check. 3645 set_control(region->in(_prim_0_path)); // go back to first null check 3646 if (!stopped()) { 3647 // Since superc is primitive, make a guard for the superc==subc case. 3648 Node* cmp_eq = _gvn.transform(new (C) CmpPNode(args[0], args[1])); 3649 Node* bol_eq = _gvn.transform(new (C) BoolNode(cmp_eq, BoolTest::eq)); 3650 generate_guard(bol_eq, region, PROB_FAIR); 3651 if (region->req() == PATH_LIMIT+1) { 3652 // A guard was added. If the added guard is taken, superc==subc. 3653 region->swap_edges(PATH_LIMIT, _prim_same_path); 3654 region->del_req(PATH_LIMIT); 3655 } 3656 region->set_req(_prim_0_path, control()); // Not equal after all. 3657 } 3658 3659 // these are the only paths that produce 'true': 3660 phi->set_req(_prim_same_path, intcon(1)); 3661 phi->set_req(_ref_subtype_path, intcon(1)); 3662 3663 // pull together the cases: 3664 assert(region->req() == PATH_LIMIT, "sane region"); 3665 for (uint i = 1; i < region->req(); i++) { 3666 Node* ctl = region->in(i); 3667 if (ctl == NULL || ctl == top()) { 3668 region->set_req(i, top()); 3669 phi ->set_req(i, top()); 3670 } else if (phi->in(i) == NULL) { 3671 phi->set_req(i, intcon(0)); // all other paths produce 'false' 3672 } 3673 } 3674 3675 set_control(_gvn.transform(region)); 3676 set_result(_gvn.transform(phi)); 3677 return true; 3678 } 3679 3680 //---------------------generate_array_guard_common------------------------ 3681 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, 3682 bool obj_array, bool not_array) { 3683 // If obj_array/non_array==false/false: 3684 // Branch around if the given klass is in fact an array (either obj or prim). 3685 // If obj_array/non_array==false/true: 3686 // Branch around if the given klass is not an array klass of any kind. 3687 // If obj_array/non_array==true/true: 3688 // Branch around if the kls is not an oop array (kls is int[], String, etc.) 3689 // If obj_array/non_array==true/false: 3690 // Branch around if the kls is an oop array (Object[] or subtype) 3691 // 3692 // Like generate_guard, adds a new path onto the region. 3693 jint layout_con = 0; 3694 Node* layout_val = get_layout_helper(kls, layout_con); 3695 if (layout_val == NULL) { 3696 bool query = (obj_array 3697 ? Klass::layout_helper_is_objArray(layout_con) 3698 : Klass::layout_helper_is_array(layout_con)); 3699 if (query == not_array) { 3700 return NULL; // never a branch 3701 } else { // always a branch 3702 Node* always_branch = control(); 3703 if (region != NULL) 3704 region->add_req(always_branch); 3705 set_control(top()); 3706 return always_branch; 3707 } 3708 } 3709 // Now test the correct condition. 3710 jint nval = (obj_array 3711 ? ((jint)Klass::_lh_array_tag_type_value 3712 << Klass::_lh_array_tag_shift) 3713 : Klass::_lh_neutral_value); 3714 Node* cmp = _gvn.transform(new(C) CmpINode(layout_val, intcon(nval))); 3715 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array 3716 // invert the test if we are looking for a non-array 3717 if (not_array) btest = BoolTest(btest).negate(); 3718 Node* bol = _gvn.transform(new(C) BoolNode(cmp, btest)); 3719 return generate_fair_guard(bol, region); 3720 } 3721 3722 3723 //-----------------------inline_native_newArray-------------------------- 3724 // private static native Object java.lang.reflect.newArray(Class<?> componentType, int length); 3725 bool LibraryCallKit::inline_native_newArray() { 3726 Node* mirror = argument(0); 3727 Node* count_val = argument(1); 3728 3729 mirror = null_check(mirror); 3730 // If mirror or obj is dead, only null-path is taken. 3731 if (stopped()) return true; 3732 3733 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 3734 RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 3735 PhiNode* result_val = new(C) PhiNode(result_reg, 3736 TypeInstPtr::NOTNULL); 3737 PhiNode* result_io = new(C) PhiNode(result_reg, Type::ABIO); 3738 PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, 3739 TypePtr::BOTTOM); 3740 3741 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3742 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 3743 result_reg, _slow_path); 3744 Node* normal_ctl = control(); 3745 Node* no_array_ctl = result_reg->in(_slow_path); 3746 3747 // Generate code for the slow case. We make a call to newArray(). 3748 set_control(no_array_ctl); 3749 if (!stopped()) { 3750 // Either the input type is void.class, or else the 3751 // array klass has not yet been cached. Either the 3752 // ensuing call will throw an exception, or else it 3753 // will cache the array klass for next time. 3754 PreserveJVMState pjvms(this); 3755 CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray); 3756 Node* slow_result = set_results_for_java_call(slow_call); 3757 // this->control() comes from set_results_for_java_call 3758 result_reg->set_req(_slow_path, control()); 3759 result_val->set_req(_slow_path, slow_result); 3760 result_io ->set_req(_slow_path, i_o()); 3761 result_mem->set_req(_slow_path, reset_memory()); 3762 } 3763 3764 set_control(normal_ctl); 3765 if (!stopped()) { 3766 // Normal case: The array type has been cached in the java.lang.Class. 3767 // The following call works fine even if the array type is polymorphic. 3768 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3769 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 3770 result_reg->init_req(_normal_path, control()); 3771 result_val->init_req(_normal_path, obj); 3772 result_io ->init_req(_normal_path, i_o()); 3773 result_mem->init_req(_normal_path, reset_memory()); 3774 } 3775 3776 // Return the combined state. 3777 set_i_o( _gvn.transform(result_io) ); 3778 set_all_memory( _gvn.transform(result_mem)); 3779 3780 C->set_has_split_ifs(true); // Has chance for split-if optimization 3781 set_result(result_reg, result_val); 3782 return true; 3783 } 3784 3785 //----------------------inline_native_getLength-------------------------- 3786 // public static native int java.lang.reflect.Array.getLength(Object array); 3787 bool LibraryCallKit::inline_native_getLength() { 3788 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3789 3790 Node* array = null_check(argument(0)); 3791 // If array is dead, only null-path is taken. 3792 if (stopped()) return true; 3793 3794 // Deoptimize if it is a non-array. 3795 Node* non_array = generate_non_array_guard(load_object_klass(array), NULL); 3796 3797 if (non_array != NULL) { 3798 PreserveJVMState pjvms(this); 3799 set_control(non_array); 3800 uncommon_trap(Deoptimization::Reason_intrinsic, 3801 Deoptimization::Action_maybe_recompile); 3802 } 3803 3804 // If control is dead, only non-array-path is taken. 3805 if (stopped()) return true; 3806 3807 // The works fine even if the array type is polymorphic. 3808 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3809 Node* result = load_array_length(array); 3810 3811 C->set_has_split_ifs(true); // Has chance for split-if optimization 3812 set_result(result); 3813 return true; 3814 } 3815 3816 //------------------------inline_array_copyOf---------------------------- 3817 // public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 3818 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 3819 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 3820 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3821 3822 // Get the arguments. 3823 Node* original = argument(0); 3824 Node* start = is_copyOfRange? argument(1): intcon(0); 3825 Node* end = is_copyOfRange? argument(2): argument(1); 3826 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 3827 3828 Node* newcopy; 3829 3830 // Set the original stack and the reexecute bit for the interpreter to reexecute 3831 // the bytecode that invokes Arrays.copyOf if deoptimization happens. 3832 { PreserveReexecuteState preexecs(this); 3833 jvms()->set_should_reexecute(true); 3834 3835 array_type_mirror = null_check(array_type_mirror); 3836 original = null_check(original); 3837 3838 // Check if a null path was taken unconditionally. 3839 if (stopped()) return true; 3840 3841 Node* orig_length = load_array_length(original); 3842 3843 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, NULL, 0); 3844 klass_node = null_check(klass_node); 3845 3846 RegionNode* bailout = new (C) RegionNode(1); 3847 record_for_igvn(bailout); 3848 3849 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 3850 // Bail out if that is so. 3851 Node* not_objArray = generate_non_objArray_guard(klass_node, bailout); 3852 if (not_objArray != NULL) { 3853 // Improve the klass node's type from the new optimistic assumption: 3854 ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 3855 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); 3856 Node* cast = new (C) CastPPNode(klass_node, akls); 3857 cast->init_req(0, control()); 3858 klass_node = _gvn.transform(cast); 3859 } 3860 3861 // Bail out if either start or end is negative. 3862 generate_negative_guard(start, bailout, &start); 3863 generate_negative_guard(end, bailout, &end); 3864 3865 Node* length = end; 3866 if (_gvn.type(start) != TypeInt::ZERO) { 3867 length = _gvn.transform(new (C) SubINode(end, start)); 3868 } 3869 3870 // Bail out if length is negative. 3871 // Without this the new_array would throw 3872 // NegativeArraySizeException but IllegalArgumentException is what 3873 // should be thrown 3874 generate_negative_guard(length, bailout, &length); 3875 3876 if (bailout->req() > 1) { 3877 PreserveJVMState pjvms(this); 3878 set_control(_gvn.transform(bailout)); 3879 uncommon_trap(Deoptimization::Reason_intrinsic, 3880 Deoptimization::Action_maybe_recompile); 3881 } 3882 3883 if (!stopped()) { 3884 // How many elements will we copy from the original? 3885 // The answer is MinI(orig_length - start, length). 3886 Node* orig_tail = _gvn.transform(new (C) SubINode(orig_length, start)); 3887 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); 3888 3889 newcopy = new_array(klass_node, length, 0); // no argments to push 3890 3891 // Generate a direct call to the right arraycopy function(s). 3892 // We know the copy is disjoint but we might not know if the 3893 // oop stores need checking. 3894 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 3895 // This will fail a store-check if x contains any non-nulls. 3896 bool disjoint_bases = true; 3897 // if start > orig_length then the length of the copy may be 3898 // negative. 3899 bool length_never_negative = !is_copyOfRange; 3900 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 3901 original, start, newcopy, intcon(0), moved, 3902 disjoint_bases, length_never_negative); 3903 } 3904 } // original reexecute is set back here 3905 3906 C->set_has_split_ifs(true); // Has chance for split-if optimization 3907 if (!stopped()) { 3908 set_result(newcopy); 3909 } 3910 return true; 3911 } 3912 3913 3914 //----------------------generate_virtual_guard--------------------------- 3915 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 3916 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 3917 RegionNode* slow_region) { 3918 ciMethod* method = callee(); 3919 int vtable_index = method->vtable_index(); 3920 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3921 err_msg_res("bad index %d", vtable_index)); 3922 // Get the Method* out of the appropriate vtable entry. 3923 int entry_offset = (InstanceKlass::vtable_start_offset() + 3924 vtable_index*vtableEntry::size()) * wordSize + 3925 vtableEntry::method_offset_in_bytes(); 3926 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 3927 Node* target_call = make_load(NULL, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3928 3929 // Compare the target method with the expected method (e.g., Object.hashCode). 3930 const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 3931 3932 Node* native_call = makecon(native_call_addr); 3933 Node* chk_native = _gvn.transform(new(C) CmpPNode(target_call, native_call)); 3934 Node* test_native = _gvn.transform(new(C) BoolNode(chk_native, BoolTest::ne)); 3935 3936 return generate_slow_guard(test_native, slow_region); 3937 } 3938 3939 //-----------------------generate_method_call---------------------------- 3940 // Use generate_method_call to make a slow-call to the real 3941 // method if the fast path fails. An alternative would be to 3942 // use a stub like OptoRuntime::slow_arraycopy_Java. 3943 // This only works for expanding the current library call, 3944 // not another intrinsic. (E.g., don't use this for making an 3945 // arraycopy call inside of the copyOf intrinsic.) 3946 CallJavaNode* 3947 LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) { 3948 // When compiling the intrinsic method itself, do not use this technique. 3949 guarantee(callee() != C->method(), "cannot make slow-call to self"); 3950 3951 ciMethod* method = callee(); 3952 // ensure the JVMS we have will be correct for this call 3953 guarantee(method_id == method->intrinsic_id(), "must match"); 3954 3955 const TypeFunc* tf = TypeFunc::make(method); 3956 CallJavaNode* slow_call; 3957 if (is_static) { 3958 assert(!is_virtual, ""); 3959 slow_call = new(C) CallStaticJavaNode(C, tf, 3960 SharedRuntime::get_resolve_static_call_stub(), 3961 method, bci()); 3962 } else if (is_virtual) { 3963 null_check_receiver(); 3964 int vtable_index = Method::invalid_vtable_index; 3965 if (UseInlineCaches) { 3966 // Suppress the vtable call 3967 } else { 3968 // hashCode and clone are not a miranda methods, 3969 // so the vtable index is fixed. 3970 // No need to use the linkResolver to get it. 3971 vtable_index = method->vtable_index(); 3972 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3973 err_msg_res("bad index %d", vtable_index)); 3974 } 3975 slow_call = new(C) CallDynamicJavaNode(tf, 3976 SharedRuntime::get_resolve_virtual_call_stub(), 3977 method, vtable_index, bci()); 3978 } else { // neither virtual nor static: opt_virtual 3979 null_check_receiver(); 3980 slow_call = new(C) CallStaticJavaNode(C, tf, 3981 SharedRuntime::get_resolve_opt_virtual_call_stub(), 3982 method, bci()); 3983 slow_call->set_optimized_virtual(true); 3984 } 3985 set_arguments_for_java_call(slow_call); 3986 set_edges_for_java_call(slow_call); 3987 return slow_call; 3988 } 3989 3990 3991 //------------------------------inline_native_hashcode-------------------- 3992 // Build special case code for calls to hashCode on an object. 3993 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 3994 assert(is_static == callee()->is_static(), "correct intrinsic selection"); 3995 assert(!(is_virtual && is_static), "either virtual, special, or static"); 3996 3997 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 3998 3999 RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 4000 PhiNode* result_val = new(C) PhiNode(result_reg, 4001 TypeInt::INT); 4002 PhiNode* result_io = new(C) PhiNode(result_reg, Type::ABIO); 4003 PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, 4004 TypePtr::BOTTOM); 4005 Node* obj = NULL; 4006 if (!is_static) { 4007 // Check for hashing null object 4008 obj = null_check_receiver(); 4009 if (stopped()) return true; // unconditionally null 4010 result_reg->init_req(_null_path, top()); 4011 result_val->init_req(_null_path, top()); 4012 } else { 4013 // Do a null check, and return zero if null. 4014 // System.identityHashCode(null) == 0 4015 obj = argument(0); 4016 Node* null_ctl = top(); 4017 obj = null_check_oop(obj, &null_ctl); 4018 result_reg->init_req(_null_path, null_ctl); 4019 result_val->init_req(_null_path, _gvn.intcon(0)); 4020 } 4021 4022 // Unconditionally null? Then return right away. 4023 if (stopped()) { 4024 set_control( result_reg->in(_null_path)); 4025 if (!stopped()) 4026 set_result(result_val->in(_null_path)); 4027 return true; 4028 } 4029 4030 // After null check, get the object's klass. 4031 Node* obj_klass = load_object_klass(obj); 4032 4033 // This call may be virtual (invokevirtual) or bound (invokespecial). 4034 // For each case we generate slightly different code. 4035 4036 // We only go to the fast case code if we pass a number of guards. The 4037 // paths which do not pass are accumulated in the slow_region. 4038 RegionNode* slow_region = new (C) RegionNode(1); 4039 record_for_igvn(slow_region); 4040 4041 // If this is a virtual call, we generate a funny guard. We pull out 4042 // the vtable entry corresponding to hashCode() from the target object. 4043 // If the target method which we are calling happens to be the native 4044 // Object hashCode() method, we pass the guard. We do not need this 4045 // guard for non-virtual calls -- the caller is known to be the native 4046 // Object hashCode(). 4047 if (is_virtual) { 4048 generate_virtual_guard(obj_klass, slow_region); 4049 } 4050 4051 // Get the header out of the object, use LoadMarkNode when available 4052 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 4053 Node* header = make_load(control(), header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 4054 4055 // Test the header to see if it is unlocked. 4056 Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); 4057 Node *lmasked_header = _gvn.transform(new (C) AndXNode(header, lock_mask)); 4058 Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); 4059 Node *chk_unlocked = _gvn.transform(new (C) CmpXNode( lmasked_header, unlocked_val)); 4060 Node *test_unlocked = _gvn.transform(new (C) BoolNode( chk_unlocked, BoolTest::ne)); 4061 4062 generate_slow_guard(test_unlocked, slow_region); 4063 4064 // Get the hash value and check to see that it has been properly assigned. 4065 // We depend on hash_mask being at most 32 bits and avoid the use of 4066 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 4067 // vm: see markOop.hpp. 4068 Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask); 4069 Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift); 4070 Node *hshifted_header= _gvn.transform(new (C) URShiftXNode(header, hash_shift)); 4071 // This hack lets the hash bits live anywhere in the mark object now, as long 4072 // as the shift drops the relevant bits into the low 32 bits. Note that 4073 // Java spec says that HashCode is an int so there's no point in capturing 4074 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 4075 hshifted_header = ConvX2I(hshifted_header); 4076 Node *hash_val = _gvn.transform(new (C) AndINode(hshifted_header, hash_mask)); 4077 4078 Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash); 4079 Node *chk_assigned = _gvn.transform(new (C) CmpINode( hash_val, no_hash_val)); 4080 Node *test_assigned = _gvn.transform(new (C) BoolNode( chk_assigned, BoolTest::eq)); 4081 4082 generate_slow_guard(test_assigned, slow_region); 4083 4084 Node* init_mem = reset_memory(); 4085 // fill in the rest of the null path: 4086 result_io ->init_req(_null_path, i_o()); 4087 result_mem->init_req(_null_path, init_mem); 4088 4089 result_val->init_req(_fast_path, hash_val); 4090 result_reg->init_req(_fast_path, control()); 4091 result_io ->init_req(_fast_path, i_o()); 4092 result_mem->init_req(_fast_path, init_mem); 4093 4094 // Generate code for the slow case. We make a call to hashCode(). 4095 set_control(_gvn.transform(slow_region)); 4096 if (!stopped()) { 4097 // No need for PreserveJVMState, because we're using up the present state. 4098 set_all_memory(init_mem); 4099 vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 4100 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static); 4101 Node* slow_result = set_results_for_java_call(slow_call); 4102 // this->control() comes from set_results_for_java_call 4103 result_reg->init_req(_slow_path, control()); 4104 result_val->init_req(_slow_path, slow_result); 4105 result_io ->set_req(_slow_path, i_o()); 4106 result_mem ->set_req(_slow_path, reset_memory()); 4107 } 4108 4109 // Return the combined state. 4110 set_i_o( _gvn.transform(result_io) ); 4111 set_all_memory( _gvn.transform(result_mem)); 4112 4113 set_result(result_reg, result_val); 4114 return true; 4115 } 4116 4117 //---------------------------inline_native_getClass---------------------------- 4118 // public final native Class<?> java.lang.Object.getClass(); 4119 // 4120 // Build special case code for calls to getClass on an object. 4121 bool LibraryCallKit::inline_native_getClass() { 4122 Node* obj = null_check_receiver(); 4123 if (stopped()) return true; 4124 set_result(load_mirror_from_klass(load_object_klass(obj))); 4125 return true; 4126 } 4127 4128 //-----------------inline_native_Reflection_getCallerClass--------------------- 4129 // public static native Class<?> sun.reflect.Reflection.getCallerClass(); 4130 // 4131 // In the presence of deep enough inlining, getCallerClass() becomes a no-op. 4132 // 4133 // NOTE: This code must perform the same logic as JVM_GetCallerClass 4134 // in that it must skip particular security frames and checks for 4135 // caller sensitive methods. 4136 bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 4137 #ifndef PRODUCT 4138 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4139 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 4140 } 4141 #endif 4142 4143 if (!jvms()->has_method()) { 4144 #ifndef PRODUCT 4145 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4146 tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 4147 } 4148 #endif 4149 return false; 4150 } 4151 4152 // Walk back up the JVM state to find the caller at the required 4153 // depth. 4154 JVMState* caller_jvms = jvms(); 4155 4156 // Cf. JVM_GetCallerClass 4157 // NOTE: Start the loop at depth 1 because the current JVM state does 4158 // not include the Reflection.getCallerClass() frame. 4159 for (int n = 1; caller_jvms != NULL; caller_jvms = caller_jvms->caller(), n++) { 4160 ciMethod* m = caller_jvms->method(); 4161 switch (n) { 4162 case 0: 4163 fatal("current JVM state does not include the Reflection.getCallerClass frame"); 4164 break; 4165 case 1: 4166 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 4167 if (!m->caller_sensitive()) { 4168 #ifndef PRODUCT 4169 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4170 tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 4171 } 4172 #endif 4173 return false; // bail-out; let JVM_GetCallerClass do the work 4174 } 4175 break; 4176 default: 4177 if (!m->is_ignored_by_security_stack_walk()) { 4178 // We have reached the desired frame; return the holder class. 4179 // Acquire method holder as java.lang.Class and push as constant. 4180 ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 4181 ciInstance* caller_mirror = caller_klass->java_mirror(); 4182 set_result(makecon(TypeInstPtr::make(caller_mirror))); 4183 4184 #ifndef PRODUCT 4185 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4186 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()); 4187 tty->print_cr(" JVM state at this point:"); 4188 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 4189 ciMethod* m = jvms()->of_depth(i)->method(); 4190 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 4191 } 4192 } 4193 #endif 4194 return true; 4195 } 4196 break; 4197 } 4198 } 4199 4200 #ifndef PRODUCT 4201 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4202 tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 4203 tty->print_cr(" JVM state at this point:"); 4204 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 4205 ciMethod* m = jvms()->of_depth(i)->method(); 4206 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 4207 } 4208 } 4209 #endif 4210 4211 return false; // bail-out; let JVM_GetCallerClass do the work 4212 } 4213 4214 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 4215 Node* arg = argument(0); 4216 Node* result; 4217 4218 switch (id) { 4219 case vmIntrinsics::_floatToRawIntBits: result = new (C) MoveF2INode(arg); break; 4220 case vmIntrinsics::_intBitsToFloat: result = new (C) MoveI2FNode(arg); break; 4221 case vmIntrinsics::_doubleToRawLongBits: result = new (C) MoveD2LNode(arg); break; 4222 case vmIntrinsics::_longBitsToDouble: result = new (C) MoveL2DNode(arg); break; 4223 4224 case vmIntrinsics::_doubleToLongBits: { 4225 // two paths (plus control) merge in a wood 4226 RegionNode *r = new (C) RegionNode(3); 4227 Node *phi = new (C) PhiNode(r, TypeLong::LONG); 4228 4229 Node *cmpisnan = _gvn.transform(new (C) CmpDNode(arg, arg)); 4230 // Build the boolean node 4231 Node *bolisnan = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::ne)); 4232 4233 // Branch either way. 4234 // NaN case is less traveled, which makes all the difference. 4235 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 4236 Node *opt_isnan = _gvn.transform(ifisnan); 4237 assert( opt_isnan->is_If(), "Expect an IfNode"); 4238 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 4239 Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan)); 4240 4241 set_control(iftrue); 4242 4243 static const jlong nan_bits = CONST64(0x7ff8000000000000); 4244 Node *slow_result = longcon(nan_bits); // return NaN 4245 phi->init_req(1, _gvn.transform( slow_result )); 4246 r->init_req(1, iftrue); 4247 4248 // Else fall through 4249 Node *iffalse = _gvn.transform(new (C) IfFalseNode(opt_ifisnan)); 4250 set_control(iffalse); 4251 4252 phi->init_req(2, _gvn.transform(new (C) MoveD2LNode(arg))); 4253 r->init_req(2, iffalse); 4254 4255 // Post merge 4256 set_control(_gvn.transform(r)); 4257 record_for_igvn(r); 4258 4259 C->set_has_split_ifs(true); // Has chance for split-if optimization 4260 result = phi; 4261 assert(result->bottom_type()->isa_long(), "must be"); 4262 break; 4263 } 4264 4265 case vmIntrinsics::_floatToIntBits: { 4266 // two paths (plus control) merge in a wood 4267 RegionNode *r = new (C) RegionNode(3); 4268 Node *phi = new (C) PhiNode(r, TypeInt::INT); 4269 4270 Node *cmpisnan = _gvn.transform(new (C) CmpFNode(arg, arg)); 4271 // Build the boolean node 4272 Node *bolisnan = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::ne)); 4273 4274 // Branch either way. 4275 // NaN case is less traveled, which makes all the difference. 4276 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 4277 Node *opt_isnan = _gvn.transform(ifisnan); 4278 assert( opt_isnan->is_If(), "Expect an IfNode"); 4279 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 4280 Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan)); 4281 4282 set_control(iftrue); 4283 4284 static const jint nan_bits = 0x7fc00000; 4285 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 4286 phi->init_req(1, _gvn.transform( slow_result )); 4287 r->init_req(1, iftrue); 4288 4289 // Else fall through 4290 Node *iffalse = _gvn.transform(new (C) IfFalseNode(opt_ifisnan)); 4291 set_control(iffalse); 4292 4293 phi->init_req(2, _gvn.transform(new (C) MoveF2INode(arg))); 4294 r->init_req(2, iffalse); 4295 4296 // Post merge 4297 set_control(_gvn.transform(r)); 4298 record_for_igvn(r); 4299 4300 C->set_has_split_ifs(true); // Has chance for split-if optimization 4301 result = phi; 4302 assert(result->bottom_type()->isa_int(), "must be"); 4303 break; 4304 } 4305 4306 default: 4307 fatal_unexpected_iid(id); 4308 break; 4309 } 4310 set_result(_gvn.transform(result)); 4311 return true; 4312 } 4313 4314 #ifdef _LP64 4315 #define XTOP ,top() /*additional argument*/ 4316 #else //_LP64 4317 #define XTOP /*no additional argument*/ 4318 #endif //_LP64 4319 4320 //----------------------inline_unsafe_copyMemory------------------------- 4321 // public native void sun.misc.Unsafe.copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 4322 bool LibraryCallKit::inline_unsafe_copyMemory() { 4323 if (callee()->is_static()) return false; // caller must have the capability! 4324 null_check_receiver(); // null-check receiver 4325 if (stopped()) return true; 4326 4327 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 4328 4329 Node* src_ptr = argument(1); // type: oop 4330 Node* src_off = ConvL2X(argument(2)); // type: long 4331 Node* dst_ptr = argument(4); // type: oop 4332 Node* dst_off = ConvL2X(argument(5)); // type: long 4333 Node* size = ConvL2X(argument(7)); // type: long 4334 4335 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 4336 "fieldOffset must be byte-scaled"); 4337 4338 Node* src = make_unsafe_address(src_ptr, src_off); 4339 Node* dst = make_unsafe_address(dst_ptr, dst_off); 4340 4341 // Conservatively insert a memory barrier on all memory slices. 4342 // Do not let writes of the copy source or destination float below the copy. 4343 insert_mem_bar(Op_MemBarCPUOrder); 4344 4345 // Call it. Note that the length argument is not scaled. 4346 make_runtime_call(RC_LEAF|RC_NO_FP, 4347 OptoRuntime::fast_arraycopy_Type(), 4348 StubRoutines::unsafe_arraycopy(), 4349 "unsafe_arraycopy", 4350 TypeRawPtr::BOTTOM, 4351 src, dst, size XTOP); 4352 4353 // Do not let reads of the copy destination float above the copy. 4354 insert_mem_bar(Op_MemBarCPUOrder); 4355 4356 return true; 4357 } 4358 4359 //------------------------clone_coping----------------------------------- 4360 // Helper function for inline_native_clone. 4361 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark) { 4362 assert(obj_size != NULL, ""); 4363 Node* raw_obj = alloc_obj->in(1); 4364 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 4365 4366 AllocateNode* alloc = NULL; 4367 if (ReduceBulkZeroing) { 4368 // We will be completely responsible for initializing this object - 4369 // mark Initialize node as complete. 4370 alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 4371 // The object was just allocated - there should be no any stores! 4372 guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), ""); 4373 // Mark as complete_with_arraycopy so that on AllocateNode 4374 // expansion, we know this AllocateNode is initialized by an array 4375 // copy and a StoreStore barrier exists after the array copy. 4376 alloc->initialization()->set_complete_with_arraycopy(); 4377 } 4378 4379 // Copy the fastest available way. 4380 // TODO: generate fields copies for small objects instead. 4381 Node* src = obj; 4382 Node* dest = alloc_obj; 4383 Node* size = _gvn.transform(obj_size); 4384 4385 // Exclude the header but include array length to copy by 8 bytes words. 4386 // Can't use base_offset_in_bytes(bt) since basic type is unknown. 4387 int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() : 4388 instanceOopDesc::base_offset_in_bytes(); 4389 // base_off: 4390 // 8 - 32-bit VM 4391 // 12 - 64-bit VM, compressed klass 4392 // 16 - 64-bit VM, normal klass 4393 if (base_off % BytesPerLong != 0) { 4394 assert(UseCompressedClassPointers, ""); 4395 if (is_array) { 4396 // Exclude length to copy by 8 bytes words. 4397 base_off += sizeof(int); 4398 } else { 4399 // Include klass to copy by 8 bytes words. 4400 base_off = instanceOopDesc::klass_offset_in_bytes(); 4401 } 4402 assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment"); 4403 } 4404 src = basic_plus_adr(src, base_off); 4405 dest = basic_plus_adr(dest, base_off); 4406 4407 // Compute the length also, if needed: 4408 Node* countx = size; 4409 countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(base_off))); 4410 countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong) )); 4411 4412 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 4413 bool disjoint_bases = true; 4414 generate_unchecked_arraycopy(raw_adr_type, T_LONG, disjoint_bases, 4415 src, NULL, dest, NULL, countx, 4416 /*dest_uninitialized*/true); 4417 4418 // If necessary, emit some card marks afterwards. (Non-arrays only.) 4419 if (card_mark) { 4420 assert(!is_array, ""); 4421 // Put in store barrier for any and all oops we are sticking 4422 // into this object. (We could avoid this if we could prove 4423 // that the object type contains no oop fields at all.) 4424 Node* no_particular_value = NULL; 4425 Node* no_particular_field = NULL; 4426 int raw_adr_idx = Compile::AliasIdxRaw; 4427 post_barrier(control(), 4428 memory(raw_adr_type), 4429 alloc_obj, 4430 no_particular_field, 4431 raw_adr_idx, 4432 no_particular_value, 4433 T_OBJECT, 4434 false); 4435 } 4436 4437 // Do not let reads from the cloned object float above the arraycopy. 4438 if (alloc != NULL) { 4439 // Do not let stores that initialize this object be reordered with 4440 // a subsequent store that would make this object accessible by 4441 // other threads. 4442 // Record what AllocateNode this StoreStore protects so that 4443 // escape analysis can go from the MemBarStoreStoreNode to the 4444 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 4445 // based on the escape status of the AllocateNode. 4446 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 4447 } else { 4448 insert_mem_bar(Op_MemBarCPUOrder); 4449 } 4450 } 4451 4452 //------------------------inline_native_clone---------------------------- 4453 // protected native Object java.lang.Object.clone(); 4454 // 4455 // Here are the simple edge cases: 4456 // null receiver => normal trap 4457 // virtual and clone was overridden => slow path to out-of-line clone 4458 // not cloneable or finalizer => slow path to out-of-line Object.clone 4459 // 4460 // The general case has two steps, allocation and copying. 4461 // Allocation has two cases, and uses GraphKit::new_instance or new_array. 4462 // 4463 // Copying also has two cases, oop arrays and everything else. 4464 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 4465 // Everything else uses the tight inline loop supplied by CopyArrayNode. 4466 // 4467 // These steps fold up nicely if and when the cloned object's klass 4468 // can be sharply typed as an object array, a type array, or an instance. 4469 // 4470 bool LibraryCallKit::inline_native_clone(bool is_virtual) { 4471 PhiNode* result_val; 4472 4473 // Set the reexecute bit for the interpreter to reexecute 4474 // the bytecode that invokes Object.clone if deoptimization happens. 4475 { PreserveReexecuteState preexecs(this); 4476 jvms()->set_should_reexecute(true); 4477 4478 Node* obj = null_check_receiver(); 4479 if (stopped()) return true; 4480 4481 Node* obj_klass = load_object_klass(obj); 4482 const TypeKlassPtr* tklass = _gvn.type(obj_klass)->isa_klassptr(); 4483 const TypeOopPtr* toop = ((tklass != NULL) 4484 ? tklass->as_instance_type() 4485 : TypeInstPtr::NOTNULL); 4486 4487 // Conservatively insert a memory barrier on all memory slices. 4488 // Do not let writes into the original float below the clone. 4489 insert_mem_bar(Op_MemBarCPUOrder); 4490 4491 // paths into result_reg: 4492 enum { 4493 _slow_path = 1, // out-of-line call to clone method (virtual or not) 4494 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 4495 _array_path, // plain array allocation, plus arrayof_long_arraycopy 4496 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 4497 PATH_LIMIT 4498 }; 4499 RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 4500 result_val = new(C) PhiNode(result_reg, 4501 TypeInstPtr::NOTNULL); 4502 PhiNode* result_i_o = new(C) PhiNode(result_reg, Type::ABIO); 4503 PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, 4504 TypePtr::BOTTOM); 4505 record_for_igvn(result_reg); 4506 4507 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 4508 int raw_adr_idx = Compile::AliasIdxRaw; 4509 4510 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); 4511 if (array_ctl != NULL) { 4512 // It's an array. 4513 PreserveJVMState pjvms(this); 4514 set_control(array_ctl); 4515 Node* obj_length = load_array_length(obj); 4516 Node* obj_size = NULL; 4517 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push 4518 4519 if (!use_ReduceInitialCardMarks()) { 4520 // If it is an oop array, it requires very special treatment, 4521 // because card marking is required on each card of the array. 4522 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); 4523 if (is_obja != NULL) { 4524 PreserveJVMState pjvms2(this); 4525 set_control(is_obja); 4526 // Generate a direct call to the right arraycopy function(s). 4527 bool disjoint_bases = true; 4528 bool length_never_negative = true; 4529 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 4530 obj, intcon(0), alloc_obj, intcon(0), 4531 obj_length, 4532 disjoint_bases, length_never_negative); 4533 result_reg->init_req(_objArray_path, control()); 4534 result_val->init_req(_objArray_path, alloc_obj); 4535 result_i_o ->set_req(_objArray_path, i_o()); 4536 result_mem ->set_req(_objArray_path, reset_memory()); 4537 } 4538 } 4539 // Otherwise, there are no card marks to worry about. 4540 // (We can dispense with card marks if we know the allocation 4541 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 4542 // causes the non-eden paths to take compensating steps to 4543 // simulate a fresh allocation, so that no further 4544 // card marks are required in compiled code to initialize 4545 // the object.) 4546 4547 if (!stopped()) { 4548 copy_to_clone(obj, alloc_obj, obj_size, true, false); 4549 4550 // Present the results of the copy. 4551 result_reg->init_req(_array_path, control()); 4552 result_val->init_req(_array_path, alloc_obj); 4553 result_i_o ->set_req(_array_path, i_o()); 4554 result_mem ->set_req(_array_path, reset_memory()); 4555 } 4556 } 4557 4558 // We only go to the instance fast case code if we pass a number of guards. 4559 // The paths which do not pass are accumulated in the slow_region. 4560 RegionNode* slow_region = new (C) RegionNode(1); 4561 record_for_igvn(slow_region); 4562 if (!stopped()) { 4563 // It's an instance (we did array above). Make the slow-path tests. 4564 // If this is a virtual call, we generate a funny guard. We grab 4565 // the vtable entry corresponding to clone() from the target object. 4566 // If the target method which we are calling happens to be the 4567 // Object clone() method, we pass the guard. We do not need this 4568 // guard for non-virtual calls; the caller is known to be the native 4569 // Object clone(). 4570 if (is_virtual) { 4571 generate_virtual_guard(obj_klass, slow_region); 4572 } 4573 4574 // The object must be cloneable and must not have a finalizer. 4575 // Both of these conditions may be checked in a single test. 4576 // We could optimize the cloneable test further, but we don't care. 4577 generate_access_flags_guard(obj_klass, 4578 // Test both conditions: 4579 JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER, 4580 // Must be cloneable but not finalizer: 4581 JVM_ACC_IS_CLONEABLE, 4582 slow_region); 4583 } 4584 4585 if (!stopped()) { 4586 // It's an instance, and it passed the slow-path tests. 4587 PreserveJVMState pjvms(this); 4588 Node* obj_size = NULL; 4589 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size); 4590 4591 copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks()); 4592 4593 // Present the results of the slow call. 4594 result_reg->init_req(_instance_path, control()); 4595 result_val->init_req(_instance_path, alloc_obj); 4596 result_i_o ->set_req(_instance_path, i_o()); 4597 result_mem ->set_req(_instance_path, reset_memory()); 4598 } 4599 4600 // Generate code for the slow case. We make a call to clone(). 4601 set_control(_gvn.transform(slow_region)); 4602 if (!stopped()) { 4603 PreserveJVMState pjvms(this); 4604 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); 4605 Node* slow_result = set_results_for_java_call(slow_call); 4606 // this->control() comes from set_results_for_java_call 4607 result_reg->init_req(_slow_path, control()); 4608 result_val->init_req(_slow_path, slow_result); 4609 result_i_o ->set_req(_slow_path, i_o()); 4610 result_mem ->set_req(_slow_path, reset_memory()); 4611 } 4612 4613 // Return the combined state. 4614 set_control( _gvn.transform(result_reg)); 4615 set_i_o( _gvn.transform(result_i_o)); 4616 set_all_memory( _gvn.transform(result_mem)); 4617 } // original reexecute is set back here 4618 4619 set_result(_gvn.transform(result_val)); 4620 return true; 4621 } 4622 4623 //------------------------------basictype2arraycopy---------------------------- 4624 address LibraryCallKit::basictype2arraycopy(BasicType t, 4625 Node* src_offset, 4626 Node* dest_offset, 4627 bool disjoint_bases, 4628 const char* &name, 4629 bool dest_uninitialized) { 4630 const TypeInt* src_offset_inttype = gvn().find_int_type(src_offset);; 4631 const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);; 4632 4633 bool aligned = false; 4634 bool disjoint = disjoint_bases; 4635 4636 // if the offsets are the same, we can treat the memory regions as 4637 // disjoint, because either the memory regions are in different arrays, 4638 // or they are identical (which we can treat as disjoint.) We can also 4639 // treat a copy with a destination index less that the source index 4640 // as disjoint since a low->high copy will work correctly in this case. 4641 if (src_offset_inttype != NULL && src_offset_inttype->is_con() && 4642 dest_offset_inttype != NULL && dest_offset_inttype->is_con()) { 4643 // both indices are constants 4644 int s_offs = src_offset_inttype->get_con(); 4645 int d_offs = dest_offset_inttype->get_con(); 4646 int element_size = type2aelembytes(t); 4647 aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) && 4648 ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0); 4649 if (s_offs >= d_offs) disjoint = true; 4650 } else if (src_offset == dest_offset && src_offset != NULL) { 4651 // This can occur if the offsets are identical non-constants. 4652 disjoint = true; 4653 } 4654 4655 return StubRoutines::select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized); 4656 } 4657 4658 4659 //------------------------------inline_arraycopy----------------------- 4660 // public static native void java.lang.System.arraycopy(Object src, int srcPos, 4661 // Object dest, int destPos, 4662 // int length); 4663 bool LibraryCallKit::inline_arraycopy() { 4664 // Get the arguments. 4665 Node* src = argument(0); // type: oop 4666 Node* src_offset = argument(1); // type: int 4667 Node* dest = argument(2); // type: oop 4668 Node* dest_offset = argument(3); // type: int 4669 Node* length = argument(4); // type: int 4670 4671 // Compile time checks. If any of these checks cannot be verified at compile time, 4672 // we do not make a fast path for this call. Instead, we let the call remain as it 4673 // is. The checks we choose to mandate at compile time are: 4674 // 4675 // (1) src and dest are arrays. 4676 const Type* src_type = src->Value(&_gvn); 4677 const Type* dest_type = dest->Value(&_gvn); 4678 const TypeAryPtr* top_src = src_type->isa_aryptr(); 4679 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 4680 4681 // Do we have the type of src? 4682 bool has_src = (top_src != NULL && top_src->klass() != NULL); 4683 // Do we have the type of dest? 4684 bool has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4685 // Is the type for src from speculation? 4686 bool src_spec = false; 4687 // Is the type for dest from speculation? 4688 bool dest_spec = false; 4689 4690 if (!has_src || !has_dest) { 4691 // We don't have sufficient type information, let's see if 4692 // speculative types can help. We need to have types for both src 4693 // and dest so that it pays off. 4694 4695 // Do we already have or could we have type information for src 4696 bool could_have_src = has_src; 4697 // Do we already have or could we have type information for dest 4698 bool could_have_dest = has_dest; 4699 4700 ciKlass* src_k = NULL; 4701 if (!has_src) { 4702 src_k = src_type->speculative_type_not_null(); 4703 if (src_k != NULL && src_k->is_array_klass()) { 4704 could_have_src = true; 4705 } 4706 } 4707 4708 ciKlass* dest_k = NULL; 4709 if (!has_dest) { 4710 dest_k = dest_type->speculative_type_not_null(); 4711 if (dest_k != NULL && dest_k->is_array_klass()) { 4712 could_have_dest = true; 4713 } 4714 } 4715 4716 if (could_have_src && could_have_dest) { 4717 // This is going to pay off so emit the required guards 4718 if (!has_src) { 4719 src = maybe_cast_profiled_obj(src, src_k); 4720 src_type = _gvn.type(src); 4721 top_src = src_type->isa_aryptr(); 4722 has_src = (top_src != NULL && top_src->klass() != NULL); 4723 src_spec = true; 4724 } 4725 if (!has_dest) { 4726 dest = maybe_cast_profiled_obj(dest, dest_k); 4727 dest_type = _gvn.type(dest); 4728 top_dest = dest_type->isa_aryptr(); 4729 has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4730 dest_spec = true; 4731 } 4732 } 4733 } 4734 4735 if (!has_src || !has_dest) { 4736 // Conservatively insert a memory barrier on all memory slices. 4737 // Do not let writes into the source float below the arraycopy. 4738 insert_mem_bar(Op_MemBarCPUOrder); 4739 4740 // Call StubRoutines::generic_arraycopy stub. 4741 generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT, 4742 src, src_offset, dest, dest_offset, length); 4743 4744 // Do not let reads from the destination float above the arraycopy. 4745 // Since we cannot type the arrays, we don't know which slices 4746 // might be affected. We could restrict this barrier only to those 4747 // memory slices which pertain to array elements--but don't bother. 4748 if (!InsertMemBarAfterArraycopy) 4749 // (If InsertMemBarAfterArraycopy, there is already one in place.) 4750 insert_mem_bar(Op_MemBarCPUOrder); 4751 return true; 4752 } 4753 4754 // (2) src and dest arrays must have elements of the same BasicType 4755 // Figure out the size and type of the elements we will be copying. 4756 BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type(); 4757 BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type(); 4758 if (src_elem == T_ARRAY) src_elem = T_OBJECT; 4759 if (dest_elem == T_ARRAY) dest_elem = T_OBJECT; 4760 4761 if (src_elem != dest_elem || dest_elem == T_VOID) { 4762 // The component types are not the same or are not recognized. Punt. 4763 // (But, avoid the native method wrapper to JVM_ArrayCopy.) 4764 generate_slow_arraycopy(TypePtr::BOTTOM, 4765 src, src_offset, dest, dest_offset, length, 4766 /*dest_uninitialized*/false); 4767 return true; 4768 } 4769 4770 if (src_elem == T_OBJECT) { 4771 // If both arrays are object arrays then having the exact types 4772 // for both will remove the need for a subtype check at runtime 4773 // before the call and may make it possible to pick a faster copy 4774 // routine (without a subtype check on every element) 4775 // Do we have the exact type of src? 4776 bool could_have_src = src_spec; 4777 // Do we have the exact type of dest? 4778 bool could_have_dest = dest_spec; 4779 ciKlass* src_k = top_src->klass(); 4780 ciKlass* dest_k = top_dest->klass(); 4781 if (!src_spec) { 4782 src_k = src_type->speculative_type_not_null(); 4783 if (src_k != NULL && src_k->is_array_klass()) { 4784 could_have_src = true; 4785 } 4786 } 4787 if (!dest_spec) { 4788 dest_k = dest_type->speculative_type_not_null(); 4789 if (dest_k != NULL && dest_k->is_array_klass()) { 4790 could_have_dest = true; 4791 } 4792 } 4793 if (could_have_src && could_have_dest) { 4794 // If we can have both exact types, emit the missing guards 4795 if (could_have_src && !src_spec) { 4796 src = maybe_cast_profiled_obj(src, src_k); 4797 } 4798 if (could_have_dest && !dest_spec) { 4799 dest = maybe_cast_profiled_obj(dest, dest_k); 4800 } 4801 } 4802 } 4803 4804 //--------------------------------------------------------------------------- 4805 // We will make a fast path for this call to arraycopy. 4806 4807 // We have the following tests left to perform: 4808 // 4809 // (3) src and dest must not be null. 4810 // (4) src_offset must not be negative. 4811 // (5) dest_offset must not be negative. 4812 // (6) length must not be negative. 4813 // (7) src_offset + length must not exceed length of src. 4814 // (8) dest_offset + length must not exceed length of dest. 4815 // (9) each element of an oop array must be assignable 4816 4817 RegionNode* slow_region = new (C) RegionNode(1); 4818 record_for_igvn(slow_region); 4819 4820 // (3) operands must not be null 4821 // We currently perform our null checks with the null_check routine. 4822 // This means that the null exceptions will be reported in the caller 4823 // rather than (correctly) reported inside of the native arraycopy call. 4824 // This should be corrected, given time. We do our null check with the 4825 // stack pointer restored. 4826 src = null_check(src, T_ARRAY); 4827 dest = null_check(dest, T_ARRAY); 4828 4829 // (4) src_offset must not be negative. 4830 generate_negative_guard(src_offset, slow_region); 4831 4832 // (5) dest_offset must not be negative. 4833 generate_negative_guard(dest_offset, slow_region); 4834 4835 // (6) length must not be negative (moved to generate_arraycopy()). 4836 // generate_negative_guard(length, slow_region); 4837 4838 // (7) src_offset + length must not exceed length of src. 4839 generate_limit_guard(src_offset, length, 4840 load_array_length(src), 4841 slow_region); 4842 4843 // (8) dest_offset + length must not exceed length of dest. 4844 generate_limit_guard(dest_offset, length, 4845 load_array_length(dest), 4846 slow_region); 4847 4848 // (9) each element of an oop array must be assignable 4849 // The generate_arraycopy subroutine checks this. 4850 4851 // This is where the memory effects are placed: 4852 const TypePtr* adr_type = TypeAryPtr::get_array_body_type(dest_elem); 4853 generate_arraycopy(adr_type, dest_elem, 4854 src, src_offset, dest, dest_offset, length, 4855 false, false, slow_region); 4856 4857 return true; 4858 } 4859 4860 //-----------------------------generate_arraycopy---------------------- 4861 // Generate an optimized call to arraycopy. 4862 // Caller must guard against non-arrays. 4863 // Caller must determine a common array basic-type for both arrays. 4864 // Caller must validate offsets against array bounds. 4865 // The slow_region has already collected guard failure paths 4866 // (such as out of bounds length or non-conformable array types). 4867 // The generated code has this shape, in general: 4868 // 4869 // if (length == 0) return // via zero_path 4870 // slowval = -1 4871 // if (types unknown) { 4872 // slowval = call generic copy loop 4873 // if (slowval == 0) return // via checked_path 4874 // } else if (indexes in bounds) { 4875 // if ((is object array) && !(array type check)) { 4876 // slowval = call checked copy loop 4877 // if (slowval == 0) return // via checked_path 4878 // } else { 4879 // call bulk copy loop 4880 // return // via fast_path 4881 // } 4882 // } 4883 // // adjust params for remaining work: 4884 // if (slowval != -1) { 4885 // n = -1^slowval; src_offset += n; dest_offset += n; length -= n 4886 // } 4887 // slow_region: 4888 // call slow arraycopy(src, src_offset, dest, dest_offset, length) 4889 // return // via slow_call_path 4890 // 4891 // This routine is used from several intrinsics: System.arraycopy, 4892 // Object.clone (the array subcase), and Arrays.copyOf[Range]. 4893 // 4894 void 4895 LibraryCallKit::generate_arraycopy(const TypePtr* adr_type, 4896 BasicType basic_elem_type, 4897 Node* src, Node* src_offset, 4898 Node* dest, Node* dest_offset, 4899 Node* copy_length, 4900 bool disjoint_bases, 4901 bool length_never_negative, 4902 RegionNode* slow_region) { 4903 4904 if (slow_region == NULL) { 4905 slow_region = new(C) RegionNode(1); 4906 record_for_igvn(slow_region); 4907 } 4908 4909 Node* original_dest = dest; 4910 AllocateArrayNode* alloc = NULL; // used for zeroing, if needed 4911 bool dest_uninitialized = false; 4912 4913 // See if this is the initialization of a newly-allocated array. 4914 // If so, we will take responsibility here for initializing it to zero. 4915 // (Note: Because tightly_coupled_allocation performs checks on the 4916 // out-edges of the dest, we need to avoid making derived pointers 4917 // from it until we have checked its uses.) 4918 if (ReduceBulkZeroing 4919 && !ZeroTLAB // pointless if already zeroed 4920 && basic_elem_type != T_CONFLICT // avoid corner case 4921 && !src->eqv_uncast(dest) 4922 && ((alloc = tightly_coupled_allocation(dest, slow_region)) 4923 != NULL) 4924 && _gvn.find_int_con(alloc->in(AllocateNode::ALength), 1) > 0 4925 && alloc->maybe_set_complete(&_gvn)) { 4926 // "You break it, you buy it." 4927 InitializeNode* init = alloc->initialization(); 4928 assert(init->is_complete(), "we just did this"); 4929 init->set_complete_with_arraycopy(); 4930 assert(dest->is_CheckCastPP(), "sanity"); 4931 assert(dest->in(0)->in(0) == init, "dest pinned"); 4932 adr_type = TypeRawPtr::BOTTOM; // all initializations are into raw memory 4933 // From this point on, every exit path is responsible for 4934 // initializing any non-copied parts of the object to zero. 4935 // Also, if this flag is set we make sure that arraycopy interacts properly 4936 // with G1, eliding pre-barriers. See CR 6627983. 4937 dest_uninitialized = true; 4938 } else { 4939 // No zeroing elimination here. 4940 alloc = NULL; 4941 //original_dest = dest; 4942 //dest_uninitialized = false; 4943 } 4944 4945 // Results are placed here: 4946 enum { fast_path = 1, // normal void-returning assembly stub 4947 checked_path = 2, // special assembly stub with cleanup 4948 slow_call_path = 3, // something went wrong; call the VM 4949 zero_path = 4, // bypass when length of copy is zero 4950 bcopy_path = 5, // copy primitive array by 64-bit blocks 4951 PATH_LIMIT = 6 4952 }; 4953 RegionNode* result_region = new(C) RegionNode(PATH_LIMIT); 4954 PhiNode* result_i_o = new(C) PhiNode(result_region, Type::ABIO); 4955 PhiNode* result_memory = new(C) PhiNode(result_region, Type::MEMORY, adr_type); 4956 record_for_igvn(result_region); 4957 _gvn.set_type_bottom(result_i_o); 4958 _gvn.set_type_bottom(result_memory); 4959 assert(adr_type != TypePtr::BOTTOM, "must be RawMem or a T[] slice"); 4960 4961 // The slow_control path: 4962 Node* slow_control; 4963 Node* slow_i_o = i_o(); 4964 Node* slow_mem = memory(adr_type); 4965 debug_only(slow_control = (Node*) badAddress); 4966 4967 // Checked control path: 4968 Node* checked_control = top(); 4969 Node* checked_mem = NULL; 4970 Node* checked_i_o = NULL; 4971 Node* checked_value = NULL; 4972 4973 if (basic_elem_type == T_CONFLICT) { 4974 assert(!dest_uninitialized, ""); 4975 Node* cv = generate_generic_arraycopy(adr_type, 4976 src, src_offset, dest, dest_offset, 4977 copy_length, dest_uninitialized); 4978 if (cv == NULL) cv = intcon(-1); // failure (no stub available) 4979 checked_control = control(); 4980 checked_i_o = i_o(); 4981 checked_mem = memory(adr_type); 4982 checked_value = cv; 4983 set_control(top()); // no fast path 4984 } 4985 4986 Node* not_pos = generate_nonpositive_guard(copy_length, length_never_negative); 4987 if (not_pos != NULL) { 4988 PreserveJVMState pjvms(this); 4989 set_control(not_pos); 4990 4991 // (6) length must not be negative. 4992 if (!length_never_negative) { 4993 generate_negative_guard(copy_length, slow_region); 4994 } 4995 4996 // copy_length is 0. 4997 if (!stopped() && dest_uninitialized) { 4998 Node* dest_length = alloc->in(AllocateNode::ALength); 4999 if (copy_length->eqv_uncast(dest_length) 5000 || _gvn.find_int_con(dest_length, 1) <= 0) { 5001 // There is no zeroing to do. No need for a secondary raw memory barrier. 5002 } else { 5003 // Clear the whole thing since there are no source elements to copy. 5004 generate_clear_array(adr_type, dest, basic_elem_type, 5005 intcon(0), NULL, 5006 alloc->in(AllocateNode::AllocSize)); 5007 // Use a secondary InitializeNode as raw memory barrier. 5008 // Currently it is needed only on this path since other 5009 // paths have stub or runtime calls as raw memory barriers. 5010 InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, 5011 Compile::AliasIdxRaw, 5012 top())->as_Initialize(); 5013 init->set_complete(&_gvn); // (there is no corresponding AllocateNode) 5014 } 5015 } 5016 5017 // Present the results of the fast call. 5018 result_region->init_req(zero_path, control()); 5019 result_i_o ->init_req(zero_path, i_o()); 5020 result_memory->init_req(zero_path, memory(adr_type)); 5021 } 5022 5023 if (!stopped() && dest_uninitialized) { 5024 // We have to initialize the *uncopied* part of the array to zero. 5025 // The copy destination is the slice dest[off..off+len]. The other slices 5026 // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length]. 5027 Node* dest_size = alloc->in(AllocateNode::AllocSize); 5028 Node* dest_length = alloc->in(AllocateNode::ALength); 5029 Node* dest_tail = _gvn.transform(new(C) AddINode(dest_offset, 5030 copy_length)); 5031 5032 // If there is a head section that needs zeroing, do it now. 5033 if (find_int_con(dest_offset, -1) != 0) { 5034 generate_clear_array(adr_type, dest, basic_elem_type, 5035 intcon(0), dest_offset, 5036 NULL); 5037 } 5038 5039 // Next, perform a dynamic check on the tail length. 5040 // It is often zero, and we can win big if we prove this. 5041 // There are two wins: Avoid generating the ClearArray 5042 // with its attendant messy index arithmetic, and upgrade 5043 // the copy to a more hardware-friendly word size of 64 bits. 5044 Node* tail_ctl = NULL; 5045 if (!stopped() && !dest_tail->eqv_uncast(dest_length)) { 5046 Node* cmp_lt = _gvn.transform(new(C) CmpINode(dest_tail, dest_length)); 5047 Node* bol_lt = _gvn.transform(new(C) BoolNode(cmp_lt, BoolTest::lt)); 5048 tail_ctl = generate_slow_guard(bol_lt, NULL); 5049 assert(tail_ctl != NULL || !stopped(), "must be an outcome"); 5050 } 5051 5052 // At this point, let's assume there is no tail. 5053 if (!stopped() && alloc != NULL && basic_elem_type != T_OBJECT) { 5054 // There is no tail. Try an upgrade to a 64-bit copy. 5055 bool didit = false; 5056 { PreserveJVMState pjvms(this); 5057 didit = generate_block_arraycopy(adr_type, basic_elem_type, alloc, 5058 src, src_offset, dest, dest_offset, 5059 dest_size, dest_uninitialized); 5060 if (didit) { 5061 // Present the results of the block-copying fast call. 5062 result_region->init_req(bcopy_path, control()); 5063 result_i_o ->init_req(bcopy_path, i_o()); 5064 result_memory->init_req(bcopy_path, memory(adr_type)); 5065 } 5066 } 5067 if (didit) 5068 set_control(top()); // no regular fast path 5069 } 5070 5071 // Clear the tail, if any. 5072 if (tail_ctl != NULL) { 5073 Node* notail_ctl = stopped() ? NULL : control(); 5074 set_control(tail_ctl); 5075 if (notail_ctl == NULL) { 5076 generate_clear_array(adr_type, dest, basic_elem_type, 5077 dest_tail, NULL, 5078 dest_size); 5079 } else { 5080 // Make a local merge. 5081 Node* done_ctl = new(C) RegionNode(3); 5082 Node* done_mem = new(C) PhiNode(done_ctl, Type::MEMORY, adr_type); 5083 done_ctl->init_req(1, notail_ctl); 5084 done_mem->init_req(1, memory(adr_type)); 5085 generate_clear_array(adr_type, dest, basic_elem_type, 5086 dest_tail, NULL, 5087 dest_size); 5088 done_ctl->init_req(2, control()); 5089 done_mem->init_req(2, memory(adr_type)); 5090 set_control( _gvn.transform(done_ctl)); 5091 set_memory( _gvn.transform(done_mem), adr_type ); 5092 } 5093 } 5094 } 5095 5096 BasicType copy_type = basic_elem_type; 5097 assert(basic_elem_type != T_ARRAY, "caller must fix this"); 5098 if (!stopped() && copy_type == T_OBJECT) { 5099 // If src and dest have compatible element types, we can copy bits. 5100 // Types S[] and D[] are compatible if D is a supertype of S. 5101 // 5102 // If they are not, we will use checked_oop_disjoint_arraycopy, 5103 // which performs a fast optimistic per-oop check, and backs off 5104 // further to JVM_ArrayCopy on the first per-oop check that fails. 5105 // (Actually, we don't move raw bits only; the GC requires card marks.) 5106 5107 // Get the Klass* for both src and dest 5108 Node* src_klass = load_object_klass(src); 5109 Node* dest_klass = load_object_klass(dest); 5110 5111 // Generate the subtype check. 5112 // This might fold up statically, or then again it might not. 5113 // 5114 // Non-static example: Copying List<String>.elements to a new String[]. 5115 // The backing store for a List<String> is always an Object[], 5116 // but its elements are always type String, if the generic types 5117 // are correct at the source level. 5118 // 5119 // Test S[] against D[], not S against D, because (probably) 5120 // the secondary supertype cache is less busy for S[] than S. 5121 // This usually only matters when D is an interface. 5122 Node* not_subtype_ctrl = gen_subtype_check(src_klass, dest_klass); 5123 // Plug failing path into checked_oop_disjoint_arraycopy 5124 if (not_subtype_ctrl != top()) { 5125 PreserveJVMState pjvms(this); 5126 set_control(not_subtype_ctrl); 5127 // (At this point we can assume disjoint_bases, since types differ.) 5128 int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset()); 5129 Node* p1 = basic_plus_adr(dest_klass, ek_offset); 5130 Node* n1 = LoadKlassNode::make(_gvn, immutable_memory(), p1, TypeRawPtr::BOTTOM); 5131 Node* dest_elem_klass = _gvn.transform(n1); 5132 Node* cv = generate_checkcast_arraycopy(adr_type, 5133 dest_elem_klass, 5134 src, src_offset, dest, dest_offset, 5135 ConvI2X(copy_length), dest_uninitialized); 5136 if (cv == NULL) cv = intcon(-1); // failure (no stub available) 5137 checked_control = control(); 5138 checked_i_o = i_o(); 5139 checked_mem = memory(adr_type); 5140 checked_value = cv; 5141 } 5142 // At this point we know we do not need type checks on oop stores. 5143 5144 // Let's see if we need card marks: 5145 if (alloc != NULL && use_ReduceInitialCardMarks()) { 5146 // If we do not need card marks, copy using the jint or jlong stub. 5147 copy_type = LP64_ONLY(UseCompressedOops ? T_INT : T_LONG) NOT_LP64(T_INT); 5148 assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type), 5149 "sizes agree"); 5150 } 5151 } 5152 5153 if (!stopped()) { 5154 // Generate the fast path, if possible. 5155 PreserveJVMState pjvms(this); 5156 generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases, 5157 src, src_offset, dest, dest_offset, 5158 ConvI2X(copy_length), dest_uninitialized); 5159 5160 // Present the results of the fast call. 5161 result_region->init_req(fast_path, control()); 5162 result_i_o ->init_req(fast_path, i_o()); 5163 result_memory->init_req(fast_path, memory(adr_type)); 5164 } 5165 5166 // Here are all the slow paths up to this point, in one bundle: 5167 slow_control = top(); 5168 if (slow_region != NULL) 5169 slow_control = _gvn.transform(slow_region); 5170 DEBUG_ONLY(slow_region = (RegionNode*)badAddress); 5171 5172 set_control(checked_control); 5173 if (!stopped()) { 5174 // Clean up after the checked call. 5175 // The returned value is either 0 or -1^K, 5176 // where K = number of partially transferred array elements. 5177 Node* cmp = _gvn.transform(new(C) CmpINode(checked_value, intcon(0))); 5178 Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq)); 5179 IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN); 5180 5181 // If it is 0, we are done, so transfer to the end. 5182 Node* checks_done = _gvn.transform(new(C) IfTrueNode(iff)); 5183 result_region->init_req(checked_path, checks_done); 5184 result_i_o ->init_req(checked_path, checked_i_o); 5185 result_memory->init_req(checked_path, checked_mem); 5186 5187 // If it is not zero, merge into the slow call. 5188 set_control( _gvn.transform(new(C) IfFalseNode(iff) )); 5189 RegionNode* slow_reg2 = new(C) RegionNode(3); 5190 PhiNode* slow_i_o2 = new(C) PhiNode(slow_reg2, Type::ABIO); 5191 PhiNode* slow_mem2 = new(C) PhiNode(slow_reg2, Type::MEMORY, adr_type); 5192 record_for_igvn(slow_reg2); 5193 slow_reg2 ->init_req(1, slow_control); 5194 slow_i_o2 ->init_req(1, slow_i_o); 5195 slow_mem2 ->init_req(1, slow_mem); 5196 slow_reg2 ->init_req(2, control()); 5197 slow_i_o2 ->init_req(2, checked_i_o); 5198 slow_mem2 ->init_req(2, checked_mem); 5199 5200 slow_control = _gvn.transform(slow_reg2); 5201 slow_i_o = _gvn.transform(slow_i_o2); 5202 slow_mem = _gvn.transform(slow_mem2); 5203 5204 if (alloc != NULL) { 5205 // We'll restart from the very beginning, after zeroing the whole thing. 5206 // This can cause double writes, but that's OK since dest is brand new. 5207 // So we ignore the low 31 bits of the value returned from the stub. 5208 } else { 5209 // We must continue the copy exactly where it failed, or else 5210 // another thread might see the wrong number of writes to dest. 5211 Node* checked_offset = _gvn.transform(new(C) XorINode(checked_value, intcon(-1))); 5212 Node* slow_offset = new(C) PhiNode(slow_reg2, TypeInt::INT); 5213 slow_offset->init_req(1, intcon(0)); 5214 slow_offset->init_req(2, checked_offset); 5215 slow_offset = _gvn.transform(slow_offset); 5216 5217 // Adjust the arguments by the conditionally incoming offset. 5218 Node* src_off_plus = _gvn.transform(new(C) AddINode(src_offset, slow_offset)); 5219 Node* dest_off_plus = _gvn.transform(new(C) AddINode(dest_offset, slow_offset)); 5220 Node* length_minus = _gvn.transform(new(C) SubINode(copy_length, slow_offset)); 5221 5222 // Tweak the node variables to adjust the code produced below: 5223 src_offset = src_off_plus; 5224 dest_offset = dest_off_plus; 5225 copy_length = length_minus; 5226 } 5227 } 5228 5229 set_control(slow_control); 5230 if (!stopped()) { 5231 // Generate the slow path, if needed. 5232 PreserveJVMState pjvms(this); // replace_in_map may trash the map 5233 5234 set_memory(slow_mem, adr_type); 5235 set_i_o(slow_i_o); 5236 5237 if (dest_uninitialized) { 5238 generate_clear_array(adr_type, dest, basic_elem_type, 5239 intcon(0), NULL, 5240 alloc->in(AllocateNode::AllocSize)); 5241 } 5242 5243 generate_slow_arraycopy(adr_type, 5244 src, src_offset, dest, dest_offset, 5245 copy_length, /*dest_uninitialized*/false); 5246 5247 result_region->init_req(slow_call_path, control()); 5248 result_i_o ->init_req(slow_call_path, i_o()); 5249 result_memory->init_req(slow_call_path, memory(adr_type)); 5250 } 5251 5252 // Remove unused edges. 5253 for (uint i = 1; i < result_region->req(); i++) { 5254 if (result_region->in(i) == NULL) 5255 result_region->init_req(i, top()); 5256 } 5257 5258 // Finished; return the combined state. 5259 set_control( _gvn.transform(result_region)); 5260 set_i_o( _gvn.transform(result_i_o) ); 5261 set_memory( _gvn.transform(result_memory), adr_type ); 5262 5263 // The memory edges above are precise in order to model effects around 5264 // array copies accurately to allow value numbering of field loads around 5265 // arraycopy. Such field loads, both before and after, are common in Java 5266 // collections and similar classes involving header/array data structures. 5267 // 5268 // But with low number of register or when some registers are used or killed 5269 // by arraycopy calls it causes registers spilling on stack. See 6544710. 5270 // The next memory barrier is added to avoid it. If the arraycopy can be 5271 // optimized away (which it can, sometimes) then we can manually remove 5272 // the membar also. 5273 // 5274 // Do not let reads from the cloned object float above the arraycopy. 5275 if (alloc != NULL) { 5276 // Do not let stores that initialize this object be reordered with 5277 // a subsequent store that would make this object accessible by 5278 // other threads. 5279 // Record what AllocateNode this StoreStore protects so that 5280 // escape analysis can go from the MemBarStoreStoreNode to the 5281 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 5282 // based on the escape status of the AllocateNode. 5283 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 5284 } else if (InsertMemBarAfterArraycopy) 5285 insert_mem_bar(Op_MemBarCPUOrder); 5286 } 5287 5288 5289 // Helper function which determines if an arraycopy immediately follows 5290 // an allocation, with no intervening tests or other escapes for the object. 5291 AllocateArrayNode* 5292 LibraryCallKit::tightly_coupled_allocation(Node* ptr, 5293 RegionNode* slow_region) { 5294 if (stopped()) return NULL; // no fast path 5295 if (C->AliasLevel() == 0) return NULL; // no MergeMems around 5296 5297 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn); 5298 if (alloc == NULL) return NULL; 5299 5300 Node* rawmem = memory(Compile::AliasIdxRaw); 5301 // Is the allocation's memory state untouched? 5302 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 5303 // Bail out if there have been raw-memory effects since the allocation. 5304 // (Example: There might have been a call or safepoint.) 5305 return NULL; 5306 } 5307 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 5308 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 5309 return NULL; 5310 } 5311 5312 // There must be no unexpected observers of this allocation. 5313 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 5314 Node* obs = ptr->fast_out(i); 5315 if (obs != this->map()) { 5316 return NULL; 5317 } 5318 } 5319 5320 // This arraycopy must unconditionally follow the allocation of the ptr. 5321 Node* alloc_ctl = ptr->in(0); 5322 assert(just_allocated_object(alloc_ctl) == ptr, "most recent allo"); 5323 5324 Node* ctl = control(); 5325 while (ctl != alloc_ctl) { 5326 // There may be guards which feed into the slow_region. 5327 // Any other control flow means that we might not get a chance 5328 // to finish initializing the allocated object. 5329 if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) { 5330 IfNode* iff = ctl->in(0)->as_If(); 5331 Node* not_ctl = iff->proj_out(1 - ctl->as_Proj()->_con); 5332 assert(not_ctl != NULL && not_ctl != ctl, "found alternate"); 5333 if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) { 5334 ctl = iff->in(0); // This test feeds the known slow_region. 5335 continue; 5336 } 5337 // One more try: Various low-level checks bottom out in 5338 // uncommon traps. If the debug-info of the trap omits 5339 // any reference to the allocation, as we've already 5340 // observed, then there can be no objection to the trap. 5341 bool found_trap = false; 5342 for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) { 5343 Node* obs = not_ctl->fast_out(j); 5344 if (obs->in(0) == not_ctl && obs->is_Call() && 5345 (obs->as_Call()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point())) { 5346 found_trap = true; break; 5347 } 5348 } 5349 if (found_trap) { 5350 ctl = iff->in(0); // This test feeds a harmless uncommon trap. 5351 continue; 5352 } 5353 } 5354 return NULL; 5355 } 5356 5357 // If we get this far, we have an allocation which immediately 5358 // precedes the arraycopy, and we can take over zeroing the new object. 5359 // The arraycopy will finish the initialization, and provide 5360 // a new control state to which we will anchor the destination pointer. 5361 5362 return alloc; 5363 } 5364 5365 // Helper for initialization of arrays, creating a ClearArray. 5366 // It writes zero bits in [start..end), within the body of an array object. 5367 // The memory effects are all chained onto the 'adr_type' alias category. 5368 // 5369 // Since the object is otherwise uninitialized, we are free 5370 // to put a little "slop" around the edges of the cleared area, 5371 // as long as it does not go back into the array's header, 5372 // or beyond the array end within the heap. 5373 // 5374 // The lower edge can be rounded down to the nearest jint and the 5375 // upper edge can be rounded up to the nearest MinObjAlignmentInBytes. 5376 // 5377 // Arguments: 5378 // adr_type memory slice where writes are generated 5379 // dest oop of the destination array 5380 // basic_elem_type element type of the destination 5381 // slice_idx array index of first element to store 5382 // slice_len number of elements to store (or NULL) 5383 // dest_size total size in bytes of the array object 5384 // 5385 // Exactly one of slice_len or dest_size must be non-NULL. 5386 // If dest_size is non-NULL, zeroing extends to the end of the object. 5387 // If slice_len is non-NULL, the slice_idx value must be a constant. 5388 void 5389 LibraryCallKit::generate_clear_array(const TypePtr* adr_type, 5390 Node* dest, 5391 BasicType basic_elem_type, 5392 Node* slice_idx, 5393 Node* slice_len, 5394 Node* dest_size) { 5395 // one or the other but not both of slice_len and dest_size: 5396 assert((slice_len != NULL? 1: 0) + (dest_size != NULL? 1: 0) == 1, ""); 5397 if (slice_len == NULL) slice_len = top(); 5398 if (dest_size == NULL) dest_size = top(); 5399 5400 // operate on this memory slice: 5401 Node* mem = memory(adr_type); // memory slice to operate on 5402 5403 // scaling and rounding of indexes: 5404 int scale = exact_log2(type2aelembytes(basic_elem_type)); 5405 int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 5406 int clear_low = (-1 << scale) & (BytesPerInt - 1); 5407 int bump_bit = (-1 << scale) & BytesPerInt; 5408 5409 // determine constant starts and ends 5410 const intptr_t BIG_NEG = -128; 5411 assert(BIG_NEG + 2*abase < 0, "neg enough"); 5412 intptr_t slice_idx_con = (intptr_t) find_int_con(slice_idx, BIG_NEG); 5413 intptr_t slice_len_con = (intptr_t) find_int_con(slice_len, BIG_NEG); 5414 if (slice_len_con == 0) { 5415 return; // nothing to do here 5416 } 5417 intptr_t start_con = (abase + (slice_idx_con << scale)) & ~clear_low; 5418 intptr_t end_con = find_intptr_t_con(dest_size, -1); 5419 if (slice_idx_con >= 0 && slice_len_con >= 0) { 5420 assert(end_con < 0, "not two cons"); 5421 end_con = round_to(abase + ((slice_idx_con + slice_len_con) << scale), 5422 BytesPerLong); 5423 } 5424 5425 if (start_con >= 0 && end_con >= 0) { 5426 // Constant start and end. Simple. 5427 mem = ClearArrayNode::clear_memory(control(), mem, dest, 5428 start_con, end_con, &_gvn); 5429 } else if (start_con >= 0 && dest_size != top()) { 5430 // Constant start, pre-rounded end after the tail of the array. 5431 Node* end = dest_size; 5432 mem = ClearArrayNode::clear_memory(control(), mem, dest, 5433 start_con, end, &_gvn); 5434 } else if (start_con >= 0 && slice_len != top()) { 5435 // Constant start, non-constant end. End needs rounding up. 5436 // End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8) 5437 intptr_t end_base = abase + (slice_idx_con << scale); 5438 int end_round = (-1 << scale) & (BytesPerLong - 1); 5439 Node* end = ConvI2X(slice_len); 5440 if (scale != 0) 5441 end = _gvn.transform(new(C) LShiftXNode(end, intcon(scale) )); 5442 end_base += end_round; 5443 end = _gvn.transform(new(C) AddXNode(end, MakeConX(end_base))); 5444 end = _gvn.transform(new(C) AndXNode(end, MakeConX(~end_round))); 5445 mem = ClearArrayNode::clear_memory(control(), mem, dest, 5446 start_con, end, &_gvn); 5447 } else if (start_con < 0 && dest_size != top()) { 5448 // Non-constant start, pre-rounded end after the tail of the array. 5449 // This is almost certainly a "round-to-end" operation. 5450 Node* start = slice_idx; 5451 start = ConvI2X(start); 5452 if (scale != 0) 5453 start = _gvn.transform(new(C) LShiftXNode( start, intcon(scale) )); 5454 start = _gvn.transform(new(C) AddXNode(start, MakeConX(abase))); 5455 if ((bump_bit | clear_low) != 0) { 5456 int to_clear = (bump_bit | clear_low); 5457 // Align up mod 8, then store a jint zero unconditionally 5458 // just before the mod-8 boundary. 5459 if (((abase + bump_bit) & ~to_clear) - bump_bit 5460 < arrayOopDesc::length_offset_in_bytes() + BytesPerInt) { 5461 bump_bit = 0; 5462 assert((abase & to_clear) == 0, "array base must be long-aligned"); 5463 } else { 5464 // Bump 'start' up to (or past) the next jint boundary: 5465 start = _gvn.transform(new(C) AddXNode(start, MakeConX(bump_bit))); 5466 assert((abase & clear_low) == 0, "array base must be int-aligned"); 5467 } 5468 // Round bumped 'start' down to jlong boundary in body of array. 5469 start = _gvn.transform(new(C) AndXNode(start, MakeConX(~to_clear))); 5470 if (bump_bit != 0) { 5471 // Store a zero to the immediately preceding jint: 5472 Node* x1 = _gvn.transform(new(C) AddXNode(start, MakeConX(-bump_bit))); 5473 Node* p1 = basic_plus_adr(dest, x1); 5474 mem = StoreNode::make(_gvn, control(), mem, p1, adr_type, intcon(0), T_INT, MemNode::unordered); 5475 mem = _gvn.transform(mem); 5476 } 5477 } 5478 Node* end = dest_size; // pre-rounded 5479 mem = ClearArrayNode::clear_memory(control(), mem, dest, 5480 start, end, &_gvn); 5481 } else { 5482 // Non-constant start, unrounded non-constant end. 5483 // (Nobody zeroes a random midsection of an array using this routine.) 5484 ShouldNotReachHere(); // fix caller 5485 } 5486 5487 // Done. 5488 set_memory(mem, adr_type); 5489 } 5490 5491 5492 bool 5493 LibraryCallKit::generate_block_arraycopy(const TypePtr* adr_type, 5494 BasicType basic_elem_type, 5495 AllocateNode* alloc, 5496 Node* src, Node* src_offset, 5497 Node* dest, Node* dest_offset, 5498 Node* dest_size, bool dest_uninitialized) { 5499 // See if there is an advantage from block transfer. 5500 int scale = exact_log2(type2aelembytes(basic_elem_type)); 5501 if (scale >= LogBytesPerLong) 5502 return false; // it is already a block transfer 5503 5504 // Look at the alignment of the starting offsets. 5505 int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 5506 5507 intptr_t src_off_con = (intptr_t) find_int_con(src_offset, -1); 5508 intptr_t dest_off_con = (intptr_t) find_int_con(dest_offset, -1); 5509 if (src_off_con < 0 || dest_off_con < 0) 5510 // At present, we can only understand constants. 5511 return false; 5512 5513 intptr_t src_off = abase + (src_off_con << scale); 5514 intptr_t dest_off = abase + (dest_off_con << scale); 5515 5516 if (((src_off | dest_off) & (BytesPerLong-1)) != 0) { 5517 // Non-aligned; too bad. 5518 // One more chance: Pick off an initial 32-bit word. 5519 // This is a common case, since abase can be odd mod 8. 5520 if (((src_off | dest_off) & (BytesPerLong-1)) == BytesPerInt && 5521 ((src_off ^ dest_off) & (BytesPerLong-1)) == 0) { 5522 Node* sptr = basic_plus_adr(src, src_off); 5523 Node* dptr = basic_plus_adr(dest, dest_off); 5524 Node* sval = make_load(control(), sptr, TypeInt::INT, T_INT, adr_type, MemNode::unordered); 5525 store_to_memory(control(), dptr, sval, T_INT, adr_type, MemNode::unordered); 5526 src_off += BytesPerInt; 5527 dest_off += BytesPerInt; 5528 } else { 5529 return false; 5530 } 5531 } 5532 assert(src_off % BytesPerLong == 0, ""); 5533 assert(dest_off % BytesPerLong == 0, ""); 5534 5535 // Do this copy by giant steps. 5536 Node* sptr = basic_plus_adr(src, src_off); 5537 Node* dptr = basic_plus_adr(dest, dest_off); 5538 Node* countx = dest_size; 5539 countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(dest_off))); 5540 countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong))); 5541 5542 bool disjoint_bases = true; // since alloc != NULL 5543 generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases, 5544 sptr, NULL, dptr, NULL, countx, dest_uninitialized); 5545 5546 return true; 5547 } 5548 5549 5550 // Helper function; generates code for the slow case. 5551 // We make a call to a runtime method which emulates the native method, 5552 // but without the native wrapper overhead. 5553 void 5554 LibraryCallKit::generate_slow_arraycopy(const TypePtr* adr_type, 5555 Node* src, Node* src_offset, 5556 Node* dest, Node* dest_offset, 5557 Node* copy_length, bool dest_uninitialized) { 5558 assert(!dest_uninitialized, "Invariant"); 5559 Node* call = make_runtime_call(RC_NO_LEAF | RC_UNCOMMON, 5560 OptoRuntime::slow_arraycopy_Type(), 5561 OptoRuntime::slow_arraycopy_Java(), 5562 "slow_arraycopy", adr_type, 5563 src, src_offset, dest, dest_offset, 5564 copy_length); 5565 5566 // Handle exceptions thrown by this fellow: 5567 make_slow_call_ex(call, env()->Throwable_klass(), false); 5568 } 5569 5570 // Helper function; generates code for cases requiring runtime checks. 5571 Node* 5572 LibraryCallKit::generate_checkcast_arraycopy(const TypePtr* adr_type, 5573 Node* dest_elem_klass, 5574 Node* src, Node* src_offset, 5575 Node* dest, Node* dest_offset, 5576 Node* copy_length, bool dest_uninitialized) { 5577 if (stopped()) return NULL; 5578 5579 address copyfunc_addr = StubRoutines::checkcast_arraycopy(dest_uninitialized); 5580 if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 5581 return NULL; 5582 } 5583 5584 // Pick out the parameters required to perform a store-check 5585 // for the target array. This is an optimistic check. It will 5586 // look in each non-null element's class, at the desired klass's 5587 // super_check_offset, for the desired klass. 5588 int sco_offset = in_bytes(Klass::super_check_offset_offset()); 5589 Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset); 5590 Node* n3 = new(C) LoadINode(NULL, memory(p3), p3, _gvn.type(p3)->is_ptr(), TypeInt::INT, MemNode::unordered); 5591 Node* check_offset = ConvI2X(_gvn.transform(n3)); 5592 Node* check_value = dest_elem_klass; 5593 5594 Node* src_start = array_element_address(src, src_offset, T_OBJECT); 5595 Node* dest_start = array_element_address(dest, dest_offset, T_OBJECT); 5596 5597 // (We know the arrays are never conjoint, because their types differ.) 5598 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 5599 OptoRuntime::checkcast_arraycopy_Type(), 5600 copyfunc_addr, "checkcast_arraycopy", adr_type, 5601 // five arguments, of which two are 5602 // intptr_t (jlong in LP64) 5603 src_start, dest_start, 5604 copy_length XTOP, 5605 check_offset XTOP, 5606 check_value); 5607 5608 return _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 5609 } 5610 5611 5612 // Helper function; generates code for cases requiring runtime checks. 5613 Node* 5614 LibraryCallKit::generate_generic_arraycopy(const TypePtr* adr_type, 5615 Node* src, Node* src_offset, 5616 Node* dest, Node* dest_offset, 5617 Node* copy_length, bool dest_uninitialized) { 5618 assert(!dest_uninitialized, "Invariant"); 5619 if (stopped()) return NULL; 5620 address copyfunc_addr = StubRoutines::generic_arraycopy(); 5621 if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 5622 return NULL; 5623 } 5624 5625 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 5626 OptoRuntime::generic_arraycopy_Type(), 5627 copyfunc_addr, "generic_arraycopy", adr_type, 5628 src, src_offset, dest, dest_offset, copy_length); 5629 5630 return _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 5631 } 5632 5633 // Helper function; generates the fast out-of-line call to an arraycopy stub. 5634 void 5635 LibraryCallKit::generate_unchecked_arraycopy(const TypePtr* adr_type, 5636 BasicType basic_elem_type, 5637 bool disjoint_bases, 5638 Node* src, Node* src_offset, 5639 Node* dest, Node* dest_offset, 5640 Node* copy_length, bool dest_uninitialized) { 5641 if (stopped()) return; // nothing to do 5642 5643 Node* src_start = src; 5644 Node* dest_start = dest; 5645 if (src_offset != NULL || dest_offset != NULL) { 5646 assert(src_offset != NULL && dest_offset != NULL, ""); 5647 src_start = array_element_address(src, src_offset, basic_elem_type); 5648 dest_start = array_element_address(dest, dest_offset, basic_elem_type); 5649 } 5650 5651 // Figure out which arraycopy runtime method to call. 5652 const char* copyfunc_name = "arraycopy"; 5653 address copyfunc_addr = 5654 basictype2arraycopy(basic_elem_type, src_offset, dest_offset, 5655 disjoint_bases, copyfunc_name, dest_uninitialized); 5656 5657 // Call it. Note that the count_ix value is not scaled to a byte-size. 5658 make_runtime_call(RC_LEAF|RC_NO_FP, 5659 OptoRuntime::fast_arraycopy_Type(), 5660 copyfunc_addr, copyfunc_name, adr_type, 5661 src_start, dest_start, copy_length XTOP); 5662 } 5663 5664 //-------------inline_encodeISOArray----------------------------------- 5665 // encode char[] to byte[] in ISO_8859_1 5666 bool LibraryCallKit::inline_encodeISOArray() { 5667 assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 5668 // no receiver since it is static method 5669 Node *src = argument(0); 5670 Node *src_offset = argument(1); 5671 Node *dst = argument(2); 5672 Node *dst_offset = argument(3); 5673 Node *length = argument(4); 5674 5675 const Type* src_type = src->Value(&_gvn); 5676 const Type* dst_type = dst->Value(&_gvn); 5677 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5678 const TypeAryPtr* top_dest = dst_type->isa_aryptr(); 5679 if (top_src == NULL || top_src->klass() == NULL || 5680 top_dest == NULL || top_dest->klass() == NULL) { 5681 // failed array check 5682 return false; 5683 } 5684 5685 // Figure out the size and type of the elements we will be copying. 5686 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5687 BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5688 if (src_elem != T_CHAR || dst_elem != T_BYTE) { 5689 return false; 5690 } 5691 Node* src_start = array_element_address(src, src_offset, src_elem); 5692 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 5693 // 'src_start' points to src array + scaled offset 5694 // 'dst_start' points to dst array + scaled offset 5695 5696 const TypeAryPtr* mtype = TypeAryPtr::BYTES; 5697 Node* enc = new (C) EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length); 5698 enc = _gvn.transform(enc); 5699 Node* res_mem = _gvn.transform(new (C) SCMemProjNode(enc)); 5700 set_memory(res_mem, mtype); 5701 set_result(enc); 5702 return true; 5703 } 5704 5705 /** 5706 * Calculate CRC32 for byte. 5707 * int java.util.zip.CRC32.update(int crc, int b) 5708 */ 5709 bool LibraryCallKit::inline_updateCRC32() { 5710 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5711 assert(callee()->signature()->size() == 2, "update has 2 parameters"); 5712 // no receiver since it is static method 5713 Node* crc = argument(0); // type: int 5714 Node* b = argument(1); // type: int 5715 5716 /* 5717 * int c = ~ crc; 5718 * b = timesXtoThe32[(b ^ c) & 0xFF]; 5719 * b = b ^ (c >>> 8); 5720 * crc = ~b; 5721 */ 5722 5723 Node* M1 = intcon(-1); 5724 crc = _gvn.transform(new (C) XorINode(crc, M1)); 5725 Node* result = _gvn.transform(new (C) XorINode(crc, b)); 5726 result = _gvn.transform(new (C) AndINode(result, intcon(0xFF))); 5727 5728 Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 5729 Node* offset = _gvn.transform(new (C) LShiftINode(result, intcon(0x2))); 5730 Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 5731 result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 5732 5733 crc = _gvn.transform(new (C) URShiftINode(crc, intcon(8))); 5734 result = _gvn.transform(new (C) XorINode(crc, result)); 5735 result = _gvn.transform(new (C) XorINode(result, M1)); 5736 set_result(result); 5737 return true; 5738 } 5739 5740 /** 5741 * Calculate CRC32 for byte[] array. 5742 * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 5743 */ 5744 bool LibraryCallKit::inline_updateBytesCRC32() { 5745 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5746 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5747 // no receiver since it is static method 5748 Node* crc = argument(0); // type: int 5749 Node* src = argument(1); // type: oop 5750 Node* offset = argument(2); // type: int 5751 Node* length = argument(3); // type: int 5752 5753 const Type* src_type = src->Value(&_gvn); 5754 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5755 if (top_src == NULL || top_src->klass() == NULL) { 5756 // failed array check 5757 return false; 5758 } 5759 5760 // Figure out the size and type of the elements we will be copying. 5761 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5762 if (src_elem != T_BYTE) { 5763 return false; 5764 } 5765 5766 // 'src_start' points to src array + scaled offset 5767 Node* src_start = array_element_address(src, offset, src_elem); 5768 5769 // We assume that range check is done by caller. 5770 // TODO: generate range check (offset+length < src.length) in debug VM. 5771 5772 // Call the stub. 5773 address stubAddr = StubRoutines::updateBytesCRC32(); 5774 const char *stubName = "updateBytesCRC32"; 5775 5776 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5777 stubAddr, stubName, TypePtr::BOTTOM, 5778 crc, src_start, length); 5779 Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 5780 set_result(result); 5781 return true; 5782 } 5783 5784 /** 5785 * Calculate CRC32 for ByteBuffer. 5786 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 5787 */ 5788 bool LibraryCallKit::inline_updateByteBufferCRC32() { 5789 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5790 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 5791 // no receiver since it is static method 5792 Node* crc = argument(0); // type: int 5793 Node* src = argument(1); // type: long 5794 Node* offset = argument(3); // type: int 5795 Node* length = argument(4); // type: int 5796 5797 src = ConvL2X(src); // adjust Java long to machine word 5798 Node* base = _gvn.transform(new (C) CastX2PNode(src)); 5799 offset = ConvI2X(offset); 5800 5801 // 'src_start' points to src array + scaled offset 5802 Node* src_start = basic_plus_adr(top(), base, offset); 5803 5804 // Call the stub. 5805 address stubAddr = StubRoutines::updateBytesCRC32(); 5806 const char *stubName = "updateBytesCRC32"; 5807 5808 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5809 stubAddr, stubName, TypePtr::BOTTOM, 5810 crc, src_start, length); 5811 Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 5812 set_result(result); 5813 return true; 5814 } 5815 5816 //----------------------------inline_reference_get---------------------------- 5817 // public T java.lang.ref.Reference.get(); 5818 bool LibraryCallKit::inline_reference_get() { 5819 const int referent_offset = java_lang_ref_Reference::referent_offset; 5820 guarantee(referent_offset > 0, "should have already been set"); 5821 5822 // Get the argument: 5823 Node* reference_obj = null_check_receiver(); 5824 if (stopped()) return true; 5825 5826 Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); 5827 5828 ciInstanceKlass* klass = env()->Object_klass(); 5829 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); 5830 5831 Node* no_ctrl = NULL; 5832 Node* result = make_load(no_ctrl, adr, object_type, T_OBJECT, MemNode::unordered); 5833 5834 // Use the pre-barrier to record the value in the referent field 5835 pre_barrier(false /* do_load */, 5836 control(), 5837 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, 5838 result /* pre_val */, 5839 T_OBJECT); 5840 5841 // Add memory barrier to prevent commoning reads from this field 5842 // across safepoint since GC can change its value. 5843 insert_mem_bar(Op_MemBarCPUOrder); 5844 5845 set_result(result); 5846 return true; 5847 } 5848 5849 5850 Node * LibraryCallKit::load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 5851 bool is_exact=true, bool is_static=false) { 5852 5853 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 5854 assert(tinst != NULL, "obj is null"); 5855 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5856 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 5857 5858 ciField* field = tinst->klass()->as_instance_klass()->get_field_by_name(ciSymbol::make(fieldName), 5859 ciSymbol::make(fieldTypeString), 5860 is_static); 5861 if (field == NULL) return (Node *) NULL; 5862 assert (field != NULL, "undefined field"); 5863 5864 // Next code copied from Parse::do_get_xxx(): 5865 5866 // Compute address and memory type. 5867 int offset = field->offset_in_bytes(); 5868 bool is_vol = field->is_volatile(); 5869 ciType* field_klass = field->type(); 5870 assert(field_klass->is_loaded(), "should be loaded"); 5871 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 5872 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 5873 BasicType bt = field->layout_type(); 5874 5875 // Build the resultant type of the load 5876 const Type *type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 5877 5878 // Build the load. 5879 Node* loadedField = make_load(NULL, adr, type, bt, adr_type, MemNode::unordered, is_vol); 5880 return loadedField; 5881 } 5882 5883 5884 //------------------------------inline_aescrypt_Block----------------------- 5885 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 5886 address stubAddr; 5887 const char *stubName; 5888 assert(UseAES, "need AES instruction support"); 5889 5890 switch(id) { 5891 case vmIntrinsics::_aescrypt_encryptBlock: 5892 stubAddr = StubRoutines::aescrypt_encryptBlock(); 5893 stubName = "aescrypt_encryptBlock"; 5894 break; 5895 case vmIntrinsics::_aescrypt_decryptBlock: 5896 stubAddr = StubRoutines::aescrypt_decryptBlock(); 5897 stubName = "aescrypt_decryptBlock"; 5898 break; 5899 } 5900 if (stubAddr == NULL) return false; 5901 5902 Node* aescrypt_object = argument(0); 5903 Node* src = argument(1); 5904 Node* src_offset = argument(2); 5905 Node* dest = argument(3); 5906 Node* dest_offset = argument(4); 5907 5908 // (1) src and dest are arrays. 5909 const Type* src_type = src->Value(&_gvn); 5910 const Type* dest_type = dest->Value(&_gvn); 5911 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5912 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5913 assert (top_src != NULL && top_src->klass() != NULL && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5914 5915 // for the quick and dirty code we will skip all the checks. 5916 // we are just trying to get the call to be generated. 5917 Node* src_start = src; 5918 Node* dest_start = dest; 5919 if (src_offset != NULL || dest_offset != NULL) { 5920 assert(src_offset != NULL && dest_offset != NULL, ""); 5921 src_start = array_element_address(src, src_offset, T_BYTE); 5922 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5923 } 5924 5925 // now need to get the start of its expanded key array 5926 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5927 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5928 if (k_start == NULL) return false; 5929 5930 if (Matcher::pass_original_key_for_aes()) { 5931 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 5932 // compatibility issues between Java key expansion and SPARC crypto instructions 5933 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 5934 if (original_k_start == NULL) return false; 5935 5936 // Call the stub. 5937 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5938 stubAddr, stubName, TypePtr::BOTTOM, 5939 src_start, dest_start, k_start, original_k_start); 5940 } else { 5941 // Call the stub. 5942 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5943 stubAddr, stubName, TypePtr::BOTTOM, 5944 src_start, dest_start, k_start); 5945 } 5946 5947 return true; 5948 } 5949 5950 //------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 5951 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 5952 address stubAddr; 5953 const char *stubName; 5954 5955 assert(UseAES, "need AES instruction support"); 5956 5957 switch(id) { 5958 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 5959 stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 5960 stubName = "cipherBlockChaining_encryptAESCrypt"; 5961 break; 5962 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 5963 stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 5964 stubName = "cipherBlockChaining_decryptAESCrypt"; 5965 break; 5966 } 5967 if (stubAddr == NULL) return false; 5968 5969 Node* cipherBlockChaining_object = argument(0); 5970 Node* src = argument(1); 5971 Node* src_offset = argument(2); 5972 Node* len = argument(3); 5973 Node* dest = argument(4); 5974 Node* dest_offset = argument(5); 5975 5976 // (1) src and dest are arrays. 5977 const Type* src_type = src->Value(&_gvn); 5978 const Type* dest_type = dest->Value(&_gvn); 5979 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5980 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5981 assert (top_src != NULL && top_src->klass() != NULL 5982 && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5983 5984 // checks are the responsibility of the caller 5985 Node* src_start = src; 5986 Node* dest_start = dest; 5987 if (src_offset != NULL || dest_offset != NULL) { 5988 assert(src_offset != NULL && dest_offset != NULL, ""); 5989 src_start = array_element_address(src, src_offset, T_BYTE); 5990 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5991 } 5992 5993 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 5994 // (because of the predicated logic executed earlier). 5995 // so we cast it here safely. 5996 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5997 5998 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5999 if (embeddedCipherObj == NULL) return false; 6000 6001 // cast it to what we know it will be at runtime 6002 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 6003 assert(tinst != NULL, "CBC obj is null"); 6004 assert(tinst->klass()->is_loaded(), "CBC obj is not loaded"); 6005 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6006 if (!klass_AESCrypt->is_loaded()) return false; 6007 6008 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6009 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 6010 const TypeOopPtr* xtype = aklass->as_instance_type(); 6011 Node* aescrypt_object = new(C) CheckCastPPNode(control(), embeddedCipherObj, xtype); 6012 aescrypt_object = _gvn.transform(aescrypt_object); 6013 6014 // we need to get the start of the aescrypt_object's expanded key array 6015 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 6016 if (k_start == NULL) return false; 6017 6018 // similarly, get the start address of the r vector 6019 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false); 6020 if (objRvec == NULL) return false; 6021 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 6022 6023 Node* cbcCrypt; 6024 if (Matcher::pass_original_key_for_aes()) { 6025 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 6026 // compatibility issues between Java key expansion and SPARC crypto instructions 6027 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 6028 if (original_k_start == NULL) return false; 6029 6030 // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start 6031 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 6032 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 6033 stubAddr, stubName, TypePtr::BOTTOM, 6034 src_start, dest_start, k_start, r_start, len, original_k_start); 6035 } else { 6036 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 6037 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 6038 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 6039 stubAddr, stubName, TypePtr::BOTTOM, 6040 src_start, dest_start, k_start, r_start, len); 6041 } 6042 6043 // return cipher length (int) 6044 Node* retvalue = _gvn.transform(new (C) ProjNode(cbcCrypt, TypeFunc::Parms)); 6045 set_result(retvalue); 6046 return true; 6047 } 6048 6049 //------------------------------get_key_start_from_aescrypt_object----------------------- 6050 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 6051 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false); 6052 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 6053 if (objAESCryptKey == NULL) return (Node *) NULL; 6054 6055 // now have the array, need to get the start address of the K array 6056 Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 6057 return k_start; 6058 } 6059 6060 //------------------------------get_original_key_start_from_aescrypt_object----------------------- 6061 Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) { 6062 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false); 6063 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 6064 if (objAESCryptKey == NULL) return (Node *) NULL; 6065 6066 // now have the array, need to get the start address of the lastKey array 6067 Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE); 6068 return original_k_start; 6069 } 6070 6071 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 6072 // Return node representing slow path of predicate check. 6073 // the pseudo code we want to emulate with this predicate is: 6074 // for encryption: 6075 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 6076 // for decryption: 6077 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6078 // note cipher==plain is more conservative than the original java code but that's OK 6079 // 6080 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 6081 // First, check receiver for NULL since it is virtual method. 6082 Node* objCBC = argument(0); 6083 objCBC = null_check(objCBC); 6084 6085 if (stopped()) return NULL; // Always NULL 6086 6087 // Load embeddedCipher field of CipherBlockChaining object. 6088 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6089 6090 // get AESCrypt klass for instanceOf check 6091 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 6092 // will have same classloader as CipherBlockChaining object 6093 const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 6094 assert(tinst != NULL, "CBCobj is null"); 6095 assert(tinst->klass()->is_loaded(), "CBCobj is not loaded"); 6096 6097 // we want to do an instanceof comparison against the AESCrypt class 6098 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6099 if (!klass_AESCrypt->is_loaded()) { 6100 // if AESCrypt is not even loaded, we never take the intrinsic fast path 6101 Node* ctrl = control(); 6102 set_control(top()); // no regular fast path 6103 return ctrl; 6104 } 6105 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6106 6107 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 6108 Node* cmp_instof = _gvn.transform(new (C) CmpINode(instof, intcon(1))); 6109 Node* bool_instof = _gvn.transform(new (C) BoolNode(cmp_instof, BoolTest::ne)); 6110 6111 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6112 6113 // for encryption, we are done 6114 if (!decrypting) 6115 return instof_false; // even if it is NULL 6116 6117 // for decryption, we need to add a further check to avoid 6118 // taking the intrinsic path when cipher and plain are the same 6119 // see the original java code for why. 6120 RegionNode* region = new(C) RegionNode(3); 6121 region->init_req(1, instof_false); 6122 Node* src = argument(1); 6123 Node* dest = argument(4); 6124 Node* cmp_src_dest = _gvn.transform(new (C) CmpPNode(src, dest)); 6125 Node* bool_src_dest = _gvn.transform(new (C) BoolNode(cmp_src_dest, BoolTest::eq)); 6126 Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN); 6127 region->init_req(2, src_dest_conjoint); 6128 6129 record_for_igvn(region); 6130 return _gvn.transform(region); 6131 }