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