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