1 /* 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/macroAssembler.hpp" 27 #include "ci/ciUtilities.inline.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "compiler/compileBroker.hpp" 31 #include "compiler/compileLog.hpp" 32 #include "gc/shared/barrierSet.hpp" 33 #include "jfr/support/jfrIntrinsics.hpp" 34 #include "memory/resourceArea.hpp" 35 #include "oops/objArrayKlass.hpp" 36 #include "opto/addnode.hpp" 37 #include "opto/arraycopynode.hpp" 38 #include "opto/c2compiler.hpp" 39 #include "opto/callGenerator.hpp" 40 #include "opto/castnode.hpp" 41 #include "opto/cfgnode.hpp" 42 #include "opto/convertnode.hpp" 43 #include "opto/countbitsnode.hpp" 44 #include "opto/intrinsicnode.hpp" 45 #include "opto/idealKit.hpp" 46 #include "opto/mathexactnode.hpp" 47 #include "opto/movenode.hpp" 48 #include "opto/mulnode.hpp" 49 #include "opto/narrowptrnode.hpp" 50 #include "opto/opaquenode.hpp" 51 #include "opto/parse.hpp" 52 #include "opto/runtime.hpp" 53 #include "opto/rootnode.hpp" 54 #include "opto/subnode.hpp" 55 #include "opto/vectornode.hpp" 56 #include "prims/nativeLookup.hpp" 57 #include "prims/unsafe.hpp" 58 #include "runtime/objectMonitor.hpp" 59 #include "runtime/sharedRuntime.hpp" 60 #include "utilities/macros.hpp" 61 62 63 class LibraryIntrinsic : public InlineCallGenerator { 64 // Extend the set of intrinsics known to the runtime: 65 public: 66 private: 67 bool _is_virtual; 68 bool _does_virtual_dispatch; 69 int8_t _predicates_count; // Intrinsic is predicated by several conditions 70 int8_t _last_predicate; // Last generated predicate 71 vmIntrinsics::ID _intrinsic_id; 72 73 public: 74 LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id) 75 : InlineCallGenerator(m), 76 _is_virtual(is_virtual), 77 _does_virtual_dispatch(does_virtual_dispatch), 78 _predicates_count((int8_t)predicates_count), 79 _last_predicate((int8_t)-1), 80 _intrinsic_id(id) 81 { 82 } 83 virtual bool is_intrinsic() const { return true; } 84 virtual bool is_virtual() const { return _is_virtual; } 85 virtual bool is_predicated() const { return _predicates_count > 0; } 86 virtual int predicates_count() const { return _predicates_count; } 87 virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; } 88 virtual JVMState* generate(JVMState* jvms); 89 virtual Node* generate_predicate(JVMState* jvms, int predicate); 90 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; } 91 }; 92 93 94 // Local helper class for LibraryIntrinsic: 95 class LibraryCallKit : public GraphKit { 96 private: 97 LibraryIntrinsic* _intrinsic; // the library intrinsic being called 98 Node* _result; // the result node, if any 99 int _reexecute_sp; // the stack pointer when bytecode needs to be reexecuted 100 101 const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type); 102 103 public: 104 LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic) 105 : GraphKit(jvms), 106 _intrinsic(intrinsic), 107 _result(NULL) 108 { 109 // Check if this is a root compile. In that case we don't have a caller. 110 if (!jvms->has_method()) { 111 _reexecute_sp = sp(); 112 } else { 113 // Find out how many arguments the interpreter needs when deoptimizing 114 // and save the stack pointer value so it can used by uncommon_trap. 115 // We find the argument count by looking at the declared signature. 116 bool ignored_will_link; 117 ciSignature* declared_signature = NULL; 118 ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature); 119 const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci())); 120 _reexecute_sp = sp() + nargs; // "push" arguments back on stack 121 } 122 } 123 124 virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; } 125 126 ciMethod* caller() const { return jvms()->method(); } 127 int bci() const { return jvms()->bci(); } 128 LibraryIntrinsic* intrinsic() const { return _intrinsic; } 129 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); } 130 ciMethod* callee() const { return _intrinsic->method(); } 131 132 bool try_to_inline(int predicate); 133 Node* try_to_predicate(int predicate); 134 135 void push_result() { 136 // Push the result onto the stack. 137 if (!stopped() && result() != NULL) { 138 BasicType bt = result()->bottom_type()->basic_type(); 139 push_node(bt, result()); 140 } 141 } 142 143 private: 144 void fatal_unexpected_iid(vmIntrinsics::ID iid) { 145 fatal("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)); 146 } 147 148 void set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; } 149 void set_result(RegionNode* region, PhiNode* value); 150 Node* result() { return _result; } 151 152 virtual int reexecute_sp() { return _reexecute_sp; } 153 154 // Helper functions to inline natives 155 Node* generate_guard(Node* test, RegionNode* region, float true_prob); 156 Node* generate_slow_guard(Node* test, RegionNode* region); 157 Node* generate_fair_guard(Node* test, RegionNode* region); 158 Node* generate_negative_guard(Node* index, RegionNode* region, 159 // resulting CastII of index: 160 Node* *pos_index = NULL); 161 Node* generate_limit_guard(Node* offset, Node* subseq_length, 162 Node* array_length, 163 RegionNode* region); 164 void generate_string_range_check(Node* array, Node* offset, 165 Node* length, bool char_count); 166 Node* generate_current_thread(Node* &tls_output); 167 Node* load_mirror_from_klass(Node* klass); 168 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null, 169 RegionNode* region, int null_path, 170 int offset); 171 Node* load_klass_from_mirror(Node* mirror, bool never_see_null, 172 RegionNode* region, int null_path) { 173 int offset = java_lang_Class::klass_offset_in_bytes(); 174 return load_klass_from_mirror_common(mirror, never_see_null, 175 region, null_path, 176 offset); 177 } 178 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null, 179 RegionNode* region, int null_path) { 180 int offset = java_lang_Class::array_klass_offset_in_bytes(); 181 return load_klass_from_mirror_common(mirror, never_see_null, 182 region, null_path, 183 offset); 184 } 185 Node* generate_access_flags_guard(Node* kls, 186 int modifier_mask, int modifier_bits, 187 RegionNode* region); 188 Node* generate_interface_guard(Node* kls, RegionNode* region); 189 Node* generate_array_guard(Node* kls, RegionNode* region) { 190 return generate_array_guard_common(kls, region, false, false); 191 } 192 Node* generate_non_array_guard(Node* kls, RegionNode* region) { 193 return generate_array_guard_common(kls, region, false, true); 194 } 195 Node* generate_objArray_guard(Node* kls, RegionNode* region) { 196 return generate_array_guard_common(kls, region, true, false); 197 } 198 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) { 199 return generate_array_guard_common(kls, region, true, true); 200 } 201 Node* generate_array_guard_common(Node* kls, RegionNode* region, 202 bool obj_array, bool not_array); 203 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region); 204 CallJavaNode* generate_method_call(vmIntrinsics::ID method_id, 205 bool is_virtual = false, bool is_static = false); 206 CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) { 207 return generate_method_call(method_id, false, true); 208 } 209 CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) { 210 return generate_method_call(method_id, true, false); 211 } 212 Node * load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass * fromKls); 213 Node * field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass * fromKls); 214 215 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae); 216 bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae); 217 bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae); 218 bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae); 219 Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count, 220 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae); 221 bool inline_string_indexOfChar(); 222 bool inline_string_equals(StrIntrinsicNode::ArgEnc ae); 223 bool inline_string_toBytesU(); 224 bool inline_string_getCharsU(); 225 bool inline_string_copy(bool compress); 226 bool inline_string_char_access(bool is_store); 227 Node* round_double_node(Node* n); 228 bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName); 229 bool inline_math_native(vmIntrinsics::ID id); 230 bool inline_math(vmIntrinsics::ID id); 231 template <typename OverflowOp> 232 bool inline_math_overflow(Node* arg1, Node* arg2); 233 void inline_math_mathExact(Node* math, Node* test); 234 bool inline_math_addExactI(bool is_increment); 235 bool inline_math_addExactL(bool is_increment); 236 bool inline_math_multiplyExactI(); 237 bool inline_math_multiplyExactL(); 238 bool inline_math_multiplyHigh(); 239 bool inline_math_negateExactI(); 240 bool inline_math_negateExactL(); 241 bool inline_math_subtractExactI(bool is_decrement); 242 bool inline_math_subtractExactL(bool is_decrement); 243 bool inline_min_max(vmIntrinsics::ID id); 244 bool inline_notify(vmIntrinsics::ID id); 245 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); 246 // This returns Type::AnyPtr, RawPtr, or OopPtr. 247 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type); 248 Node* make_unsafe_address(Node*& base, Node* offset, DecoratorSet decorators, BasicType type = T_ILLEGAL, bool can_cast = false); 249 250 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind; 251 DecoratorSet mo_decorator_for_access_kind(AccessKind kind); 252 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned); 253 static bool klass_needs_init_guard(Node* kls); 254 bool inline_unsafe_allocate(); 255 bool inline_unsafe_newArray(bool uninitialized); 256 bool inline_unsafe_copyMemory(); 257 bool inline_native_currentThread(); 258 259 bool inline_native_time_funcs(address method, const char* funcName); 260 #ifdef JFR_HAVE_INTRINSICS 261 bool inline_native_classID(); 262 bool inline_native_getEventWriter(); 263 #endif 264 bool inline_native_isInterrupted(); 265 bool inline_native_Class_query(vmIntrinsics::ID id); 266 bool inline_native_subtype_check(); 267 bool inline_native_getLength(); 268 bool inline_array_copyOf(bool is_copyOfRange); 269 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae); 270 bool inline_preconditions_checkIndex(); 271 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array); 272 bool inline_native_clone(bool is_virtual); 273 bool inline_native_Reflection_getCallerClass(); 274 // Helper function for inlining native object hash method 275 bool inline_native_hashcode(bool is_virtual, bool is_static); 276 bool inline_native_getClass(); 277 278 // Helper functions for inlining arraycopy 279 bool inline_arraycopy(); 280 AllocateArrayNode* tightly_coupled_allocation(Node* ptr, 281 RegionNode* slow_region); 282 JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp); 283 void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp, 284 uint new_idx); 285 286 typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind; 287 bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind, AccessKind access_kind); 288 bool inline_unsafe_fence(vmIntrinsics::ID id); 289 bool inline_onspinwait(); 290 bool inline_fp_conversions(vmIntrinsics::ID id); 291 bool inline_number_methods(vmIntrinsics::ID id); 292 bool inline_reference_get(); 293 bool inline_Class_cast(); 294 bool inline_aescrypt_Block(vmIntrinsics::ID id); 295 bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id); 296 bool inline_counterMode_AESCrypt(vmIntrinsics::ID id); 297 Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting); 298 Node* inline_counterMode_AESCrypt_predicate(); 299 Node* get_key_start_from_aescrypt_object(Node* aescrypt_object); 300 Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object); 301 bool inline_ghash_processBlocks(); 302 bool inline_base64_encodeBlock(); 303 bool inline_sha_implCompress(vmIntrinsics::ID id); 304 bool inline_digestBase_implCompressMB(int predicate); 305 bool inline_sha_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass_SHA, 306 bool long_state, address stubAddr, const char *stubName, 307 Node* src_start, Node* ofs, Node* limit); 308 Node* get_state_from_sha_object(Node *sha_object); 309 Node* get_state_from_sha5_object(Node *sha_object); 310 Node* inline_digestBase_implCompressMB_predicate(int predicate); 311 bool inline_encodeISOArray(); 312 bool inline_updateCRC32(); 313 bool inline_updateBytesCRC32(); 314 bool inline_updateByteBufferCRC32(); 315 Node* get_table_from_crc32c_class(ciInstanceKlass *crc32c_class); 316 bool inline_updateBytesCRC32C(); 317 bool inline_updateDirectByteBufferCRC32C(); 318 bool inline_updateBytesAdler32(); 319 bool inline_updateByteBufferAdler32(); 320 bool inline_multiplyToLen(); 321 bool inline_hasNegatives(); 322 bool inline_squareToLen(); 323 bool inline_mulAdd(); 324 bool inline_montgomeryMultiply(); 325 bool inline_montgomerySquare(); 326 bool inline_vectorizedMismatch(); 327 bool inline_fma(vmIntrinsics::ID id); 328 bool inline_character_compare(vmIntrinsics::ID id); 329 bool inline_fp_min_max(vmIntrinsics::ID id); 330 331 bool inline_profileBoolean(); 332 bool inline_isCompileConstant(); 333 334 // Vector API support 335 bool inline_vector_nary_operation(int n); 336 bool inline_vector_broadcast_coerced(); 337 bool inline_vector_mem_operation(bool is_store); 338 bool inline_vector_gather_scatter(bool is_scatter); 339 bool inline_vector_reduction(); 340 bool inline_vector_test(); 341 bool inline_vector_blend(); 342 bool inline_vector_rearrange(); 343 bool inline_vector_compare(); 344 bool inline_vector_broadcast_int(); 345 bool inline_vector_cast_reinterpret(bool is_cast); 346 bool inline_vector_extract(); 347 bool inline_vector_insert(); 348 Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType bt, int num_elem); 349 Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType bt, int num_elem); 350 Node* shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem); 351 Node* gen_call_to_svml(int vector_api_op_id, BasicType bt, int num_elem, Node* opd1, Node* opd2); 352 void set_vector_result(Node* result, bool set_res = true); 353 354 void clear_upper_avx() { 355 #ifdef X86 356 if (UseAVX >= 2) { 357 C->set_clear_upper_avx(true); 358 } 359 #endif 360 } 361 }; 362 363 //---------------------------make_vm_intrinsic---------------------------- 364 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 365 vmIntrinsics::ID id = m->intrinsic_id(); 366 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 367 368 if (!m->is_loaded()) { 369 // Do not attempt to inline unloaded methods. 370 return NULL; 371 } 372 373 C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization); 374 bool is_available = false; 375 376 { 377 // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag 378 // the compiler must transition to '_thread_in_vm' state because both 379 // methods access VM-internal data. 380 VM_ENTRY_MARK; 381 methodHandle mh(THREAD, m->get_Method()); 382 is_available = compiler != NULL && compiler->is_intrinsic_supported(mh, is_virtual) && 383 !C->directive()->is_intrinsic_disabled(mh) && 384 !vmIntrinsics::is_disabled_by_flags(mh); 385 386 } 387 388 if (is_available) { 389 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility"); 390 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?"); 391 return new LibraryIntrinsic(m, is_virtual, 392 vmIntrinsics::predicates_needed(id), 393 vmIntrinsics::does_virtual_dispatch(id), 394 (vmIntrinsics::ID) id); 395 } else { 396 return NULL; 397 } 398 } 399 400 //----------------------register_library_intrinsics----------------------- 401 // Initialize this file's data structures, for each Compile instance. 402 void Compile::register_library_intrinsics() { 403 // Nothing to do here. 404 } 405 406 JVMState* LibraryIntrinsic::generate(JVMState* jvms) { 407 LibraryCallKit kit(jvms, this); 408 Compile* C = kit.C; 409 int nodes = C->unique(); 410 #ifndef PRODUCT 411 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 412 char buf[1000]; 413 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 414 tty->print_cr("Intrinsic %s", str); 415 } 416 #endif 417 ciMethod* callee = kit.callee(); 418 const int bci = kit.bci(); 419 420 // Try to inline the intrinsic. 421 if ((CheckIntrinsics ? callee->intrinsic_candidate() : true) && 422 kit.try_to_inline(_last_predicate)) { 423 const char *inline_msg = is_virtual() ? "(intrinsic, virtual)" 424 : "(intrinsic)"; 425 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg); 426 if (C->print_intrinsics() || C->print_inlining()) { 427 C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg); 428 } 429 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 430 if (C->log()) { 431 C->log()->elem("intrinsic id='%s'%s nodes='%d'", 432 vmIntrinsics::name_at(intrinsic_id()), 433 (is_virtual() ? " virtual='1'" : ""), 434 C->unique() - nodes); 435 } 436 // Push the result from the inlined method onto the stack. 437 kit.push_result(); 438 C->print_inlining_update(this); 439 return kit.transfer_exceptions_into_jvms(); 440 } 441 442 // The intrinsic bailed out 443 if (jvms->has_method()) { 444 // Not a root compile. 445 const char* msg; 446 if (callee->intrinsic_candidate()) { 447 msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)"; 448 } else { 449 msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated" 450 : "failed to inline (intrinsic), method not annotated"; 451 } 452 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, msg); 453 if (C->print_intrinsics() || C->print_inlining()) { 454 C->print_inlining(callee, jvms->depth() - 1, bci, msg); 455 } 456 } else { 457 // Root compile 458 ResourceMark rm; 459 stringStream msg_stream; 460 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 461 vmIntrinsics::name_at(intrinsic_id()), 462 is_virtual() ? " (virtual)" : "", bci); 463 const char *msg = msg_stream.as_string(); 464 log_debug(jit, inlining)("%s", msg); 465 if (C->print_intrinsics() || C->print_inlining()) { 466 tty->print("%s", msg); 467 } 468 } 469 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 470 C->print_inlining_update(this); 471 return NULL; 472 } 473 474 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) { 475 LibraryCallKit kit(jvms, this); 476 Compile* C = kit.C; 477 int nodes = C->unique(); 478 _last_predicate = predicate; 479 #ifndef PRODUCT 480 assert(is_predicated() && predicate < predicates_count(), "sanity"); 481 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 482 char buf[1000]; 483 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 484 tty->print_cr("Predicate for intrinsic %s", str); 485 } 486 #endif 487 ciMethod* callee = kit.callee(); 488 const int bci = kit.bci(); 489 490 Node* slow_ctl = kit.try_to_predicate(predicate); 491 if (!kit.failing()) { 492 const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)" 493 : "(intrinsic, predicate)"; 494 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg); 495 if (C->print_intrinsics() || C->print_inlining()) { 496 C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg); 497 } 498 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 499 if (C->log()) { 500 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 501 vmIntrinsics::name_at(intrinsic_id()), 502 (is_virtual() ? " virtual='1'" : ""), 503 C->unique() - nodes); 504 } 505 return slow_ctl; // Could be NULL if the check folds. 506 } 507 508 // The intrinsic bailed out 509 if (jvms->has_method()) { 510 // Not a root compile. 511 const char* msg = "failed to generate predicate for intrinsic"; 512 CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, msg); 513 if (C->print_intrinsics() || C->print_inlining()) { 514 C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg); 515 } 516 } else { 517 // Root compile 518 ResourceMark rm; 519 stringStream msg_stream; 520 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in", 521 vmIntrinsics::name_at(intrinsic_id()), 522 is_virtual() ? " (virtual)" : "", bci); 523 const char *msg = msg_stream.as_string(); 524 log_debug(jit, inlining)("%s", msg); 525 if (C->print_intrinsics() || C->print_inlining()) { 526 C->print_inlining_stream()->print("%s", msg); 527 } 528 } 529 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 530 return NULL; 531 } 532 533 bool LibraryCallKit::try_to_inline(int predicate) { 534 // Handle symbolic names for otherwise undistinguished boolean switches: 535 const bool is_store = true; 536 const bool is_compress = true; 537 const bool is_static = true; 538 const bool is_volatile = true; 539 540 if (!jvms()->has_method()) { 541 // Root JVMState has a null method. 542 assert(map()->memory()->Opcode() == Op_Parm, ""); 543 // Insert the memory aliasing node 544 set_all_memory(reset_memory()); 545 } 546 assert(merged_memory(), ""); 547 548 switch (intrinsic_id()) { 549 case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 550 case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static); 551 case vmIntrinsics::_getClass: return inline_native_getClass(); 552 553 case vmIntrinsics::_dsin: 554 case vmIntrinsics::_dcos: 555 case vmIntrinsics::_dtan: 556 case vmIntrinsics::_dabs: 557 case vmIntrinsics::_datan2: 558 case vmIntrinsics::_dsqrt: 559 case vmIntrinsics::_dexp: 560 case vmIntrinsics::_dlog: 561 case vmIntrinsics::_dlog10: 562 case vmIntrinsics::_dpow: return inline_math_native(intrinsic_id()); 563 564 case vmIntrinsics::_min: 565 case vmIntrinsics::_max: return inline_min_max(intrinsic_id()); 566 567 case vmIntrinsics::_notify: 568 case vmIntrinsics::_notifyAll: 569 return inline_notify(intrinsic_id()); 570 571 case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 572 case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 573 case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 574 case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 575 case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 576 case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 577 case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 578 case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 579 case vmIntrinsics::_multiplyHigh: return inline_math_multiplyHigh(); 580 case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 581 case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 582 case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 583 case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 584 585 case vmIntrinsics::_arraycopy: return inline_arraycopy(); 586 587 case vmIntrinsics::_compareToL: return inline_string_compareTo(StrIntrinsicNode::LL); 588 case vmIntrinsics::_compareToU: return inline_string_compareTo(StrIntrinsicNode::UU); 589 case vmIntrinsics::_compareToLU: return inline_string_compareTo(StrIntrinsicNode::LU); 590 case vmIntrinsics::_compareToUL: return inline_string_compareTo(StrIntrinsicNode::UL); 591 592 case vmIntrinsics::_indexOfL: return inline_string_indexOf(StrIntrinsicNode::LL); 593 case vmIntrinsics::_indexOfU: return inline_string_indexOf(StrIntrinsicNode::UU); 594 case vmIntrinsics::_indexOfUL: return inline_string_indexOf(StrIntrinsicNode::UL); 595 case vmIntrinsics::_indexOfIL: return inline_string_indexOfI(StrIntrinsicNode::LL); 596 case vmIntrinsics::_indexOfIU: return inline_string_indexOfI(StrIntrinsicNode::UU); 597 case vmIntrinsics::_indexOfIUL: return inline_string_indexOfI(StrIntrinsicNode::UL); 598 case vmIntrinsics::_indexOfU_char: return inline_string_indexOfChar(); 599 600 case vmIntrinsics::_equalsL: return inline_string_equals(StrIntrinsicNode::LL); 601 case vmIntrinsics::_equalsU: return inline_string_equals(StrIntrinsicNode::UU); 602 603 case vmIntrinsics::_toBytesStringU: return inline_string_toBytesU(); 604 case vmIntrinsics::_getCharsStringU: return inline_string_getCharsU(); 605 case vmIntrinsics::_getCharStringU: return inline_string_char_access(!is_store); 606 case vmIntrinsics::_putCharStringU: return inline_string_char_access( is_store); 607 608 case vmIntrinsics::_compressStringC: 609 case vmIntrinsics::_compressStringB: return inline_string_copy( is_compress); 610 case vmIntrinsics::_inflateStringC: 611 case vmIntrinsics::_inflateStringB: return inline_string_copy(!is_compress); 612 613 case vmIntrinsics::_getReference: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false); 614 case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_store, T_BOOLEAN, Relaxed, false); 615 case vmIntrinsics::_getByte: return inline_unsafe_access(!is_store, T_BYTE, Relaxed, false); 616 case vmIntrinsics::_getShort: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, false); 617 case vmIntrinsics::_getChar: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, false); 618 case vmIntrinsics::_getInt: return inline_unsafe_access(!is_store, T_INT, Relaxed, false); 619 case vmIntrinsics::_getLong: return inline_unsafe_access(!is_store, T_LONG, Relaxed, false); 620 case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_store, T_FLOAT, Relaxed, false); 621 case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_store, T_DOUBLE, Relaxed, false); 622 623 case vmIntrinsics::_putReference: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false); 624 case vmIntrinsics::_putBoolean: return inline_unsafe_access( is_store, T_BOOLEAN, Relaxed, false); 625 case vmIntrinsics::_putByte: return inline_unsafe_access( is_store, T_BYTE, Relaxed, false); 626 case vmIntrinsics::_putShort: return inline_unsafe_access( is_store, T_SHORT, Relaxed, false); 627 case vmIntrinsics::_putChar: return inline_unsafe_access( is_store, T_CHAR, Relaxed, false); 628 case vmIntrinsics::_putInt: return inline_unsafe_access( is_store, T_INT, Relaxed, false); 629 case vmIntrinsics::_putLong: return inline_unsafe_access( is_store, T_LONG, Relaxed, false); 630 case vmIntrinsics::_putFloat: return inline_unsafe_access( is_store, T_FLOAT, Relaxed, false); 631 case vmIntrinsics::_putDouble: return inline_unsafe_access( is_store, T_DOUBLE, Relaxed, false); 632 633 case vmIntrinsics::_getReferenceVolatile: return inline_unsafe_access(!is_store, T_OBJECT, Volatile, false); 634 case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_store, T_BOOLEAN, Volatile, false); 635 case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_store, T_BYTE, Volatile, false); 636 case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_store, T_SHORT, Volatile, false); 637 case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_store, T_CHAR, Volatile, false); 638 case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_store, T_INT, Volatile, false); 639 case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_store, T_LONG, Volatile, false); 640 case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_store, T_FLOAT, Volatile, false); 641 case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_store, T_DOUBLE, Volatile, false); 642 643 case vmIntrinsics::_putReferenceVolatile: return inline_unsafe_access( is_store, T_OBJECT, Volatile, false); 644 case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access( is_store, T_BOOLEAN, Volatile, false); 645 case vmIntrinsics::_putByteVolatile: return inline_unsafe_access( is_store, T_BYTE, Volatile, false); 646 case vmIntrinsics::_putShortVolatile: return inline_unsafe_access( is_store, T_SHORT, Volatile, false); 647 case vmIntrinsics::_putCharVolatile: return inline_unsafe_access( is_store, T_CHAR, Volatile, false); 648 case vmIntrinsics::_putIntVolatile: return inline_unsafe_access( is_store, T_INT, Volatile, false); 649 case vmIntrinsics::_putLongVolatile: return inline_unsafe_access( is_store, T_LONG, Volatile, false); 650 case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access( is_store, T_FLOAT, Volatile, false); 651 case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access( is_store, T_DOUBLE, Volatile, false); 652 653 case vmIntrinsics::_getShortUnaligned: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, true); 654 case vmIntrinsics::_getCharUnaligned: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, true); 655 case vmIntrinsics::_getIntUnaligned: return inline_unsafe_access(!is_store, T_INT, Relaxed, true); 656 case vmIntrinsics::_getLongUnaligned: return inline_unsafe_access(!is_store, T_LONG, Relaxed, true); 657 658 case vmIntrinsics::_putShortUnaligned: return inline_unsafe_access( is_store, T_SHORT, Relaxed, true); 659 case vmIntrinsics::_putCharUnaligned: return inline_unsafe_access( is_store, T_CHAR, Relaxed, true); 660 case vmIntrinsics::_putIntUnaligned: return inline_unsafe_access( is_store, T_INT, Relaxed, true); 661 case vmIntrinsics::_putLongUnaligned: return inline_unsafe_access( is_store, T_LONG, Relaxed, true); 662 663 case vmIntrinsics::_getReferenceAcquire: return inline_unsafe_access(!is_store, T_OBJECT, Acquire, false); 664 case vmIntrinsics::_getBooleanAcquire: return inline_unsafe_access(!is_store, T_BOOLEAN, Acquire, false); 665 case vmIntrinsics::_getByteAcquire: return inline_unsafe_access(!is_store, T_BYTE, Acquire, false); 666 case vmIntrinsics::_getShortAcquire: return inline_unsafe_access(!is_store, T_SHORT, Acquire, false); 667 case vmIntrinsics::_getCharAcquire: return inline_unsafe_access(!is_store, T_CHAR, Acquire, false); 668 case vmIntrinsics::_getIntAcquire: return inline_unsafe_access(!is_store, T_INT, Acquire, false); 669 case vmIntrinsics::_getLongAcquire: return inline_unsafe_access(!is_store, T_LONG, Acquire, false); 670 case vmIntrinsics::_getFloatAcquire: return inline_unsafe_access(!is_store, T_FLOAT, Acquire, false); 671 case vmIntrinsics::_getDoubleAcquire: return inline_unsafe_access(!is_store, T_DOUBLE, Acquire, false); 672 673 case vmIntrinsics::_putReferenceRelease: return inline_unsafe_access( is_store, T_OBJECT, Release, false); 674 case vmIntrinsics::_putBooleanRelease: return inline_unsafe_access( is_store, T_BOOLEAN, Release, false); 675 case vmIntrinsics::_putByteRelease: return inline_unsafe_access( is_store, T_BYTE, Release, false); 676 case vmIntrinsics::_putShortRelease: return inline_unsafe_access( is_store, T_SHORT, Release, false); 677 case vmIntrinsics::_putCharRelease: return inline_unsafe_access( is_store, T_CHAR, Release, false); 678 case vmIntrinsics::_putIntRelease: return inline_unsafe_access( is_store, T_INT, Release, false); 679 case vmIntrinsics::_putLongRelease: return inline_unsafe_access( is_store, T_LONG, Release, false); 680 case vmIntrinsics::_putFloatRelease: return inline_unsafe_access( is_store, T_FLOAT, Release, false); 681 case vmIntrinsics::_putDoubleRelease: return inline_unsafe_access( is_store, T_DOUBLE, Release, false); 682 683 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false); 684 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false); 685 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false); 686 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false); 687 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false); 688 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false); 689 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false); 690 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false); 691 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false); 692 693 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false); 694 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false); 695 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false); 696 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false); 697 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false); 698 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false); 699 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false); 700 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false); 701 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false); 702 703 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile); 704 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile); 705 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile); 706 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile); 707 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile); 708 709 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed); 710 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire); 711 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release); 712 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile); 713 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed); 714 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire); 715 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release); 716 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile); 717 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed); 718 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire); 719 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release); 720 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile); 721 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed); 722 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire); 723 case vmIntrinsics::_weakCompareAndSetIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Release); 724 case vmIntrinsics::_weakCompareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Volatile); 725 case vmIntrinsics::_weakCompareAndSetLongPlain: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Relaxed); 726 case vmIntrinsics::_weakCompareAndSetLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Acquire); 727 case vmIntrinsics::_weakCompareAndSetLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Release); 728 case vmIntrinsics::_weakCompareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Volatile); 729 730 case vmIntrinsics::_compareAndExchangeReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Volatile); 731 case vmIntrinsics::_compareAndExchangeReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Acquire); 732 case vmIntrinsics::_compareAndExchangeReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Release); 733 case vmIntrinsics::_compareAndExchangeByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Volatile); 734 case vmIntrinsics::_compareAndExchangeByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Acquire); 735 case vmIntrinsics::_compareAndExchangeByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Release); 736 case vmIntrinsics::_compareAndExchangeShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Volatile); 737 case vmIntrinsics::_compareAndExchangeShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Acquire); 738 case vmIntrinsics::_compareAndExchangeShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Release); 739 case vmIntrinsics::_compareAndExchangeInt: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Volatile); 740 case vmIntrinsics::_compareAndExchangeIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Acquire); 741 case vmIntrinsics::_compareAndExchangeIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Release); 742 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile); 743 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire); 744 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release); 745 746 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile); 747 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile); 748 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile); 749 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile); 750 751 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile); 752 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile); 753 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile); 754 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile); 755 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile); 756 757 case vmIntrinsics::_loadFence: 758 case vmIntrinsics::_storeFence: 759 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id()); 760 761 case vmIntrinsics::_onSpinWait: return inline_onspinwait(); 762 763 case vmIntrinsics::_currentThread: return inline_native_currentThread(); 764 case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted(); 765 766 #ifdef JFR_HAVE_INTRINSICS 767 case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), "counterTime"); 768 case vmIntrinsics::_getClassId: return inline_native_classID(); 769 case vmIntrinsics::_getEventWriter: return inline_native_getEventWriter(); 770 #endif 771 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis"); 772 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime"); 773 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate(); 774 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory(); 775 case vmIntrinsics::_getLength: return inline_native_getLength(); 776 case vmIntrinsics::_copyOf: return inline_array_copyOf(false); 777 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true); 778 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL); 779 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU); 780 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex(); 781 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual()); 782 783 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true); 784 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false); 785 786 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check(); 787 788 case vmIntrinsics::_isInstance: 789 case vmIntrinsics::_getModifiers: 790 case vmIntrinsics::_isInterface: 791 case vmIntrinsics::_isArray: 792 case vmIntrinsics::_isPrimitive: 793 case vmIntrinsics::_getSuperclass: 794 case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id()); 795 796 case vmIntrinsics::_floatToRawIntBits: 797 case vmIntrinsics::_floatToIntBits: 798 case vmIntrinsics::_intBitsToFloat: 799 case vmIntrinsics::_doubleToRawLongBits: 800 case vmIntrinsics::_doubleToLongBits: 801 case vmIntrinsics::_longBitsToDouble: return inline_fp_conversions(intrinsic_id()); 802 803 case vmIntrinsics::_numberOfLeadingZeros_i: 804 case vmIntrinsics::_numberOfLeadingZeros_l: 805 case vmIntrinsics::_numberOfTrailingZeros_i: 806 case vmIntrinsics::_numberOfTrailingZeros_l: 807 case vmIntrinsics::_bitCount_i: 808 case vmIntrinsics::_bitCount_l: 809 case vmIntrinsics::_reverseBytes_i: 810 case vmIntrinsics::_reverseBytes_l: 811 case vmIntrinsics::_reverseBytes_s: 812 case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id()); 813 814 case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass(); 815 816 case vmIntrinsics::_Reference_get: return inline_reference_get(); 817 818 case vmIntrinsics::_Class_cast: return inline_Class_cast(); 819 820 case vmIntrinsics::_aescrypt_encryptBlock: 821 case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id()); 822 823 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 824 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 825 return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 826 827 case vmIntrinsics::_counterMode_AESCrypt: 828 return inline_counterMode_AESCrypt(intrinsic_id()); 829 830 case vmIntrinsics::_sha_implCompress: 831 case vmIntrinsics::_sha2_implCompress: 832 case vmIntrinsics::_sha5_implCompress: 833 return inline_sha_implCompress(intrinsic_id()); 834 835 case vmIntrinsics::_digestBase_implCompressMB: 836 return inline_digestBase_implCompressMB(predicate); 837 838 case vmIntrinsics::_multiplyToLen: 839 return inline_multiplyToLen(); 840 841 case vmIntrinsics::_squareToLen: 842 return inline_squareToLen(); 843 844 case vmIntrinsics::_mulAdd: 845 return inline_mulAdd(); 846 847 case vmIntrinsics::_montgomeryMultiply: 848 return inline_montgomeryMultiply(); 849 case vmIntrinsics::_montgomerySquare: 850 return inline_montgomerySquare(); 851 852 case vmIntrinsics::_vectorizedMismatch: 853 return inline_vectorizedMismatch(); 854 855 case vmIntrinsics::_ghash_processBlocks: 856 return inline_ghash_processBlocks(); 857 case vmIntrinsics::_base64_encodeBlock: 858 return inline_base64_encodeBlock(); 859 860 case vmIntrinsics::_encodeISOArray: 861 case vmIntrinsics::_encodeByteISOArray: 862 return inline_encodeISOArray(); 863 864 case vmIntrinsics::_updateCRC32: 865 return inline_updateCRC32(); 866 case vmIntrinsics::_updateBytesCRC32: 867 return inline_updateBytesCRC32(); 868 case vmIntrinsics::_updateByteBufferCRC32: 869 return inline_updateByteBufferCRC32(); 870 871 case vmIntrinsics::_updateBytesCRC32C: 872 return inline_updateBytesCRC32C(); 873 case vmIntrinsics::_updateDirectByteBufferCRC32C: 874 return inline_updateDirectByteBufferCRC32C(); 875 876 case vmIntrinsics::_updateBytesAdler32: 877 return inline_updateBytesAdler32(); 878 case vmIntrinsics::_updateByteBufferAdler32: 879 return inline_updateByteBufferAdler32(); 880 881 case vmIntrinsics::_profileBoolean: 882 return inline_profileBoolean(); 883 case vmIntrinsics::_isCompileConstant: 884 return inline_isCompileConstant(); 885 886 case vmIntrinsics::_hasNegatives: 887 return inline_hasNegatives(); 888 889 case vmIntrinsics::_fmaD: 890 case vmIntrinsics::_fmaF: 891 return inline_fma(intrinsic_id()); 892 893 case vmIntrinsics::_isDigit: 894 case vmIntrinsics::_isLowerCase: 895 case vmIntrinsics::_isUpperCase: 896 case vmIntrinsics::_isWhitespace: 897 return inline_character_compare(intrinsic_id()); 898 899 case vmIntrinsics::_maxF: 900 case vmIntrinsics::_minF: 901 case vmIntrinsics::_maxD: 902 case vmIntrinsics::_minD: 903 return inline_fp_min_max(intrinsic_id()); 904 905 case vmIntrinsics::_VectorUnaryOp: 906 return inline_vector_nary_operation(1); 907 case vmIntrinsics::_VectorBinaryOp: 908 return inline_vector_nary_operation(2); 909 case vmIntrinsics::_VectorTernaryOp: 910 return inline_vector_nary_operation(3); 911 case vmIntrinsics::_VectorBroadcastCoerced: 912 return inline_vector_broadcast_coerced(); 913 case vmIntrinsics::_VectorLoadOp: 914 return inline_vector_mem_operation(/*is_store=*/false); 915 case vmIntrinsics::_VectorStoreOp: 916 return inline_vector_mem_operation(/*is_store=*/true); 917 case vmIntrinsics::_VectorGatherOp: 918 return inline_vector_gather_scatter(/*is_scatter*/ false); 919 case vmIntrinsics::_VectorScatterOp: 920 return inline_vector_gather_scatter(/*is_scatter*/ true); 921 case vmIntrinsics::_VectorReductionCoerced: 922 return inline_vector_reduction(); 923 case vmIntrinsics::_VectorTest: 924 return inline_vector_test(); 925 case vmIntrinsics::_VectorBlend: 926 return inline_vector_blend(); 927 case vmIntrinsics::_VectorRearrange: 928 return inline_vector_rearrange(); 929 case vmIntrinsics::_VectorCompare: 930 return inline_vector_compare(); 931 case vmIntrinsics::_VectorBroadcastInt: 932 return inline_vector_broadcast_int(); 933 case vmIntrinsics::_VectorReinterpret: 934 return inline_vector_cast_reinterpret(/*is_cast*/ false); 935 case vmIntrinsics::_VectorCast: 936 return inline_vector_cast_reinterpret(/*is_cast*/ true); 937 case vmIntrinsics::_VectorInsert: 938 return inline_vector_insert(); 939 case vmIntrinsics::_VectorExtract: 940 return inline_vector_extract(); 941 942 default: 943 // If you get here, it may be that someone has added a new intrinsic 944 // to the list in vmSymbols.hpp without implementing it here. 945 #ifndef PRODUCT 946 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 947 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 948 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 949 } 950 #endif 951 return false; 952 } 953 } 954 955 Node* LibraryCallKit::try_to_predicate(int predicate) { 956 if (!jvms()->has_method()) { 957 // Root JVMState has a null method. 958 assert(map()->memory()->Opcode() == Op_Parm, ""); 959 // Insert the memory aliasing node 960 set_all_memory(reset_memory()); 961 } 962 assert(merged_memory(), ""); 963 964 switch (intrinsic_id()) { 965 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 966 return inline_cipherBlockChaining_AESCrypt_predicate(false); 967 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 968 return inline_cipherBlockChaining_AESCrypt_predicate(true); 969 case vmIntrinsics::_counterMode_AESCrypt: 970 return inline_counterMode_AESCrypt_predicate(); 971 case vmIntrinsics::_digestBase_implCompressMB: 972 return inline_digestBase_implCompressMB_predicate(predicate); 973 974 default: 975 // If you get here, it may be that someone has added a new intrinsic 976 // to the list in vmSymbols.hpp without implementing it here. 977 #ifndef PRODUCT 978 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 979 tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)", 980 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 981 } 982 #endif 983 Node* slow_ctl = control(); 984 set_control(top()); // No fast path instrinsic 985 return slow_ctl; 986 } 987 } 988 989 //------------------------------set_result------------------------------- 990 // Helper function for finishing intrinsics. 991 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) { 992 record_for_igvn(region); 993 set_control(_gvn.transform(region)); 994 set_result( _gvn.transform(value)); 995 assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity"); 996 } 997 998 //------------------------------generate_guard--------------------------- 999 // Helper function for generating guarded fast-slow graph structures. 1000 // The given 'test', if true, guards a slow path. If the test fails 1001 // then a fast path can be taken. (We generally hope it fails.) 1002 // In all cases, GraphKit::control() is updated to the fast path. 1003 // The returned value represents the control for the slow path. 1004 // The return value is never 'top'; it is either a valid control 1005 // or NULL if it is obvious that the slow path can never be taken. 1006 // Also, if region and the slow control are not NULL, the slow edge 1007 // is appended to the region. 1008 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 1009 if (stopped()) { 1010 // Already short circuited. 1011 return NULL; 1012 } 1013 1014 // Build an if node and its projections. 1015 // If test is true we take the slow path, which we assume is uncommon. 1016 if (_gvn.type(test) == TypeInt::ZERO) { 1017 // The slow branch is never taken. No need to build this guard. 1018 return NULL; 1019 } 1020 1021 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 1022 1023 Node* if_slow = _gvn.transform(new IfTrueNode(iff)); 1024 if (if_slow == top()) { 1025 // The slow branch is never taken. No need to build this guard. 1026 return NULL; 1027 } 1028 1029 if (region != NULL) 1030 region->add_req(if_slow); 1031 1032 Node* if_fast = _gvn.transform(new IfFalseNode(iff)); 1033 set_control(if_fast); 1034 1035 return if_slow; 1036 } 1037 1038 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 1039 return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 1040 } 1041 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 1042 return generate_guard(test, region, PROB_FAIR); 1043 } 1044 1045 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 1046 Node* *pos_index) { 1047 if (stopped()) 1048 return NULL; // already stopped 1049 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 1050 return NULL; // index is already adequately typed 1051 Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0))); 1052 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 1053 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 1054 if (is_neg != NULL && pos_index != NULL) { 1055 // Emulate effect of Parse::adjust_map_after_if. 1056 Node* ccast = new CastIINode(index, TypeInt::POS); 1057 ccast->set_req(0, control()); 1058 (*pos_index) = _gvn.transform(ccast); 1059 } 1060 return is_neg; 1061 } 1062 1063 // Make sure that 'position' is a valid limit index, in [0..length]. 1064 // There are two equivalent plans for checking this: 1065 // A. (offset + copyLength) unsigned<= arrayLength 1066 // B. offset <= (arrayLength - copyLength) 1067 // We require that all of the values above, except for the sum and 1068 // difference, are already known to be non-negative. 1069 // Plan A is robust in the face of overflow, if offset and copyLength 1070 // are both hugely positive. 1071 // 1072 // Plan B is less direct and intuitive, but it does not overflow at 1073 // all, since the difference of two non-negatives is always 1074 // representable. Whenever Java methods must perform the equivalent 1075 // check they generally use Plan B instead of Plan A. 1076 // For the moment we use Plan A. 1077 inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 1078 Node* subseq_length, 1079 Node* array_length, 1080 RegionNode* region) { 1081 if (stopped()) 1082 return NULL; // already stopped 1083 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 1084 if (zero_offset && subseq_length->eqv_uncast(array_length)) 1085 return NULL; // common case of whole-array copy 1086 Node* last = subseq_length; 1087 if (!zero_offset) // last += offset 1088 last = _gvn.transform(new AddINode(last, offset)); 1089 Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last)); 1090 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt)); 1091 Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 1092 return is_over; 1093 } 1094 1095 // Emit range checks for the given String.value byte array 1096 void LibraryCallKit::generate_string_range_check(Node* array, Node* offset, Node* count, bool char_count) { 1097 if (stopped()) { 1098 return; // already stopped 1099 } 1100 RegionNode* bailout = new RegionNode(1); 1101 record_for_igvn(bailout); 1102 if (char_count) { 1103 // Convert char count to byte count 1104 count = _gvn.transform(new LShiftINode(count, intcon(1))); 1105 } 1106 1107 // Offset and count must not be negative 1108 generate_negative_guard(offset, bailout); 1109 generate_negative_guard(count, bailout); 1110 // Offset + count must not exceed length of array 1111 generate_limit_guard(offset, count, load_array_length(array), bailout); 1112 1113 if (bailout->req() > 1) { 1114 PreserveJVMState pjvms(this); 1115 set_control(_gvn.transform(bailout)); 1116 uncommon_trap(Deoptimization::Reason_intrinsic, 1117 Deoptimization::Action_maybe_recompile); 1118 } 1119 } 1120 1121 //--------------------------generate_current_thread-------------------- 1122 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1123 ciKlass* thread_klass = env()->Thread_klass(); 1124 const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 1125 Node* thread = _gvn.transform(new ThreadLocalNode()); 1126 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset())); 1127 Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT, MemNode::unordered); 1128 tls_output = thread; 1129 return threadObj; 1130 } 1131 1132 1133 //------------------------------make_string_method_node------------------------ 1134 // Helper method for String intrinsic functions. This version is called with 1135 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded 1136 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes 1137 // containing the lengths of str1 and str2. 1138 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) { 1139 Node* result = NULL; 1140 switch (opcode) { 1141 case Op_StrIndexOf: 1142 result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES), 1143 str1_start, cnt1, str2_start, cnt2, ae); 1144 break; 1145 case Op_StrComp: 1146 result = new StrCompNode(control(), memory(TypeAryPtr::BYTES), 1147 str1_start, cnt1, str2_start, cnt2, ae); 1148 break; 1149 case Op_StrEquals: 1150 // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals'). 1151 // Use the constant length if there is one because optimized match rule may exist. 1152 result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES), 1153 str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae); 1154 break; 1155 default: 1156 ShouldNotReachHere(); 1157 return NULL; 1158 } 1159 1160 // All these intrinsics have checks. 1161 C->set_has_split_ifs(true); // Has chance for split-if optimization 1162 clear_upper_avx(); 1163 1164 return _gvn.transform(result); 1165 } 1166 1167 //------------------------------inline_string_compareTo------------------------ 1168 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) { 1169 Node* arg1 = argument(0); 1170 Node* arg2 = argument(1); 1171 1172 arg1 = must_be_not_null(arg1, true); 1173 arg2 = must_be_not_null(arg2, true); 1174 1175 arg1 = access_resolve(arg1, ACCESS_READ); 1176 arg2 = access_resolve(arg2, ACCESS_READ); 1177 1178 // Get start addr and length of first argument 1179 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1180 Node* arg1_cnt = load_array_length(arg1); 1181 1182 // Get start addr and length of second argument 1183 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1184 Node* arg2_cnt = load_array_length(arg2); 1185 1186 Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1187 set_result(result); 1188 return true; 1189 } 1190 1191 //------------------------------inline_string_equals------------------------ 1192 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) { 1193 Node* arg1 = argument(0); 1194 Node* arg2 = argument(1); 1195 1196 // paths (plus control) merge 1197 RegionNode* region = new RegionNode(3); 1198 Node* phi = new PhiNode(region, TypeInt::BOOL); 1199 1200 if (!stopped()) { 1201 1202 arg1 = must_be_not_null(arg1, true); 1203 arg2 = must_be_not_null(arg2, true); 1204 1205 arg1 = access_resolve(arg1, ACCESS_READ); 1206 arg2 = access_resolve(arg2, ACCESS_READ); 1207 1208 // Get start addr and length of first argument 1209 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE); 1210 Node* arg1_cnt = load_array_length(arg1); 1211 1212 // Get start addr and length of second argument 1213 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE); 1214 Node* arg2_cnt = load_array_length(arg2); 1215 1216 // Check for arg1_cnt != arg2_cnt 1217 Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt)); 1218 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 1219 Node* if_ne = generate_slow_guard(bol, NULL); 1220 if (if_ne != NULL) { 1221 phi->init_req(2, intcon(0)); 1222 region->init_req(2, if_ne); 1223 } 1224 1225 // Check for count == 0 is done by assembler code for StrEquals. 1226 1227 if (!stopped()) { 1228 Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae); 1229 phi->init_req(1, equals); 1230 region->init_req(1, control()); 1231 } 1232 } 1233 1234 // post merge 1235 set_control(_gvn.transform(region)); 1236 record_for_igvn(region); 1237 1238 set_result(_gvn.transform(phi)); 1239 return true; 1240 } 1241 1242 //------------------------------inline_array_equals---------------------------- 1243 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) { 1244 assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types"); 1245 Node* arg1 = argument(0); 1246 Node* arg2 = argument(1); 1247 1248 arg1 = access_resolve(arg1, ACCESS_READ); 1249 arg2 = access_resolve(arg2, ACCESS_READ); 1250 1251 const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES; 1252 set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae))); 1253 clear_upper_avx(); 1254 1255 return true; 1256 } 1257 1258 //------------------------------inline_hasNegatives------------------------------ 1259 bool LibraryCallKit::inline_hasNegatives() { 1260 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1261 return false; 1262 } 1263 1264 assert(callee()->signature()->size() == 3, "hasNegatives has 3 parameters"); 1265 // no receiver since it is static method 1266 Node* ba = argument(0); 1267 Node* offset = argument(1); 1268 Node* len = argument(2); 1269 1270 ba = must_be_not_null(ba, true); 1271 1272 // Range checks 1273 generate_string_range_check(ba, offset, len, false); 1274 if (stopped()) { 1275 return true; 1276 } 1277 ba = access_resolve(ba, ACCESS_READ); 1278 Node* ba_start = array_element_address(ba, offset, T_BYTE); 1279 Node* result = new HasNegativesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len); 1280 set_result(_gvn.transform(result)); 1281 return true; 1282 } 1283 1284 bool LibraryCallKit::inline_preconditions_checkIndex() { 1285 Node* index = argument(0); 1286 Node* length = argument(1); 1287 if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) { 1288 return false; 1289 } 1290 1291 Node* len_pos_cmp = _gvn.transform(new CmpINode(length, intcon(0))); 1292 Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge)); 1293 1294 { 1295 BuildCutout unless(this, len_pos_bol, PROB_MAX); 1296 uncommon_trap(Deoptimization::Reason_intrinsic, 1297 Deoptimization::Action_make_not_entrant); 1298 } 1299 1300 if (stopped()) { 1301 return false; 1302 } 1303 1304 Node* rc_cmp = _gvn.transform(new CmpUNode(index, length)); 1305 BoolTest::mask btest = BoolTest::lt; 1306 Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest)); 1307 RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN); 1308 _gvn.set_type(rc, rc->Value(&_gvn)); 1309 if (!rc_bool->is_Con()) { 1310 record_for_igvn(rc); 1311 } 1312 set_control(_gvn.transform(new IfTrueNode(rc))); 1313 { 1314 PreserveJVMState pjvms(this); 1315 set_control(_gvn.transform(new IfFalseNode(rc))); 1316 uncommon_trap(Deoptimization::Reason_range_check, 1317 Deoptimization::Action_make_not_entrant); 1318 } 1319 1320 if (stopped()) { 1321 return false; 1322 } 1323 1324 Node* result = new CastIINode(index, TypeInt::make(0, _gvn.type(length)->is_int()->_hi, Type::WidenMax)); 1325 result->set_req(0, control()); 1326 result = _gvn.transform(result); 1327 set_result(result); 1328 replace_in_map(index, result); 1329 clear_upper_avx(); 1330 return true; 1331 } 1332 1333 //------------------------------inline_string_indexOf------------------------ 1334 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) { 1335 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1336 return false; 1337 } 1338 Node* src = argument(0); 1339 Node* tgt = argument(1); 1340 1341 // Make the merge point 1342 RegionNode* result_rgn = new RegionNode(4); 1343 Node* result_phi = new PhiNode(result_rgn, TypeInt::INT); 1344 1345 src = must_be_not_null(src, true); 1346 tgt = must_be_not_null(tgt, true); 1347 1348 src = access_resolve(src, ACCESS_READ); 1349 tgt = access_resolve(tgt, ACCESS_READ); 1350 1351 // Get start addr and length of source string 1352 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 1353 Node* src_count = load_array_length(src); 1354 1355 // Get start addr and length of substring 1356 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1357 Node* tgt_count = load_array_length(tgt); 1358 1359 if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) { 1360 // Divide src size by 2 if String is UTF16 encoded 1361 src_count = _gvn.transform(new RShiftINode(src_count, intcon(1))); 1362 } 1363 if (ae == StrIntrinsicNode::UU) { 1364 // Divide substring size by 2 if String is UTF16 encoded 1365 tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1))); 1366 } 1367 1368 Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, result_rgn, result_phi, ae); 1369 if (result != NULL) { 1370 result_phi->init_req(3, result); 1371 result_rgn->init_req(3, control()); 1372 } 1373 set_control(_gvn.transform(result_rgn)); 1374 record_for_igvn(result_rgn); 1375 set_result(_gvn.transform(result_phi)); 1376 1377 return true; 1378 } 1379 1380 //-----------------------------inline_string_indexOf----------------------- 1381 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) { 1382 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1383 return false; 1384 } 1385 if (!Matcher::match_rule_supported(Op_StrIndexOf)) { 1386 return false; 1387 } 1388 assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments"); 1389 Node* src = argument(0); // byte[] 1390 Node* src_count = argument(1); // char count 1391 Node* tgt = argument(2); // byte[] 1392 Node* tgt_count = argument(3); // char count 1393 Node* from_index = argument(4); // char index 1394 1395 src = must_be_not_null(src, true); 1396 tgt = must_be_not_null(tgt, true); 1397 1398 src = access_resolve(src, ACCESS_READ); 1399 tgt = access_resolve(tgt, ACCESS_READ); 1400 1401 // Multiply byte array index by 2 if String is UTF16 encoded 1402 Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1))); 1403 src_count = _gvn.transform(new SubINode(src_count, from_index)); 1404 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1405 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE); 1406 1407 // Range checks 1408 generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL); 1409 generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU); 1410 if (stopped()) { 1411 return true; 1412 } 1413 1414 RegionNode* region = new RegionNode(5); 1415 Node* phi = new PhiNode(region, TypeInt::INT); 1416 1417 Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, region, phi, ae); 1418 if (result != NULL) { 1419 // The result is index relative to from_index if substring was found, -1 otherwise. 1420 // Generate code which will fold into cmove. 1421 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1422 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1423 1424 Node* if_lt = generate_slow_guard(bol, NULL); 1425 if (if_lt != NULL) { 1426 // result == -1 1427 phi->init_req(3, result); 1428 region->init_req(3, if_lt); 1429 } 1430 if (!stopped()) { 1431 result = _gvn.transform(new AddINode(result, from_index)); 1432 phi->init_req(4, result); 1433 region->init_req(4, control()); 1434 } 1435 } 1436 1437 set_control(_gvn.transform(region)); 1438 record_for_igvn(region); 1439 set_result(_gvn.transform(phi)); 1440 clear_upper_avx(); 1441 1442 return true; 1443 } 1444 1445 // Create StrIndexOfNode with fast path checks 1446 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count, 1447 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) { 1448 // Check for substr count > string count 1449 Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count)); 1450 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt)); 1451 Node* if_gt = generate_slow_guard(bol, NULL); 1452 if (if_gt != NULL) { 1453 phi->init_req(1, intcon(-1)); 1454 region->init_req(1, if_gt); 1455 } 1456 if (!stopped()) { 1457 // Check for substr count == 0 1458 cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0))); 1459 bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 1460 Node* if_zero = generate_slow_guard(bol, NULL); 1461 if (if_zero != NULL) { 1462 phi->init_req(2, intcon(0)); 1463 region->init_req(2, if_zero); 1464 } 1465 } 1466 if (!stopped()) { 1467 return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae); 1468 } 1469 return NULL; 1470 } 1471 1472 //-----------------------------inline_string_indexOfChar----------------------- 1473 bool LibraryCallKit::inline_string_indexOfChar() { 1474 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1475 return false; 1476 } 1477 if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) { 1478 return false; 1479 } 1480 assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments"); 1481 Node* src = argument(0); // byte[] 1482 Node* tgt = argument(1); // tgt is int ch 1483 Node* from_index = argument(2); 1484 Node* max = argument(3); 1485 1486 src = must_be_not_null(src, true); 1487 src = access_resolve(src, ACCESS_READ); 1488 1489 Node* src_offset = _gvn.transform(new LShiftINode(from_index, intcon(1))); 1490 Node* src_start = array_element_address(src, src_offset, T_BYTE); 1491 Node* src_count = _gvn.transform(new SubINode(max, from_index)); 1492 1493 // Range checks 1494 generate_string_range_check(src, src_offset, src_count, true); 1495 if (stopped()) { 1496 return true; 1497 } 1498 1499 RegionNode* region = new RegionNode(3); 1500 Node* phi = new PhiNode(region, TypeInt::INT); 1501 1502 Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, tgt, StrIntrinsicNode::none); 1503 C->set_has_split_ifs(true); // Has chance for split-if optimization 1504 _gvn.transform(result); 1505 1506 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0))); 1507 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt)); 1508 1509 Node* if_lt = generate_slow_guard(bol, NULL); 1510 if (if_lt != NULL) { 1511 // result == -1 1512 phi->init_req(2, result); 1513 region->init_req(2, if_lt); 1514 } 1515 if (!stopped()) { 1516 result = _gvn.transform(new AddINode(result, from_index)); 1517 phi->init_req(1, result); 1518 region->init_req(1, control()); 1519 } 1520 set_control(_gvn.transform(region)); 1521 record_for_igvn(region); 1522 set_result(_gvn.transform(phi)); 1523 1524 return true; 1525 } 1526 //---------------------------inline_string_copy--------------------- 1527 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[]) 1528 // int StringUTF16.compress(char[] src, int srcOff, byte[] dst, int dstOff, int len) 1529 // int StringUTF16.compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1530 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[]) 1531 // void StringLatin1.inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len) 1532 // void StringLatin1.inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) 1533 bool LibraryCallKit::inline_string_copy(bool compress) { 1534 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1535 return false; 1536 } 1537 int nargs = 5; // 2 oops, 3 ints 1538 assert(callee()->signature()->size() == nargs, "string copy has 5 arguments"); 1539 1540 Node* src = argument(0); 1541 Node* src_offset = argument(1); 1542 Node* dst = argument(2); 1543 Node* dst_offset = argument(3); 1544 Node* length = argument(4); 1545 1546 // Check for allocation before we add nodes that would confuse 1547 // tightly_coupled_allocation() 1548 AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL); 1549 1550 // Figure out the size and type of the elements we will be copying. 1551 const Type* src_type = src->Value(&_gvn); 1552 const Type* dst_type = dst->Value(&_gvn); 1553 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 1554 BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 1555 assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) || 1556 (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)), 1557 "Unsupported array types for inline_string_copy"); 1558 1559 src = must_be_not_null(src, true); 1560 dst = must_be_not_null(dst, true); 1561 1562 // Convert char[] offsets to byte[] offsets 1563 bool convert_src = (compress && src_elem == T_BYTE); 1564 bool convert_dst = (!compress && dst_elem == T_BYTE); 1565 if (convert_src) { 1566 src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1))); 1567 } else if (convert_dst) { 1568 dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1))); 1569 } 1570 1571 // Range checks 1572 generate_string_range_check(src, src_offset, length, convert_src); 1573 generate_string_range_check(dst, dst_offset, length, convert_dst); 1574 if (stopped()) { 1575 return true; 1576 } 1577 1578 src = access_resolve(src, ACCESS_READ); 1579 dst = access_resolve(dst, ACCESS_WRITE); 1580 1581 Node* src_start = array_element_address(src, src_offset, src_elem); 1582 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 1583 // 'src_start' points to src array + scaled offset 1584 // 'dst_start' points to dst array + scaled offset 1585 Node* count = NULL; 1586 if (compress) { 1587 count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length); 1588 } else { 1589 inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length); 1590 } 1591 1592 if (alloc != NULL) { 1593 if (alloc->maybe_set_complete(&_gvn)) { 1594 // "You break it, you buy it." 1595 InitializeNode* init = alloc->initialization(); 1596 assert(init->is_complete(), "we just did this"); 1597 init->set_complete_with_arraycopy(); 1598 assert(dst->is_CheckCastPP(), "sanity"); 1599 assert(dst->in(0)->in(0) == init, "dest pinned"); 1600 } 1601 // Do not let stores that initialize this object be reordered with 1602 // a subsequent store that would make this object accessible by 1603 // other threads. 1604 // Record what AllocateNode this StoreStore protects so that 1605 // escape analysis can go from the MemBarStoreStoreNode to the 1606 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1607 // based on the escape status of the AllocateNode. 1608 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1609 } 1610 if (compress) { 1611 set_result(_gvn.transform(count)); 1612 } 1613 clear_upper_avx(); 1614 1615 return true; 1616 } 1617 1618 #ifdef _LP64 1619 #define XTOP ,top() /*additional argument*/ 1620 #else //_LP64 1621 #define XTOP /*no additional argument*/ 1622 #endif //_LP64 1623 1624 //------------------------inline_string_toBytesU-------------------------- 1625 // public static byte[] StringUTF16.toBytes(char[] value, int off, int len) 1626 bool LibraryCallKit::inline_string_toBytesU() { 1627 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1628 return false; 1629 } 1630 // Get the arguments. 1631 Node* value = argument(0); 1632 Node* offset = argument(1); 1633 Node* length = argument(2); 1634 1635 Node* newcopy = NULL; 1636 1637 // Set the original stack and the reexecute bit for the interpreter to reexecute 1638 // the bytecode that invokes StringUTF16.toBytes() if deoptimization happens. 1639 { PreserveReexecuteState preexecs(this); 1640 jvms()->set_should_reexecute(true); 1641 1642 // Check if a null path was taken unconditionally. 1643 value = null_check(value); 1644 1645 RegionNode* bailout = new RegionNode(1); 1646 record_for_igvn(bailout); 1647 1648 // Range checks 1649 generate_negative_guard(offset, bailout); 1650 generate_negative_guard(length, bailout); 1651 generate_limit_guard(offset, length, load_array_length(value), bailout); 1652 // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE 1653 generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout); 1654 1655 if (bailout->req() > 1) { 1656 PreserveJVMState pjvms(this); 1657 set_control(_gvn.transform(bailout)); 1658 uncommon_trap(Deoptimization::Reason_intrinsic, 1659 Deoptimization::Action_maybe_recompile); 1660 } 1661 if (stopped()) { 1662 return true; 1663 } 1664 1665 Node* size = _gvn.transform(new LShiftINode(length, intcon(1))); 1666 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE))); 1667 newcopy = new_array(klass_node, size, 0); // no arguments to push 1668 AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy, NULL); 1669 1670 // Calculate starting addresses. 1671 value = access_resolve(value, ACCESS_READ); 1672 Node* src_start = array_element_address(value, offset, T_CHAR); 1673 Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE)); 1674 1675 // Check if src array address is aligned to HeapWordSize (dst is always aligned) 1676 const TypeInt* toffset = gvn().type(offset)->is_int(); 1677 bool aligned = toffset->is_con() && ((toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1678 1679 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1680 const char* copyfunc_name = "arraycopy"; 1681 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1682 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1683 OptoRuntime::fast_arraycopy_Type(), 1684 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1685 src_start, dst_start, ConvI2X(length) XTOP); 1686 // Do not let reads from the cloned object float above the arraycopy. 1687 if (alloc != NULL) { 1688 if (alloc->maybe_set_complete(&_gvn)) { 1689 // "You break it, you buy it." 1690 InitializeNode* init = alloc->initialization(); 1691 assert(init->is_complete(), "we just did this"); 1692 init->set_complete_with_arraycopy(); 1693 assert(newcopy->is_CheckCastPP(), "sanity"); 1694 assert(newcopy->in(0)->in(0) == init, "dest pinned"); 1695 } 1696 // Do not let stores that initialize this object be reordered with 1697 // a subsequent store that would make this object accessible by 1698 // other threads. 1699 // Record what AllocateNode this StoreStore protects so that 1700 // escape analysis can go from the MemBarStoreStoreNode to the 1701 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1702 // based on the escape status of the AllocateNode. 1703 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1704 } else { 1705 insert_mem_bar(Op_MemBarCPUOrder); 1706 } 1707 } // original reexecute is set back here 1708 1709 C->set_has_split_ifs(true); // Has chance for split-if optimization 1710 if (!stopped()) { 1711 set_result(newcopy); 1712 } 1713 clear_upper_avx(); 1714 1715 return true; 1716 } 1717 1718 //------------------------inline_string_getCharsU-------------------------- 1719 // public void StringUTF16.getChars(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin) 1720 bool LibraryCallKit::inline_string_getCharsU() { 1721 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 1722 return false; 1723 } 1724 1725 // Get the arguments. 1726 Node* src = argument(0); 1727 Node* src_begin = argument(1); 1728 Node* src_end = argument(2); // exclusive offset (i < src_end) 1729 Node* dst = argument(3); 1730 Node* dst_begin = argument(4); 1731 1732 // Check for allocation before we add nodes that would confuse 1733 // tightly_coupled_allocation() 1734 AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL); 1735 1736 // Check if a null path was taken unconditionally. 1737 src = null_check(src); 1738 dst = null_check(dst); 1739 if (stopped()) { 1740 return true; 1741 } 1742 1743 // Get length and convert char[] offset to byte[] offset 1744 Node* length = _gvn.transform(new SubINode(src_end, src_begin)); 1745 src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1))); 1746 1747 // Range checks 1748 generate_string_range_check(src, src_begin, length, true); 1749 generate_string_range_check(dst, dst_begin, length, false); 1750 if (stopped()) { 1751 return true; 1752 } 1753 1754 if (!stopped()) { 1755 src = access_resolve(src, ACCESS_READ); 1756 dst = access_resolve(dst, ACCESS_WRITE); 1757 1758 // Calculate starting addresses. 1759 Node* src_start = array_element_address(src, src_begin, T_BYTE); 1760 Node* dst_start = array_element_address(dst, dst_begin, T_CHAR); 1761 1762 // Check if array addresses are aligned to HeapWordSize 1763 const TypeInt* tsrc = gvn().type(src_begin)->is_int(); 1764 const TypeInt* tdst = gvn().type(dst_begin)->is_int(); 1765 bool aligned = tsrc->is_con() && ((tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) && 1766 tdst->is_con() && ((tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0); 1767 1768 // Figure out which arraycopy runtime method to call (disjoint, uninitialized). 1769 const char* copyfunc_name = "arraycopy"; 1770 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true); 1771 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1772 OptoRuntime::fast_arraycopy_Type(), 1773 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM, 1774 src_start, dst_start, ConvI2X(length) XTOP); 1775 // Do not let reads from the cloned object float above the arraycopy. 1776 if (alloc != NULL) { 1777 if (alloc->maybe_set_complete(&_gvn)) { 1778 // "You break it, you buy it." 1779 InitializeNode* init = alloc->initialization(); 1780 assert(init->is_complete(), "we just did this"); 1781 init->set_complete_with_arraycopy(); 1782 assert(dst->is_CheckCastPP(), "sanity"); 1783 assert(dst->in(0)->in(0) == init, "dest pinned"); 1784 } 1785 // Do not let stores that initialize this object be reordered with 1786 // a subsequent store that would make this object accessible by 1787 // other threads. 1788 // Record what AllocateNode this StoreStore protects so that 1789 // escape analysis can go from the MemBarStoreStoreNode to the 1790 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1791 // based on the escape status of the AllocateNode. 1792 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 1793 } else { 1794 insert_mem_bar(Op_MemBarCPUOrder); 1795 } 1796 } 1797 1798 C->set_has_split_ifs(true); // Has chance for split-if optimization 1799 return true; 1800 } 1801 1802 //----------------------inline_string_char_access---------------------------- 1803 // Store/Load char to/from byte[] array. 1804 // static void StringUTF16.putChar(byte[] val, int index, int c) 1805 // static char StringUTF16.getChar(byte[] val, int index) 1806 bool LibraryCallKit::inline_string_char_access(bool is_store) { 1807 Node* value = argument(0); 1808 Node* index = argument(1); 1809 Node* ch = is_store ? argument(2) : NULL; 1810 1811 // This intrinsic accesses byte[] array as char[] array. Computing the offsets 1812 // correctly requires matched array shapes. 1813 assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE), 1814 "sanity: byte[] and char[] bases agree"); 1815 assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2, 1816 "sanity: byte[] and char[] scales agree"); 1817 1818 // Bail when getChar over constants is requested: constant folding would 1819 // reject folding mismatched char access over byte[]. A normal inlining for getChar 1820 // Java method would constant fold nicely instead. 1821 if (!is_store && value->is_Con() && index->is_Con()) { 1822 return false; 1823 } 1824 1825 value = must_be_not_null(value, true); 1826 value = access_resolve(value, is_store ? ACCESS_WRITE : ACCESS_READ); 1827 1828 Node* adr = array_element_address(value, index, T_CHAR); 1829 if (adr->is_top()) { 1830 return false; 1831 } 1832 if (is_store) { 1833 access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED); 1834 } else { 1835 ch = access_load_at(value, adr, TypeAryPtr::BYTES, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD); 1836 set_result(ch); 1837 } 1838 return true; 1839 } 1840 1841 //--------------------------round_double_node-------------------------------- 1842 // Round a double node if necessary. 1843 Node* LibraryCallKit::round_double_node(Node* n) { 1844 if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1) 1845 n = _gvn.transform(new RoundDoubleNode(0, n)); 1846 return n; 1847 } 1848 1849 //------------------------------inline_math----------------------------------- 1850 // public static double Math.abs(double) 1851 // public static double Math.sqrt(double) 1852 // public static double Math.log(double) 1853 // public static double Math.log10(double) 1854 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) { 1855 Node* arg = round_double_node(argument(0)); 1856 Node* n = NULL; 1857 switch (id) { 1858 case vmIntrinsics::_dabs: n = new AbsDNode( arg); break; 1859 case vmIntrinsics::_dsqrt: n = new SqrtDNode(C, control(), arg); break; 1860 default: fatal_unexpected_iid(id); break; 1861 } 1862 set_result(_gvn.transform(n)); 1863 return true; 1864 } 1865 1866 //------------------------------runtime_math----------------------------- 1867 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1868 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1869 "must be (DD)D or (D)D type"); 1870 1871 // Inputs 1872 Node* a = round_double_node(argument(0)); 1873 Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? round_double_node(argument(2)) : NULL; 1874 1875 const TypePtr* no_memory_effects = NULL; 1876 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1877 no_memory_effects, 1878 a, top(), b, b ? top() : NULL); 1879 Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0)); 1880 #ifdef ASSERT 1881 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1)); 1882 assert(value_top == top(), "second value must be top"); 1883 #endif 1884 1885 set_result(value); 1886 return true; 1887 } 1888 1889 //------------------------------inline_math_native----------------------------- 1890 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1891 #define FN_PTR(f) CAST_FROM_FN_PTR(address, f) 1892 switch (id) { 1893 // These intrinsics are not properly supported on all hardware 1894 case vmIntrinsics::_dsin: 1895 return StubRoutines::dsin() != NULL ? 1896 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") : 1897 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dsin), "SIN"); 1898 case vmIntrinsics::_dcos: 1899 return StubRoutines::dcos() != NULL ? 1900 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") : 1901 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dcos), "COS"); 1902 case vmIntrinsics::_dtan: 1903 return StubRoutines::dtan() != NULL ? 1904 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") : 1905 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dtan), "TAN"); 1906 case vmIntrinsics::_dlog: 1907 return StubRoutines::dlog() != NULL ? 1908 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") : 1909 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog), "LOG"); 1910 case vmIntrinsics::_dlog10: 1911 return StubRoutines::dlog10() != NULL ? 1912 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") : 1913 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog10), "LOG10"); 1914 1915 // These intrinsics are supported on all hardware 1916 case vmIntrinsics::_dsqrt: return Matcher::match_rule_supported(Op_SqrtD) ? inline_math(id) : false; 1917 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_math(id) : false; 1918 1919 case vmIntrinsics::_dexp: 1920 return StubRoutines::dexp() != NULL ? 1921 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") : 1922 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dexp), "EXP"); 1923 case vmIntrinsics::_dpow: { 1924 Node* exp = round_double_node(argument(2)); 1925 const TypeD* d = _gvn.type(exp)->isa_double_constant(); 1926 if (d != NULL && d->getd() == 2.0) { 1927 // Special case: pow(x, 2.0) => x * x 1928 Node* base = round_double_node(argument(0)); 1929 set_result(_gvn.transform(new MulDNode(base, base))); 1930 return true; 1931 } 1932 return StubRoutines::dpow() != NULL ? 1933 runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") : 1934 runtime_math(OptoRuntime::Math_DD_D_Type(), FN_PTR(SharedRuntime::dpow), "POW"); 1935 } 1936 #undef FN_PTR 1937 1938 // These intrinsics are not yet correctly implemented 1939 case vmIntrinsics::_datan2: 1940 return false; 1941 1942 default: 1943 fatal_unexpected_iid(id); 1944 return false; 1945 } 1946 } 1947 1948 static bool is_simple_name(Node* n) { 1949 return (n->req() == 1 // constant 1950 || (n->is_Type() && n->as_Type()->type()->singleton()) 1951 || n->is_Proj() // parameter or return value 1952 || n->is_Phi() // local of some sort 1953 ); 1954 } 1955 1956 //----------------------------inline_notify-----------------------------------* 1957 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) { 1958 const TypeFunc* ftype = OptoRuntime::monitor_notify_Type(); 1959 address func; 1960 if (id == vmIntrinsics::_notify) { 1961 func = OptoRuntime::monitor_notify_Java(); 1962 } else { 1963 func = OptoRuntime::monitor_notifyAll_Java(); 1964 } 1965 Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, NULL, TypeRawPtr::BOTTOM, argument(0)); 1966 make_slow_call_ex(call, env()->Throwable_klass(), false); 1967 return true; 1968 } 1969 1970 1971 //----------------------------inline_min_max----------------------------------- 1972 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 1973 set_result(generate_min_max(id, argument(0), argument(1))); 1974 return true; 1975 } 1976 1977 void LibraryCallKit::inline_math_mathExact(Node* math, Node *test) { 1978 Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) ); 1979 IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 1980 Node* fast_path = _gvn.transform( new IfFalseNode(check)); 1981 Node* slow_path = _gvn.transform( new IfTrueNode(check) ); 1982 1983 { 1984 PreserveJVMState pjvms(this); 1985 PreserveReexecuteState preexecs(this); 1986 jvms()->set_should_reexecute(true); 1987 1988 set_control(slow_path); 1989 set_i_o(i_o()); 1990 1991 uncommon_trap(Deoptimization::Reason_intrinsic, 1992 Deoptimization::Action_none); 1993 } 1994 1995 set_control(fast_path); 1996 set_result(math); 1997 } 1998 1999 template <typename OverflowOp> 2000 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) { 2001 typedef typename OverflowOp::MathOp MathOp; 2002 2003 MathOp* mathOp = new MathOp(arg1, arg2); 2004 Node* operation = _gvn.transform( mathOp ); 2005 Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) ); 2006 inline_math_mathExact(operation, ofcheck); 2007 return true; 2008 } 2009 2010 bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 2011 return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1)); 2012 } 2013 2014 bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 2015 return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2)); 2016 } 2017 2018 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 2019 return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1)); 2020 } 2021 2022 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 2023 return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2)); 2024 } 2025 2026 bool LibraryCallKit::inline_math_negateExactI() { 2027 return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0)); 2028 } 2029 2030 bool LibraryCallKit::inline_math_negateExactL() { 2031 return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0)); 2032 } 2033 2034 bool LibraryCallKit::inline_math_multiplyExactI() { 2035 return inline_math_overflow<OverflowMulINode>(argument(0), argument(1)); 2036 } 2037 2038 bool LibraryCallKit::inline_math_multiplyExactL() { 2039 return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2)); 2040 } 2041 2042 bool LibraryCallKit::inline_math_multiplyHigh() { 2043 set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2)))); 2044 return true; 2045 } 2046 2047 Node* 2048 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) { 2049 // These are the candidate return value: 2050 Node* xvalue = x0; 2051 Node* yvalue = y0; 2052 2053 if (xvalue == yvalue) { 2054 return xvalue; 2055 } 2056 2057 bool want_max = (id == vmIntrinsics::_max); 2058 2059 const TypeInt* txvalue = _gvn.type(xvalue)->isa_int(); 2060 const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int(); 2061 if (txvalue == NULL || tyvalue == NULL) return top(); 2062 // This is not really necessary, but it is consistent with a 2063 // hypothetical MaxINode::Value method: 2064 int widen = MAX2(txvalue->_widen, tyvalue->_widen); 2065 2066 // %%% This folding logic should (ideally) be in a different place. 2067 // Some should be inside IfNode, and there to be a more reliable 2068 // transformation of ?: style patterns into cmoves. We also want 2069 // more powerful optimizations around cmove and min/max. 2070 2071 // Try to find a dominating comparison of these guys. 2072 // It can simplify the index computation for Arrays.copyOf 2073 // and similar uses of System.arraycopy. 2074 // First, compute the normalized version of CmpI(x, y). 2075 int cmp_op = Op_CmpI; 2076 Node* xkey = xvalue; 2077 Node* ykey = yvalue; 2078 Node* ideal_cmpxy = _gvn.transform(new CmpINode(xkey, ykey)); 2079 if (ideal_cmpxy->is_Cmp()) { 2080 // E.g., if we have CmpI(length - offset, count), 2081 // it might idealize to CmpI(length, count + offset) 2082 cmp_op = ideal_cmpxy->Opcode(); 2083 xkey = ideal_cmpxy->in(1); 2084 ykey = ideal_cmpxy->in(2); 2085 } 2086 2087 // Start by locating any relevant comparisons. 2088 Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey; 2089 Node* cmpxy = NULL; 2090 Node* cmpyx = NULL; 2091 for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) { 2092 Node* cmp = start_from->fast_out(k); 2093 if (cmp->outcnt() > 0 && // must have prior uses 2094 cmp->in(0) == NULL && // must be context-independent 2095 cmp->Opcode() == cmp_op) { // right kind of compare 2096 if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp; 2097 if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp; 2098 } 2099 } 2100 2101 const int NCMPS = 2; 2102 Node* cmps[NCMPS] = { cmpxy, cmpyx }; 2103 int cmpn; 2104 for (cmpn = 0; cmpn < NCMPS; cmpn++) { 2105 if (cmps[cmpn] != NULL) break; // find a result 2106 } 2107 if (cmpn < NCMPS) { 2108 // Look for a dominating test that tells us the min and max. 2109 int depth = 0; // Limit search depth for speed 2110 Node* dom = control(); 2111 for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) { 2112 if (++depth >= 100) break; 2113 Node* ifproj = dom; 2114 if (!ifproj->is_Proj()) continue; 2115 Node* iff = ifproj->in(0); 2116 if (!iff->is_If()) continue; 2117 Node* bol = iff->in(1); 2118 if (!bol->is_Bool()) continue; 2119 Node* cmp = bol->in(1); 2120 if (cmp == NULL) continue; 2121 for (cmpn = 0; cmpn < NCMPS; cmpn++) 2122 if (cmps[cmpn] == cmp) break; 2123 if (cmpn == NCMPS) continue; 2124 BoolTest::mask btest = bol->as_Bool()->_test._test; 2125 if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate(); 2126 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 2127 // At this point, we know that 'x btest y' is true. 2128 switch (btest) { 2129 case BoolTest::eq: 2130 // They are proven equal, so we can collapse the min/max. 2131 // Either value is the answer. Choose the simpler. 2132 if (is_simple_name(yvalue) && !is_simple_name(xvalue)) 2133 return yvalue; 2134 return xvalue; 2135 case BoolTest::lt: // x < y 2136 case BoolTest::le: // x <= y 2137 return (want_max ? yvalue : xvalue); 2138 case BoolTest::gt: // x > y 2139 case BoolTest::ge: // x >= y 2140 return (want_max ? xvalue : yvalue); 2141 default: 2142 break; 2143 } 2144 } 2145 } 2146 2147 // We failed to find a dominating test. 2148 // Let's pick a test that might GVN with prior tests. 2149 Node* best_bol = NULL; 2150 BoolTest::mask best_btest = BoolTest::illegal; 2151 for (cmpn = 0; cmpn < NCMPS; cmpn++) { 2152 Node* cmp = cmps[cmpn]; 2153 if (cmp == NULL) continue; 2154 for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) { 2155 Node* bol = cmp->fast_out(j); 2156 if (!bol->is_Bool()) continue; 2157 BoolTest::mask btest = bol->as_Bool()->_test._test; 2158 if (btest == BoolTest::eq || btest == BoolTest::ne) continue; 2159 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 2160 if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) { 2161 best_bol = bol->as_Bool(); 2162 best_btest = btest; 2163 } 2164 } 2165 } 2166 2167 Node* answer_if_true = NULL; 2168 Node* answer_if_false = NULL; 2169 switch (best_btest) { 2170 default: 2171 if (cmpxy == NULL) 2172 cmpxy = ideal_cmpxy; 2173 best_bol = _gvn.transform(new BoolNode(cmpxy, BoolTest::lt)); 2174 // and fall through: 2175 case BoolTest::lt: // x < y 2176 case BoolTest::le: // x <= y 2177 answer_if_true = (want_max ? yvalue : xvalue); 2178 answer_if_false = (want_max ? xvalue : yvalue); 2179 break; 2180 case BoolTest::gt: // x > y 2181 case BoolTest::ge: // x >= y 2182 answer_if_true = (want_max ? xvalue : yvalue); 2183 answer_if_false = (want_max ? yvalue : xvalue); 2184 break; 2185 } 2186 2187 jint hi, lo; 2188 if (want_max) { 2189 // We can sharpen the minimum. 2190 hi = MAX2(txvalue->_hi, tyvalue->_hi); 2191 lo = MAX2(txvalue->_lo, tyvalue->_lo); 2192 } else { 2193 // We can sharpen the maximum. 2194 hi = MIN2(txvalue->_hi, tyvalue->_hi); 2195 lo = MIN2(txvalue->_lo, tyvalue->_lo); 2196 } 2197 2198 // Use a flow-free graph structure, to avoid creating excess control edges 2199 // which could hinder other optimizations. 2200 // Since Math.min/max is often used with arraycopy, we want 2201 // tightly_coupled_allocation to be able to see beyond min/max expressions. 2202 Node* cmov = CMoveNode::make(NULL, best_bol, 2203 answer_if_false, answer_if_true, 2204 TypeInt::make(lo, hi, widen)); 2205 2206 return _gvn.transform(cmov); 2207 2208 /* 2209 // This is not as desirable as it may seem, since Min and Max 2210 // nodes do not have a full set of optimizations. 2211 // And they would interfere, anyway, with 'if' optimizations 2212 // and with CMoveI canonical forms. 2213 switch (id) { 2214 case vmIntrinsics::_min: 2215 result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break; 2216 case vmIntrinsics::_max: 2217 result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break; 2218 default: 2219 ShouldNotReachHere(); 2220 } 2221 */ 2222 } 2223 2224 inline int 2225 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) { 2226 const TypePtr* base_type = TypePtr::NULL_PTR; 2227 if (base != NULL) base_type = _gvn.type(base)->isa_ptr(); 2228 if (base_type == NULL) { 2229 // Unknown type. 2230 return Type::AnyPtr; 2231 } else if (base_type == TypePtr::NULL_PTR) { 2232 // Since this is a NULL+long form, we have to switch to a rawptr. 2233 base = _gvn.transform(new CastX2PNode(offset)); 2234 offset = MakeConX(0); 2235 return Type::RawPtr; 2236 } else if (base_type->base() == Type::RawPtr) { 2237 return Type::RawPtr; 2238 } else if (base_type->isa_oopptr()) { 2239 // Base is never null => always a heap address. 2240 if (!TypePtr::NULL_PTR->higher_equal(base_type)) { 2241 return Type::OopPtr; 2242 } 2243 // Offset is small => always a heap address. 2244 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 2245 if (offset_type != NULL && 2246 base_type->offset() == 0 && // (should always be?) 2247 offset_type->_lo >= 0 && 2248 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 2249 return Type::OopPtr; 2250 } else if (type == T_OBJECT) { 2251 // off heap access to an oop doesn't make any sense. Has to be on 2252 // heap. 2253 return Type::OopPtr; 2254 } 2255 // Otherwise, it might either be oop+off or NULL+addr. 2256 return Type::AnyPtr; 2257 } else { 2258 // No information: 2259 return Type::AnyPtr; 2260 } 2261 } 2262 2263 inline Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, DecoratorSet decorators, BasicType type, bool can_cast) { 2264 Node* uncasted_base = base; 2265 int kind = classify_unsafe_addr(uncasted_base, offset, type); 2266 if (kind == Type::RawPtr) { 2267 return basic_plus_adr(top(), uncasted_base, offset); 2268 } else if (kind == Type::AnyPtr) { 2269 assert(base == uncasted_base, "unexpected base change"); 2270 if (can_cast) { 2271 if (!_gvn.type(base)->speculative_maybe_null() && 2272 !too_many_traps(Deoptimization::Reason_speculate_null_check)) { 2273 // According to profiling, this access is always on 2274 // heap. Casting the base to not null and thus avoiding membars 2275 // around the access should allow better optimizations 2276 Node* null_ctl = top(); 2277 base = null_check_oop(base, &null_ctl, true, true, true); 2278 assert(null_ctl->is_top(), "no null control here"); 2279 return basic_plus_adr(base, offset); 2280 } else if (_gvn.type(base)->speculative_always_null() && 2281 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) { 2282 // According to profiling, this access is always off 2283 // heap. 2284 base = null_assert(base); 2285 Node* raw_base = _gvn.transform(new CastX2PNode(offset)); 2286 offset = MakeConX(0); 2287 return basic_plus_adr(top(), raw_base, offset); 2288 } 2289 } 2290 // We don't know if it's an on heap or off heap access. Fall back 2291 // to raw memory access. 2292 base = access_resolve(base, decorators); 2293 Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM)); 2294 return basic_plus_adr(top(), raw, offset); 2295 } else { 2296 assert(base == uncasted_base, "unexpected base change"); 2297 // We know it's an on heap access so base can't be null 2298 if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) { 2299 base = must_be_not_null(base, true); 2300 } 2301 return basic_plus_adr(base, offset); 2302 } 2303 } 2304 2305 //--------------------------inline_number_methods----------------------------- 2306 // inline int Integer.numberOfLeadingZeros(int) 2307 // inline int Long.numberOfLeadingZeros(long) 2308 // 2309 // inline int Integer.numberOfTrailingZeros(int) 2310 // inline int Long.numberOfTrailingZeros(long) 2311 // 2312 // inline int Integer.bitCount(int) 2313 // inline int Long.bitCount(long) 2314 // 2315 // inline char Character.reverseBytes(char) 2316 // inline short Short.reverseBytes(short) 2317 // inline int Integer.reverseBytes(int) 2318 // inline long Long.reverseBytes(long) 2319 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 2320 Node* arg = argument(0); 2321 Node* n = NULL; 2322 switch (id) { 2323 case vmIntrinsics::_numberOfLeadingZeros_i: n = new CountLeadingZerosINode( arg); break; 2324 case vmIntrinsics::_numberOfLeadingZeros_l: n = new CountLeadingZerosLNode( arg); break; 2325 case vmIntrinsics::_numberOfTrailingZeros_i: n = new CountTrailingZerosINode(arg); break; 2326 case vmIntrinsics::_numberOfTrailingZeros_l: n = new CountTrailingZerosLNode(arg); break; 2327 case vmIntrinsics::_bitCount_i: n = new PopCountINode( arg); break; 2328 case vmIntrinsics::_bitCount_l: n = new PopCountLNode( arg); break; 2329 case vmIntrinsics::_reverseBytes_c: n = new ReverseBytesUSNode(0, arg); break; 2330 case vmIntrinsics::_reverseBytes_s: n = new ReverseBytesSNode( 0, arg); break; 2331 case vmIntrinsics::_reverseBytes_i: n = new ReverseBytesINode( 0, arg); break; 2332 case vmIntrinsics::_reverseBytes_l: n = new ReverseBytesLNode( 0, arg); break; 2333 default: fatal_unexpected_iid(id); break; 2334 } 2335 set_result(_gvn.transform(n)); 2336 return true; 2337 } 2338 2339 //----------------------------inline_unsafe_access---------------------------- 2340 2341 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) { 2342 // Attempt to infer a sharper value type from the offset and base type. 2343 ciKlass* sharpened_klass = NULL; 2344 2345 // See if it is an instance field, with an object type. 2346 if (alias_type->field() != NULL) { 2347 if (alias_type->field()->type()->is_klass()) { 2348 sharpened_klass = alias_type->field()->type()->as_klass(); 2349 } 2350 } 2351 2352 // See if it is a narrow oop array. 2353 if (adr_type->isa_aryptr()) { 2354 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) { 2355 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr(); 2356 if (elem_type != NULL) { 2357 sharpened_klass = elem_type->klass(); 2358 } 2359 } 2360 } 2361 2362 // The sharpened class might be unloaded if there is no class loader 2363 // contraint in place. 2364 if (sharpened_klass != NULL && sharpened_klass->is_loaded()) { 2365 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass); 2366 2367 #ifndef PRODUCT 2368 if (C->print_intrinsics() || C->print_inlining()) { 2369 tty->print(" from base type: "); adr_type->dump(); tty->cr(); 2370 tty->print(" sharpened value: "); tjp->dump(); tty->cr(); 2371 } 2372 #endif 2373 // Sharpen the value type. 2374 return tjp; 2375 } 2376 return NULL; 2377 } 2378 2379 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) { 2380 switch (kind) { 2381 case Relaxed: 2382 return MO_UNORDERED; 2383 case Opaque: 2384 return MO_RELAXED; 2385 case Acquire: 2386 return MO_ACQUIRE; 2387 case Release: 2388 return MO_RELEASE; 2389 case Volatile: 2390 return MO_SEQ_CST; 2391 default: 2392 ShouldNotReachHere(); 2393 return 0; 2394 } 2395 } 2396 2397 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) { 2398 if (callee()->is_static()) return false; // caller must have the capability! 2399 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2400 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads"); 2401 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores"); 2402 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type"); 2403 2404 if (type == T_OBJECT || type == T_ARRAY) { 2405 decorators |= ON_UNKNOWN_OOP_REF; 2406 } 2407 2408 if (unaligned) { 2409 decorators |= C2_UNALIGNED; 2410 } 2411 2412 #ifndef PRODUCT 2413 { 2414 ResourceMark rm; 2415 // Check the signatures. 2416 ciSignature* sig = callee()->signature(); 2417 #ifdef ASSERT 2418 if (!is_store) { 2419 // Object getReference(Object base, int/long offset), etc. 2420 BasicType rtype = sig->return_type()->basic_type(); 2421 assert(rtype == type, "getter must return the expected value"); 2422 assert(sig->count() == 2, "oop getter has 2 arguments"); 2423 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 2424 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 2425 } else { 2426 // void putReference(Object base, int/long offset, Object x), etc. 2427 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 2428 assert(sig->count() == 3, "oop putter has 3 arguments"); 2429 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 2430 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 2431 BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 2432 assert(vtype == type, "putter must accept the expected value"); 2433 } 2434 #endif // ASSERT 2435 } 2436 #endif //PRODUCT 2437 2438 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2439 2440 Node* receiver = argument(0); // type: oop 2441 2442 // Build address expression. 2443 Node* adr; 2444 Node* heap_base_oop = top(); 2445 Node* offset = top(); 2446 Node* val; 2447 2448 // The base is either a Java object or a value produced by Unsafe.staticFieldBase 2449 Node* base = argument(1); // type: oop 2450 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 2451 offset = argument(2); // type: long 2452 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2453 // to be plain byte offsets, which are also the same as those accepted 2454 // by oopDesc::field_addr. 2455 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 2456 "fieldOffset must be byte-scaled"); 2457 // 32-bit machines ignore the high half! 2458 offset = ConvL2X(offset); 2459 adr = make_unsafe_address(base, offset, is_store ? ACCESS_WRITE : ACCESS_READ, type, kind == Relaxed); 2460 2461 if (_gvn.type(base)->isa_ptr() != TypePtr::NULL_PTR) { 2462 heap_base_oop = base; 2463 } else if (type == T_OBJECT) { 2464 return false; // off-heap oop accesses are not supported 2465 } 2466 2467 // Can base be NULL? Otherwise, always on-heap access. 2468 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base)); 2469 2470 if (!can_access_non_heap) { 2471 decorators |= IN_HEAP; 2472 } 2473 2474 val = is_store ? argument(4) : NULL; 2475 2476 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 2477 2478 // Try to categorize the address. 2479 Compile::AliasType* alias_type = C->alias_type(adr_type); 2480 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2481 2482 if (alias_type->adr_type() == TypeInstPtr::KLASS || 2483 alias_type->adr_type() == TypeAryPtr::RANGE) { 2484 return false; // not supported 2485 } 2486 2487 bool mismatched = false; 2488 BasicType bt = alias_type->basic_type(); 2489 if (bt != T_ILLEGAL) { 2490 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access"); 2491 if (bt == T_BYTE && adr_type->isa_aryptr()) { 2492 // Alias type doesn't differentiate between byte[] and boolean[]). 2493 // Use address type to get the element type. 2494 bt = adr_type->is_aryptr()->elem()->array_element_basic_type(); 2495 } 2496 if (bt == T_ARRAY || bt == T_NARROWOOP) { 2497 // accessing an array field with getReference is not a mismatch 2498 bt = T_OBJECT; 2499 } 2500 if ((bt == T_OBJECT) != (type == T_OBJECT)) { 2501 // Don't intrinsify mismatched object accesses 2502 return false; 2503 } 2504 mismatched = (bt != type); 2505 } else if (alias_type->adr_type()->isa_oopptr()) { 2506 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched 2507 } 2508 2509 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched"); 2510 2511 if (mismatched) { 2512 decorators |= C2_MISMATCHED; 2513 } 2514 2515 // First guess at the value type. 2516 const Type *value_type = Type::get_const_basic_type(type); 2517 2518 // Figure out the memory ordering. 2519 decorators |= mo_decorator_for_access_kind(kind); 2520 2521 if (!is_store && type == T_OBJECT) { 2522 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2523 if (tjp != NULL) { 2524 value_type = tjp; 2525 } 2526 } 2527 2528 receiver = null_check(receiver); 2529 if (stopped()) { 2530 return true; 2531 } 2532 // Heap pointers get a null-check from the interpreter, 2533 // as a courtesy. However, this is not guaranteed by Unsafe, 2534 // and it is not possible to fully distinguish unintended nulls 2535 // from intended ones in this API. 2536 2537 if (!is_store) { 2538 Node* p = NULL; 2539 // Try to constant fold a load from a constant field 2540 ciField* field = alias_type->field(); 2541 if (heap_base_oop != top() && field != NULL && field->is_constant() && !mismatched) { 2542 // final or stable field 2543 p = make_constant_from_field(field, heap_base_oop); 2544 } 2545 2546 if (p == NULL) { // Could not constant fold the load 2547 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators); 2548 // Normalize the value returned by getBoolean in the following cases 2549 if (type == T_BOOLEAN && 2550 (mismatched || 2551 heap_base_oop == top() || // - heap_base_oop is NULL or 2552 (can_access_non_heap && field == NULL)) // - heap_base_oop is potentially NULL 2553 // and the unsafe access is made to large offset 2554 // (i.e., larger than the maximum offset necessary for any 2555 // field access) 2556 ) { 2557 IdealKit ideal = IdealKit(this); 2558 #define __ ideal. 2559 IdealVariable normalized_result(ideal); 2560 __ declarations_done(); 2561 __ set(normalized_result, p); 2562 __ if_then(p, BoolTest::ne, ideal.ConI(0)); 2563 __ set(normalized_result, ideal.ConI(1)); 2564 ideal.end_if(); 2565 final_sync(ideal); 2566 p = __ value(normalized_result); 2567 #undef __ 2568 } 2569 } 2570 if (type == T_ADDRESS) { 2571 p = gvn().transform(new CastP2XNode(NULL, p)); 2572 p = ConvX2UL(p); 2573 } 2574 // The load node has the control of the preceding MemBarCPUOrder. All 2575 // following nodes will have the control of the MemBarCPUOrder inserted at 2576 // the end of this method. So, pushing the load onto the stack at a later 2577 // point is fine. 2578 set_result(p); 2579 } else { 2580 if (bt == T_ADDRESS) { 2581 // Repackage the long as a pointer. 2582 val = ConvL2X(val); 2583 val = gvn().transform(new CastX2PNode(val)); 2584 } 2585 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators); 2586 } 2587 2588 return true; 2589 } 2590 2591 //----------------------------inline_unsafe_load_store---------------------------- 2592 // This method serves a couple of different customers (depending on LoadStoreKind): 2593 // 2594 // LS_cmp_swap: 2595 // 2596 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x); 2597 // boolean compareAndSetInt( Object o, long offset, int expected, int x); 2598 // boolean compareAndSetLong( Object o, long offset, long expected, long x); 2599 // 2600 // LS_cmp_swap_weak: 2601 // 2602 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x); 2603 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x); 2604 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x); 2605 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x); 2606 // 2607 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x); 2608 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x); 2609 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x); 2610 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x); 2611 // 2612 // boolean weakCompareAndSetLong( Object o, long offset, long expected, long x); 2613 // boolean weakCompareAndSetLongPlain( Object o, long offset, long expected, long x); 2614 // boolean weakCompareAndSetLongAcquire( Object o, long offset, long expected, long x); 2615 // boolean weakCompareAndSetLongRelease( Object o, long offset, long expected, long x); 2616 // 2617 // LS_cmp_exchange: 2618 // 2619 // Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x); 2620 // Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x); 2621 // Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x); 2622 // 2623 // Object compareAndExchangeIntVolatile( Object o, long offset, Object expected, Object x); 2624 // Object compareAndExchangeIntAcquire( Object o, long offset, Object expected, Object x); 2625 // Object compareAndExchangeIntRelease( Object o, long offset, Object expected, Object x); 2626 // 2627 // Object compareAndExchangeLongVolatile( Object o, long offset, Object expected, Object x); 2628 // Object compareAndExchangeLongAcquire( Object o, long offset, Object expected, Object x); 2629 // Object compareAndExchangeLongRelease( Object o, long offset, Object expected, Object x); 2630 // 2631 // LS_get_add: 2632 // 2633 // int getAndAddInt( Object o, long offset, int delta) 2634 // long getAndAddLong(Object o, long offset, long delta) 2635 // 2636 // LS_get_set: 2637 // 2638 // int getAndSet(Object o, long offset, int newValue) 2639 // long getAndSet(Object o, long offset, long newValue) 2640 // Object getAndSet(Object o, long offset, Object newValue) 2641 // 2642 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) { 2643 // This basic scheme here is the same as inline_unsafe_access, but 2644 // differs in enough details that combining them would make the code 2645 // overly confusing. (This is a true fact! I originally combined 2646 // them, but even I was confused by it!) As much code/comments as 2647 // possible are retained from inline_unsafe_access though to make 2648 // the correspondences clearer. - dl 2649 2650 if (callee()->is_static()) return false; // caller must have the capability! 2651 2652 DecoratorSet decorators = C2_UNSAFE_ACCESS; 2653 decorators |= mo_decorator_for_access_kind(access_kind); 2654 2655 #ifndef PRODUCT 2656 BasicType rtype; 2657 { 2658 ResourceMark rm; 2659 // Check the signatures. 2660 ciSignature* sig = callee()->signature(); 2661 rtype = sig->return_type()->basic_type(); 2662 switch(kind) { 2663 case LS_get_add: 2664 case LS_get_set: { 2665 // Check the signatures. 2666 #ifdef ASSERT 2667 assert(rtype == type, "get and set must return the expected type"); 2668 assert(sig->count() == 3, "get and set has 3 arguments"); 2669 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 2670 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 2671 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 2672 assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation"); 2673 #endif // ASSERT 2674 break; 2675 } 2676 case LS_cmp_swap: 2677 case LS_cmp_swap_weak: { 2678 // Check the signatures. 2679 #ifdef ASSERT 2680 assert(rtype == T_BOOLEAN, "CAS must return boolean"); 2681 assert(sig->count() == 4, "CAS has 4 arguments"); 2682 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 2683 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 2684 #endif // ASSERT 2685 break; 2686 } 2687 case LS_cmp_exchange: { 2688 // Check the signatures. 2689 #ifdef ASSERT 2690 assert(rtype == type, "CAS must return the expected type"); 2691 assert(sig->count() == 4, "CAS has 4 arguments"); 2692 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 2693 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 2694 #endif // ASSERT 2695 break; 2696 } 2697 default: 2698 ShouldNotReachHere(); 2699 } 2700 } 2701 #endif //PRODUCT 2702 2703 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 2704 2705 // Get arguments: 2706 Node* receiver = NULL; 2707 Node* base = NULL; 2708 Node* offset = NULL; 2709 Node* oldval = NULL; 2710 Node* newval = NULL; 2711 switch(kind) { 2712 case LS_cmp_swap: 2713 case LS_cmp_swap_weak: 2714 case LS_cmp_exchange: { 2715 const bool two_slot_type = type2size[type] == 2; 2716 receiver = argument(0); // type: oop 2717 base = argument(1); // type: oop 2718 offset = argument(2); // type: long 2719 oldval = argument(4); // type: oop, int, or long 2720 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 2721 break; 2722 } 2723 case LS_get_add: 2724 case LS_get_set: { 2725 receiver = argument(0); // type: oop 2726 base = argument(1); // type: oop 2727 offset = argument(2); // type: long 2728 oldval = NULL; 2729 newval = argument(4); // type: oop, int, or long 2730 break; 2731 } 2732 default: 2733 ShouldNotReachHere(); 2734 } 2735 2736 // Build field offset expression. 2737 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 2738 // to be plain byte offsets, which are also the same as those accepted 2739 // by oopDesc::field_addr. 2740 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 2741 // 32-bit machines ignore the high half of long offsets 2742 offset = ConvL2X(offset); 2743 Node* adr = make_unsafe_address(base, offset, ACCESS_WRITE | ACCESS_READ, type, false); 2744 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 2745 2746 Compile::AliasType* alias_type = C->alias_type(adr_type); 2747 BasicType bt = alias_type->basic_type(); 2748 if (bt != T_ILLEGAL && 2749 ((bt == T_OBJECT || bt == T_ARRAY) != (type == T_OBJECT))) { 2750 // Don't intrinsify mismatched object accesses. 2751 return false; 2752 } 2753 2754 // For CAS, unlike inline_unsafe_access, there seems no point in 2755 // trying to refine types. Just use the coarse types here. 2756 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 2757 const Type *value_type = Type::get_const_basic_type(type); 2758 2759 switch (kind) { 2760 case LS_get_set: 2761 case LS_cmp_exchange: { 2762 if (type == T_OBJECT) { 2763 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 2764 if (tjp != NULL) { 2765 value_type = tjp; 2766 } 2767 } 2768 break; 2769 } 2770 case LS_cmp_swap: 2771 case LS_cmp_swap_weak: 2772 case LS_get_add: 2773 break; 2774 default: 2775 ShouldNotReachHere(); 2776 } 2777 2778 // Null check receiver. 2779 receiver = null_check(receiver); 2780 if (stopped()) { 2781 return true; 2782 } 2783 2784 int alias_idx = C->get_alias_index(adr_type); 2785 2786 if (type == T_OBJECT || type == T_ARRAY) { 2787 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF; 2788 2789 // Transformation of a value which could be NULL pointer (CastPP #NULL) 2790 // could be delayed during Parse (for example, in adjust_map_after_if()). 2791 // Execute transformation here to avoid barrier generation in such case. 2792 if (_gvn.type(newval) == TypePtr::NULL_PTR) 2793 newval = _gvn.makecon(TypePtr::NULL_PTR); 2794 2795 if (oldval != NULL && _gvn.type(oldval) == TypePtr::NULL_PTR) { 2796 // Refine the value to a null constant, when it is known to be null 2797 oldval = _gvn.makecon(TypePtr::NULL_PTR); 2798 } 2799 } 2800 2801 Node* result = NULL; 2802 switch (kind) { 2803 case LS_cmp_exchange: { 2804 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx, 2805 oldval, newval, value_type, type, decorators); 2806 break; 2807 } 2808 case LS_cmp_swap_weak: 2809 decorators |= C2_WEAK_CMPXCHG; 2810 case LS_cmp_swap: { 2811 result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx, 2812 oldval, newval, value_type, type, decorators); 2813 break; 2814 } 2815 case LS_get_set: { 2816 result = access_atomic_xchg_at(base, adr, adr_type, alias_idx, 2817 newval, value_type, type, decorators); 2818 break; 2819 } 2820 case LS_get_add: { 2821 result = access_atomic_add_at(base, adr, adr_type, alias_idx, 2822 newval, value_type, type, decorators); 2823 break; 2824 } 2825 default: 2826 ShouldNotReachHere(); 2827 } 2828 2829 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 2830 set_result(result); 2831 return true; 2832 } 2833 2834 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 2835 // Regardless of form, don't allow previous ld/st to move down, 2836 // then issue acquire, release, or volatile mem_bar. 2837 insert_mem_bar(Op_MemBarCPUOrder); 2838 switch(id) { 2839 case vmIntrinsics::_loadFence: 2840 insert_mem_bar(Op_LoadFence); 2841 return true; 2842 case vmIntrinsics::_storeFence: 2843 insert_mem_bar(Op_StoreFence); 2844 return true; 2845 case vmIntrinsics::_fullFence: 2846 insert_mem_bar(Op_MemBarVolatile); 2847 return true; 2848 default: 2849 fatal_unexpected_iid(id); 2850 return false; 2851 } 2852 } 2853 2854 bool LibraryCallKit::inline_onspinwait() { 2855 insert_mem_bar(Op_OnSpinWait); 2856 return true; 2857 } 2858 2859 bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 2860 if (!kls->is_Con()) { 2861 return true; 2862 } 2863 const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr(); 2864 if (klsptr == NULL) { 2865 return true; 2866 } 2867 ciInstanceKlass* ik = klsptr->klass()->as_instance_klass(); 2868 // don't need a guard for a klass that is already initialized 2869 return !ik->is_initialized(); 2870 } 2871 2872 //----------------------------inline_unsafe_allocate--------------------------- 2873 // public native Object Unsafe.allocateInstance(Class<?> cls); 2874 bool LibraryCallKit::inline_unsafe_allocate() { 2875 if (callee()->is_static()) return false; // caller must have the capability! 2876 2877 null_check_receiver(); // null-check, then ignore 2878 Node* cls = null_check(argument(1)); 2879 if (stopped()) return true; 2880 2881 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 2882 kls = null_check(kls); 2883 if (stopped()) return true; // argument was like int.class 2884 2885 Node* test = NULL; 2886 if (LibraryCallKit::klass_needs_init_guard(kls)) { 2887 // Note: The argument might still be an illegal value like 2888 // Serializable.class or Object[].class. The runtime will handle it. 2889 // But we must make an explicit check for initialization. 2890 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 2891 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 2892 // can generate code to load it as unsigned byte. 2893 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); 2894 Node* bits = intcon(InstanceKlass::fully_initialized); 2895 test = _gvn.transform(new SubINode(inst, bits)); 2896 // The 'test' is non-zero if we need to take a slow path. 2897 } 2898 2899 Node* obj = new_instance(kls, test); 2900 set_result(obj); 2901 return true; 2902 } 2903 2904 //------------------------inline_native_time_funcs-------------- 2905 // inline code for System.currentTimeMillis() and System.nanoTime() 2906 // these have the same type and signature 2907 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 2908 const TypeFunc* tf = OptoRuntime::void_long_Type(); 2909 const TypePtr* no_memory_effects = NULL; 2910 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 2911 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0)); 2912 #ifdef ASSERT 2913 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1)); 2914 assert(value_top == top(), "second value must be top"); 2915 #endif 2916 set_result(value); 2917 return true; 2918 } 2919 2920 #ifdef JFR_HAVE_INTRINSICS 2921 2922 /* 2923 * oop -> myklass 2924 * myklass->trace_id |= USED 2925 * return myklass->trace_id & ~0x3 2926 */ 2927 bool LibraryCallKit::inline_native_classID() { 2928 Node* cls = null_check(argument(0), T_OBJECT); 2929 Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 2930 kls = null_check(kls, T_OBJECT); 2931 2932 ByteSize offset = KLASS_TRACE_ID_OFFSET; 2933 Node* insp = basic_plus_adr(kls, in_bytes(offset)); 2934 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered); 2935 2936 Node* clsused = longcon(0x01l); // set the class bit 2937 Node* orl = _gvn.transform(new OrLNode(tvalue, clsused)); 2938 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr(); 2939 store_to_memory(control(), insp, orl, T_LONG, adr_type, MemNode::unordered); 2940 2941 #ifdef TRACE_ID_META_BITS 2942 Node* mbits = longcon(~TRACE_ID_META_BITS); 2943 tvalue = _gvn.transform(new AndLNode(tvalue, mbits)); 2944 #endif 2945 #ifdef TRACE_ID_SHIFT 2946 Node* cbits = intcon(TRACE_ID_SHIFT); 2947 tvalue = _gvn.transform(new URShiftLNode(tvalue, cbits)); 2948 #endif 2949 2950 set_result(tvalue); 2951 return true; 2952 2953 } 2954 2955 bool LibraryCallKit::inline_native_getEventWriter() { 2956 Node* tls_ptr = _gvn.transform(new ThreadLocalNode()); 2957 2958 Node* jobj_ptr = basic_plus_adr(top(), tls_ptr, 2959 in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR)); 2960 2961 Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); 2962 2963 Node* jobj_cmp_null = _gvn.transform( new CmpPNode(jobj, null()) ); 2964 Node* test_jobj_eq_null = _gvn.transform( new BoolNode(jobj_cmp_null, BoolTest::eq) ); 2965 2966 IfNode* iff_jobj_null = 2967 create_and_map_if(control(), test_jobj_eq_null, PROB_MIN, COUNT_UNKNOWN); 2968 2969 enum { _normal_path = 1, 2970 _null_path = 2, 2971 PATH_LIMIT }; 2972 2973 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 2974 PhiNode* result_val = new PhiNode(result_rgn, TypeInstPtr::BOTTOM); 2975 2976 Node* jobj_is_null = _gvn.transform(new IfTrueNode(iff_jobj_null)); 2977 result_rgn->init_req(_null_path, jobj_is_null); 2978 result_val->init_req(_null_path, null()); 2979 2980 Node* jobj_is_not_null = _gvn.transform(new IfFalseNode(iff_jobj_null)); 2981 set_control(jobj_is_not_null); 2982 Node* res = access_load(jobj, TypeInstPtr::NOTNULL, T_OBJECT, 2983 IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD); 2984 result_rgn->init_req(_normal_path, control()); 2985 result_val->init_req(_normal_path, res); 2986 2987 set_result(result_rgn, result_val); 2988 2989 return true; 2990 } 2991 2992 #endif // JFR_HAVE_INTRINSICS 2993 2994 //------------------------inline_native_currentThread------------------ 2995 bool LibraryCallKit::inline_native_currentThread() { 2996 Node* junk = NULL; 2997 set_result(generate_current_thread(junk)); 2998 return true; 2999 } 3000 3001 //------------------------inline_native_isInterrupted------------------ 3002 // private native boolean java.lang.Thread.isInterrupted(boolean ClearInterrupted); 3003 bool LibraryCallKit::inline_native_isInterrupted() { 3004 // Add a fast path to t.isInterrupted(clear_int): 3005 // (t == Thread.current() && 3006 // (!TLS._osthread._interrupted || WINDOWS_ONLY(false) NOT_WINDOWS(!clear_int))) 3007 // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int) 3008 // So, in the common case that the interrupt bit is false, 3009 // we avoid making a call into the VM. Even if the interrupt bit 3010 // is true, if the clear_int argument is false, we avoid the VM call. 3011 // However, if the receiver is not currentThread, we must call the VM, 3012 // because there must be some locking done around the operation. 3013 3014 // We only go to the fast case code if we pass two guards. 3015 // Paths which do not pass are accumulated in the slow_region. 3016 3017 enum { 3018 no_int_result_path = 1, // t == Thread.current() && !TLS._osthread._interrupted 3019 no_clear_result_path = 2, // t == Thread.current() && TLS._osthread._interrupted && !clear_int 3020 slow_result_path = 3, // slow path: t.isInterrupted(clear_int) 3021 PATH_LIMIT 3022 }; 3023 3024 // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag 3025 // out of the function. 3026 insert_mem_bar(Op_MemBarCPUOrder); 3027 3028 RegionNode* result_rgn = new RegionNode(PATH_LIMIT); 3029 PhiNode* result_val = new PhiNode(result_rgn, TypeInt::BOOL); 3030 3031 RegionNode* slow_region = new RegionNode(1); 3032 record_for_igvn(slow_region); 3033 3034 // (a) Receiving thread must be the current thread. 3035 Node* rec_thr = argument(0); 3036 Node* tls_ptr = NULL; 3037 Node* cur_thr = generate_current_thread(tls_ptr); 3038 3039 // Resolve oops to stable for CmpP below. 3040 cur_thr = access_resolve(cur_thr, 0); 3041 rec_thr = access_resolve(rec_thr, 0); 3042 3043 Node* cmp_thr = _gvn.transform(new CmpPNode(cur_thr, rec_thr)); 3044 Node* bol_thr = _gvn.transform(new BoolNode(cmp_thr, BoolTest::ne)); 3045 3046 generate_slow_guard(bol_thr, slow_region); 3047 3048 // (b) Interrupt bit on TLS must be false. 3049 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 3050 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3051 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset())); 3052 3053 // Set the control input on the field _interrupted read to prevent it floating up. 3054 Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered); 3055 Node* cmp_bit = _gvn.transform(new CmpINode(int_bit, intcon(0))); 3056 Node* bol_bit = _gvn.transform(new BoolNode(cmp_bit, BoolTest::ne)); 3057 3058 IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 3059 3060 // First fast path: if (!TLS._interrupted) return false; 3061 Node* false_bit = _gvn.transform(new IfFalseNode(iff_bit)); 3062 result_rgn->init_req(no_int_result_path, false_bit); 3063 result_val->init_req(no_int_result_path, intcon(0)); 3064 3065 // drop through to next case 3066 set_control( _gvn.transform(new IfTrueNode(iff_bit))); 3067 3068 #ifndef _WINDOWS 3069 // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path. 3070 Node* clr_arg = argument(1); 3071 Node* cmp_arg = _gvn.transform(new CmpINode(clr_arg, intcon(0))); 3072 Node* bol_arg = _gvn.transform(new BoolNode(cmp_arg, BoolTest::ne)); 3073 IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN); 3074 3075 // Second fast path: ... else if (!clear_int) return true; 3076 Node* false_arg = _gvn.transform(new IfFalseNode(iff_arg)); 3077 result_rgn->init_req(no_clear_result_path, false_arg); 3078 result_val->init_req(no_clear_result_path, intcon(1)); 3079 3080 // drop through to next case 3081 set_control( _gvn.transform(new IfTrueNode(iff_arg))); 3082 #else 3083 // To return true on Windows you must read the _interrupted field 3084 // and check the event state i.e. take the slow path. 3085 #endif // _WINDOWS 3086 3087 // (d) Otherwise, go to the slow path. 3088 slow_region->add_req(control()); 3089 set_control( _gvn.transform(slow_region)); 3090 3091 if (stopped()) { 3092 // There is no slow path. 3093 result_rgn->init_req(slow_result_path, top()); 3094 result_val->init_req(slow_result_path, top()); 3095 } else { 3096 // non-virtual because it is a private non-static 3097 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted); 3098 3099 Node* slow_val = set_results_for_java_call(slow_call); 3100 // this->control() comes from set_results_for_java_call 3101 3102 Node* fast_io = slow_call->in(TypeFunc::I_O); 3103 Node* fast_mem = slow_call->in(TypeFunc::Memory); 3104 3105 // These two phis are pre-filled with copies of of the fast IO and Memory 3106 PhiNode* result_mem = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); 3107 PhiNode* result_io = PhiNode::make(result_rgn, fast_io, Type::ABIO); 3108 3109 result_rgn->init_req(slow_result_path, control()); 3110 result_io ->init_req(slow_result_path, i_o()); 3111 result_mem->init_req(slow_result_path, reset_memory()); 3112 result_val->init_req(slow_result_path, slow_val); 3113 3114 set_all_memory(_gvn.transform(result_mem)); 3115 set_i_o( _gvn.transform(result_io)); 3116 } 3117 3118 C->set_has_split_ifs(true); // Has chance for split-if optimization 3119 set_result(result_rgn, result_val); 3120 return true; 3121 } 3122 3123 //---------------------------load_mirror_from_klass---------------------------- 3124 // Given a klass oop, load its java mirror (a java.lang.Class oop). 3125 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) { 3126 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset())); 3127 Node* load = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3128 // mirror = ((OopHandle)mirror)->resolve(); 3129 return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE); 3130 } 3131 3132 //-----------------------load_klass_from_mirror_common------------------------- 3133 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 3134 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 3135 // and branch to the given path on the region. 3136 // If never_see_null, take an uncommon trap on null, so we can optimistically 3137 // compile for the non-null case. 3138 // If the region is NULL, force never_see_null = true. 3139 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 3140 bool never_see_null, 3141 RegionNode* region, 3142 int null_path, 3143 int offset) { 3144 if (region == NULL) never_see_null = true; 3145 Node* p = basic_plus_adr(mirror, offset); 3146 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3147 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 3148 Node* null_ctl = top(); 3149 kls = null_check_oop(kls, &null_ctl, never_see_null); 3150 if (region != NULL) { 3151 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 3152 region->init_req(null_path, null_ctl); 3153 } else { 3154 assert(null_ctl == top(), "no loose ends"); 3155 } 3156 return kls; 3157 } 3158 3159 //--------------------(inline_native_Class_query helpers)--------------------- 3160 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE_FAST, JVM_ACC_HAS_FINALIZER. 3161 // Fall through if (mods & mask) == bits, take the guard otherwise. 3162 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 3163 // Branch around if the given klass has the given modifier bit set. 3164 // Like generate_guard, adds a new path onto the region. 3165 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 3166 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered); 3167 Node* mask = intcon(modifier_mask); 3168 Node* bits = intcon(modifier_bits); 3169 Node* mbit = _gvn.transform(new AndINode(mods, mask)); 3170 Node* cmp = _gvn.transform(new CmpINode(mbit, bits)); 3171 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne)); 3172 return generate_fair_guard(bol, region); 3173 } 3174 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 3175 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region); 3176 } 3177 3178 //-------------------------inline_native_Class_query------------------- 3179 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 3180 const Type* return_type = TypeInt::BOOL; 3181 Node* prim_return_value = top(); // what happens if it's a primitive class? 3182 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3183 bool expect_prim = false; // most of these guys expect to work on refs 3184 3185 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 3186 3187 Node* mirror = argument(0); 3188 Node* obj = top(); 3189 3190 switch (id) { 3191 case vmIntrinsics::_isInstance: 3192 // nothing is an instance of a primitive type 3193 prim_return_value = intcon(0); 3194 obj = argument(1); 3195 break; 3196 case vmIntrinsics::_getModifiers: 3197 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 3198 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line"); 3199 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin); 3200 break; 3201 case vmIntrinsics::_isInterface: 3202 prim_return_value = intcon(0); 3203 break; 3204 case vmIntrinsics::_isArray: 3205 prim_return_value = intcon(0); 3206 expect_prim = true; // cf. ObjectStreamClass.getClassSignature 3207 break; 3208 case vmIntrinsics::_isPrimitive: 3209 prim_return_value = intcon(1); 3210 expect_prim = true; // obviously 3211 break; 3212 case vmIntrinsics::_getSuperclass: 3213 prim_return_value = null(); 3214 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 3215 break; 3216 case vmIntrinsics::_getClassAccessFlags: 3217 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 3218 return_type = TypeInt::INT; // not bool! 6297094 3219 break; 3220 default: 3221 fatal_unexpected_iid(id); 3222 break; 3223 } 3224 3225 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 3226 if (mirror_con == NULL) return false; // cannot happen? 3227 3228 #ifndef PRODUCT 3229 if (C->print_intrinsics() || C->print_inlining()) { 3230 ciType* k = mirror_con->java_mirror_type(); 3231 if (k) { 3232 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 3233 k->print_name(); 3234 tty->cr(); 3235 } 3236 } 3237 #endif 3238 3239 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 3240 RegionNode* region = new RegionNode(PATH_LIMIT); 3241 record_for_igvn(region); 3242 PhiNode* phi = new PhiNode(region, return_type); 3243 3244 // The mirror will never be null of Reflection.getClassAccessFlags, however 3245 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 3246 // if it is. See bug 4774291. 3247 3248 // For Reflection.getClassAccessFlags(), the null check occurs in 3249 // the wrong place; see inline_unsafe_access(), above, for a similar 3250 // situation. 3251 mirror = null_check(mirror); 3252 // If mirror or obj is dead, only null-path is taken. 3253 if (stopped()) return true; 3254 3255 if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 3256 3257 // Now load the mirror's klass metaobject, and null-check it. 3258 // Side-effects region with the control path if the klass is null. 3259 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 3260 // If kls is null, we have a primitive mirror. 3261 phi->init_req(_prim_path, prim_return_value); 3262 if (stopped()) { set_result(region, phi); return true; } 3263 bool safe_for_replace = (region->in(_prim_path) == top()); 3264 3265 Node* p; // handy temp 3266 Node* null_ctl; 3267 3268 // Now that we have the non-null klass, we can perform the real query. 3269 // For constant classes, the query will constant-fold in LoadNode::Value. 3270 Node* query_value = top(); 3271 switch (id) { 3272 case vmIntrinsics::_isInstance: 3273 // nothing is an instance of a primitive type 3274 query_value = gen_instanceof(obj, kls, safe_for_replace); 3275 break; 3276 3277 case vmIntrinsics::_getModifiers: 3278 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset())); 3279 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 3280 break; 3281 3282 case vmIntrinsics::_isInterface: 3283 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 3284 if (generate_interface_guard(kls, region) != NULL) 3285 // A guard was added. If the guard is taken, it was an interface. 3286 phi->add_req(intcon(1)); 3287 // If we fall through, it's a plain class. 3288 query_value = intcon(0); 3289 break; 3290 3291 case vmIntrinsics::_isArray: 3292 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.) 3293 if (generate_array_guard(kls, region) != NULL) 3294 // A guard was added. If the guard is taken, it was an array. 3295 phi->add_req(intcon(1)); 3296 // If we fall through, it's a plain class. 3297 query_value = intcon(0); 3298 break; 3299 3300 case vmIntrinsics::_isPrimitive: 3301 query_value = intcon(0); // "normal" path produces false 3302 break; 3303 3304 case vmIntrinsics::_getSuperclass: 3305 // The rules here are somewhat unfortunate, but we can still do better 3306 // with random logic than with a JNI call. 3307 // Interfaces store null or Object as _super, but must report null. 3308 // Arrays store an intermediate super as _super, but must report Object. 3309 // Other types can report the actual _super. 3310 // (To verify this code sequence, check the asserts in JVM_IsInterface.) 3311 if (generate_interface_guard(kls, region) != NULL) 3312 // A guard was added. If the guard is taken, it was an interface. 3313 phi->add_req(null()); 3314 if (generate_array_guard(kls, region) != NULL) 3315 // A guard was added. If the guard is taken, it was an array. 3316 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 3317 // If we fall through, it's a plain class. Get its _super. 3318 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 3319 kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 3320 null_ctl = top(); 3321 kls = null_check_oop(kls, &null_ctl); 3322 if (null_ctl != top()) { 3323 // If the guard is taken, Object.superClass is null (both klass and mirror). 3324 region->add_req(null_ctl); 3325 phi ->add_req(null()); 3326 } 3327 if (!stopped()) { 3328 query_value = load_mirror_from_klass(kls); 3329 } 3330 break; 3331 3332 case vmIntrinsics::_getClassAccessFlags: 3333 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 3334 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 3335 break; 3336 3337 default: 3338 fatal_unexpected_iid(id); 3339 break; 3340 } 3341 3342 // Fall-through is the normal case of a query to a real class. 3343 phi->init_req(1, query_value); 3344 region->init_req(1, control()); 3345 3346 C->set_has_split_ifs(true); // Has chance for split-if optimization 3347 set_result(region, phi); 3348 return true; 3349 } 3350 3351 //-------------------------inline_Class_cast------------------- 3352 bool LibraryCallKit::inline_Class_cast() { 3353 Node* mirror = argument(0); // Class 3354 Node* obj = argument(1); 3355 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 3356 if (mirror_con == NULL) { 3357 return false; // dead path (mirror->is_top()). 3358 } 3359 if (obj == NULL || obj->is_top()) { 3360 return false; // dead path 3361 } 3362 const TypeOopPtr* tp = _gvn.type(obj)->isa_oopptr(); 3363 3364 // First, see if Class.cast() can be folded statically. 3365 // java_mirror_type() returns non-null for compile-time Class constants. 3366 ciType* tm = mirror_con->java_mirror_type(); 3367 if (tm != NULL && tm->is_klass() && 3368 tp != NULL && tp->klass() != NULL) { 3369 if (!tp->klass()->is_loaded()) { 3370 // Don't use intrinsic when class is not loaded. 3371 return false; 3372 } else { 3373 int static_res = C->static_subtype_check(tm->as_klass(), tp->klass()); 3374 if (static_res == Compile::SSC_always_true) { 3375 // isInstance() is true - fold the code. 3376 set_result(obj); 3377 return true; 3378 } else if (static_res == Compile::SSC_always_false) { 3379 // Don't use intrinsic, have to throw ClassCastException. 3380 // If the reference is null, the non-intrinsic bytecode will 3381 // be optimized appropriately. 3382 return false; 3383 } 3384 } 3385 } 3386 3387 // Bailout intrinsic and do normal inlining if exception path is frequent. 3388 if (too_many_traps(Deoptimization::Reason_intrinsic)) { 3389 return false; 3390 } 3391 3392 // Generate dynamic checks. 3393 // Class.cast() is java implementation of _checkcast bytecode. 3394 // Do checkcast (Parse::do_checkcast()) optimizations here. 3395 3396 mirror = null_check(mirror); 3397 // If mirror is dead, only null-path is taken. 3398 if (stopped()) { 3399 return true; 3400 } 3401 3402 // Not-subtype or the mirror's klass ptr is NULL (in case it is a primitive). 3403 enum { _bad_type_path = 1, _prim_path = 2, PATH_LIMIT }; 3404 RegionNode* region = new RegionNode(PATH_LIMIT); 3405 record_for_igvn(region); 3406 3407 // Now load the mirror's klass metaobject, and null-check it. 3408 // If kls is null, we have a primitive mirror and 3409 // nothing is an instance of a primitive type. 3410 Node* kls = load_klass_from_mirror(mirror, false, region, _prim_path); 3411 3412 Node* res = top(); 3413 if (!stopped()) { 3414 Node* bad_type_ctrl = top(); 3415 // Do checkcast optimizations. 3416 res = gen_checkcast(obj, kls, &bad_type_ctrl); 3417 region->init_req(_bad_type_path, bad_type_ctrl); 3418 } 3419 if (region->in(_prim_path) != top() || 3420 region->in(_bad_type_path) != top()) { 3421 // Let Interpreter throw ClassCastException. 3422 PreserveJVMState pjvms(this); 3423 set_control(_gvn.transform(region)); 3424 uncommon_trap(Deoptimization::Reason_intrinsic, 3425 Deoptimization::Action_maybe_recompile); 3426 } 3427 if (!stopped()) { 3428 set_result(res); 3429 } 3430 return true; 3431 } 3432 3433 3434 //--------------------------inline_native_subtype_check------------------------ 3435 // This intrinsic takes the JNI calls out of the heart of 3436 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 3437 bool LibraryCallKit::inline_native_subtype_check() { 3438 // Pull both arguments off the stack. 3439 Node* args[2]; // two java.lang.Class mirrors: superc, subc 3440 args[0] = argument(0); 3441 args[1] = argument(1); 3442 Node* klasses[2]; // corresponding Klasses: superk, subk 3443 klasses[0] = klasses[1] = top(); 3444 3445 enum { 3446 // A full decision tree on {superc is prim, subc is prim}: 3447 _prim_0_path = 1, // {P,N} => false 3448 // {P,P} & superc!=subc => false 3449 _prim_same_path, // {P,P} & superc==subc => true 3450 _prim_1_path, // {N,P} => false 3451 _ref_subtype_path, // {N,N} & subtype check wins => true 3452 _both_ref_path, // {N,N} & subtype check loses => false 3453 PATH_LIMIT 3454 }; 3455 3456 RegionNode* region = new RegionNode(PATH_LIMIT); 3457 Node* phi = new PhiNode(region, TypeInt::BOOL); 3458 record_for_igvn(region); 3459 3460 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 3461 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3462 int class_klass_offset = java_lang_Class::klass_offset_in_bytes(); 3463 3464 // First null-check both mirrors and load each mirror's klass metaobject. 3465 int which_arg; 3466 for (which_arg = 0; which_arg <= 1; which_arg++) { 3467 Node* arg = args[which_arg]; 3468 arg = null_check(arg); 3469 if (stopped()) break; 3470 args[which_arg] = arg; 3471 3472 Node* p = basic_plus_adr(arg, class_klass_offset); 3473 Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type); 3474 klasses[which_arg] = _gvn.transform(kls); 3475 } 3476 3477 // Resolve oops to stable for CmpP below. 3478 args[0] = access_resolve(args[0], 0); 3479 args[1] = access_resolve(args[1], 0); 3480 3481 // Having loaded both klasses, test each for null. 3482 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3483 for (which_arg = 0; which_arg <= 1; which_arg++) { 3484 Node* kls = klasses[which_arg]; 3485 Node* null_ctl = top(); 3486 kls = null_check_oop(kls, &null_ctl, never_see_null); 3487 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path); 3488 region->init_req(prim_path, null_ctl); 3489 if (stopped()) break; 3490 klasses[which_arg] = kls; 3491 } 3492 3493 if (!stopped()) { 3494 // now we have two reference types, in klasses[0..1] 3495 Node* subk = klasses[1]; // the argument to isAssignableFrom 3496 Node* superk = klasses[0]; // the receiver 3497 region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 3498 // now we have a successful reference subtype check 3499 region->set_req(_ref_subtype_path, control()); 3500 } 3501 3502 // If both operands are primitive (both klasses null), then 3503 // we must return true when they are identical primitives. 3504 // It is convenient to test this after the first null klass check. 3505 set_control(region->in(_prim_0_path)); // go back to first null check 3506 if (!stopped()) { 3507 // Since superc is primitive, make a guard for the superc==subc case. 3508 Node* cmp_eq = _gvn.transform(new CmpPNode(args[0], args[1])); 3509 Node* bol_eq = _gvn.transform(new BoolNode(cmp_eq, BoolTest::eq)); 3510 generate_guard(bol_eq, region, PROB_FAIR); 3511 if (region->req() == PATH_LIMIT+1) { 3512 // A guard was added. If the added guard is taken, superc==subc. 3513 region->swap_edges(PATH_LIMIT, _prim_same_path); 3514 region->del_req(PATH_LIMIT); 3515 } 3516 region->set_req(_prim_0_path, control()); // Not equal after all. 3517 } 3518 3519 // these are the only paths that produce 'true': 3520 phi->set_req(_prim_same_path, intcon(1)); 3521 phi->set_req(_ref_subtype_path, intcon(1)); 3522 3523 // pull together the cases: 3524 assert(region->req() == PATH_LIMIT, "sane region"); 3525 for (uint i = 1; i < region->req(); i++) { 3526 Node* ctl = region->in(i); 3527 if (ctl == NULL || ctl == top()) { 3528 region->set_req(i, top()); 3529 phi ->set_req(i, top()); 3530 } else if (phi->in(i) == NULL) { 3531 phi->set_req(i, intcon(0)); // all other paths produce 'false' 3532 } 3533 } 3534 3535 set_control(_gvn.transform(region)); 3536 set_result(_gvn.transform(phi)); 3537 return true; 3538 } 3539 3540 //---------------------generate_array_guard_common------------------------ 3541 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, 3542 bool obj_array, bool not_array) { 3543 3544 if (stopped()) { 3545 return NULL; 3546 } 3547 3548 // If obj_array/non_array==false/false: 3549 // Branch around if the given klass is in fact an array (either obj or prim). 3550 // If obj_array/non_array==false/true: 3551 // Branch around if the given klass is not an array klass of any kind. 3552 // If obj_array/non_array==true/true: 3553 // Branch around if the kls is not an oop array (kls is int[], String, etc.) 3554 // If obj_array/non_array==true/false: 3555 // Branch around if the kls is an oop array (Object[] or subtype) 3556 // 3557 // Like generate_guard, adds a new path onto the region. 3558 jint layout_con = 0; 3559 Node* layout_val = get_layout_helper(kls, layout_con); 3560 if (layout_val == NULL) { 3561 bool query = (obj_array 3562 ? Klass::layout_helper_is_objArray(layout_con) 3563 : Klass::layout_helper_is_array(layout_con)); 3564 if (query == not_array) { 3565 return NULL; // never a branch 3566 } else { // always a branch 3567 Node* always_branch = control(); 3568 if (region != NULL) 3569 region->add_req(always_branch); 3570 set_control(top()); 3571 return always_branch; 3572 } 3573 } 3574 // Now test the correct condition. 3575 jint nval = (obj_array 3576 ? (jint)(Klass::_lh_array_tag_type_value 3577 << Klass::_lh_array_tag_shift) 3578 : Klass::_lh_neutral_value); 3579 Node* cmp = _gvn.transform(new CmpINode(layout_val, intcon(nval))); 3580 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array 3581 // invert the test if we are looking for a non-array 3582 if (not_array) btest = BoolTest(btest).negate(); 3583 Node* bol = _gvn.transform(new BoolNode(cmp, btest)); 3584 return generate_fair_guard(bol, region); 3585 } 3586 3587 3588 //-----------------------inline_native_newArray-------------------------- 3589 // private static native Object java.lang.reflect.newArray(Class<?> componentType, int length); 3590 // private native Object Unsafe.allocateUninitializedArray0(Class<?> cls, int size); 3591 bool LibraryCallKit::inline_unsafe_newArray(bool uninitialized) { 3592 Node* mirror; 3593 Node* count_val; 3594 if (uninitialized) { 3595 mirror = argument(1); 3596 count_val = argument(2); 3597 } else { 3598 mirror = argument(0); 3599 count_val = argument(1); 3600 } 3601 3602 mirror = null_check(mirror); 3603 // If mirror or obj is dead, only null-path is taken. 3604 if (stopped()) return true; 3605 3606 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 3607 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 3608 PhiNode* result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 3609 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 3610 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 3611 3612 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3613 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 3614 result_reg, _slow_path); 3615 Node* normal_ctl = control(); 3616 Node* no_array_ctl = result_reg->in(_slow_path); 3617 3618 // Generate code for the slow case. We make a call to newArray(). 3619 set_control(no_array_ctl); 3620 if (!stopped()) { 3621 // Either the input type is void.class, or else the 3622 // array klass has not yet been cached. Either the 3623 // ensuing call will throw an exception, or else it 3624 // will cache the array klass for next time. 3625 PreserveJVMState pjvms(this); 3626 CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray); 3627 Node* slow_result = set_results_for_java_call(slow_call); 3628 // this->control() comes from set_results_for_java_call 3629 result_reg->set_req(_slow_path, control()); 3630 result_val->set_req(_slow_path, slow_result); 3631 result_io ->set_req(_slow_path, i_o()); 3632 result_mem->set_req(_slow_path, reset_memory()); 3633 } 3634 3635 set_control(normal_ctl); 3636 if (!stopped()) { 3637 // Normal case: The array type has been cached in the java.lang.Class. 3638 // The following call works fine even if the array type is polymorphic. 3639 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3640 Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 3641 result_reg->init_req(_normal_path, control()); 3642 result_val->init_req(_normal_path, obj); 3643 result_io ->init_req(_normal_path, i_o()); 3644 result_mem->init_req(_normal_path, reset_memory()); 3645 3646 if (uninitialized) { 3647 // Mark the allocation so that zeroing is skipped 3648 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(obj, &_gvn); 3649 alloc->maybe_set_complete(&_gvn); 3650 } 3651 } 3652 3653 // Return the combined state. 3654 set_i_o( _gvn.transform(result_io) ); 3655 set_all_memory( _gvn.transform(result_mem)); 3656 3657 C->set_has_split_ifs(true); // Has chance for split-if optimization 3658 set_result(result_reg, result_val); 3659 return true; 3660 } 3661 3662 //----------------------inline_native_getLength-------------------------- 3663 // public static native int java.lang.reflect.Array.getLength(Object array); 3664 bool LibraryCallKit::inline_native_getLength() { 3665 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3666 3667 Node* array = null_check(argument(0)); 3668 // If array is dead, only null-path is taken. 3669 if (stopped()) return true; 3670 3671 // Deoptimize if it is a non-array. 3672 Node* non_array = generate_non_array_guard(load_object_klass(array), NULL); 3673 3674 if (non_array != NULL) { 3675 PreserveJVMState pjvms(this); 3676 set_control(non_array); 3677 uncommon_trap(Deoptimization::Reason_intrinsic, 3678 Deoptimization::Action_maybe_recompile); 3679 } 3680 3681 // If control is dead, only non-array-path is taken. 3682 if (stopped()) return true; 3683 3684 // The works fine even if the array type is polymorphic. 3685 // It could be a dynamic mix of int[], boolean[], Object[], etc. 3686 Node* result = load_array_length(array); 3687 3688 C->set_has_split_ifs(true); // Has chance for split-if optimization 3689 set_result(result); 3690 return true; 3691 } 3692 3693 //------------------------inline_array_copyOf---------------------------- 3694 // public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 3695 // public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 3696 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 3697 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 3698 3699 // Get the arguments. 3700 Node* original = argument(0); 3701 Node* start = is_copyOfRange? argument(1): intcon(0); 3702 Node* end = is_copyOfRange? argument(2): argument(1); 3703 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 3704 3705 Node* newcopy = NULL; 3706 3707 // Set the original stack and the reexecute bit for the interpreter to reexecute 3708 // the bytecode that invokes Arrays.copyOf if deoptimization happens. 3709 { PreserveReexecuteState preexecs(this); 3710 jvms()->set_should_reexecute(true); 3711 3712 array_type_mirror = null_check(array_type_mirror); 3713 original = null_check(original); 3714 3715 // Check if a null path was taken unconditionally. 3716 if (stopped()) return true; 3717 3718 Node* orig_length = load_array_length(original); 3719 3720 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, NULL, 0); 3721 klass_node = null_check(klass_node); 3722 3723 RegionNode* bailout = new RegionNode(1); 3724 record_for_igvn(bailout); 3725 3726 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 3727 // Bail out if that is so. 3728 Node* not_objArray = generate_non_objArray_guard(klass_node, bailout); 3729 if (not_objArray != NULL) { 3730 // Improve the klass node's type from the new optimistic assumption: 3731 ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 3732 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); 3733 Node* cast = new CastPPNode(klass_node, akls); 3734 cast->init_req(0, control()); 3735 klass_node = _gvn.transform(cast); 3736 } 3737 3738 // Bail out if either start or end is negative. 3739 generate_negative_guard(start, bailout, &start); 3740 generate_negative_guard(end, bailout, &end); 3741 3742 Node* length = end; 3743 if (_gvn.type(start) != TypeInt::ZERO) { 3744 length = _gvn.transform(new SubINode(end, start)); 3745 } 3746 3747 // Bail out if length is negative. 3748 // Without this the new_array would throw 3749 // NegativeArraySizeException but IllegalArgumentException is what 3750 // should be thrown 3751 generate_negative_guard(length, bailout, &length); 3752 3753 if (bailout->req() > 1) { 3754 PreserveJVMState pjvms(this); 3755 set_control(_gvn.transform(bailout)); 3756 uncommon_trap(Deoptimization::Reason_intrinsic, 3757 Deoptimization::Action_maybe_recompile); 3758 } 3759 3760 if (!stopped()) { 3761 // How many elements will we copy from the original? 3762 // The answer is MinI(orig_length - start, length). 3763 Node* orig_tail = _gvn.transform(new SubINode(orig_length, start)); 3764 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); 3765 3766 original = access_resolve(original, ACCESS_READ); 3767 3768 // Generate a direct call to the right arraycopy function(s). 3769 // We know the copy is disjoint but we might not know if the 3770 // oop stores need checking. 3771 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 3772 // This will fail a store-check if x contains any non-nulls. 3773 3774 // ArrayCopyNode:Ideal may transform the ArrayCopyNode to 3775 // loads/stores but it is legal only if we're sure the 3776 // Arrays.copyOf would succeed. So we need all input arguments 3777 // to the copyOf to be validated, including that the copy to the 3778 // new array won't trigger an ArrayStoreException. That subtype 3779 // check can be optimized if we know something on the type of 3780 // the input array from type speculation. 3781 if (_gvn.type(klass_node)->singleton()) { 3782 ciKlass* subk = _gvn.type(load_object_klass(original))->is_klassptr()->klass(); 3783 ciKlass* superk = _gvn.type(klass_node)->is_klassptr()->klass(); 3784 3785 int test = C->static_subtype_check(superk, subk); 3786 if (test != Compile::SSC_always_true && test != Compile::SSC_always_false) { 3787 const TypeOopPtr* t_original = _gvn.type(original)->is_oopptr(); 3788 if (t_original->speculative_type() != NULL) { 3789 original = maybe_cast_profiled_obj(original, t_original->speculative_type(), true); 3790 } 3791 } 3792 } 3793 3794 bool validated = false; 3795 // Reason_class_check rather than Reason_intrinsic because we 3796 // want to intrinsify even if this traps. 3797 if (!too_many_traps(Deoptimization::Reason_class_check)) { 3798 Node* not_subtype_ctrl = gen_subtype_check(load_object_klass(original), 3799 klass_node); 3800 3801 if (not_subtype_ctrl != top()) { 3802 PreserveJVMState pjvms(this); 3803 set_control(not_subtype_ctrl); 3804 uncommon_trap(Deoptimization::Reason_class_check, 3805 Deoptimization::Action_make_not_entrant); 3806 assert(stopped(), "Should be stopped"); 3807 } 3808 validated = true; 3809 } 3810 3811 if (!stopped()) { 3812 newcopy = new_array(klass_node, length, 0); // no arguments to push 3813 3814 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, original, start, newcopy, intcon(0), moved, true, false, 3815 load_object_klass(original), klass_node); 3816 if (!is_copyOfRange) { 3817 ac->set_copyof(validated); 3818 } else { 3819 ac->set_copyofrange(validated); 3820 } 3821 Node* n = _gvn.transform(ac); 3822 if (n == ac) { 3823 ac->connect_outputs(this); 3824 } else { 3825 assert(validated, "shouldn't transform if all arguments not validated"); 3826 set_all_memory(n); 3827 } 3828 } 3829 } 3830 } // original reexecute is set back here 3831 3832 C->set_has_split_ifs(true); // Has chance for split-if optimization 3833 if (!stopped()) { 3834 set_result(newcopy); 3835 } 3836 return true; 3837 } 3838 3839 3840 //----------------------generate_virtual_guard--------------------------- 3841 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 3842 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 3843 RegionNode* slow_region) { 3844 ciMethod* method = callee(); 3845 int vtable_index = method->vtable_index(); 3846 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3847 "bad index %d", vtable_index); 3848 // Get the Method* out of the appropriate vtable entry. 3849 int entry_offset = in_bytes(Klass::vtable_start_offset()) + 3850 vtable_index*vtableEntry::size_in_bytes() + 3851 vtableEntry::method_offset_in_bytes(); 3852 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 3853 Node* target_call = make_load(NULL, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 3854 3855 // Compare the target method with the expected method (e.g., Object.hashCode). 3856 const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 3857 3858 Node* native_call = makecon(native_call_addr); 3859 Node* chk_native = _gvn.transform(new CmpPNode(target_call, native_call)); 3860 Node* test_native = _gvn.transform(new BoolNode(chk_native, BoolTest::ne)); 3861 3862 return generate_slow_guard(test_native, slow_region); 3863 } 3864 3865 //-----------------------generate_method_call---------------------------- 3866 // Use generate_method_call to make a slow-call to the real 3867 // method if the fast path fails. An alternative would be to 3868 // use a stub like OptoRuntime::slow_arraycopy_Java. 3869 // This only works for expanding the current library call, 3870 // not another intrinsic. (E.g., don't use this for making an 3871 // arraycopy call inside of the copyOf intrinsic.) 3872 CallJavaNode* 3873 LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) { 3874 // When compiling the intrinsic method itself, do not use this technique. 3875 guarantee(callee() != C->method(), "cannot make slow-call to self"); 3876 3877 ciMethod* method = callee(); 3878 // ensure the JVMS we have will be correct for this call 3879 guarantee(method_id == method->intrinsic_id(), "must match"); 3880 3881 const TypeFunc* tf = TypeFunc::make(method); 3882 CallJavaNode* slow_call; 3883 if (is_static) { 3884 assert(!is_virtual, ""); 3885 slow_call = new CallStaticJavaNode(C, tf, 3886 SharedRuntime::get_resolve_static_call_stub(), 3887 method, bci()); 3888 } else if (is_virtual) { 3889 null_check_receiver(); 3890 int vtable_index = Method::invalid_vtable_index; 3891 if (UseInlineCaches) { 3892 // Suppress the vtable call 3893 } else { 3894 // hashCode and clone are not a miranda methods, 3895 // so the vtable index is fixed. 3896 // No need to use the linkResolver to get it. 3897 vtable_index = method->vtable_index(); 3898 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 3899 "bad index %d", vtable_index); 3900 } 3901 slow_call = new CallDynamicJavaNode(tf, 3902 SharedRuntime::get_resolve_virtual_call_stub(), 3903 method, vtable_index, bci()); 3904 } else { // neither virtual nor static: opt_virtual 3905 null_check_receiver(); 3906 slow_call = new CallStaticJavaNode(C, tf, 3907 SharedRuntime::get_resolve_opt_virtual_call_stub(), 3908 method, bci()); 3909 slow_call->set_optimized_virtual(true); 3910 } 3911 if (CallGenerator::is_inlined_method_handle_intrinsic(this->method(), bci(), callee())) { 3912 // To be able to issue a direct call (optimized virtual or virtual) 3913 // and skip a call to MH.linkTo*/invokeBasic adapter, additional information 3914 // about the method being invoked should be attached to the call site to 3915 // make resolution logic work (see SharedRuntime::resolve_{virtual,opt_virtual}_call_C). 3916 slow_call->set_override_symbolic_info(true); 3917 } 3918 set_arguments_for_java_call(slow_call); 3919 set_edges_for_java_call(slow_call); 3920 return slow_call; 3921 } 3922 3923 3924 /** 3925 * Build special case code for calls to hashCode on an object. This call may 3926 * be virtual (invokevirtual) or bound (invokespecial). For each case we generate 3927 * slightly different code. 3928 */ 3929 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 3930 assert(is_static == callee()->is_static(), "correct intrinsic selection"); 3931 assert(!(is_virtual && is_static), "either virtual, special, or static"); 3932 3933 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 3934 3935 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 3936 PhiNode* result_val = new PhiNode(result_reg, TypeInt::INT); 3937 PhiNode* result_io = new PhiNode(result_reg, Type::ABIO); 3938 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 3939 Node* obj = NULL; 3940 if (!is_static) { 3941 // Check for hashing null object 3942 obj = null_check_receiver(); 3943 if (stopped()) return true; // unconditionally null 3944 result_reg->init_req(_null_path, top()); 3945 result_val->init_req(_null_path, top()); 3946 } else { 3947 // Do a null check, and return zero if null. 3948 // System.identityHashCode(null) == 0 3949 obj = argument(0); 3950 Node* null_ctl = top(); 3951 obj = null_check_oop(obj, &null_ctl); 3952 result_reg->init_req(_null_path, null_ctl); 3953 result_val->init_req(_null_path, _gvn.intcon(0)); 3954 } 3955 3956 // Unconditionally null? Then return right away. 3957 if (stopped()) { 3958 set_control( result_reg->in(_null_path)); 3959 if (!stopped()) 3960 set_result(result_val->in(_null_path)); 3961 return true; 3962 } 3963 3964 // We only go to the fast case code if we pass a number of guards. The 3965 // paths which do not pass are accumulated in the slow_region. 3966 RegionNode* slow_region = new RegionNode(1); 3967 record_for_igvn(slow_region); 3968 3969 // If this is a virtual call, we generate a funny guard. We pull out 3970 // the vtable entry corresponding to hashCode() from the target object. 3971 // If the target method which we are calling happens to be the native 3972 // Object hashCode() method, we pass the guard. We do not need this 3973 // guard for non-virtual calls -- the caller is known to be the native 3974 // Object hashCode(). 3975 if (is_virtual) { 3976 // After null check, get the object's klass. 3977 Node* obj_klass = load_object_klass(obj); 3978 generate_virtual_guard(obj_klass, slow_region); 3979 } 3980 3981 // Get the header out of the object, use LoadMarkNode when available 3982 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 3983 // The control of the load must be NULL. Otherwise, the load can move before 3984 // the null check after castPP removal. 3985 Node* no_ctrl = NULL; 3986 Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 3987 3988 // Test the header to see if it is unlocked. 3989 Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); 3990 Node *lmasked_header = _gvn.transform(new AndXNode(header, lock_mask)); 3991 Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); 3992 Node *chk_unlocked = _gvn.transform(new CmpXNode( lmasked_header, unlocked_val)); 3993 Node *test_unlocked = _gvn.transform(new BoolNode( chk_unlocked, BoolTest::ne)); 3994 3995 generate_slow_guard(test_unlocked, slow_region); 3996 3997 // Get the hash value and check to see that it has been properly assigned. 3998 // We depend on hash_mask being at most 32 bits and avoid the use of 3999 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 4000 // vm: see markOop.hpp. 4001 Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask); 4002 Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift); 4003 Node *hshifted_header= _gvn.transform(new URShiftXNode(header, hash_shift)); 4004 // This hack lets the hash bits live anywhere in the mark object now, as long 4005 // as the shift drops the relevant bits into the low 32 bits. Note that 4006 // Java spec says that HashCode is an int so there's no point in capturing 4007 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 4008 hshifted_header = ConvX2I(hshifted_header); 4009 Node *hash_val = _gvn.transform(new AndINode(hshifted_header, hash_mask)); 4010 4011 Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash); 4012 Node *chk_assigned = _gvn.transform(new CmpINode( hash_val, no_hash_val)); 4013 Node *test_assigned = _gvn.transform(new BoolNode( chk_assigned, BoolTest::eq)); 4014 4015 generate_slow_guard(test_assigned, slow_region); 4016 4017 Node* init_mem = reset_memory(); 4018 // fill in the rest of the null path: 4019 result_io ->init_req(_null_path, i_o()); 4020 result_mem->init_req(_null_path, init_mem); 4021 4022 result_val->init_req(_fast_path, hash_val); 4023 result_reg->init_req(_fast_path, control()); 4024 result_io ->init_req(_fast_path, i_o()); 4025 result_mem->init_req(_fast_path, init_mem); 4026 4027 // Generate code for the slow case. We make a call to hashCode(). 4028 set_control(_gvn.transform(slow_region)); 4029 if (!stopped()) { 4030 // No need for PreserveJVMState, because we're using up the present state. 4031 set_all_memory(init_mem); 4032 vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 4033 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static); 4034 Node* slow_result = set_results_for_java_call(slow_call); 4035 // this->control() comes from set_results_for_java_call 4036 result_reg->init_req(_slow_path, control()); 4037 result_val->init_req(_slow_path, slow_result); 4038 result_io ->set_req(_slow_path, i_o()); 4039 result_mem ->set_req(_slow_path, reset_memory()); 4040 } 4041 4042 // Return the combined state. 4043 set_i_o( _gvn.transform(result_io) ); 4044 set_all_memory( _gvn.transform(result_mem)); 4045 4046 set_result(result_reg, result_val); 4047 return true; 4048 } 4049 4050 //---------------------------inline_native_getClass---------------------------- 4051 // public final native Class<?> java.lang.Object.getClass(); 4052 // 4053 // Build special case code for calls to getClass on an object. 4054 bool LibraryCallKit::inline_native_getClass() { 4055 Node* obj = null_check_receiver(); 4056 if (stopped()) return true; 4057 set_result(load_mirror_from_klass(load_object_klass(obj))); 4058 return true; 4059 } 4060 4061 //-----------------inline_native_Reflection_getCallerClass--------------------- 4062 // public static native Class<?> sun.reflect.Reflection.getCallerClass(); 4063 // 4064 // In the presence of deep enough inlining, getCallerClass() becomes a no-op. 4065 // 4066 // NOTE: This code must perform the same logic as JVM_GetCallerClass 4067 // in that it must skip particular security frames and checks for 4068 // caller sensitive methods. 4069 bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 4070 #ifndef PRODUCT 4071 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4072 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 4073 } 4074 #endif 4075 4076 if (!jvms()->has_method()) { 4077 #ifndef PRODUCT 4078 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4079 tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 4080 } 4081 #endif 4082 return false; 4083 } 4084 4085 // Walk back up the JVM state to find the caller at the required 4086 // depth. 4087 JVMState* caller_jvms = jvms(); 4088 4089 // Cf. JVM_GetCallerClass 4090 // NOTE: Start the loop at depth 1 because the current JVM state does 4091 // not include the Reflection.getCallerClass() frame. 4092 for (int n = 1; caller_jvms != NULL; caller_jvms = caller_jvms->caller(), n++) { 4093 ciMethod* m = caller_jvms->method(); 4094 switch (n) { 4095 case 0: 4096 fatal("current JVM state does not include the Reflection.getCallerClass frame"); 4097 break; 4098 case 1: 4099 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 4100 if (!m->caller_sensitive()) { 4101 #ifndef PRODUCT 4102 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4103 tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 4104 } 4105 #endif 4106 return false; // bail-out; let JVM_GetCallerClass do the work 4107 } 4108 break; 4109 default: 4110 if (!m->is_ignored_by_security_stack_walk()) { 4111 // We have reached the desired frame; return the holder class. 4112 // Acquire method holder as java.lang.Class and push as constant. 4113 ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 4114 ciInstance* caller_mirror = caller_klass->java_mirror(); 4115 set_result(makecon(TypeInstPtr::make(caller_mirror))); 4116 4117 #ifndef PRODUCT 4118 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4119 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()); 4120 tty->print_cr(" JVM state at this point:"); 4121 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 4122 ciMethod* m = jvms()->of_depth(i)->method(); 4123 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 4124 } 4125 } 4126 #endif 4127 return true; 4128 } 4129 break; 4130 } 4131 } 4132 4133 #ifndef PRODUCT 4134 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 4135 tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 4136 tty->print_cr(" JVM state at this point:"); 4137 for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 4138 ciMethod* m = jvms()->of_depth(i)->method(); 4139 tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 4140 } 4141 } 4142 #endif 4143 4144 return false; // bail-out; let JVM_GetCallerClass do the work 4145 } 4146 4147 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 4148 Node* arg = argument(0); 4149 Node* result = NULL; 4150 4151 switch (id) { 4152 case vmIntrinsics::_floatToRawIntBits: result = new MoveF2INode(arg); break; 4153 case vmIntrinsics::_intBitsToFloat: result = new MoveI2FNode(arg); break; 4154 case vmIntrinsics::_doubleToRawLongBits: result = new MoveD2LNode(arg); break; 4155 case vmIntrinsics::_longBitsToDouble: result = new MoveL2DNode(arg); break; 4156 4157 case vmIntrinsics::_doubleToLongBits: { 4158 // two paths (plus control) merge in a wood 4159 RegionNode *r = new RegionNode(3); 4160 Node *phi = new PhiNode(r, TypeLong::LONG); 4161 4162 Node *cmpisnan = _gvn.transform(new CmpDNode(arg, arg)); 4163 // Build the boolean node 4164 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 4165 4166 // Branch either way. 4167 // NaN case is less traveled, which makes all the difference. 4168 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 4169 Node *opt_isnan = _gvn.transform(ifisnan); 4170 assert( opt_isnan->is_If(), "Expect an IfNode"); 4171 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 4172 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 4173 4174 set_control(iftrue); 4175 4176 static const jlong nan_bits = CONST64(0x7ff8000000000000); 4177 Node *slow_result = longcon(nan_bits); // return NaN 4178 phi->init_req(1, _gvn.transform( slow_result )); 4179 r->init_req(1, iftrue); 4180 4181 // Else fall through 4182 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 4183 set_control(iffalse); 4184 4185 phi->init_req(2, _gvn.transform(new MoveD2LNode(arg))); 4186 r->init_req(2, iffalse); 4187 4188 // Post merge 4189 set_control(_gvn.transform(r)); 4190 record_for_igvn(r); 4191 4192 C->set_has_split_ifs(true); // Has chance for split-if optimization 4193 result = phi; 4194 assert(result->bottom_type()->isa_long(), "must be"); 4195 break; 4196 } 4197 4198 case vmIntrinsics::_floatToIntBits: { 4199 // two paths (plus control) merge in a wood 4200 RegionNode *r = new RegionNode(3); 4201 Node *phi = new PhiNode(r, TypeInt::INT); 4202 4203 Node *cmpisnan = _gvn.transform(new CmpFNode(arg, arg)); 4204 // Build the boolean node 4205 Node *bolisnan = _gvn.transform(new BoolNode(cmpisnan, BoolTest::ne)); 4206 4207 // Branch either way. 4208 // NaN case is less traveled, which makes all the difference. 4209 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 4210 Node *opt_isnan = _gvn.transform(ifisnan); 4211 assert( opt_isnan->is_If(), "Expect an IfNode"); 4212 IfNode *opt_ifisnan = (IfNode*)opt_isnan; 4213 Node *iftrue = _gvn.transform(new IfTrueNode(opt_ifisnan)); 4214 4215 set_control(iftrue); 4216 4217 static const jint nan_bits = 0x7fc00000; 4218 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 4219 phi->init_req(1, _gvn.transform( slow_result )); 4220 r->init_req(1, iftrue); 4221 4222 // Else fall through 4223 Node *iffalse = _gvn.transform(new IfFalseNode(opt_ifisnan)); 4224 set_control(iffalse); 4225 4226 phi->init_req(2, _gvn.transform(new MoveF2INode(arg))); 4227 r->init_req(2, iffalse); 4228 4229 // Post merge 4230 set_control(_gvn.transform(r)); 4231 record_for_igvn(r); 4232 4233 C->set_has_split_ifs(true); // Has chance for split-if optimization 4234 result = phi; 4235 assert(result->bottom_type()->isa_int(), "must be"); 4236 break; 4237 } 4238 4239 default: 4240 fatal_unexpected_iid(id); 4241 break; 4242 } 4243 set_result(_gvn.transform(result)); 4244 return true; 4245 } 4246 4247 //----------------------inline_unsafe_copyMemory------------------------- 4248 // public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 4249 bool LibraryCallKit::inline_unsafe_copyMemory() { 4250 if (callee()->is_static()) return false; // caller must have the capability! 4251 null_check_receiver(); // null-check receiver 4252 if (stopped()) return true; 4253 4254 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 4255 4256 Node* src_ptr = argument(1); // type: oop 4257 Node* src_off = ConvL2X(argument(2)); // type: long 4258 Node* dst_ptr = argument(4); // type: oop 4259 Node* dst_off = ConvL2X(argument(5)); // type: long 4260 Node* size = ConvL2X(argument(7)); // type: long 4261 4262 assert(Unsafe_field_offset_to_byte_offset(11) == 11, 4263 "fieldOffset must be byte-scaled"); 4264 4265 src_ptr = access_resolve(src_ptr, ACCESS_READ); 4266 dst_ptr = access_resolve(dst_ptr, ACCESS_WRITE); 4267 Node* src = make_unsafe_address(src_ptr, src_off, ACCESS_READ); 4268 Node* dst = make_unsafe_address(dst_ptr, dst_off, ACCESS_WRITE); 4269 4270 // Conservatively insert a memory barrier on all memory slices. 4271 // Do not let writes of the copy source or destination float below the copy. 4272 insert_mem_bar(Op_MemBarCPUOrder); 4273 4274 // Call it. Note that the length argument is not scaled. 4275 make_runtime_call(RC_LEAF|RC_NO_FP, 4276 OptoRuntime::fast_arraycopy_Type(), 4277 StubRoutines::unsafe_arraycopy(), 4278 "unsafe_arraycopy", 4279 TypeRawPtr::BOTTOM, 4280 src, dst, size XTOP); 4281 4282 // Do not let reads of the copy destination float above the copy. 4283 insert_mem_bar(Op_MemBarCPUOrder); 4284 4285 return true; 4286 } 4287 4288 //------------------------clone_coping----------------------------------- 4289 // Helper function for inline_native_clone. 4290 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array) { 4291 assert(obj_size != NULL, ""); 4292 Node* raw_obj = alloc_obj->in(1); 4293 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 4294 4295 AllocateNode* alloc = NULL; 4296 if (ReduceBulkZeroing) { 4297 // We will be completely responsible for initializing this object - 4298 // mark Initialize node as complete. 4299 alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 4300 // The object was just allocated - there should be no any stores! 4301 guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), ""); 4302 // Mark as complete_with_arraycopy so that on AllocateNode 4303 // expansion, we know this AllocateNode is initialized by an array 4304 // copy and a StoreStore barrier exists after the array copy. 4305 alloc->initialization()->set_complete_with_arraycopy(); 4306 } 4307 4308 // Copy the fastest available way. 4309 // TODO: generate fields copies for small objects instead. 4310 Node* size = _gvn.transform(obj_size); 4311 4312 access_clone(obj, alloc_obj, size, is_array); 4313 4314 // Do not let reads from the cloned object float above the arraycopy. 4315 if (alloc != NULL) { 4316 // Do not let stores that initialize this object be reordered with 4317 // a subsequent store that would make this object accessible by 4318 // other threads. 4319 // Record what AllocateNode this StoreStore protects so that 4320 // escape analysis can go from the MemBarStoreStoreNode to the 4321 // AllocateNode and eliminate the MemBarStoreStoreNode if possible 4322 // based on the escape status of the AllocateNode. 4323 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress)); 4324 } else { 4325 insert_mem_bar(Op_MemBarCPUOrder); 4326 } 4327 } 4328 4329 //------------------------inline_native_clone---------------------------- 4330 // protected native Object java.lang.Object.clone(); 4331 // 4332 // Here are the simple edge cases: 4333 // null receiver => normal trap 4334 // virtual and clone was overridden => slow path to out-of-line clone 4335 // not cloneable or finalizer => slow path to out-of-line Object.clone 4336 // 4337 // The general case has two steps, allocation and copying. 4338 // Allocation has two cases, and uses GraphKit::new_instance or new_array. 4339 // 4340 // Copying also has two cases, oop arrays and everything else. 4341 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 4342 // Everything else uses the tight inline loop supplied by CopyArrayNode. 4343 // 4344 // These steps fold up nicely if and when the cloned object's klass 4345 // can be sharply typed as an object array, a type array, or an instance. 4346 // 4347 bool LibraryCallKit::inline_native_clone(bool is_virtual) { 4348 PhiNode* result_val; 4349 4350 // Set the reexecute bit for the interpreter to reexecute 4351 // the bytecode that invokes Object.clone if deoptimization happens. 4352 { PreserveReexecuteState preexecs(this); 4353 jvms()->set_should_reexecute(true); 4354 4355 Node* obj = null_check_receiver(); 4356 if (stopped()) return true; 4357 4358 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 4359 4360 // If we are going to clone an instance, we need its exact type to 4361 // know the number and types of fields to convert the clone to 4362 // loads/stores. Maybe a speculative type can help us. 4363 if (!obj_type->klass_is_exact() && 4364 obj_type->speculative_type() != NULL && 4365 obj_type->speculative_type()->is_instance_klass()) { 4366 ciInstanceKlass* spec_ik = obj_type->speculative_type()->as_instance_klass(); 4367 if (spec_ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem && 4368 !spec_ik->has_injected_fields()) { 4369 ciKlass* k = obj_type->klass(); 4370 if (!k->is_instance_klass() || 4371 k->as_instance_klass()->is_interface() || 4372 k->as_instance_klass()->has_subklass()) { 4373 obj = maybe_cast_profiled_obj(obj, obj_type->speculative_type(), false); 4374 } 4375 } 4376 } 4377 4378 Node* obj_klass = load_object_klass(obj); 4379 const TypeKlassPtr* tklass = _gvn.type(obj_klass)->isa_klassptr(); 4380 const TypeOopPtr* toop = ((tklass != NULL) 4381 ? tklass->as_instance_type() 4382 : TypeInstPtr::NOTNULL); 4383 4384 // Conservatively insert a memory barrier on all memory slices. 4385 // Do not let writes into the original float below the clone. 4386 insert_mem_bar(Op_MemBarCPUOrder); 4387 4388 // paths into result_reg: 4389 enum { 4390 _slow_path = 1, // out-of-line call to clone method (virtual or not) 4391 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 4392 _array_path, // plain array allocation, plus arrayof_long_arraycopy 4393 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 4394 PATH_LIMIT 4395 }; 4396 RegionNode* result_reg = new RegionNode(PATH_LIMIT); 4397 result_val = new PhiNode(result_reg, TypeInstPtr::NOTNULL); 4398 PhiNode* result_i_o = new PhiNode(result_reg, Type::ABIO); 4399 PhiNode* result_mem = new PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 4400 record_for_igvn(result_reg); 4401 4402 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); 4403 if (array_ctl != NULL) { 4404 // It's an array. 4405 PreserveJVMState pjvms(this); 4406 set_control(array_ctl); 4407 Node* obj_length = load_array_length(obj); 4408 Node* obj_size = NULL; 4409 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push 4410 4411 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); 4412 if (bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Parsing)) { 4413 // If it is an oop array, it requires very special treatment, 4414 // because gc barriers are required when accessing the array. 4415 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); 4416 if (is_obja != NULL) { 4417 PreserveJVMState pjvms2(this); 4418 set_control(is_obja); 4419 obj = access_resolve(obj, ACCESS_READ); 4420 // Generate a direct call to the right arraycopy function(s). 4421 Node* alloc = tightly_coupled_allocation(alloc_obj, NULL); 4422 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, obj, intcon(0), alloc_obj, intcon(0), obj_length, alloc != NULL, false); 4423 ac->set_cloneoop(); 4424 Node* n = _gvn.transform(ac); 4425 assert(n == ac, "cannot disappear"); 4426 ac->connect_outputs(this); 4427 4428 result_reg->init_req(_objArray_path, control()); 4429 result_val->init_req(_objArray_path, alloc_obj); 4430 result_i_o ->set_req(_objArray_path, i_o()); 4431 result_mem ->set_req(_objArray_path, reset_memory()); 4432 } 4433 } 4434 // Otherwise, there are no barriers to worry about. 4435 // (We can dispense with card marks if we know the allocation 4436 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 4437 // causes the non-eden paths to take compensating steps to 4438 // simulate a fresh allocation, so that no further 4439 // card marks are required in compiled code to initialize 4440 // the object.) 4441 4442 if (!stopped()) { 4443 copy_to_clone(obj, alloc_obj, obj_size, true); 4444 4445 // Present the results of the copy. 4446 result_reg->init_req(_array_path, control()); 4447 result_val->init_req(_array_path, alloc_obj); 4448 result_i_o ->set_req(_array_path, i_o()); 4449 result_mem ->set_req(_array_path, reset_memory()); 4450 } 4451 } 4452 4453 // We only go to the instance fast case code if we pass a number of guards. 4454 // The paths which do not pass are accumulated in the slow_region. 4455 RegionNode* slow_region = new RegionNode(1); 4456 record_for_igvn(slow_region); 4457 if (!stopped()) { 4458 // It's an instance (we did array above). Make the slow-path tests. 4459 // If this is a virtual call, we generate a funny guard. We grab 4460 // the vtable entry corresponding to clone() from the target object. 4461 // If the target method which we are calling happens to be the 4462 // Object clone() method, we pass the guard. We do not need this 4463 // guard for non-virtual calls; the caller is known to be the native 4464 // Object clone(). 4465 if (is_virtual) { 4466 generate_virtual_guard(obj_klass, slow_region); 4467 } 4468 4469 // The object must be easily cloneable and must not have a finalizer. 4470 // Both of these conditions may be checked in a single test. 4471 // We could optimize the test further, but we don't care. 4472 generate_access_flags_guard(obj_klass, 4473 // Test both conditions: 4474 JVM_ACC_IS_CLONEABLE_FAST | JVM_ACC_HAS_FINALIZER, 4475 // Must be cloneable but not finalizer: 4476 JVM_ACC_IS_CLONEABLE_FAST, 4477 slow_region); 4478 } 4479 4480 if (!stopped()) { 4481 // It's an instance, and it passed the slow-path tests. 4482 PreserveJVMState pjvms(this); 4483 Node* obj_size = NULL; 4484 // Need to deoptimize on exception from allocation since Object.clone intrinsic 4485 // is reexecuted if deoptimization occurs and there could be problems when merging 4486 // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). 4487 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); 4488 4489 copy_to_clone(obj, alloc_obj, obj_size, false); 4490 4491 // Present the results of the slow call. 4492 result_reg->init_req(_instance_path, control()); 4493 result_val->init_req(_instance_path, alloc_obj); 4494 result_i_o ->set_req(_instance_path, i_o()); 4495 result_mem ->set_req(_instance_path, reset_memory()); 4496 } 4497 4498 // Generate code for the slow case. We make a call to clone(). 4499 set_control(_gvn.transform(slow_region)); 4500 if (!stopped()) { 4501 PreserveJVMState pjvms(this); 4502 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); 4503 // We need to deoptimize on exception (see comment above) 4504 Node* slow_result = set_results_for_java_call(slow_call, false, /* deoptimize */ true); 4505 // this->control() comes from set_results_for_java_call 4506 result_reg->init_req(_slow_path, control()); 4507 result_val->init_req(_slow_path, slow_result); 4508 result_i_o ->set_req(_slow_path, i_o()); 4509 result_mem ->set_req(_slow_path, reset_memory()); 4510 } 4511 4512 // Return the combined state. 4513 set_control( _gvn.transform(result_reg)); 4514 set_i_o( _gvn.transform(result_i_o)); 4515 set_all_memory( _gvn.transform(result_mem)); 4516 } // original reexecute is set back here 4517 4518 set_result(_gvn.transform(result_val)); 4519 return true; 4520 } 4521 4522 // If we have a tightly coupled allocation, the arraycopy may take care 4523 // of the array initialization. If one of the guards we insert between 4524 // the allocation and the arraycopy causes a deoptimization, an 4525 // unitialized array will escape the compiled method. To prevent that 4526 // we set the JVM state for uncommon traps between the allocation and 4527 // the arraycopy to the state before the allocation so, in case of 4528 // deoptimization, we'll reexecute the allocation and the 4529 // initialization. 4530 JVMState* LibraryCallKit::arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp) { 4531 if (alloc != NULL) { 4532 ciMethod* trap_method = alloc->jvms()->method(); 4533 int trap_bci = alloc->jvms()->bci(); 4534 4535 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) & 4536 !C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_null_check)) { 4537 // Make sure there's no store between the allocation and the 4538 // arraycopy otherwise visible side effects could be rexecuted 4539 // in case of deoptimization and cause incorrect execution. 4540 bool no_interfering_store = true; 4541 Node* mem = alloc->in(TypeFunc::Memory); 4542 if (mem->is_MergeMem()) { 4543 for (MergeMemStream mms(merged_memory(), mem->as_MergeMem()); mms.next_non_empty2(); ) { 4544 Node* n = mms.memory(); 4545 if (n != mms.memory2() && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 4546 assert(n->is_Store() || n->Opcode() == Op_ShenandoahWBMemProj, "what else?"); 4547 no_interfering_store = false; 4548 break; 4549 } 4550 } 4551 } else { 4552 for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { 4553 Node* n = mms.memory(); 4554 if (n != mem && !(n->is_Proj() && n->in(0) == alloc->initialization())) { 4555 assert(n->is_Store() || n->Opcode() == Op_ShenandoahWBMemProj, "what else?"); 4556 no_interfering_store = false; 4557 break; 4558 } 4559 } 4560 } 4561 4562 if (no_interfering_store) { 4563 JVMState* old_jvms = alloc->jvms()->clone_shallow(C); 4564 uint size = alloc->req(); 4565 SafePointNode* sfpt = new SafePointNode(size, old_jvms); 4566 old_jvms->set_map(sfpt); 4567 for (uint i = 0; i < size; i++) { 4568 sfpt->init_req(i, alloc->in(i)); 4569 } 4570 // re-push array length for deoptimization 4571 sfpt->ins_req(old_jvms->stkoff() + old_jvms->sp(), alloc->in(AllocateNode::ALength)); 4572 old_jvms->set_sp(old_jvms->sp()+1); 4573 old_jvms->set_monoff(old_jvms->monoff()+1); 4574 old_jvms->set_scloff(old_jvms->scloff()+1); 4575 old_jvms->set_endoff(old_jvms->endoff()+1); 4576 old_jvms->set_should_reexecute(true); 4577 4578 sfpt->set_i_o(map()->i_o()); 4579 sfpt->set_memory(map()->memory()); 4580 sfpt->set_control(map()->control()); 4581 4582 JVMState* saved_jvms = jvms(); 4583 saved_reexecute_sp = _reexecute_sp; 4584 4585 set_jvms(sfpt->jvms()); 4586 _reexecute_sp = jvms()->sp(); 4587 4588 return saved_jvms; 4589 } 4590 } 4591 } 4592 return NULL; 4593 } 4594 4595 // In case of a deoptimization, we restart execution at the 4596 // allocation, allocating a new array. We would leave an uninitialized 4597 // array in the heap that GCs wouldn't expect. Move the allocation 4598 // after the traps so we don't allocate the array if we 4599 // deoptimize. This is possible because tightly_coupled_allocation() 4600 // guarantees there's no observer of the allocated array at this point 4601 // and the control flow is simple enough. 4602 void LibraryCallKit::arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, 4603 int saved_reexecute_sp, uint new_idx) { 4604 if (saved_jvms != NULL && !stopped()) { 4605 assert(alloc != NULL, "only with a tightly coupled allocation"); 4606 // restore JVM state to the state at the arraycopy 4607 saved_jvms->map()->set_control(map()->control()); 4608 assert(saved_jvms->map()->memory() == map()->memory(), "memory state changed?"); 4609 assert(saved_jvms->map()->i_o() == map()->i_o(), "IO state changed?"); 4610 // If we've improved the types of some nodes (null check) while 4611 // emitting the guards, propagate them to the current state 4612 map()->replaced_nodes().apply(saved_jvms->map(), new_idx); 4613 set_jvms(saved_jvms); 4614 _reexecute_sp = saved_reexecute_sp; 4615 4616 // Remove the allocation from above the guards 4617 CallProjections callprojs; 4618 alloc->extract_projections(&callprojs, true); 4619 InitializeNode* init = alloc->initialization(); 4620 Node* alloc_mem = alloc->in(TypeFunc::Memory); 4621 C->gvn_replace_by(callprojs.fallthrough_ioproj, alloc->in(TypeFunc::I_O)); 4622 C->gvn_replace_by(init->proj_out(TypeFunc::Memory), alloc_mem); 4623 C->gvn_replace_by(init->proj_out(TypeFunc::Control), alloc->in(0)); 4624 4625 // move the allocation here (after the guards) 4626 _gvn.hash_delete(alloc); 4627 alloc->set_req(TypeFunc::Control, control()); 4628 alloc->set_req(TypeFunc::I_O, i_o()); 4629 Node *mem = reset_memory(); 4630 set_all_memory(mem); 4631 alloc->set_req(TypeFunc::Memory, mem); 4632 set_control(init->proj_out_or_null(TypeFunc::Control)); 4633 set_i_o(callprojs.fallthrough_ioproj); 4634 4635 // Update memory as done in GraphKit::set_output_for_allocation() 4636 const TypeInt* length_type = _gvn.find_int_type(alloc->in(AllocateNode::ALength)); 4637 const TypeOopPtr* ary_type = _gvn.type(alloc->in(AllocateNode::KlassNode))->is_klassptr()->as_instance_type(); 4638 if (ary_type->isa_aryptr() && length_type != NULL) { 4639 ary_type = ary_type->is_aryptr()->cast_to_size(length_type); 4640 } 4641 const TypePtr* telemref = ary_type->add_offset(Type::OffsetBot); 4642 int elemidx = C->get_alias_index(telemref); 4643 set_memory(init->proj_out_or_null(TypeFunc::Memory), Compile::AliasIdxRaw); 4644 set_memory(init->proj_out_or_null(TypeFunc::Memory), elemidx); 4645 4646 Node* allocx = _gvn.transform(alloc); 4647 assert(allocx == alloc, "where has the allocation gone?"); 4648 assert(dest->is_CheckCastPP(), "not an allocation result?"); 4649 4650 _gvn.hash_delete(dest); 4651 dest->set_req(0, control()); 4652 Node* destx = _gvn.transform(dest); 4653 assert(destx == dest, "where has the allocation result gone?"); 4654 } 4655 } 4656 4657 4658 //------------------------------inline_arraycopy----------------------- 4659 // public static native void java.lang.System.arraycopy(Object src, int srcPos, 4660 // Object dest, int destPos, 4661 // int length); 4662 bool LibraryCallKit::inline_arraycopy() { 4663 // Get the arguments. 4664 Node* src = argument(0); // type: oop 4665 Node* src_offset = argument(1); // type: int 4666 Node* dest = argument(2); // type: oop 4667 Node* dest_offset = argument(3); // type: int 4668 Node* length = argument(4); // type: int 4669 4670 uint new_idx = C->unique(); 4671 4672 // Check for allocation before we add nodes that would confuse 4673 // tightly_coupled_allocation() 4674 AllocateArrayNode* alloc = tightly_coupled_allocation(dest, NULL); 4675 4676 int saved_reexecute_sp = -1; 4677 JVMState* saved_jvms = arraycopy_restore_alloc_state(alloc, saved_reexecute_sp); 4678 // See arraycopy_restore_alloc_state() comment 4679 // if alloc == NULL we don't have to worry about a tightly coupled allocation so we can emit all needed guards 4680 // if saved_jvms != NULL (then alloc != NULL) then we can handle guards and a tightly coupled allocation 4681 // if saved_jvms == NULL and alloc != NULL, we can't emit any guards 4682 bool can_emit_guards = (alloc == NULL || saved_jvms != NULL); 4683 4684 // The following tests must be performed 4685 // (1) src and dest are arrays. 4686 // (2) src and dest arrays must have elements of the same BasicType 4687 // (3) src and dest must not be null. 4688 // (4) src_offset must not be negative. 4689 // (5) dest_offset must not be negative. 4690 // (6) length must not be negative. 4691 // (7) src_offset + length must not exceed length of src. 4692 // (8) dest_offset + length must not exceed length of dest. 4693 // (9) each element of an oop array must be assignable 4694 4695 // (3) src and dest must not be null. 4696 // always do this here because we need the JVM state for uncommon traps 4697 Node* null_ctl = top(); 4698 src = saved_jvms != NULL ? null_check_oop(src, &null_ctl, true, true) : null_check(src, T_ARRAY); 4699 assert(null_ctl->is_top(), "no null control here"); 4700 dest = null_check(dest, T_ARRAY); 4701 4702 if (!can_emit_guards) { 4703 // if saved_jvms == NULL and alloc != NULL, we don't emit any 4704 // guards but the arraycopy node could still take advantage of a 4705 // tightly allocated allocation. tightly_coupled_allocation() is 4706 // called again to make sure it takes the null check above into 4707 // account: the null check is mandatory and if it caused an 4708 // uncommon trap to be emitted then the allocation can't be 4709 // considered tightly coupled in this context. 4710 alloc = tightly_coupled_allocation(dest, NULL); 4711 } 4712 4713 bool validated = false; 4714 4715 const Type* src_type = _gvn.type(src); 4716 const Type* dest_type = _gvn.type(dest); 4717 const TypeAryPtr* top_src = src_type->isa_aryptr(); 4718 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 4719 4720 // Do we have the type of src? 4721 bool has_src = (top_src != NULL && top_src->klass() != NULL); 4722 // Do we have the type of dest? 4723 bool has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4724 // Is the type for src from speculation? 4725 bool src_spec = false; 4726 // Is the type for dest from speculation? 4727 bool dest_spec = false; 4728 4729 if ((!has_src || !has_dest) && can_emit_guards) { 4730 // We don't have sufficient type information, let's see if 4731 // speculative types can help. We need to have types for both src 4732 // and dest so that it pays off. 4733 4734 // Do we already have or could we have type information for src 4735 bool could_have_src = has_src; 4736 // Do we already have or could we have type information for dest 4737 bool could_have_dest = has_dest; 4738 4739 ciKlass* src_k = NULL; 4740 if (!has_src) { 4741 src_k = src_type->speculative_type_not_null(); 4742 if (src_k != NULL && src_k->is_array_klass()) { 4743 could_have_src = true; 4744 } 4745 } 4746 4747 ciKlass* dest_k = NULL; 4748 if (!has_dest) { 4749 dest_k = dest_type->speculative_type_not_null(); 4750 if (dest_k != NULL && dest_k->is_array_klass()) { 4751 could_have_dest = true; 4752 } 4753 } 4754 4755 if (could_have_src && could_have_dest) { 4756 // This is going to pay off so emit the required guards 4757 if (!has_src) { 4758 src = maybe_cast_profiled_obj(src, src_k, true); 4759 src_type = _gvn.type(src); 4760 top_src = src_type->isa_aryptr(); 4761 has_src = (top_src != NULL && top_src->klass() != NULL); 4762 src_spec = true; 4763 } 4764 if (!has_dest) { 4765 dest = maybe_cast_profiled_obj(dest, dest_k, true); 4766 dest_type = _gvn.type(dest); 4767 top_dest = dest_type->isa_aryptr(); 4768 has_dest = (top_dest != NULL && top_dest->klass() != NULL); 4769 dest_spec = true; 4770 } 4771 } 4772 } 4773 4774 if (has_src && has_dest && can_emit_guards) { 4775 BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type(); 4776 BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type(); 4777 if (src_elem == T_ARRAY) src_elem = T_OBJECT; 4778 if (dest_elem == T_ARRAY) dest_elem = T_OBJECT; 4779 4780 if (src_elem == dest_elem && src_elem == T_OBJECT) { 4781 // If both arrays are object arrays then having the exact types 4782 // for both will remove the need for a subtype check at runtime 4783 // before the call and may make it possible to pick a faster copy 4784 // routine (without a subtype check on every element) 4785 // Do we have the exact type of src? 4786 bool could_have_src = src_spec; 4787 // Do we have the exact type of dest? 4788 bool could_have_dest = dest_spec; 4789 ciKlass* src_k = top_src->klass(); 4790 ciKlass* dest_k = top_dest->klass(); 4791 if (!src_spec) { 4792 src_k = src_type->speculative_type_not_null(); 4793 if (src_k != NULL && src_k->is_array_klass()) { 4794 could_have_src = true; 4795 } 4796 } 4797 if (!dest_spec) { 4798 dest_k = dest_type->speculative_type_not_null(); 4799 if (dest_k != NULL && dest_k->is_array_klass()) { 4800 could_have_dest = true; 4801 } 4802 } 4803 if (could_have_src && could_have_dest) { 4804 // If we can have both exact types, emit the missing guards 4805 if (could_have_src && !src_spec) { 4806 src = maybe_cast_profiled_obj(src, src_k, true); 4807 } 4808 if (could_have_dest && !dest_spec) { 4809 dest = maybe_cast_profiled_obj(dest, dest_k, true); 4810 } 4811 } 4812 } 4813 } 4814 4815 ciMethod* trap_method = method(); 4816 int trap_bci = bci(); 4817 if (saved_jvms != NULL) { 4818 trap_method = alloc->jvms()->method(); 4819 trap_bci = alloc->jvms()->bci(); 4820 } 4821 4822 bool negative_length_guard_generated = false; 4823 4824 if (!C->too_many_traps(trap_method, trap_bci, Deoptimization::Reason_intrinsic) && 4825 can_emit_guards && 4826 !src->is_top() && !dest->is_top()) { 4827 // validate arguments: enables transformation the ArrayCopyNode 4828 validated = true; 4829 4830 RegionNode* slow_region = new RegionNode(1); 4831 record_for_igvn(slow_region); 4832 4833 // (1) src and dest are arrays. 4834 generate_non_array_guard(load_object_klass(src), slow_region); 4835 generate_non_array_guard(load_object_klass(dest), slow_region); 4836 4837 // (2) src and dest arrays must have elements of the same BasicType 4838 // done at macro expansion or at Ideal transformation time 4839 4840 // (4) src_offset must not be negative. 4841 generate_negative_guard(src_offset, slow_region); 4842 4843 // (5) dest_offset must not be negative. 4844 generate_negative_guard(dest_offset, slow_region); 4845 4846 // (7) src_offset + length must not exceed length of src. 4847 generate_limit_guard(src_offset, length, 4848 load_array_length(src), 4849 slow_region); 4850 4851 // (8) dest_offset + length must not exceed length of dest. 4852 generate_limit_guard(dest_offset, length, 4853 load_array_length(dest), 4854 slow_region); 4855 4856 // (6) length must not be negative. 4857 // This is also checked in generate_arraycopy() during macro expansion, but 4858 // we also have to check it here for the case where the ArrayCopyNode will 4859 // be eliminated by Escape Analysis. 4860 if (EliminateAllocations) { 4861 generate_negative_guard(length, slow_region); 4862 negative_length_guard_generated = true; 4863 } 4864 4865 // (9) each element of an oop array must be assignable 4866 Node* src_klass = load_object_klass(src); 4867 Node* dest_klass = load_object_klass(dest); 4868 Node* not_subtype_ctrl = gen_subtype_check(src_klass, dest_klass); 4869 4870 if (not_subtype_ctrl != top()) { 4871 PreserveJVMState pjvms(this); 4872 set_control(not_subtype_ctrl); 4873 uncommon_trap(Deoptimization::Reason_intrinsic, 4874 Deoptimization::Action_make_not_entrant); 4875 assert(stopped(), "Should be stopped"); 4876 } 4877 { 4878 PreserveJVMState pjvms(this); 4879 set_control(_gvn.transform(slow_region)); 4880 uncommon_trap(Deoptimization::Reason_intrinsic, 4881 Deoptimization::Action_make_not_entrant); 4882 assert(stopped(), "Should be stopped"); 4883 } 4884 4885 const TypeKlassPtr* dest_klass_t = _gvn.type(dest_klass)->is_klassptr(); 4886 const Type *toop = TypeOopPtr::make_from_klass(dest_klass_t->klass()); 4887 src = _gvn.transform(new CheckCastPPNode(control(), src, toop)); 4888 } 4889 4890 arraycopy_move_allocation_here(alloc, dest, saved_jvms, saved_reexecute_sp, new_idx); 4891 4892 if (stopped()) { 4893 return true; 4894 } 4895 4896 Node* new_src = access_resolve(src, ACCESS_READ); 4897 Node* new_dest = access_resolve(dest, ACCESS_WRITE); 4898 4899 ArrayCopyNode* ac = ArrayCopyNode::make(this, true, new_src, src_offset, new_dest, dest_offset, length, alloc != NULL, negative_length_guard_generated, 4900 // Create LoadRange and LoadKlass nodes for use during macro expansion here 4901 // so the compiler has a chance to eliminate them: during macro expansion, 4902 // we have to set their control (CastPP nodes are eliminated). 4903 load_object_klass(src), load_object_klass(dest), 4904 load_array_length(src), load_array_length(dest)); 4905 4906 ac->set_arraycopy(validated); 4907 4908 Node* n = _gvn.transform(ac); 4909 if (n == ac) { 4910 ac->connect_outputs(this); 4911 } else { 4912 assert(validated, "shouldn't transform if all arguments not validated"); 4913 set_all_memory(n); 4914 } 4915 clear_upper_avx(); 4916 4917 4918 return true; 4919 } 4920 4921 4922 // Helper function which determines if an arraycopy immediately follows 4923 // an allocation, with no intervening tests or other escapes for the object. 4924 AllocateArrayNode* 4925 LibraryCallKit::tightly_coupled_allocation(Node* ptr, 4926 RegionNode* slow_region) { 4927 if (stopped()) return NULL; // no fast path 4928 if (C->AliasLevel() == 0) return NULL; // no MergeMems around 4929 4930 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn); 4931 if (alloc == NULL) return NULL; 4932 4933 Node* rawmem = memory(Compile::AliasIdxRaw); 4934 // Is the allocation's memory state untouched? 4935 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 4936 // Bail out if there have been raw-memory effects since the allocation. 4937 // (Example: There might have been a call or safepoint.) 4938 return NULL; 4939 } 4940 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 4941 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 4942 return NULL; 4943 } 4944 4945 // There must be no unexpected observers of this allocation. 4946 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 4947 Node* obs = ptr->fast_out(i); 4948 if (obs != this->map()) { 4949 return NULL; 4950 } 4951 } 4952 4953 // This arraycopy must unconditionally follow the allocation of the ptr. 4954 Node* alloc_ctl = ptr->in(0); 4955 assert(just_allocated_object(alloc_ctl) == ptr, "most recent allo"); 4956 4957 Node* ctl = control(); 4958 while (ctl != alloc_ctl) { 4959 // There may be guards which feed into the slow_region. 4960 // Any other control flow means that we might not get a chance 4961 // to finish initializing the allocated object. 4962 if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) { 4963 IfNode* iff = ctl->in(0)->as_If(); 4964 Node* not_ctl = iff->proj_out_or_null(1 - ctl->as_Proj()->_con); 4965 assert(not_ctl != NULL && not_ctl != ctl, "found alternate"); 4966 if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) { 4967 ctl = iff->in(0); // This test feeds the known slow_region. 4968 continue; 4969 } 4970 // One more try: Various low-level checks bottom out in 4971 // uncommon traps. If the debug-info of the trap omits 4972 // any reference to the allocation, as we've already 4973 // observed, then there can be no objection to the trap. 4974 bool found_trap = false; 4975 for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) { 4976 Node* obs = not_ctl->fast_out(j); 4977 if (obs->in(0) == not_ctl && obs->is_Call() && 4978 (obs->as_Call()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point())) { 4979 found_trap = true; break; 4980 } 4981 } 4982 if (found_trap) { 4983 ctl = iff->in(0); // This test feeds a harmless uncommon trap. 4984 continue; 4985 } 4986 } 4987 return NULL; 4988 } 4989 4990 // If we get this far, we have an allocation which immediately 4991 // precedes the arraycopy, and we can take over zeroing the new object. 4992 // The arraycopy will finish the initialization, and provide 4993 // a new control state to which we will anchor the destination pointer. 4994 4995 return alloc; 4996 } 4997 4998 //-------------inline_encodeISOArray----------------------------------- 4999 // encode char[] to byte[] in ISO_8859_1 5000 bool LibraryCallKit::inline_encodeISOArray() { 5001 assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 5002 // no receiver since it is static method 5003 Node *src = argument(0); 5004 Node *src_offset = argument(1); 5005 Node *dst = argument(2); 5006 Node *dst_offset = argument(3); 5007 Node *length = argument(4); 5008 5009 src = must_be_not_null(src, true); 5010 dst = must_be_not_null(dst, true); 5011 5012 src = access_resolve(src, ACCESS_READ); 5013 dst = access_resolve(dst, ACCESS_WRITE); 5014 5015 const Type* src_type = src->Value(&_gvn); 5016 const Type* dst_type = dst->Value(&_gvn); 5017 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5018 const TypeAryPtr* top_dest = dst_type->isa_aryptr(); 5019 if (top_src == NULL || top_src->klass() == NULL || 5020 top_dest == NULL || top_dest->klass() == NULL) { 5021 // failed array check 5022 return false; 5023 } 5024 5025 // Figure out the size and type of the elements we will be copying. 5026 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5027 BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5028 if (!((src_elem == T_CHAR) || (src_elem== T_BYTE)) || dst_elem != T_BYTE) { 5029 return false; 5030 } 5031 5032 Node* src_start = array_element_address(src, src_offset, T_CHAR); 5033 Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 5034 // 'src_start' points to src array + scaled offset 5035 // 'dst_start' points to dst array + scaled offset 5036 5037 const TypeAryPtr* mtype = TypeAryPtr::BYTES; 5038 Node* enc = new EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length); 5039 enc = _gvn.transform(enc); 5040 Node* res_mem = _gvn.transform(new SCMemProjNode(enc)); 5041 set_memory(res_mem, mtype); 5042 set_result(enc); 5043 clear_upper_avx(); 5044 5045 return true; 5046 } 5047 5048 //-------------inline_multiplyToLen----------------------------------- 5049 bool LibraryCallKit::inline_multiplyToLen() { 5050 assert(UseMultiplyToLenIntrinsic, "not implemented on this platform"); 5051 5052 address stubAddr = StubRoutines::multiplyToLen(); 5053 if (stubAddr == NULL) { 5054 return false; // Intrinsic's stub is not implemented on this platform 5055 } 5056 const char* stubName = "multiplyToLen"; 5057 5058 assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters"); 5059 5060 // no receiver because it is a static method 5061 Node* x = argument(0); 5062 Node* xlen = argument(1); 5063 Node* y = argument(2); 5064 Node* ylen = argument(3); 5065 Node* z = argument(4); 5066 5067 x = must_be_not_null(x, true); 5068 y = must_be_not_null(y, true); 5069 5070 x = access_resolve(x, ACCESS_READ); 5071 y = access_resolve(y, ACCESS_READ); 5072 z = access_resolve(z, ACCESS_WRITE); 5073 5074 const Type* x_type = x->Value(&_gvn); 5075 const Type* y_type = y->Value(&_gvn); 5076 const TypeAryPtr* top_x = x_type->isa_aryptr(); 5077 const TypeAryPtr* top_y = y_type->isa_aryptr(); 5078 if (top_x == NULL || top_x->klass() == NULL || 5079 top_y == NULL || top_y->klass() == NULL) { 5080 // failed array check 5081 return false; 5082 } 5083 5084 BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5085 BasicType y_elem = y_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5086 if (x_elem != T_INT || y_elem != T_INT) { 5087 return false; 5088 } 5089 5090 // Set the original stack and the reexecute bit for the interpreter to reexecute 5091 // the bytecode that invokes BigInteger.multiplyToLen() if deoptimization happens 5092 // on the return from z array allocation in runtime. 5093 { PreserveReexecuteState preexecs(this); 5094 jvms()->set_should_reexecute(true); 5095 5096 Node* x_start = array_element_address(x, intcon(0), x_elem); 5097 Node* y_start = array_element_address(y, intcon(0), y_elem); 5098 // 'x_start' points to x array + scaled xlen 5099 // 'y_start' points to y array + scaled ylen 5100 5101 // Allocate the result array 5102 Node* zlen = _gvn.transform(new AddINode(xlen, ylen)); 5103 ciKlass* klass = ciTypeArrayKlass::make(T_INT); 5104 Node* klass_node = makecon(TypeKlassPtr::make(klass)); 5105 5106 IdealKit ideal(this); 5107 5108 #define __ ideal. 5109 Node* one = __ ConI(1); 5110 Node* zero = __ ConI(0); 5111 IdealVariable need_alloc(ideal), z_alloc(ideal); __ declarations_done(); 5112 __ set(need_alloc, zero); 5113 __ set(z_alloc, z); 5114 __ if_then(z, BoolTest::eq, null()); { 5115 __ increment (need_alloc, one); 5116 } __ else_(); { 5117 // Update graphKit memory and control from IdealKit. 5118 sync_kit(ideal); 5119 Node *cast = new CastPPNode(z, TypePtr::NOTNULL); 5120 cast->init_req(0, control()); 5121 _gvn.set_type(cast, cast->bottom_type()); 5122 C->record_for_igvn(cast); 5123 5124 Node* zlen_arg = load_array_length(cast); 5125 // Update IdealKit memory and control from graphKit. 5126 __ sync_kit(this); 5127 __ if_then(zlen_arg, BoolTest::lt, zlen); { 5128 __ increment (need_alloc, one); 5129 } __ end_if(); 5130 } __ end_if(); 5131 5132 __ if_then(__ value(need_alloc), BoolTest::ne, zero); { 5133 // Update graphKit memory and control from IdealKit. 5134 sync_kit(ideal); 5135 Node * narr = new_array(klass_node, zlen, 1); 5136 // Update IdealKit memory and control from graphKit. 5137 __ sync_kit(this); 5138 __ set(z_alloc, narr); 5139 } __ end_if(); 5140 5141 sync_kit(ideal); 5142 z = __ value(z_alloc); 5143 // Can't use TypeAryPtr::INTS which uses Bottom offset. 5144 _gvn.set_type(z, TypeOopPtr::make_from_klass(klass)); 5145 // Final sync IdealKit and GraphKit. 5146 final_sync(ideal); 5147 #undef __ 5148 5149 Node* z_start = array_element_address(z, intcon(0), T_INT); 5150 5151 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 5152 OptoRuntime::multiplyToLen_Type(), 5153 stubAddr, stubName, TypePtr::BOTTOM, 5154 x_start, xlen, y_start, ylen, z_start, zlen); 5155 } // original reexecute is set back here 5156 5157 C->set_has_split_ifs(true); // Has chance for split-if optimization 5158 set_result(z); 5159 return true; 5160 } 5161 5162 //-------------inline_squareToLen------------------------------------ 5163 bool LibraryCallKit::inline_squareToLen() { 5164 assert(UseSquareToLenIntrinsic, "not implemented on this platform"); 5165 5166 address stubAddr = StubRoutines::squareToLen(); 5167 if (stubAddr == NULL) { 5168 return false; // Intrinsic's stub is not implemented on this platform 5169 } 5170 const char* stubName = "squareToLen"; 5171 5172 assert(callee()->signature()->size() == 4, "implSquareToLen has 4 parameters"); 5173 5174 Node* x = argument(0); 5175 Node* len = argument(1); 5176 Node* z = argument(2); 5177 Node* zlen = argument(3); 5178 5179 x = must_be_not_null(x, true); 5180 z = must_be_not_null(z, true); 5181 5182 x = access_resolve(x, ACCESS_READ); 5183 z = access_resolve(z, ACCESS_WRITE); 5184 5185 const Type* x_type = x->Value(&_gvn); 5186 const Type* z_type = z->Value(&_gvn); 5187 const TypeAryPtr* top_x = x_type->isa_aryptr(); 5188 const TypeAryPtr* top_z = z_type->isa_aryptr(); 5189 if (top_x == NULL || top_x->klass() == NULL || 5190 top_z == NULL || top_z->klass() == NULL) { 5191 // failed array check 5192 return false; 5193 } 5194 5195 BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5196 BasicType z_elem = z_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5197 if (x_elem != T_INT || z_elem != T_INT) { 5198 return false; 5199 } 5200 5201 5202 Node* x_start = array_element_address(x, intcon(0), x_elem); 5203 Node* z_start = array_element_address(z, intcon(0), z_elem); 5204 5205 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 5206 OptoRuntime::squareToLen_Type(), 5207 stubAddr, stubName, TypePtr::BOTTOM, 5208 x_start, len, z_start, zlen); 5209 5210 set_result(z); 5211 return true; 5212 } 5213 5214 //-------------inline_mulAdd------------------------------------------ 5215 bool LibraryCallKit::inline_mulAdd() { 5216 assert(UseMulAddIntrinsic, "not implemented on this platform"); 5217 5218 address stubAddr = StubRoutines::mulAdd(); 5219 if (stubAddr == NULL) { 5220 return false; // Intrinsic's stub is not implemented on this platform 5221 } 5222 const char* stubName = "mulAdd"; 5223 5224 assert(callee()->signature()->size() == 5, "mulAdd has 5 parameters"); 5225 5226 Node* out = argument(0); 5227 Node* in = argument(1); 5228 Node* offset = argument(2); 5229 Node* len = argument(3); 5230 Node* k = argument(4); 5231 5232 out = must_be_not_null(out, true); 5233 5234 in = access_resolve(in, ACCESS_READ); 5235 out = access_resolve(out, ACCESS_WRITE); 5236 5237 const Type* out_type = out->Value(&_gvn); 5238 const Type* in_type = in->Value(&_gvn); 5239 const TypeAryPtr* top_out = out_type->isa_aryptr(); 5240 const TypeAryPtr* top_in = in_type->isa_aryptr(); 5241 if (top_out == NULL || top_out->klass() == NULL || 5242 top_in == NULL || top_in->klass() == NULL) { 5243 // failed array check 5244 return false; 5245 } 5246 5247 BasicType out_elem = out_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5248 BasicType in_elem = in_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5249 if (out_elem != T_INT || in_elem != T_INT) { 5250 return false; 5251 } 5252 5253 Node* outlen = load_array_length(out); 5254 Node* new_offset = _gvn.transform(new SubINode(outlen, offset)); 5255 Node* out_start = array_element_address(out, intcon(0), out_elem); 5256 Node* in_start = array_element_address(in, intcon(0), in_elem); 5257 5258 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 5259 OptoRuntime::mulAdd_Type(), 5260 stubAddr, stubName, TypePtr::BOTTOM, 5261 out_start,in_start, new_offset, len, k); 5262 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5263 set_result(result); 5264 return true; 5265 } 5266 5267 //-------------inline_montgomeryMultiply----------------------------------- 5268 bool LibraryCallKit::inline_montgomeryMultiply() { 5269 address stubAddr = StubRoutines::montgomeryMultiply(); 5270 if (stubAddr == NULL) { 5271 return false; // Intrinsic's stub is not implemented on this platform 5272 } 5273 5274 assert(UseMontgomeryMultiplyIntrinsic, "not implemented on this platform"); 5275 const char* stubName = "montgomery_multiply"; 5276 5277 assert(callee()->signature()->size() == 7, "montgomeryMultiply has 7 parameters"); 5278 5279 Node* a = argument(0); 5280 Node* b = argument(1); 5281 Node* n = argument(2); 5282 Node* len = argument(3); 5283 Node* inv = argument(4); 5284 Node* m = argument(6); 5285 5286 a = access_resolve(a, ACCESS_READ); 5287 b = access_resolve(b, ACCESS_READ); 5288 n = access_resolve(n, ACCESS_READ); 5289 m = access_resolve(m, ACCESS_WRITE); 5290 5291 const Type* a_type = a->Value(&_gvn); 5292 const TypeAryPtr* top_a = a_type->isa_aryptr(); 5293 const Type* b_type = b->Value(&_gvn); 5294 const TypeAryPtr* top_b = b_type->isa_aryptr(); 5295 const Type* n_type = a->Value(&_gvn); 5296 const TypeAryPtr* top_n = n_type->isa_aryptr(); 5297 const Type* m_type = a->Value(&_gvn); 5298 const TypeAryPtr* top_m = m_type->isa_aryptr(); 5299 if (top_a == NULL || top_a->klass() == NULL || 5300 top_b == NULL || top_b->klass() == NULL || 5301 top_n == NULL || top_n->klass() == NULL || 5302 top_m == NULL || top_m->klass() == NULL) { 5303 // failed array check 5304 return false; 5305 } 5306 5307 BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5308 BasicType b_elem = b_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5309 BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5310 BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5311 if (a_elem != T_INT || b_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 5312 return false; 5313 } 5314 5315 // Make the call 5316 { 5317 Node* a_start = array_element_address(a, intcon(0), a_elem); 5318 Node* b_start = array_element_address(b, intcon(0), b_elem); 5319 Node* n_start = array_element_address(n, intcon(0), n_elem); 5320 Node* m_start = array_element_address(m, intcon(0), m_elem); 5321 5322 Node* call = make_runtime_call(RC_LEAF, 5323 OptoRuntime::montgomeryMultiply_Type(), 5324 stubAddr, stubName, TypePtr::BOTTOM, 5325 a_start, b_start, n_start, len, inv, top(), 5326 m_start); 5327 set_result(m); 5328 } 5329 5330 return true; 5331 } 5332 5333 bool LibraryCallKit::inline_montgomerySquare() { 5334 address stubAddr = StubRoutines::montgomerySquare(); 5335 if (stubAddr == NULL) { 5336 return false; // Intrinsic's stub is not implemented on this platform 5337 } 5338 5339 assert(UseMontgomerySquareIntrinsic, "not implemented on this platform"); 5340 const char* stubName = "montgomery_square"; 5341 5342 assert(callee()->signature()->size() == 6, "montgomerySquare has 6 parameters"); 5343 5344 Node* a = argument(0); 5345 Node* n = argument(1); 5346 Node* len = argument(2); 5347 Node* inv = argument(3); 5348 Node* m = argument(5); 5349 5350 a = access_resolve(a, ACCESS_READ); 5351 n = access_resolve(n, ACCESS_READ); 5352 m = access_resolve(m, ACCESS_WRITE); 5353 5354 const Type* a_type = a->Value(&_gvn); 5355 const TypeAryPtr* top_a = a_type->isa_aryptr(); 5356 const Type* n_type = a->Value(&_gvn); 5357 const TypeAryPtr* top_n = n_type->isa_aryptr(); 5358 const Type* m_type = a->Value(&_gvn); 5359 const TypeAryPtr* top_m = m_type->isa_aryptr(); 5360 if (top_a == NULL || top_a->klass() == NULL || 5361 top_n == NULL || top_n->klass() == NULL || 5362 top_m == NULL || top_m->klass() == NULL) { 5363 // failed array check 5364 return false; 5365 } 5366 5367 BasicType a_elem = a_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5368 BasicType n_elem = n_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5369 BasicType m_elem = m_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5370 if (a_elem != T_INT || n_elem != T_INT || m_elem != T_INT) { 5371 return false; 5372 } 5373 5374 // Make the call 5375 { 5376 Node* a_start = array_element_address(a, intcon(0), a_elem); 5377 Node* n_start = array_element_address(n, intcon(0), n_elem); 5378 Node* m_start = array_element_address(m, intcon(0), m_elem); 5379 5380 Node* call = make_runtime_call(RC_LEAF, 5381 OptoRuntime::montgomerySquare_Type(), 5382 stubAddr, stubName, TypePtr::BOTTOM, 5383 a_start, n_start, len, inv, top(), 5384 m_start); 5385 set_result(m); 5386 } 5387 5388 return true; 5389 } 5390 5391 //-------------inline_vectorizedMismatch------------------------------ 5392 bool LibraryCallKit::inline_vectorizedMismatch() { 5393 assert(UseVectorizedMismatchIntrinsic, "not implementated on this platform"); 5394 5395 address stubAddr = StubRoutines::vectorizedMismatch(); 5396 if (stubAddr == NULL) { 5397 return false; // Intrinsic's stub is not implemented on this platform 5398 } 5399 const char* stubName = "vectorizedMismatch"; 5400 int size_l = callee()->signature()->size(); 5401 assert(callee()->signature()->size() == 8, "vectorizedMismatch has 6 parameters"); 5402 5403 Node* obja = argument(0); 5404 Node* aoffset = argument(1); 5405 Node* objb = argument(3); 5406 Node* boffset = argument(4); 5407 Node* length = argument(6); 5408 Node* scale = argument(7); 5409 5410 const Type* a_type = obja->Value(&_gvn); 5411 const Type* b_type = objb->Value(&_gvn); 5412 const TypeAryPtr* top_a = a_type->isa_aryptr(); 5413 const TypeAryPtr* top_b = b_type->isa_aryptr(); 5414 if (top_a == NULL || top_a->klass() == NULL || 5415 top_b == NULL || top_b->klass() == NULL) { 5416 // failed array check 5417 return false; 5418 } 5419 5420 Node* call; 5421 jvms()->set_should_reexecute(true); 5422 5423 obja = access_resolve(obja, ACCESS_READ); 5424 objb = access_resolve(objb, ACCESS_READ); 5425 Node* obja_adr = make_unsafe_address(obja, aoffset, ACCESS_READ); 5426 Node* objb_adr = make_unsafe_address(objb, boffset, ACCESS_READ); 5427 5428 call = make_runtime_call(RC_LEAF, 5429 OptoRuntime::vectorizedMismatch_Type(), 5430 stubAddr, stubName, TypePtr::BOTTOM, 5431 obja_adr, objb_adr, length, scale); 5432 5433 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5434 set_result(result); 5435 return true; 5436 } 5437 5438 /** 5439 * Calculate CRC32 for byte. 5440 * int java.util.zip.CRC32.update(int crc, int b) 5441 */ 5442 bool LibraryCallKit::inline_updateCRC32() { 5443 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5444 assert(callee()->signature()->size() == 2, "update has 2 parameters"); 5445 // no receiver since it is static method 5446 Node* crc = argument(0); // type: int 5447 Node* b = argument(1); // type: int 5448 5449 /* 5450 * int c = ~ crc; 5451 * b = timesXtoThe32[(b ^ c) & 0xFF]; 5452 * b = b ^ (c >>> 8); 5453 * crc = ~b; 5454 */ 5455 5456 Node* M1 = intcon(-1); 5457 crc = _gvn.transform(new XorINode(crc, M1)); 5458 Node* result = _gvn.transform(new XorINode(crc, b)); 5459 result = _gvn.transform(new AndINode(result, intcon(0xFF))); 5460 5461 Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 5462 Node* offset = _gvn.transform(new LShiftINode(result, intcon(0x2))); 5463 Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 5464 result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 5465 5466 crc = _gvn.transform(new URShiftINode(crc, intcon(8))); 5467 result = _gvn.transform(new XorINode(crc, result)); 5468 result = _gvn.transform(new XorINode(result, M1)); 5469 set_result(result); 5470 return true; 5471 } 5472 5473 /** 5474 * Calculate CRC32 for byte[] array. 5475 * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 5476 */ 5477 bool LibraryCallKit::inline_updateBytesCRC32() { 5478 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5479 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5480 // no receiver since it is static method 5481 Node* crc = argument(0); // type: int 5482 Node* src = argument(1); // type: oop 5483 Node* offset = argument(2); // type: int 5484 Node* length = argument(3); // type: int 5485 5486 const Type* src_type = src->Value(&_gvn); 5487 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5488 if (top_src == NULL || top_src->klass() == NULL) { 5489 // failed array check 5490 return false; 5491 } 5492 5493 // Figure out the size and type of the elements we will be copying. 5494 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5495 if (src_elem != T_BYTE) { 5496 return false; 5497 } 5498 5499 // 'src_start' points to src array + scaled offset 5500 src = must_be_not_null(src, true); 5501 src = access_resolve(src, ACCESS_READ); 5502 Node* src_start = array_element_address(src, offset, src_elem); 5503 5504 // We assume that range check is done by caller. 5505 // TODO: generate range check (offset+length < src.length) in debug VM. 5506 5507 // Call the stub. 5508 address stubAddr = StubRoutines::updateBytesCRC32(); 5509 const char *stubName = "updateBytesCRC32"; 5510 5511 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5512 stubAddr, stubName, TypePtr::BOTTOM, 5513 crc, src_start, length); 5514 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5515 set_result(result); 5516 return true; 5517 } 5518 5519 /** 5520 * Calculate CRC32 for ByteBuffer. 5521 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 5522 */ 5523 bool LibraryCallKit::inline_updateByteBufferCRC32() { 5524 assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 5525 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 5526 // no receiver since it is static method 5527 Node* crc = argument(0); // type: int 5528 Node* src = argument(1); // type: long 5529 Node* offset = argument(3); // type: int 5530 Node* length = argument(4); // type: int 5531 5532 src = ConvL2X(src); // adjust Java long to machine word 5533 Node* base = _gvn.transform(new CastX2PNode(src)); 5534 offset = ConvI2X(offset); 5535 5536 // 'src_start' points to src array + scaled offset 5537 Node* src_start = basic_plus_adr(top(), base, offset); 5538 5539 // Call the stub. 5540 address stubAddr = StubRoutines::updateBytesCRC32(); 5541 const char *stubName = "updateBytesCRC32"; 5542 5543 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 5544 stubAddr, stubName, TypePtr::BOTTOM, 5545 crc, src_start, length); 5546 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5547 set_result(result); 5548 return true; 5549 } 5550 5551 //------------------------------get_table_from_crc32c_class----------------------- 5552 Node * LibraryCallKit::get_table_from_crc32c_class(ciInstanceKlass *crc32c_class) { 5553 Node* table = load_field_from_object(NULL, "byteTable", "[I", /*is_exact*/ false, /*is_static*/ true, crc32c_class); 5554 assert (table != NULL, "wrong version of java.util.zip.CRC32C"); 5555 5556 return table; 5557 } 5558 5559 //------------------------------inline_updateBytesCRC32C----------------------- 5560 // 5561 // Calculate CRC32C for byte[] array. 5562 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] buf, int off, int end) 5563 // 5564 bool LibraryCallKit::inline_updateBytesCRC32C() { 5565 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 5566 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5567 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 5568 // no receiver since it is a static method 5569 Node* crc = argument(0); // type: int 5570 Node* src = argument(1); // type: oop 5571 Node* offset = argument(2); // type: int 5572 Node* end = argument(3); // type: int 5573 5574 Node* length = _gvn.transform(new SubINode(end, offset)); 5575 5576 const Type* src_type = src->Value(&_gvn); 5577 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5578 if (top_src == NULL || top_src->klass() == NULL) { 5579 // failed array check 5580 return false; 5581 } 5582 5583 // Figure out the size and type of the elements we will be copying. 5584 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5585 if (src_elem != T_BYTE) { 5586 return false; 5587 } 5588 5589 // 'src_start' points to src array + scaled offset 5590 src = must_be_not_null(src, true); 5591 src = access_resolve(src, ACCESS_READ); 5592 Node* src_start = array_element_address(src, offset, src_elem); 5593 5594 // static final int[] byteTable in class CRC32C 5595 Node* table = get_table_from_crc32c_class(callee()->holder()); 5596 table = must_be_not_null(table, true); 5597 table = access_resolve(table, ACCESS_READ); 5598 Node* table_start = array_element_address(table, intcon(0), T_INT); 5599 5600 // We assume that range check is done by caller. 5601 // TODO: generate range check (offset+length < src.length) in debug VM. 5602 5603 // Call the stub. 5604 address stubAddr = StubRoutines::updateBytesCRC32C(); 5605 const char *stubName = "updateBytesCRC32C"; 5606 5607 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 5608 stubAddr, stubName, TypePtr::BOTTOM, 5609 crc, src_start, length, table_start); 5610 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5611 set_result(result); 5612 return true; 5613 } 5614 5615 //------------------------------inline_updateDirectByteBufferCRC32C----------------------- 5616 // 5617 // Calculate CRC32C for DirectByteBuffer. 5618 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int end) 5619 // 5620 bool LibraryCallKit::inline_updateDirectByteBufferCRC32C() { 5621 assert(UseCRC32CIntrinsics, "need CRC32C instruction support"); 5622 assert(callee()->signature()->size() == 5, "updateDirectByteBuffer has 4 parameters and one is long"); 5623 assert(callee()->holder()->is_loaded(), "CRC32C class must be loaded"); 5624 // no receiver since it is a static method 5625 Node* crc = argument(0); // type: int 5626 Node* src = argument(1); // type: long 5627 Node* offset = argument(3); // type: int 5628 Node* end = argument(4); // type: int 5629 5630 Node* length = _gvn.transform(new SubINode(end, offset)); 5631 5632 src = ConvL2X(src); // adjust Java long to machine word 5633 Node* base = _gvn.transform(new CastX2PNode(src)); 5634 offset = ConvI2X(offset); 5635 5636 // 'src_start' points to src array + scaled offset 5637 Node* src_start = basic_plus_adr(top(), base, offset); 5638 5639 // static final int[] byteTable in class CRC32C 5640 Node* table = get_table_from_crc32c_class(callee()->holder()); 5641 table = must_be_not_null(table, true); 5642 table = access_resolve(table, ACCESS_READ); 5643 Node* table_start = array_element_address(table, intcon(0), T_INT); 5644 5645 // Call the stub. 5646 address stubAddr = StubRoutines::updateBytesCRC32C(); 5647 const char *stubName = "updateBytesCRC32C"; 5648 5649 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesCRC32C_Type(), 5650 stubAddr, stubName, TypePtr::BOTTOM, 5651 crc, src_start, length, table_start); 5652 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5653 set_result(result); 5654 return true; 5655 } 5656 5657 //------------------------------inline_updateBytesAdler32---------------------- 5658 // 5659 // Calculate Adler32 checksum for byte[] array. 5660 // int java.util.zip.Adler32.updateBytes(int crc, byte[] buf, int off, int len) 5661 // 5662 bool LibraryCallKit::inline_updateBytesAdler32() { 5663 assert(UseAdler32Intrinsics, "Adler32 Instrinsic support need"); // check if we actually need to check this flag or check a different one 5664 assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 5665 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 5666 // no receiver since it is static method 5667 Node* crc = argument(0); // type: int 5668 Node* src = argument(1); // type: oop 5669 Node* offset = argument(2); // type: int 5670 Node* length = argument(3); // type: int 5671 5672 const Type* src_type = src->Value(&_gvn); 5673 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5674 if (top_src == NULL || top_src->klass() == NULL) { 5675 // failed array check 5676 return false; 5677 } 5678 5679 // Figure out the size and type of the elements we will be copying. 5680 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 5681 if (src_elem != T_BYTE) { 5682 return false; 5683 } 5684 5685 // 'src_start' points to src array + scaled offset 5686 src = access_resolve(src, ACCESS_READ); 5687 Node* src_start = array_element_address(src, offset, src_elem); 5688 5689 // We assume that range check is done by caller. 5690 // TODO: generate range check (offset+length < src.length) in debug VM. 5691 5692 // Call the stub. 5693 address stubAddr = StubRoutines::updateBytesAdler32(); 5694 const char *stubName = "updateBytesAdler32"; 5695 5696 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 5697 stubAddr, stubName, TypePtr::BOTTOM, 5698 crc, src_start, length); 5699 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5700 set_result(result); 5701 return true; 5702 } 5703 5704 //------------------------------inline_updateByteBufferAdler32--------------- 5705 // 5706 // Calculate Adler32 checksum for DirectByteBuffer. 5707 // int java.util.zip.Adler32.updateByteBuffer(int crc, long buf, int off, int len) 5708 // 5709 bool LibraryCallKit::inline_updateByteBufferAdler32() { 5710 assert(UseAdler32Intrinsics, "Adler32 Instrinsic support need"); // check if we actually need to check this flag or check a different one 5711 assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 5712 assert(callee()->holder()->is_loaded(), "Adler32 class must be loaded"); 5713 // no receiver since it is static method 5714 Node* crc = argument(0); // type: int 5715 Node* src = argument(1); // type: long 5716 Node* offset = argument(3); // type: int 5717 Node* length = argument(4); // type: int 5718 5719 src = ConvL2X(src); // adjust Java long to machine word 5720 Node* base = _gvn.transform(new CastX2PNode(src)); 5721 offset = ConvI2X(offset); 5722 5723 // 'src_start' points to src array + scaled offset 5724 Node* src_start = basic_plus_adr(top(), base, offset); 5725 5726 // Call the stub. 5727 address stubAddr = StubRoutines::updateBytesAdler32(); 5728 const char *stubName = "updateBytesAdler32"; 5729 5730 Node* call = make_runtime_call(RC_LEAF, OptoRuntime::updateBytesAdler32_Type(), 5731 stubAddr, stubName, TypePtr::BOTTOM, 5732 crc, src_start, length); 5733 5734 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 5735 set_result(result); 5736 return true; 5737 } 5738 5739 //----------------------------inline_reference_get---------------------------- 5740 // public T java.lang.ref.Reference.get(); 5741 bool LibraryCallKit::inline_reference_get() { 5742 const int referent_offset = java_lang_ref_Reference::referent_offset; 5743 guarantee(referent_offset > 0, "should have already been set"); 5744 5745 // Get the argument: 5746 Node* reference_obj = null_check_receiver(); 5747 if (stopped()) return true; 5748 5749 const TypeInstPtr* tinst = _gvn.type(reference_obj)->isa_instptr(); 5750 assert(tinst != NULL, "obj is null"); 5751 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5752 ciInstanceKlass* referenceKlass = tinst->klass()->as_instance_klass(); 5753 ciField* field = referenceKlass->get_field_by_name(ciSymbol::make("referent"), 5754 ciSymbol::make("Ljava/lang/Object;"), 5755 false); 5756 assert (field != NULL, "undefined field"); 5757 5758 Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); 5759 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 5760 5761 ciInstanceKlass* klass = env()->Object_klass(); 5762 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); 5763 5764 DecoratorSet decorators = IN_HEAP | ON_WEAK_OOP_REF; 5765 Node* result = access_load_at(reference_obj, adr, adr_type, object_type, T_OBJECT, decorators); 5766 // Add memory barrier to prevent commoning reads from this field 5767 // across safepoint since GC can change its value. 5768 insert_mem_bar(Op_MemBarCPUOrder); 5769 5770 set_result(result); 5771 return true; 5772 } 5773 5774 5775 Node * LibraryCallKit::load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 5776 bool is_exact=true, bool is_static=false, 5777 ciInstanceKlass * fromKls=NULL) { 5778 if (fromKls == NULL) { 5779 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 5780 assert(tinst != NULL, "obj is null"); 5781 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5782 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 5783 fromKls = tinst->klass()->as_instance_klass(); 5784 } else { 5785 assert(is_static, "only for static field access"); 5786 } 5787 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 5788 ciSymbol::make(fieldTypeString), 5789 is_static); 5790 5791 assert (field != NULL, "undefined field"); 5792 if (field == NULL) return (Node *) NULL; 5793 5794 if (is_static) { 5795 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 5796 fromObj = makecon(tip); 5797 } 5798 5799 // Next code copied from Parse::do_get_xxx(): 5800 5801 // Compute address and memory type. 5802 int offset = field->offset_in_bytes(); 5803 bool is_vol = field->is_volatile(); 5804 ciType* field_klass = field->type(); 5805 assert(field_klass->is_loaded(), "should be loaded"); 5806 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 5807 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 5808 BasicType bt = field->layout_type(); 5809 5810 // Build the resultant type of the load 5811 const Type *type; 5812 if (bt == T_OBJECT) { 5813 type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 5814 } else { 5815 type = Type::get_const_basic_type(bt); 5816 } 5817 5818 DecoratorSet decorators = IN_HEAP; 5819 5820 if (is_vol) { 5821 decorators |= MO_SEQ_CST; 5822 } 5823 5824 return access_load_at(fromObj, adr, adr_type, type, bt, decorators); 5825 } 5826 5827 Node * LibraryCallKit::field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 5828 bool is_exact = true, bool is_static = false, 5829 ciInstanceKlass * fromKls = NULL) { 5830 if (fromKls == NULL) { 5831 const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 5832 assert(tinst != NULL, "obj is null"); 5833 assert(tinst->klass()->is_loaded(), "obj is not loaded"); 5834 assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 5835 fromKls = tinst->klass()->as_instance_klass(); 5836 } 5837 else { 5838 assert(is_static, "only for static field access"); 5839 } 5840 ciField* field = fromKls->get_field_by_name(ciSymbol::make(fieldName), 5841 ciSymbol::make(fieldTypeString), 5842 is_static); 5843 5844 assert(field != NULL, "undefined field"); 5845 assert(!field->is_volatile(), "not defined for volatile fields"); 5846 5847 if (is_static) { 5848 const TypeInstPtr* tip = TypeInstPtr::make(fromKls->java_mirror()); 5849 fromObj = makecon(tip); 5850 } 5851 5852 // Next code copied from Parse::do_get_xxx(): 5853 5854 // Compute address and memory type. 5855 int offset = field->offset_in_bytes(); 5856 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 5857 5858 return adr; 5859 } 5860 5861 //------------------------------inline_aescrypt_Block----------------------- 5862 bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 5863 address stubAddr = NULL; 5864 const char *stubName; 5865 assert(UseAES, "need AES instruction support"); 5866 5867 switch(id) { 5868 case vmIntrinsics::_aescrypt_encryptBlock: 5869 stubAddr = StubRoutines::aescrypt_encryptBlock(); 5870 stubName = "aescrypt_encryptBlock"; 5871 break; 5872 case vmIntrinsics::_aescrypt_decryptBlock: 5873 stubAddr = StubRoutines::aescrypt_decryptBlock(); 5874 stubName = "aescrypt_decryptBlock"; 5875 break; 5876 default: 5877 break; 5878 } 5879 if (stubAddr == NULL) return false; 5880 5881 Node* aescrypt_object = argument(0); 5882 Node* src = argument(1); 5883 Node* src_offset = argument(2); 5884 Node* dest = argument(3); 5885 Node* dest_offset = argument(4); 5886 5887 src = must_be_not_null(src, true); 5888 dest = must_be_not_null(dest, true); 5889 5890 src = access_resolve(src, ACCESS_READ); 5891 dest = access_resolve(dest, ACCESS_WRITE); 5892 5893 // (1) src and dest are arrays. 5894 const Type* src_type = src->Value(&_gvn); 5895 const Type* dest_type = dest->Value(&_gvn); 5896 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5897 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5898 assert (top_src != NULL && top_src->klass() != NULL && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5899 5900 // for the quick and dirty code we will skip all the checks. 5901 // we are just trying to get the call to be generated. 5902 Node* src_start = src; 5903 Node* dest_start = dest; 5904 if (src_offset != NULL || dest_offset != NULL) { 5905 assert(src_offset != NULL && dest_offset != NULL, ""); 5906 src_start = array_element_address(src, src_offset, T_BYTE); 5907 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5908 } 5909 5910 // now need to get the start of its expanded key array 5911 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5912 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 5913 if (k_start == NULL) return false; 5914 5915 if (Matcher::pass_original_key_for_aes()) { 5916 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 5917 // compatibility issues between Java key expansion and SPARC crypto instructions 5918 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 5919 if (original_k_start == NULL) return false; 5920 5921 // Call the stub. 5922 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5923 stubAddr, stubName, TypePtr::BOTTOM, 5924 src_start, dest_start, k_start, original_k_start); 5925 } else { 5926 // Call the stub. 5927 make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 5928 stubAddr, stubName, TypePtr::BOTTOM, 5929 src_start, dest_start, k_start); 5930 } 5931 5932 return true; 5933 } 5934 5935 //------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 5936 bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 5937 address stubAddr = NULL; 5938 const char *stubName = NULL; 5939 5940 assert(UseAES, "need AES instruction support"); 5941 5942 switch(id) { 5943 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 5944 stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 5945 stubName = "cipherBlockChaining_encryptAESCrypt"; 5946 break; 5947 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 5948 stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 5949 stubName = "cipherBlockChaining_decryptAESCrypt"; 5950 break; 5951 default: 5952 break; 5953 } 5954 if (stubAddr == NULL) return false; 5955 5956 Node* cipherBlockChaining_object = argument(0); 5957 Node* src = argument(1); 5958 Node* src_offset = argument(2); 5959 Node* len = argument(3); 5960 Node* dest = argument(4); 5961 Node* dest_offset = argument(5); 5962 5963 src = must_be_not_null(src, false); 5964 dest = must_be_not_null(dest, false); 5965 5966 src = access_resolve(src, ACCESS_READ); 5967 dest = access_resolve(dest, ACCESS_WRITE); 5968 5969 // (1) src and dest are arrays. 5970 const Type* src_type = src->Value(&_gvn); 5971 const Type* dest_type = dest->Value(&_gvn); 5972 const TypeAryPtr* top_src = src_type->isa_aryptr(); 5973 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 5974 assert (top_src != NULL && top_src->klass() != NULL 5975 && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 5976 5977 // checks are the responsibility of the caller 5978 Node* src_start = src; 5979 Node* dest_start = dest; 5980 if (src_offset != NULL || dest_offset != NULL) { 5981 assert(src_offset != NULL && dest_offset != NULL, ""); 5982 src_start = array_element_address(src, src_offset, T_BYTE); 5983 dest_start = array_element_address(dest, dest_offset, T_BYTE); 5984 } 5985 5986 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 5987 // (because of the predicated logic executed earlier). 5988 // so we cast it here safely. 5989 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 5990 5991 Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 5992 if (embeddedCipherObj == NULL) return false; 5993 5994 // cast it to what we know it will be at runtime 5995 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 5996 assert(tinst != NULL, "CBC obj is null"); 5997 assert(tinst->klass()->is_loaded(), "CBC obj is not loaded"); 5998 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 5999 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 6000 6001 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6002 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 6003 const TypeOopPtr* xtype = aklass->as_instance_type(); 6004 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 6005 aescrypt_object = _gvn.transform(aescrypt_object); 6006 6007 // we need to get the start of the aescrypt_object's expanded key array 6008 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 6009 if (k_start == NULL) return false; 6010 6011 // similarly, get the start address of the r vector 6012 Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false); 6013 if (objRvec == NULL) return false; 6014 objRvec = access_resolve(objRvec, ACCESS_WRITE); 6015 Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 6016 6017 Node* cbcCrypt; 6018 if (Matcher::pass_original_key_for_aes()) { 6019 // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 6020 // compatibility issues between Java key expansion and SPARC crypto instructions 6021 Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 6022 if (original_k_start == NULL) return false; 6023 6024 // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start 6025 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 6026 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 6027 stubAddr, stubName, TypePtr::BOTTOM, 6028 src_start, dest_start, k_start, r_start, len, original_k_start); 6029 } else { 6030 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 6031 cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 6032 OptoRuntime::cipherBlockChaining_aescrypt_Type(), 6033 stubAddr, stubName, TypePtr::BOTTOM, 6034 src_start, dest_start, k_start, r_start, len); 6035 } 6036 6037 // return cipher length (int) 6038 Node* retvalue = _gvn.transform(new ProjNode(cbcCrypt, TypeFunc::Parms)); 6039 set_result(retvalue); 6040 return true; 6041 } 6042 6043 //------------------------------inline_counterMode_AESCrypt----------------------- 6044 bool LibraryCallKit::inline_counterMode_AESCrypt(vmIntrinsics::ID id) { 6045 assert(UseAES, "need AES instruction support"); 6046 if (!UseAESCTRIntrinsics) return false; 6047 6048 address stubAddr = NULL; 6049 const char *stubName = NULL; 6050 if (id == vmIntrinsics::_counterMode_AESCrypt) { 6051 stubAddr = StubRoutines::counterMode_AESCrypt(); 6052 stubName = "counterMode_AESCrypt"; 6053 } 6054 if (stubAddr == NULL) return false; 6055 6056 Node* counterMode_object = argument(0); 6057 Node* src = argument(1); 6058 Node* src_offset = argument(2); 6059 Node* len = argument(3); 6060 Node* dest = argument(4); 6061 Node* dest_offset = argument(5); 6062 6063 src = access_resolve(src, ACCESS_READ); 6064 dest = access_resolve(dest, ACCESS_WRITE); 6065 counterMode_object = access_resolve(counterMode_object, ACCESS_WRITE); 6066 6067 // (1) src and dest are arrays. 6068 const Type* src_type = src->Value(&_gvn); 6069 const Type* dest_type = dest->Value(&_gvn); 6070 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6071 const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 6072 assert(top_src != NULL && top_src->klass() != NULL && 6073 top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 6074 6075 // checks are the responsibility of the caller 6076 Node* src_start = src; 6077 Node* dest_start = dest; 6078 if (src_offset != NULL || dest_offset != NULL) { 6079 assert(src_offset != NULL && dest_offset != NULL, ""); 6080 src_start = array_element_address(src, src_offset, T_BYTE); 6081 dest_start = array_element_address(dest, dest_offset, T_BYTE); 6082 } 6083 6084 // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 6085 // (because of the predicated logic executed earlier). 6086 // so we cast it here safely. 6087 // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 6088 Node* embeddedCipherObj = load_field_from_object(counterMode_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6089 if (embeddedCipherObj == NULL) return false; 6090 // cast it to what we know it will be at runtime 6091 const TypeInstPtr* tinst = _gvn.type(counterMode_object)->isa_instptr(); 6092 assert(tinst != NULL, "CTR obj is null"); 6093 assert(tinst->klass()->is_loaded(), "CTR obj is not loaded"); 6094 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6095 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded"); 6096 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6097 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 6098 const TypeOopPtr* xtype = aklass->as_instance_type(); 6099 Node* aescrypt_object = new CheckCastPPNode(control(), embeddedCipherObj, xtype); 6100 aescrypt_object = _gvn.transform(aescrypt_object); 6101 // we need to get the start of the aescrypt_object's expanded key array 6102 Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 6103 if (k_start == NULL) return false; 6104 // similarly, get the start address of the r vector 6105 Node* obj_counter = load_field_from_object(counterMode_object, "counter", "[B", /*is_exact*/ false); 6106 if (obj_counter == NULL) return false; 6107 obj_counter = access_resolve(obj_counter, ACCESS_WRITE); 6108 Node* cnt_start = array_element_address(obj_counter, intcon(0), T_BYTE); 6109 6110 Node* saved_encCounter = load_field_from_object(counterMode_object, "encryptedCounter", "[B", /*is_exact*/ false); 6111 if (saved_encCounter == NULL) return false; 6112 saved_encCounter = access_resolve(saved_encCounter, ACCESS_WRITE); 6113 Node* saved_encCounter_start = array_element_address(saved_encCounter, intcon(0), T_BYTE); 6114 Node* used = field_address_from_object(counterMode_object, "used", "I", /*is_exact*/ false); 6115 6116 Node* ctrCrypt; 6117 if (Matcher::pass_original_key_for_aes()) { 6118 // no SPARC version for AES/CTR intrinsics now. 6119 return false; 6120 } 6121 // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 6122 ctrCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 6123 OptoRuntime::counterMode_aescrypt_Type(), 6124 stubAddr, stubName, TypePtr::BOTTOM, 6125 src_start, dest_start, k_start, cnt_start, len, saved_encCounter_start, used); 6126 6127 // return cipher length (int) 6128 Node* retvalue = _gvn.transform(new ProjNode(ctrCrypt, TypeFunc::Parms)); 6129 set_result(retvalue); 6130 return true; 6131 } 6132 6133 //------------------------------get_key_start_from_aescrypt_object----------------------- 6134 Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 6135 #if defined(PPC64) || defined(S390) 6136 // MixColumns for decryption can be reduced by preprocessing MixColumns with round keys. 6137 // Intel's extention is based on this optimization and AESCrypt generates round keys by preprocessing MixColumns. 6138 // However, ppc64 vncipher processes MixColumns and requires the same round keys with encryption. 6139 // The ppc64 stubs of encryption and decryption use the same round keys (sessionK[0]). 6140 Node* objSessionK = load_field_from_object(aescrypt_object, "sessionK", "[[I", /*is_exact*/ false); 6141 assert (objSessionK != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 6142 if (objSessionK == NULL) { 6143 return (Node *) NULL; 6144 } 6145 Node* objAESCryptKey = load_array_element(control(), objSessionK, intcon(0), TypeAryPtr::OOPS); 6146 #else 6147 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false); 6148 #endif // PPC64 6149 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 6150 if (objAESCryptKey == NULL) return (Node *) NULL; 6151 6152 // now have the array, need to get the start address of the K array 6153 objAESCryptKey = access_resolve(objAESCryptKey, ACCESS_READ); 6154 Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 6155 return k_start; 6156 } 6157 6158 //------------------------------get_original_key_start_from_aescrypt_object----------------------- 6159 Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) { 6160 Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false); 6161 assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 6162 if (objAESCryptKey == NULL) return (Node *) NULL; 6163 6164 // now have the array, need to get the start address of the lastKey array 6165 objAESCryptKey = access_resolve(objAESCryptKey, ACCESS_READ); 6166 Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE); 6167 return original_k_start; 6168 } 6169 6170 //----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 6171 // Return node representing slow path of predicate check. 6172 // the pseudo code we want to emulate with this predicate is: 6173 // for encryption: 6174 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 6175 // for decryption: 6176 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6177 // note cipher==plain is more conservative than the original java code but that's OK 6178 // 6179 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 6180 // The receiver was checked for NULL already. 6181 Node* objCBC = argument(0); 6182 6183 Node* src = argument(1); 6184 Node* dest = argument(4); 6185 6186 // Load embeddedCipher field of CipherBlockChaining object. 6187 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6188 6189 // get AESCrypt klass for instanceOf check 6190 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 6191 // will have same classloader as CipherBlockChaining object 6192 const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 6193 assert(tinst != NULL, "CBCobj is null"); 6194 assert(tinst->klass()->is_loaded(), "CBCobj is not loaded"); 6195 6196 // we want to do an instanceof comparison against the AESCrypt class 6197 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6198 if (!klass_AESCrypt->is_loaded()) { 6199 // if AESCrypt is not even loaded, we never take the intrinsic fast path 6200 Node* ctrl = control(); 6201 set_control(top()); // no regular fast path 6202 return ctrl; 6203 } 6204 6205 src = must_be_not_null(src, true); 6206 dest = must_be_not_null(dest, true); 6207 6208 // Resolve oops to stable for CmpP below. 6209 src = access_resolve(src, 0); 6210 dest = access_resolve(dest, 0); 6211 6212 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6213 6214 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 6215 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 6216 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 6217 6218 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6219 6220 // for encryption, we are done 6221 if (!decrypting) 6222 return instof_false; // even if it is NULL 6223 6224 // for decryption, we need to add a further check to avoid 6225 // taking the intrinsic path when cipher and plain are the same 6226 // see the original java code for why. 6227 RegionNode* region = new RegionNode(3); 6228 region->init_req(1, instof_false); 6229 6230 Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest)); 6231 Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq)); 6232 Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN); 6233 region->init_req(2, src_dest_conjoint); 6234 6235 record_for_igvn(region); 6236 return _gvn.transform(region); 6237 } 6238 6239 //----------------------------inline_counterMode_AESCrypt_predicate---------------------------- 6240 // Return node representing slow path of predicate check. 6241 // the pseudo code we want to emulate with this predicate is: 6242 // for encryption: 6243 // if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 6244 // for decryption: 6245 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6246 // note cipher==plain is more conservative than the original java code but that's OK 6247 // 6248 6249 Node* LibraryCallKit::inline_counterMode_AESCrypt_predicate() { 6250 // The receiver was checked for NULL already. 6251 Node* objCTR = argument(0); 6252 6253 // Load embeddedCipher field of CipherBlockChaining object. 6254 Node* embeddedCipherObj = load_field_from_object(objCTR, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6255 6256 // get AESCrypt klass for instanceOf check 6257 // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 6258 // will have same classloader as CipherBlockChaining object 6259 const TypeInstPtr* tinst = _gvn.type(objCTR)->isa_instptr(); 6260 assert(tinst != NULL, "CTRobj is null"); 6261 assert(tinst->klass()->is_loaded(), "CTRobj is not loaded"); 6262 6263 // we want to do an instanceof comparison against the AESCrypt class 6264 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 6265 if (!klass_AESCrypt->is_loaded()) { 6266 // if AESCrypt is not even loaded, we never take the intrinsic fast path 6267 Node* ctrl = control(); 6268 set_control(top()); // no regular fast path 6269 return ctrl; 6270 } 6271 6272 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6273 Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 6274 Node* cmp_instof = _gvn.transform(new CmpINode(instof, intcon(1))); 6275 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 6276 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 6277 6278 return instof_false; // even if it is NULL 6279 } 6280 6281 //------------------------------inline_ghash_processBlocks 6282 bool LibraryCallKit::inline_ghash_processBlocks() { 6283 address stubAddr; 6284 const char *stubName; 6285 assert(UseGHASHIntrinsics, "need GHASH intrinsics support"); 6286 6287 stubAddr = StubRoutines::ghash_processBlocks(); 6288 stubName = "ghash_processBlocks"; 6289 6290 Node* data = argument(0); 6291 Node* offset = argument(1); 6292 Node* len = argument(2); 6293 Node* state = argument(3); 6294 Node* subkeyH = argument(4); 6295 6296 state = must_be_not_null(state, true); 6297 subkeyH = must_be_not_null(subkeyH, true); 6298 data = must_be_not_null(data, true); 6299 6300 state = access_resolve(state, ACCESS_WRITE); 6301 subkeyH = access_resolve(subkeyH, ACCESS_READ); 6302 data = access_resolve(data, ACCESS_READ); 6303 6304 Node* state_start = array_element_address(state, intcon(0), T_LONG); 6305 assert(state_start, "state is NULL"); 6306 Node* subkeyH_start = array_element_address(subkeyH, intcon(0), T_LONG); 6307 assert(subkeyH_start, "subkeyH is NULL"); 6308 Node* data_start = array_element_address(data, offset, T_BYTE); 6309 assert(data_start, "data is NULL"); 6310 6311 Node* ghash = make_runtime_call(RC_LEAF|RC_NO_FP, 6312 OptoRuntime::ghash_processBlocks_Type(), 6313 stubAddr, stubName, TypePtr::BOTTOM, 6314 state_start, subkeyH_start, data_start, len); 6315 return true; 6316 } 6317 6318 bool LibraryCallKit::inline_base64_encodeBlock() { 6319 address stubAddr; 6320 const char *stubName; 6321 assert(UseBASE64Intrinsics, "need Base64 intrinsics support"); 6322 assert(callee()->signature()->size() == 6, "base64_encodeBlock has 6 parameters"); 6323 stubAddr = StubRoutines::base64_encodeBlock(); 6324 stubName = "encodeBlock"; 6325 6326 if (!stubAddr) return false; 6327 Node* base64obj = argument(0); 6328 Node* src = argument(1); 6329 Node* offset = argument(2); 6330 Node* len = argument(3); 6331 Node* dest = argument(4); 6332 Node* dp = argument(5); 6333 Node* isURL = argument(6); 6334 6335 src = must_be_not_null(src, true); 6336 src = access_resolve(src, ACCESS_READ); 6337 dest = must_be_not_null(dest, true); 6338 dest = access_resolve(dest, ACCESS_WRITE); 6339 6340 Node* src_start = array_element_address(src, intcon(0), T_BYTE); 6341 assert(src_start, "source array is NULL"); 6342 Node* dest_start = array_element_address(dest, intcon(0), T_BYTE); 6343 assert(dest_start, "destination array is NULL"); 6344 6345 Node* base64 = make_runtime_call(RC_LEAF, 6346 OptoRuntime::base64_encodeBlock_Type(), 6347 stubAddr, stubName, TypePtr::BOTTOM, 6348 src_start, offset, len, dest_start, dp, isURL); 6349 return true; 6350 } 6351 6352 //------------------------------inline_sha_implCompress----------------------- 6353 // 6354 // Calculate SHA (i.e., SHA-1) for single-block byte[] array. 6355 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs) 6356 // 6357 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array. 6358 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs) 6359 // 6360 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array. 6361 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs) 6362 // 6363 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) { 6364 assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters"); 6365 6366 Node* sha_obj = argument(0); 6367 Node* src = argument(1); // type oop 6368 Node* ofs = argument(2); // type int 6369 6370 const Type* src_type = src->Value(&_gvn); 6371 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6372 if (top_src == NULL || top_src->klass() == NULL) { 6373 // failed array check 6374 return false; 6375 } 6376 // Figure out the size and type of the elements we will be copying. 6377 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 6378 if (src_elem != T_BYTE) { 6379 return false; 6380 } 6381 // 'src_start' points to src array + offset 6382 src = must_be_not_null(src, true); 6383 src = access_resolve(src, ACCESS_READ); 6384 Node* src_start = array_element_address(src, ofs, src_elem); 6385 Node* state = NULL; 6386 address stubAddr; 6387 const char *stubName; 6388 6389 switch(id) { 6390 case vmIntrinsics::_sha_implCompress: 6391 assert(UseSHA1Intrinsics, "need SHA1 instruction support"); 6392 state = get_state_from_sha_object(sha_obj); 6393 stubAddr = StubRoutines::sha1_implCompress(); 6394 stubName = "sha1_implCompress"; 6395 break; 6396 case vmIntrinsics::_sha2_implCompress: 6397 assert(UseSHA256Intrinsics, "need SHA256 instruction support"); 6398 state = get_state_from_sha_object(sha_obj); 6399 stubAddr = StubRoutines::sha256_implCompress(); 6400 stubName = "sha256_implCompress"; 6401 break; 6402 case vmIntrinsics::_sha5_implCompress: 6403 assert(UseSHA512Intrinsics, "need SHA512 instruction support"); 6404 state = get_state_from_sha5_object(sha_obj); 6405 stubAddr = StubRoutines::sha512_implCompress(); 6406 stubName = "sha512_implCompress"; 6407 break; 6408 default: 6409 fatal_unexpected_iid(id); 6410 return false; 6411 } 6412 if (state == NULL) return false; 6413 6414 assert(stubAddr != NULL, "Stub is generated"); 6415 if (stubAddr == NULL) return false; 6416 6417 // Call the stub. 6418 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::sha_implCompress_Type(), 6419 stubAddr, stubName, TypePtr::BOTTOM, 6420 src_start, state); 6421 6422 return true; 6423 } 6424 6425 //------------------------------inline_digestBase_implCompressMB----------------------- 6426 // 6427 // Calculate SHA/SHA2/SHA5 for multi-block byte[] array. 6428 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit) 6429 // 6430 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) { 6431 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics, 6432 "need SHA1/SHA256/SHA512 instruction support"); 6433 assert((uint)predicate < 3, "sanity"); 6434 assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters"); 6435 6436 Node* digestBase_obj = argument(0); // The receiver was checked for NULL already. 6437 Node* src = argument(1); // byte[] array 6438 Node* ofs = argument(2); // type int 6439 Node* limit = argument(3); // type int 6440 6441 const Type* src_type = src->Value(&_gvn); 6442 const TypeAryPtr* top_src = src_type->isa_aryptr(); 6443 if (top_src == NULL || top_src->klass() == NULL) { 6444 // failed array check 6445 return false; 6446 } 6447 // Figure out the size and type of the elements we will be copying. 6448 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 6449 if (src_elem != T_BYTE) { 6450 return false; 6451 } 6452 // 'src_start' points to src array + offset 6453 src = must_be_not_null(src, false); 6454 src = access_resolve(src, ACCESS_READ); 6455 Node* src_start = array_element_address(src, ofs, src_elem); 6456 6457 const char* klass_SHA_name = NULL; 6458 const char* stub_name = NULL; 6459 address stub_addr = NULL; 6460 bool long_state = false; 6461 6462 switch (predicate) { 6463 case 0: 6464 if (UseSHA1Intrinsics) { 6465 klass_SHA_name = "sun/security/provider/SHA"; 6466 stub_name = "sha1_implCompressMB"; 6467 stub_addr = StubRoutines::sha1_implCompressMB(); 6468 } 6469 break; 6470 case 1: 6471 if (UseSHA256Intrinsics) { 6472 klass_SHA_name = "sun/security/provider/SHA2"; 6473 stub_name = "sha256_implCompressMB"; 6474 stub_addr = StubRoutines::sha256_implCompressMB(); 6475 } 6476 break; 6477 case 2: 6478 if (UseSHA512Intrinsics) { 6479 klass_SHA_name = "sun/security/provider/SHA5"; 6480 stub_name = "sha512_implCompressMB"; 6481 stub_addr = StubRoutines::sha512_implCompressMB(); 6482 long_state = true; 6483 } 6484 break; 6485 default: 6486 fatal("unknown SHA intrinsic predicate: %d", predicate); 6487 } 6488 if (klass_SHA_name != NULL) { 6489 assert(stub_addr != NULL, "Stub is generated"); 6490 if (stub_addr == NULL) return false; 6491 6492 // get DigestBase klass to lookup for SHA klass 6493 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr(); 6494 assert(tinst != NULL, "digestBase_obj is not instance???"); 6495 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded"); 6496 6497 ciKlass* klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name)); 6498 assert(klass_SHA->is_loaded(), "predicate checks that this class is loaded"); 6499 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass(); 6500 return inline_sha_implCompressMB(digestBase_obj, instklass_SHA, long_state, stub_addr, stub_name, src_start, ofs, limit); 6501 } 6502 return false; 6503 } 6504 //------------------------------inline_sha_implCompressMB----------------------- 6505 bool LibraryCallKit::inline_sha_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_SHA, 6506 bool long_state, address stubAddr, const char *stubName, 6507 Node* src_start, Node* ofs, Node* limit) { 6508 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_SHA); 6509 const TypeOopPtr* xtype = aklass->as_instance_type(); 6510 Node* sha_obj = new CheckCastPPNode(control(), digestBase_obj, xtype); 6511 sha_obj = _gvn.transform(sha_obj); 6512 6513 Node* state; 6514 if (long_state) { 6515 state = get_state_from_sha5_object(sha_obj); 6516 } else { 6517 state = get_state_from_sha_object(sha_obj); 6518 } 6519 if (state == NULL) return false; 6520 6521 // Call the stub. 6522 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 6523 OptoRuntime::digestBase_implCompressMB_Type(), 6524 stubAddr, stubName, TypePtr::BOTTOM, 6525 src_start, state, ofs, limit); 6526 // return ofs (int) 6527 Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms)); 6528 set_result(result); 6529 6530 return true; 6531 } 6532 6533 enum VectorApiObjectType { 6534 VECAPI_VECTOR, 6535 VECAPI_MASK, 6536 VECAPI_SPECIES, 6537 VECAPI_SHUFFLE, 6538 }; 6539 6540 enum VectorMaskUseType { 6541 VecMaskUseLoad, 6542 VecMaskUseStore, 6543 VecMaskUseAll, 6544 VecMaskNotUsed 6545 }; 6546 6547 static bool arch_supports_vector(int op, int num_elem, BasicType type, VectorMaskUseType mask_use_type, int op_arity = 0) { 6548 // Check that the operation is valid. 6549 if (op <= 0) { 6550 #ifndef PRODUCT 6551 if (DebugVectorApi) { 6552 tty->print_cr("Rejected intrinsification because no valid vector op could be extracted"); 6553 } 6554 #endif 6555 return false; 6556 } 6557 6558 // Check that architecture supports this op-size-type combination. 6559 if (!Matcher::match_rule_supported_vector(op, num_elem, type, op_arity)) { 6560 #ifndef PRODUCT 6561 if (DebugVectorApi) { 6562 tty->print_cr("Rejected vector op (%s,%s,%d) because architecture does not support it", 6563 NodeClassNames[op], type2name(type), num_elem); 6564 } 6565 #endif 6566 return false; 6567 } else { 6568 assert(Matcher::match_rule_supported(op), "must be supported"); 6569 } 6570 6571 // Check whether mask unboxing is supported. 6572 if (mask_use_type == VecMaskUseAll || mask_use_type == VecMaskUseLoad) { 6573 if (!Matcher::match_rule_supported_vector(Op_VectorLoadMask, num_elem, type)) { 6574 #ifndef PRODUCT 6575 if (DebugVectorApi) { 6576 tty->print_cr("Rejected vector mask loading (%s,%s,%d) because architecture does not support it", 6577 NodeClassNames[Op_VectorLoadMask], type2name(type), num_elem); 6578 } 6579 #endif 6580 return false; 6581 } 6582 } 6583 6584 // Check whether mask boxing is supported. 6585 if (mask_use_type == VecMaskUseAll || mask_use_type == VecMaskUseStore) { 6586 if (!Matcher::match_rule_supported_vector(Op_VectorStoreMask, num_elem, type)) { 6587 #ifndef PRODUCT 6588 if (DebugVectorApi) { 6589 tty->print_cr("Rejected vector mask storing (%s,%s,%d) because architecture does not support it", 6590 NodeClassNames[Op_VectorStoreMask], type2name(type), num_elem); 6591 } 6592 #endif 6593 return false; 6594 } 6595 } 6596 6597 return true; 6598 } 6599 6600 // Should be aligned with constants in jdk.incubator.vector.VectorIntrinsics. 6601 enum { 6602 // Unary 6603 OP_ABS = 0, 6604 OP_NEG = 1, 6605 OP_SQRT = 2, 6606 OP_NOT = 3, 6607 // Binary 6608 OP_ADD = 4, 6609 OP_SUB = 5, 6610 OP_MUL = 6, 6611 OP_DIV = 7, 6612 OP_MIN = 8, 6613 OP_MAX = 9, 6614 OP_AND = 10, 6615 OP_OR = 11, 6616 OP_XOR = 12, 6617 // Ternary 6618 OP_FMA = 13, 6619 // Broadcast int 6620 OP_LSHIFT = 14, 6621 OP_RSHIFT = 15, 6622 OP_URSHIFT = 16, 6623 // Vector Math Library 6624 OP_TAN = 101, 6625 OP_SVML_START = OP_TAN, 6626 OP_TANH = 102, 6627 OP_SIN = 103, 6628 OP_SINH = 104, 6629 OP_COS = 105, 6630 OP_COSH = 106, 6631 OP_ASIN = 107, 6632 OP_ACOS = 108, 6633 OP_ATAN = 109, 6634 OP_ATAN2 = 110, 6635 OP_CBRT = 111, 6636 OP_LOG = 112, 6637 OP_LOG10 = 113, 6638 OP_LOG1P = 114, 6639 OP_POW = 115, 6640 OP_EXP = 116, 6641 OP_EXPM1 = 117, 6642 OP_HYPOT = 118, 6643 OP_SVML_END = OP_HYPOT, 6644 }; 6645 6646 static int get_opc(jint op, BasicType bt) { 6647 switch (op) { 6648 case OP_ADD: { 6649 switch (bt) { 6650 case T_BYTE: // fall-through 6651 case T_SHORT: // fall-through 6652 case T_INT: return Op_AddI; 6653 case T_LONG: return Op_AddL; 6654 case T_FLOAT: return Op_AddF; 6655 case T_DOUBLE: return Op_AddD; 6656 default: fatal("ADD: %s", type2name(bt)); 6657 } 6658 break; 6659 } 6660 case OP_SUB: { 6661 switch (bt) { 6662 case T_BYTE: // fall-through 6663 case T_SHORT: // fall-through 6664 case T_INT: return Op_SubI; 6665 case T_LONG: return Op_SubL; 6666 case T_FLOAT: return Op_SubF; 6667 case T_DOUBLE: return Op_SubD; 6668 default: fatal("SUB: %s", type2name(bt)); 6669 } 6670 break; 6671 } 6672 case OP_MUL: { 6673 switch (bt) { 6674 case T_BYTE: // fall-through 6675 case T_SHORT: // fall-through 6676 case T_INT: return Op_MulI; 6677 case T_LONG: return Op_MulL; 6678 case T_FLOAT: return Op_MulF; 6679 case T_DOUBLE: return Op_MulD; 6680 default: fatal("MUL: %s", type2name(bt)); 6681 } 6682 break; 6683 } 6684 case OP_DIV: { 6685 switch (bt) { 6686 case T_BYTE: // fall-through 6687 case T_SHORT: // fall-through 6688 case T_INT: return Op_DivI; 6689 case T_LONG: return Op_DivL; 6690 case T_FLOAT: return Op_DivF; 6691 case T_DOUBLE: return Op_DivD; 6692 default: fatal("DIV: %s", type2name(bt)); 6693 } 6694 break; 6695 } 6696 case OP_MIN: { 6697 switch (bt) { 6698 case T_BYTE: 6699 case T_SHORT: 6700 case T_INT: return Op_MinI; 6701 case T_LONG: return Op_MinL; 6702 case T_FLOAT: return Op_MinF; 6703 case T_DOUBLE: return Op_MinD; 6704 default: fatal("MIN: %s", type2name(bt)); 6705 } 6706 break; 6707 } 6708 case OP_MAX: { 6709 switch (bt) { 6710 case T_BYTE: 6711 case T_SHORT: 6712 case T_INT: return Op_MaxI; 6713 case T_LONG: return Op_MaxL; 6714 case T_FLOAT: return Op_MaxF; 6715 case T_DOUBLE: return Op_MaxD; 6716 default: fatal("MAX: %s", type2name(bt)); 6717 } 6718 break; 6719 } 6720 case OP_ABS: { 6721 switch (bt) { 6722 case T_BYTE: // fall-through 6723 case T_SHORT: // fall-through 6724 case T_LONG: // fall-through 6725 case T_INT: return Op_AbsI; 6726 case T_FLOAT: return Op_AbsF; 6727 case T_DOUBLE: return Op_AbsD; 6728 default: fatal("ABS: %s", type2name(bt)); 6729 } 6730 break; 6731 } 6732 case OP_NEG: { 6733 switch (bt) { 6734 case T_BYTE: // fall-through 6735 case T_SHORT: // fall-through 6736 case T_INT: return Op_NegI; 6737 case T_FLOAT: return Op_NegF; 6738 case T_DOUBLE: return Op_NegD; 6739 default: fatal("NEG: %s", type2name(bt)); 6740 } 6741 break; 6742 } 6743 case OP_AND: { 6744 switch (bt) { 6745 case T_BYTE: // fall-through 6746 case T_SHORT: // fall-through 6747 case T_INT: return Op_AndI; 6748 case T_LONG: return Op_AndL; 6749 default: fatal("AND: %s", type2name(bt)); 6750 } 6751 break; 6752 } 6753 case OP_OR: { 6754 switch (bt) { 6755 case T_BYTE: // fall-through 6756 case T_SHORT: // fall-through 6757 case T_INT: return Op_OrI; 6758 case T_LONG: return Op_OrL; 6759 default: fatal("OR: %s", type2name(bt)); 6760 } 6761 break; 6762 } 6763 case OP_XOR: { 6764 switch (bt) { 6765 case T_BYTE: // fall-through 6766 case T_SHORT: // fall-through 6767 case T_INT: return Op_XorI; 6768 case T_LONG: return Op_XorL; 6769 default: fatal("XOR: %s", type2name(bt)); 6770 } 6771 break; 6772 } 6773 case OP_SQRT: { 6774 switch (bt) { 6775 case T_FLOAT: return Op_SqrtF; 6776 case T_DOUBLE: return Op_SqrtD; 6777 default: fatal("SQRT: %s", type2name(bt)); 6778 } 6779 break; 6780 } 6781 case OP_NOT: { 6782 switch (bt) { 6783 case T_BYTE: // fall-through 6784 case T_SHORT: // fall-through 6785 case T_INT: // fall-through 6786 case T_LONG: return Op_Not; 6787 default: fatal("NOT: %s", type2name(bt)); 6788 } 6789 break; 6790 } 6791 case OP_FMA: { 6792 switch (bt) { 6793 case T_FLOAT: return Op_FmaF; 6794 case T_DOUBLE: return Op_FmaD; 6795 default: fatal("FMA: %s", type2name(bt)); 6796 } 6797 break; 6798 } 6799 case OP_LSHIFT: { 6800 switch (bt) { 6801 case T_BYTE: // fall-through 6802 case T_SHORT: // fall-through 6803 case T_INT: return Op_LShiftI; 6804 case T_LONG: return Op_LShiftL; 6805 default: fatal("LSHIFT: %s", type2name(bt)); 6806 } 6807 break; 6808 } 6809 case OP_RSHIFT: { 6810 switch (bt) { 6811 case T_BYTE: // fall-through 6812 case T_SHORT: // fall-through 6813 case T_INT: return Op_RShiftI; 6814 case T_LONG: return Op_RShiftL; 6815 default: fatal("RSHIFT: %s", type2name(bt)); 6816 } 6817 break; 6818 } 6819 case OP_URSHIFT: { 6820 switch (bt) { 6821 case T_BYTE: return Op_URShiftB; 6822 case T_SHORT: return Op_URShiftS; 6823 case T_INT: return Op_URShiftI; 6824 case T_LONG: return Op_URShiftL; 6825 default: fatal("URSHIFT: %s", type2name(bt)); 6826 } 6827 break; 6828 } 6829 case OP_TAN: 6830 case OP_TANH: 6831 case OP_SIN: 6832 case OP_SINH: 6833 case OP_COS: 6834 case OP_COSH: 6835 case OP_ASIN: 6836 case OP_ACOS: 6837 case OP_ATAN: 6838 case OP_ATAN2: 6839 case OP_CBRT: 6840 case OP_LOG: 6841 case OP_LOG10: 6842 case OP_LOG1P: 6843 case OP_POW: 6844 case OP_EXP: 6845 case OP_EXPM1: 6846 case OP_HYPOT: 6847 return Op_CallLeafVector; 6848 default: fatal("unknown op: %d", op); 6849 } 6850 return 0; // Unimplemented 6851 } 6852 6853 static int get_sopc(int opc, BasicType elem_bt) { 6854 int sopc = 0; 6855 switch (opc) { 6856 case Op_CallLeafVector: 6857 sopc = Op_CallLeafVector; 6858 break; 6859 default: 6860 sopc = VectorNode::opcode(opc, elem_bt); 6861 break; 6862 } 6863 return sopc; 6864 } 6865 Node* LibraryCallKit::box_vector(Node* vector, const TypeInstPtr* vbox_type, 6866 BasicType elem_bt, int num_elem) { 6867 6868 const TypeVect* vec_type = TypeVect::make(elem_bt, num_elem); 6869 6870 VectorBoxAllocateNode* alloc = new VectorBoxAllocateNode(C, vbox_type); 6871 set_edges_for_java_call(alloc, /*must_throw=*/false, /*separate_io_proj=*/true); 6872 make_slow_call_ex(alloc, env()->Throwable_klass(), /*separate_io_proj=*/true); 6873 set_i_o(_gvn.transform( new ProjNode(alloc, TypeFunc::I_O) )); 6874 set_all_memory(_gvn.transform( new ProjNode(alloc, TypeFunc::Memory) )); 6875 Node* ret = _gvn.transform(new ProjNode(alloc, TypeFunc::Parms)); 6876 6877 VectorBoxNode* vbox = new VectorBoxNode(C, ret, vector, vbox_type, vec_type); 6878 return _gvn.transform(vbox); 6879 } 6880 6881 Node* LibraryCallKit::unbox_vector(Node* v, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem) { 6882 const TypeInstPtr* vbox_type_v = gvn().type(v)->is_instptr(); 6883 if (vbox_type->klass() != vbox_type_v->klass()) { 6884 return NULL; // arguments don't agree on vector shapes 6885 } 6886 if (vbox_type_v->maybe_null()) { 6887 return NULL; // no nulls are allowed 6888 } 6889 const TypeVect* vec_type = TypeVect::make(elem_bt, num_elem); 6890 Node* unbox = gvn().transform(new VectorUnboxNode(C, vec_type, v, merged_memory())); 6891 return unbox; 6892 } 6893 6894 void LibraryCallKit::set_vector_result(Node* result, bool set_res) { 6895 if (DebugVectorApi) { 6896 #ifndef PRODUCT 6897 tty->print("============ "); 6898 callee()->print(); 6899 tty->print_cr(" ============"); 6900 result->dump(5); 6901 tty->print_cr("----------------------------------------------------"); 6902 #endif 6903 } 6904 if (set_res) { 6905 set_result(result); 6906 } 6907 } 6908 6909 bool LibraryCallKit::inline_vector_nary_operation(int n) { 6910 const TypeInt* opr = gvn().type(argument(0))->is_int(); 6911 const TypeInstPtr* vector_klass = gvn().type(argument(1))->is_instptr(); 6912 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 6913 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 6914 6915 if (!opr->is_con() || vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 6916 return false; // not enough info for intrinsification 6917 } 6918 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 6919 if (!elem_type->is_primitive_type()) { 6920 return false; // should be primitive type 6921 } 6922 BasicType elem_bt = elem_type->basic_type(); 6923 int num_elem = vlen->get_con(); 6924 int opc = get_opc(opr->get_con(), elem_bt); 6925 int sopc = get_sopc(opc, elem_bt); 6926 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 6927 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 6928 6929 if (opc == Op_CallLeafVector && !Matcher::supports_vector_calling_convention()) { 6930 return false; 6931 } 6932 6933 // TODO When mask usage is supported, VecMaskNotUsed needs to be VecMaskUseLoad. 6934 if (!arch_supports_vector(sopc, num_elem, elem_bt, vbox_klass->is_vectormask() ? VecMaskUseAll : VecMaskNotUsed, n)) { 6935 return false; // not supported 6936 } 6937 6938 Node* opd1 = NULL; Node* opd2 = NULL; Node* opd3 = NULL; 6939 switch (n) { 6940 case 3: { 6941 opd3 = unbox_vector(argument(6), vbox_type, elem_bt, num_elem); 6942 if (opd3 == NULL) { 6943 return false; 6944 } 6945 // fall-through 6946 } 6947 case 2: { 6948 opd2 = unbox_vector(argument(5), vbox_type, elem_bt, num_elem); 6949 if (opd2 == NULL) { 6950 return false; 6951 } 6952 // fall-through 6953 } 6954 case 1: { 6955 opd1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 6956 if (opd1 == NULL) { 6957 return false; 6958 } 6959 break; 6960 } 6961 default: fatal("unsupported arity: %d", n); 6962 } 6963 6964 Node* operation = NULL; 6965 if (sopc == Op_CallLeafVector) { 6966 operation = gen_call_to_svml(opr->get_con(), elem_bt, num_elem, opd1, opd2); 6967 if (operation == NULL) { 6968 return false; 6969 } 6970 } else { 6971 switch (n) { 6972 case 1: 6973 case 2: { 6974 operation = _gvn.transform(VectorNode::make(opc, opd1, opd2, num_elem, elem_bt)); 6975 break; 6976 } 6977 case 3: { 6978 operation = _gvn.transform(VectorNode::make(opc, opd1, opd2, opd3, num_elem, elem_bt)); 6979 break; 6980 } 6981 default: fatal("unsupported arity: %d", n); 6982 } 6983 } 6984 // Wrap it up in VectorBox to keep object type information. 6985 operation = box_vector(operation, vbox_type, elem_bt, num_elem); 6986 set_vector_result(operation); 6987 6988 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 6989 return true; 6990 } 6991 6992 // <V extends Vector<?,?>> 6993 // V broadcastCoerced(Class<?> vectorClass, Class<?> elementType, int vlen, 6994 // long bits, 6995 // LongFunction<V> defaultImpl) 6996 bool LibraryCallKit::inline_vector_broadcast_coerced() { 6997 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 6998 const TypeInstPtr* elem_klass = gvn().type(argument(1))->is_instptr(); 6999 const TypeInt* vlen = gvn().type(argument(2))->is_int(); 7000 7001 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 7002 return false; // not enough info for intrinsification 7003 } 7004 7005 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7006 if (!elem_type->is_primitive_type()) { 7007 return false; // should be primitive type 7008 } 7009 BasicType elem_bt = elem_type->basic_type(); 7010 int num_elem = vlen->get_con(); 7011 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7012 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7013 7014 // TODO When mask usage is supported, VecMaskNotUsed needs to be VecMaskUseLoad. 7015 if (!arch_supports_vector(VectorNode::replicate_opcode(elem_bt), num_elem, elem_bt, 7016 vbox_klass->is_vectormask() ? VecMaskUseStore : VecMaskNotUsed)) { 7017 return false; // not supported 7018 } 7019 7020 Node* bits = argument(3); // long 7021 7022 Node* elem = NULL; 7023 switch (elem_bt) { 7024 case T_BOOLEAN: // fall-through 7025 case T_BYTE: // fall-through 7026 case T_SHORT: // fall-through 7027 case T_CHAR: // fall-through 7028 case T_INT: { 7029 elem = gvn().transform(new ConvL2INode(bits)); 7030 break; 7031 } 7032 case T_DOUBLE: { 7033 elem = gvn().transform(new MoveL2DNode(bits)); 7034 break; 7035 } 7036 case T_FLOAT: { 7037 bits = gvn().transform(new ConvL2INode(bits)); 7038 elem = gvn().transform(new MoveI2FNode(bits)); 7039 break; 7040 } 7041 case T_LONG: { 7042 elem = bits; // no conversion needed 7043 break; 7044 } 7045 default: fatal("%s", type2name(elem_bt)); 7046 } 7047 7048 Node* broadcast = VectorNode::scalar2vector(elem, num_elem, Type::get_const_basic_type(elem_bt)); 7049 broadcast = gvn().transform(broadcast); 7050 Node* box = box_vector(broadcast, vbox_type, elem_bt, num_elem); 7051 set_vector_result(box); 7052 7053 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7054 return true; 7055 } 7056 7057 // <C, V extends Vector<?,?>> 7058 // V load(Class<?> vectorClass, Class<?> elementType, int vlen, 7059 // Object base, long offset, 7060 // /* Vector.Mask<E,S> m*/ 7061 // Object container, int index, 7062 // LoadOperation<C, VM> defaultImpl) { 7063 // 7064 // <C, V extends Vector<?,?>> 7065 // void store(Class<?> vectorClass, Class<?> elementType, int vlen, 7066 // Object base, long offset, 7067 // V v, /*Vector.Mask<E,S> m*/ 7068 // Object container, int index, 7069 // StoreVectorOperation<C, V> defaultImpl) { 7070 7071 bool LibraryCallKit::inline_vector_mem_operation(bool is_store) { 7072 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 7073 const TypeInstPtr* elem_klass = gvn().type(argument(1))->is_instptr(); 7074 const TypeInt* vlen = gvn().type(argument(2))->is_int(); 7075 7076 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 7077 return false; // not enough info for intrinsification 7078 } 7079 7080 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7081 if (!elem_type->is_primitive_type()) { 7082 return false; // should be primitive type 7083 } 7084 BasicType elem_bt = elem_type->basic_type(); 7085 int num_elem = vlen->get_con(); 7086 7087 // TODO When mask usage is supported, VecMaskNotUsed needs to be VecMaskUseLoad. 7088 if (!arch_supports_vector(is_store ? Op_StoreVector : Op_LoadVector, num_elem, elem_bt, VecMaskNotUsed)) { 7089 return false; // not supported 7090 } 7091 7092 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7093 bool is_mask = vbox_klass->is_vectormask(); 7094 7095 Node* base = argument(3); 7096 Node* offset = ConvL2X(argument(4)); 7097 DecoratorSet decorators = C2_UNSAFE_ACCESS; 7098 Node* addr = make_unsafe_address(base, offset, decorators, (is_mask ? T_BOOLEAN : elem_bt), true); 7099 7100 // Can base be NULL? Otherwise, always on-heap access. 7101 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(base)); 7102 7103 const TypePtr *addr_type = gvn().type(addr)->isa_ptr(); 7104 const TypeAryPtr* arr_type = addr_type->isa_aryptr(); 7105 7106 // Now handle special case where load/store happens from/to byte array but element type is not byte. 7107 bool using_byte_array = arr_type != NULL && arr_type->elem()->array_element_basic_type() == T_BYTE && elem_bt != T_BYTE; 7108 // Handle loading masks. 7109 // If there is no consistency between array and vector element types, it must be special byte array case or loading masks 7110 if (arr_type != NULL && !using_byte_array && elem_bt != arr_type->elem()->array_element_basic_type() && !is_mask) { 7111 return false; 7112 } 7113 // Since we are using byte array, we need to double check that the byte operations are supported by backend. 7114 if (using_byte_array) { 7115 int byte_num_elem = num_elem * type2aelembytes(elem_bt); 7116 if (!arch_supports_vector(is_store ? Op_StoreVector : Op_LoadVector, byte_num_elem, T_BYTE, VecMaskNotUsed)) { 7117 return false; // not supported 7118 } 7119 } 7120 if (is_mask) { 7121 if (!arch_supports_vector(Op_LoadVector, num_elem, T_BOOLEAN, VecMaskNotUsed)) { 7122 return false; // not supported 7123 } 7124 } 7125 7126 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7127 7128 if (can_access_non_heap) { 7129 insert_mem_bar(Op_MemBarCPUOrder); 7130 } 7131 7132 if (is_store) { 7133 Node* val = unbox_vector(argument(6), vbox_type, elem_bt, num_elem); 7134 if (val == NULL) { 7135 return false; // operand unboxing failed 7136 } 7137 set_all_memory(reset_memory()); 7138 7139 // In case the store needs to happen to byte array, reinterpret the incoming vector to byte vector. 7140 int store_num_elem = num_elem; 7141 if (using_byte_array) { 7142 store_num_elem = num_elem * type2aelembytes(elem_bt); 7143 const TypeVect* to_vect_type = TypeVect::make(T_BYTE, store_num_elem); 7144 val = gvn().transform(new VectorReinterpretNode(val, val->bottom_type()->is_vect(), to_vect_type)); 7145 } 7146 7147 Node* vstore = gvn().transform(StoreVectorNode::make(0, control(), memory(addr), addr, addr_type, val, store_num_elem)); 7148 set_memory(vstore, addr_type); 7149 set_vector_result(vstore, false); 7150 } else { 7151 // When using byte array, we need to load as byte then reinterpret the value. Otherwise, do a simple vector load. 7152 Node* vload = NULL; 7153 if (using_byte_array) { 7154 int load_num_elem = num_elem * type2aelembytes(elem_bt); 7155 vload = gvn().transform(LoadVectorNode::make(0, control(), memory(addr), addr, addr_type, load_num_elem, T_BYTE)); 7156 const TypeVect* to_vect_type = TypeVect::make(elem_bt, num_elem); 7157 vload = gvn().transform(new VectorReinterpretNode(vload, vload->bottom_type()->is_vect(), to_vect_type)); 7158 } else { 7159 // Special handle for masks 7160 if (is_mask) { 7161 vload = gvn().transform(LoadVectorNode::make(0, control(), memory(addr), addr, addr_type, num_elem, T_BOOLEAN)); 7162 const TypeVect* to_vect_type = TypeVect::make(elem_bt, num_elem); 7163 vload = gvn().transform(new VectorLoadMaskNode(vload, to_vect_type)); 7164 } else { 7165 vload = gvn().transform(LoadVectorNode::make(0, control(), memory(addr), addr, addr_type, num_elem, elem_bt)); 7166 } 7167 } 7168 Node* box = box_vector(vload, vbox_type, elem_bt, num_elem); 7169 set_vector_result(box); 7170 } 7171 7172 if (can_access_non_heap) { 7173 insert_mem_bar(Op_MemBarCPUOrder); 7174 } 7175 7176 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7177 return true; 7178 } 7179 7180 // <C, V extends Vector<?>, W extends IntVector> 7181 // void storeWithMap(Class<?> vectorClass, Class<?> elementType, int length, Class<?> vectorIndexClass, 7182 // Object base, long offset, // Unsafe addressing 7183 // W index_vector, V v, 7184 // C container, int index, int[] indexMap, int indexM, // Arguments for default implementation 7185 // StoreVectorOperationWithMap<C, V> defaultImpl) { 7186 // 7187 bool LibraryCallKit::inline_vector_gather_scatter(bool is_scatter) { 7188 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 7189 const TypeInstPtr* elem_klass = gvn().type(argument(1))->is_instptr(); 7190 const TypeInt* vlen = gvn().type(argument(2))->is_int(); 7191 const TypeInstPtr* vector_idx_klass = gvn().type(argument(3))->is_instptr(); 7192 7193 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || vector_idx_klass->const_oop() == NULL || !vlen->is_con()) { 7194 return false; // not enough info for intrinsification 7195 } 7196 7197 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7198 if (!elem_type->is_primitive_type()) { 7199 return false; // should be primitive type 7200 } 7201 BasicType elem_bt = elem_type->basic_type(); 7202 int num_elem = vlen->get_con(); 7203 7204 if (!arch_supports_vector(is_scatter ? Op_StoreVectorScatter : Op_LoadVectorGather, num_elem, elem_bt, VecMaskNotUsed)) { 7205 return false; // not supported 7206 } 7207 7208 // Check that the vector holding indices is supported by architecture 7209 if (!arch_supports_vector(Op_LoadVector, num_elem, T_INT, VecMaskNotUsed)) { 7210 return false; // not supported 7211 } 7212 7213 Node* base = argument(4); 7214 Node* offset = ConvL2X(argument(5)); 7215 Node* addr = make_unsafe_address(base, offset, C2_UNSAFE_ACCESS, elem_bt, true); 7216 7217 const TypePtr *addr_type = gvn().type(addr)->isa_ptr(); 7218 const TypeAryPtr* arr_type = addr_type->isa_aryptr(); 7219 7220 // The array must be consistent with vector type 7221 if (arr_type == NULL || (arr_type != NULL && elem_bt != arr_type->elem()->array_element_basic_type())) { 7222 return false; 7223 } 7224 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7225 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7226 7227 ciKlass* vbox_idx_klass = vector_idx_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7228 7229 if (vbox_idx_klass == NULL) { 7230 return false; 7231 } 7232 7233 const TypeInstPtr* vbox_idx_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_idx_klass); 7234 7235 Node* index_vect = unbox_vector(argument(7), vbox_idx_type, T_INT, num_elem); 7236 if (index_vect == NULL) { 7237 return false; 7238 } 7239 7240 const TypeVect* index_src_type = index_vect->as_Vector()->vect_type(); 7241 const TypeVect* index_dst_type = TypeVect::make(T_INT, num_elem); 7242 7243 if (Type::cmp(index_src_type, index_dst_type) != 0) { 7244 // For DoubleMaxVector and LongMaxVector, indexVector's length is twice. 7245 assert((elem_bt == T_DOUBLE || elem_bt == T_LONG) && 7246 index_src_type->element_basic_type() == T_INT && 7247 index_src_type->length() == index_dst_type->length() * 2, 7248 "Expect double the length"); 7249 7250 // Check whether resizing is support. 7251 if (!arch_supports_vector(Op_VectorReinterpret, 7252 index_src_type->length(), 7253 index_src_type->element_basic_type(), 7254 VecMaskNotUsed)) { 7255 return false; 7256 } 7257 if (!arch_supports_vector(Op_VectorReinterpret, 7258 num_elem, 7259 T_INT, 7260 VecMaskNotUsed)) { 7261 return false; 7262 } 7263 index_vect = gvn().transform(new VectorReinterpretNode(index_vect, index_src_type, index_dst_type)); 7264 } 7265 7266 const TypeVect* vector_type = TypeVect::make(elem_bt, num_elem); 7267 if (is_scatter) { 7268 Node* val = unbox_vector(argument(8), vbox_type, elem_bt, num_elem); 7269 if (val == NULL) { 7270 return false; // operand unboxing failed 7271 } 7272 set_all_memory(reset_memory()); 7273 7274 Node* vstore = gvn().transform(new StoreVectorScatterNode(control(), memory(addr), addr, addr_type, val, index_vect)); 7275 set_memory(vstore, addr_type); 7276 set_vector_result(vstore, false); 7277 } else { 7278 Node* vload = gvn().transform(new LoadVectorGatherNode(control(), memory(addr), addr, addr_type, vector_type, index_vect)); 7279 7280 Node* box = box_vector(vload, vbox_type, elem_bt, num_elem); 7281 set_vector_result(box); 7282 } 7283 7284 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7285 return true; 7286 } 7287 7288 // <V extends Vector<?,?>> 7289 // long reductionCoerced(int oprId, Class<?> vectorClass, Class<?> elementType, int vlen, 7290 // V v, 7291 // Function<V,Long> defaultImpl) 7292 7293 bool LibraryCallKit::inline_vector_reduction() { 7294 const TypeInt* opr = gvn().type(argument(0))->is_int(); 7295 const TypeInstPtr* vector_klass = gvn().type(argument(1))->is_instptr(); 7296 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 7297 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 7298 7299 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 7300 return false; // not enough info for intrinsification 7301 } 7302 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7303 if (!elem_type->is_primitive_type()) { 7304 return false; // should be primitive type 7305 } 7306 BasicType elem_bt = elem_type->basic_type(); 7307 int num_elem = vlen->get_con(); 7308 7309 int opc = get_opc(opr->get_con(), elem_bt); 7310 int sopc = ReductionNode::opcode(opc, elem_bt); 7311 7312 // FIXME: When encountering a SubReduction, we want to check for support of 7313 // the corresponding AddReduction node. 7314 if (sopc == Op_SubReductionV) { 7315 if (gvn().type(argument(2))->isa_int()) { 7316 sopc = Op_AddReductionVI; 7317 } else if (gvn().type(argument(2))->isa_long()) { 7318 sopc = Op_AddReductionVL; 7319 } 7320 } 7321 7322 // TODO When mask usage is supported, VecMaskNotUsed needs to be VecMaskUseLoad. 7323 if (!arch_supports_vector(sopc, num_elem, elem_bt, VecMaskNotUsed)) { 7324 return false; 7325 } 7326 7327 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7328 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7329 7330 Node* opd = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 7331 if (opd == NULL) { 7332 return false; // operand unboxing failed 7333 } 7334 7335 Node* init = ReductionNode::make_reduction_input(_gvn, opc, elem_bt); 7336 Node* rn = gvn().transform(ReductionNode::make(opc, NULL, init, opd, elem_bt)); 7337 7338 Node* bits = NULL; 7339 switch (elem_bt) { 7340 case T_BYTE: 7341 case T_SHORT: 7342 case T_INT: { 7343 bits = gvn().transform(new ConvI2LNode(rn)); 7344 break; 7345 } 7346 case T_FLOAT: { 7347 rn = gvn().transform(new MoveF2INode(rn)); 7348 bits = gvn().transform(new ConvI2LNode(rn)); 7349 break; 7350 } 7351 case T_DOUBLE: { 7352 bits = gvn().transform(new MoveD2LNode(rn)); 7353 break; 7354 } 7355 case T_LONG: { 7356 bits = rn; // no conversion needed 7357 break; 7358 } 7359 default: fatal("%s", type2name(elem_bt)); 7360 } 7361 set_vector_result(bits); 7362 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7363 return true; 7364 } 7365 7366 // static <V> boolean test(int cond, Class<?> vectorClass, Class<?> elementType, int vlen, 7367 // V v1, V v2, 7368 // BiFunction<V, V, Boolean> defaultImpl) { 7369 7370 bool LibraryCallKit::inline_vector_test() { 7371 const TypeInt* cond = gvn().type(argument(0))->is_int(); 7372 const TypeInstPtr* vector_klass = gvn().type(argument(1))->is_instptr(); 7373 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 7374 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 7375 7376 if (!cond->is_con() || vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 7377 return false; // not enough info for intrinsification 7378 } 7379 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7380 if (!elem_type->is_primitive_type()) { 7381 return false; // should be primitive type 7382 } 7383 BasicType elem_bt = elem_type->basic_type(); 7384 int num_elem = vlen->get_con(); 7385 BoolTest::mask booltest = (BoolTest::mask)cond->get_con(); 7386 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7387 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7388 7389 if (!arch_supports_vector(Op_VectorTest, num_elem, elem_bt, vbox_klass->is_vectormask() ? VecMaskUseLoad : VecMaskNotUsed)) { 7390 return false; 7391 } 7392 7393 Node* opd1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 7394 Node* opd2 = unbox_vector(argument(5), vbox_type, elem_bt, num_elem); 7395 if (opd1 == NULL || opd2 == NULL) { 7396 return false; // operand unboxing failed 7397 } 7398 Node* test = new VectorTestNode(opd1, opd2, booltest); 7399 test = _gvn.transform(test); 7400 set_vector_result(test); 7401 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7402 return true; 7403 } 7404 7405 // static 7406 // <V extends Vector, M extends Mask> 7407 // V blend(Class<V> vectorClass, Class<M> maskClass, Class<?> elementType, int vlen, 7408 // V v1, V v2, M m, 7409 // VectorBlendOp<V,M> defaultImpl) { ... 7410 // 7411 bool LibraryCallKit::inline_vector_blend() { 7412 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 7413 const TypeInstPtr* mask_klass = gvn().type(argument(1))->is_instptr(); 7414 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 7415 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 7416 7417 if (mask_klass->const_oop() == NULL || vector_klass->const_oop() == NULL || 7418 elem_klass->const_oop() == NULL || !vlen->is_con()) { 7419 return false; // not enough info for intrinsification 7420 } 7421 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7422 if (!elem_type->is_primitive_type()) { 7423 return false; // should be primitive type 7424 } 7425 BasicType elem_bt = elem_type->basic_type(); 7426 BasicType mask_bt = elem_bt; 7427 int num_elem = vlen->get_con(); 7428 7429 if (!arch_supports_vector(Op_VectorBlend, num_elem, elem_bt, VecMaskUseLoad)) { 7430 return false; // not supported 7431 } 7432 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7433 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7434 7435 ciKlass* mbox_klass = mask_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7436 const TypeInstPtr* mbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, mbox_klass); 7437 7438 Node* v1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 7439 Node* v2 = unbox_vector(argument(5), vbox_type, elem_bt, num_elem); 7440 Node* mask = unbox_vector(argument(6), mbox_type, mask_bt, num_elem); 7441 7442 if (v1 == NULL || v2 == NULL || mask == NULL) { 7443 return false; // operand unboxing failed 7444 } 7445 7446 Node* blend = _gvn.transform(new VectorBlendNode(v1, v2, mask)); 7447 Node* box = box_vector(blend, vbox_type, elem_bt, num_elem); 7448 set_vector_result(box); 7449 7450 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7451 return true; 7452 } 7453 7454 // static <V extends Vector<E,S>, 7455 // M extends Vector.Mask<E,S>, 7456 // S extends Vector.Shape, E> 7457 // M compare(int cond, Class<V> vectorClass, Class<M> maskClass, Class<?> elementType, int vlen, 7458 // V v1, V v2, 7459 // VectorCompareOp<V,M> defaultImpl) { ... 7460 // 7461 bool LibraryCallKit::inline_vector_compare() { 7462 const TypeInt* cond = gvn().type(argument(0))->is_int(); 7463 const TypeInstPtr* vector_klass = gvn().type(argument(1))->is_instptr(); 7464 const TypeInstPtr* mask_klass = gvn().type(argument(2))->is_instptr(); 7465 const TypeInstPtr* elem_klass = gvn().type(argument(3))->is_instptr(); 7466 const TypeInt* vlen = gvn().type(argument(4))->is_int(); 7467 7468 if (!cond->is_con() || vector_klass->const_oop() == NULL || mask_klass->const_oop() == NULL || 7469 elem_klass->const_oop() == NULL || !vlen->is_con()) { 7470 return false; // not enough info for intrinsification 7471 } 7472 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7473 if (!elem_type->is_primitive_type()) { 7474 return false; // should be primitive type 7475 } 7476 7477 int num_elem = vlen->get_con(); 7478 BasicType elem_bt = elem_type->basic_type(); 7479 BasicType mask_bt = elem_bt; 7480 7481 if (!arch_supports_vector(Op_VectorMaskCmp, num_elem, elem_bt, VecMaskUseStore)) { 7482 return false; 7483 } 7484 7485 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7486 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7487 7488 ciKlass* mbox_klass = mask_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7489 const TypeInstPtr* mbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, mbox_klass); 7490 7491 Node* v1 = unbox_vector(argument(5), vbox_type, elem_bt, num_elem); 7492 Node* v2 = unbox_vector(argument(6), vbox_type, elem_bt, num_elem); 7493 7494 if (v1 == NULL || v2 == NULL) { 7495 return false; // operand unboxing failed 7496 } 7497 BoolTest::mask pred = (BoolTest::mask)cond->get_con(); 7498 const TypeVect* vt = TypeVect::make(mask_bt, num_elem); 7499 Node* operation = _gvn.transform(new VectorMaskCmpNode(pred, v1, v2, vt)); 7500 7501 Node* box = box_vector(operation, mbox_type, mask_bt, num_elem); 7502 set_vector_result(box); 7503 7504 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7505 return true; 7506 } 7507 7508 // static 7509 // <V extends Vector, Sh extends Shuffle> 7510 // V rearrangeOp(Class<V> vectorClass, Class<Sh> shuffleClass, Class< ? > elementType, int vlen, 7511 // V v1, Sh sh, 7512 // VectorSwizzleOp<V, Sh, S, E> defaultImpl) { ... 7513 7514 bool LibraryCallKit::inline_vector_rearrange() { 7515 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 7516 const TypeInstPtr* shuffle_klass = gvn().type(argument(1))->is_instptr(); 7517 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 7518 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 7519 7520 if (shuffle_klass->const_oop() == NULL || vector_klass->const_oop() == NULL || 7521 elem_klass->const_oop() == NULL || !vlen->is_con()) { 7522 return false; // not enough info for intrinsification 7523 } 7524 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7525 if (!elem_type->is_primitive_type()) { 7526 return false; // should be primitive type 7527 } 7528 BasicType elem_bt = elem_type->basic_type(); 7529 BasicType shuffle_bt = elem_bt; 7530 int num_elem = vlen->get_con(); 7531 7532 if (!arch_supports_vector(Op_VectorLoadShuffle, num_elem, elem_bt, VecMaskNotUsed)) { 7533 return false; // not supported 7534 } 7535 if (!arch_supports_vector(Op_VectorRearrange, num_elem, elem_bt, VecMaskNotUsed)) { 7536 return false; // not supported 7537 } 7538 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7539 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 7540 7541 ciKlass* shbox_klass = shuffle_klass->const_oop()->as_instance()->java_lang_Class_klass(); 7542 const TypeInstPtr* shbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, shbox_klass); 7543 7544 Node* v1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 7545 Node* shuffle = unbox_vector(argument(5), shbox_type, shuffle_bt, num_elem); 7546 7547 if (v1 == NULL || shuffle == NULL) { 7548 return false; // operand unboxing failed 7549 } 7550 7551 Node* rearrange = _gvn.transform(new VectorRearrangeNode(v1, shuffle)); 7552 Node* box = box_vector(rearrange, vbox_type, elem_bt, num_elem); 7553 set_result(box); 7554 7555 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 7556 return true; 7557 } 7558 7559 Node* LibraryCallKit::shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem) { 7560 assert(bt == T_INT || bt == T_LONG || bt == T_SHORT || bt == T_BYTE, "byte, short, long and int are supported"); 7561 juint mask = (type2aelembytes(bt) * BitsPerByte - 1); 7562 Node* nmask = _gvn.transform(ConNode::make(TypeInt::make(mask))); 7563 Node* mcnt = _gvn.transform(new AndINode(cnt, nmask)); 7564 return _gvn.transform(VectorNode::shift_count(shift_op, mcnt, num_elem, bt)); 7565 } 7566 7567 static void get_svml_address(int op, int bits, BasicType bt, const char** name_ptr, address* addr_ptr) { 7568 assert(name_ptr != NULL, "unexpected"); 7569 assert(addr_ptr != NULL, "unexpected"); 7570 7571 // Since the addresses are resolved at runtime, using switch instead of table - otherwise might get NULL addresses. 7572 if (bt == T_FLOAT) { 7573 switch(op) { 7574 case OP_EXP: { 7575 switch(bits) { 7576 case 64: *name_ptr = "vector_float64_exp"; *addr_ptr = StubRoutines::vector_float64_exp(); break; 7577 case 128: *name_ptr = "vector_float128_exp"; *addr_ptr = StubRoutines::vector_float128_exp(); break; 7578 case 256: *name_ptr = "vector_float256_exp"; *addr_ptr = StubRoutines::vector_float256_exp(); break; 7579 case 512: *name_ptr = "vector_float512_exp"; *addr_ptr = StubRoutines::vector_float512_exp(); break; 7580 default: Unimplemented(); break; 7581 } 7582 } 7583 break; 7584 case OP_LOG1P: { 7585 switch(bits) { 7586 case 64: *name_ptr = "vector_float64_log1p"; *addr_ptr = StubRoutines::vector_float64_log1p(); break; 7587 case 128: *name_ptr = "vector_float128_log1p"; *addr_ptr = StubRoutines::vector_float128_log1p(); break; 7588 case 256: *name_ptr = "vector_float256_log1p"; *addr_ptr = StubRoutines::vector_float256_log1p(); break; 7589 case 512: *name_ptr = "vector_float512_log1p"; *addr_ptr = StubRoutines::vector_float512_log1p(); break; 7590 default: Unimplemented(); break; 7591 } 7592 } 7593 break; 7594 case OP_LOG: { 7595 switch(bits) { 7596 case 64: *name_ptr = "vector_float64_log"; *addr_ptr = StubRoutines::vector_float64_log(); break; 7597 case 128: *name_ptr = "vector_float128_log"; *addr_ptr = StubRoutines::vector_float128_log(); break; 7598 case 256: *name_ptr = "vector_float256_log"; *addr_ptr = StubRoutines::vector_float256_log(); break; 7599 case 512: *name_ptr = "vector_float512_log"; *addr_ptr = StubRoutines::vector_float512_log(); break; 7600 default: Unimplemented(); break; 7601 } 7602 } 7603 break; 7604 case OP_LOG10: { 7605 switch(bits) { 7606 case 64: *name_ptr = "vector_float64_log10"; *addr_ptr = StubRoutines::vector_float64_log10(); break; 7607 case 128: *name_ptr = "vector_float128_log10"; *addr_ptr = StubRoutines::vector_float128_log10(); break; 7608 case 256: *name_ptr = "vector_float256_log10"; *addr_ptr = StubRoutines::vector_float256_log10(); break; 7609 case 512: *name_ptr = "vector_float512_log10"; *addr_ptr = StubRoutines::vector_float512_log10(); break; 7610 default: Unimplemented(); break; 7611 } 7612 } 7613 break; 7614 case OP_EXPM1: { 7615 switch(bits) { 7616 case 64: *name_ptr = "vector_float64_expm1"; *addr_ptr = StubRoutines::vector_float64_expm1(); break; 7617 case 128: *name_ptr = "vector_float128_expm1"; *addr_ptr = StubRoutines::vector_float128_expm1(); break; 7618 case 256: *name_ptr = "vector_float256_expm1"; *addr_ptr = StubRoutines::vector_float256_expm1(); break; 7619 case 512: *name_ptr = "vector_float512_expm1"; *addr_ptr = StubRoutines::vector_float512_expm1(); break; 7620 default: Unimplemented(); break; 7621 } 7622 } 7623 break; 7624 case OP_SIN: { 7625 switch(bits) { 7626 case 64: *name_ptr = "vector_float64_sin"; *addr_ptr = StubRoutines::vector_float64_sin(); break; 7627 case 128: *name_ptr = "vector_float128_sin"; *addr_ptr = StubRoutines::vector_float128_sin(); break; 7628 case 256: *name_ptr = "vector_float256_sin"; *addr_ptr = StubRoutines::vector_float256_sin(); break; 7629 case 512: *name_ptr = "vector_float512_sin"; *addr_ptr = StubRoutines::vector_float512_sin(); break; 7630 default: Unimplemented(); break; 7631 } 7632 } 7633 break; 7634 case OP_COS: { 7635 switch(bits) { 7636 case 64: *name_ptr = "vector_float64_cos"; *addr_ptr = StubRoutines::vector_float64_cos(); break; 7637 case 128: *name_ptr = "vector_float128_cos"; *addr_ptr = StubRoutines::vector_float128_cos(); break; 7638 case 256: *name_ptr = "vector_float256_cos"; *addr_ptr = StubRoutines::vector_float256_cos(); break; 7639 case 512: *name_ptr = "vector_float512_cos"; *addr_ptr = StubRoutines::vector_float512_cos(); break; 7640 default: Unimplemented(); break; 7641 } 7642 } 7643 break; 7644 case OP_TAN: { 7645 switch(bits) { 7646 case 64: *name_ptr = "vector_float64_tan"; *addr_ptr = StubRoutines::vector_float64_tan(); break; 7647 case 128: *name_ptr = "vector_float128_tan"; *addr_ptr = StubRoutines::vector_float128_tan(); break; 7648 case 256: *name_ptr = "vector_float256_tan"; *addr_ptr = StubRoutines::vector_float256_tan(); break; 7649 case 512: *name_ptr = "vector_float512_tan"; *addr_ptr = StubRoutines::vector_float512_tan(); break; 7650 default: Unimplemented(); break; 7651 } 7652 } 7653 break; 7654 case OP_SINH: { 7655 switch(bits) { 7656 case 64: *name_ptr = "vector_float64_sinh"; *addr_ptr = StubRoutines::vector_float64_sinh(); break; 7657 case 128: *name_ptr = "vector_float128_sinh"; *addr_ptr = StubRoutines::vector_float128_sinh(); break; 7658 case 256: *name_ptr = "vector_float256_sinh"; *addr_ptr = StubRoutines::vector_float256_sinh(); break; 7659 case 512: *name_ptr = "vector_float512_sinh"; *addr_ptr = StubRoutines::vector_float512_sinh(); break; 7660 default: Unimplemented(); break; 7661 } 7662 } 7663 break; 7664 case OP_COSH: { 7665 switch(bits) { 7666 case 64: *name_ptr = "vector_float64_cosh"; *addr_ptr = StubRoutines::vector_float64_cosh(); break; 7667 case 128: *name_ptr = "vector_float128_cosh"; *addr_ptr = StubRoutines::vector_float128_cosh(); break; 7668 case 256: *name_ptr = "vector_float256_cosh"; *addr_ptr = StubRoutines::vector_float256_cosh(); break; 7669 case 512: *name_ptr = "vector_float512_cosh"; *addr_ptr = StubRoutines::vector_float512_cosh(); break; 7670 default: Unimplemented(); break; 7671 } 7672 } 7673 break; 7674 case OP_TANH: { 7675 switch(bits) { 7676 case 64: *name_ptr = "vector_float64_tanh"; *addr_ptr = StubRoutines::vector_float64_tanh(); break; 7677 case 128: *name_ptr = "vector_float128_tanh"; *addr_ptr = StubRoutines::vector_float128_tanh(); break; 7678 case 256: *name_ptr = "vector_float256_tanh"; *addr_ptr = StubRoutines::vector_float256_tanh(); break; 7679 case 512: *name_ptr = "vector_float512_tanh"; *addr_ptr = StubRoutines::vector_float512_tanh(); break; 7680 default: Unimplemented(); break; 7681 } 7682 } 7683 break; 7684 case OP_ASIN: { 7685 switch(bits) { 7686 case 64: *name_ptr = "vector_float64_asin"; *addr_ptr = StubRoutines::vector_float64_asin(); break; 7687 case 128: *name_ptr = "vector_float128_asin"; *addr_ptr = StubRoutines::vector_float128_asin(); break; 7688 case 256: *name_ptr = "vector_float256_asin"; *addr_ptr = StubRoutines::vector_float256_asin(); break; 7689 case 512: *name_ptr = "vector_float512_asin"; *addr_ptr = StubRoutines::vector_float512_asin(); break; 7690 default: Unimplemented(); break; 7691 } 7692 } 7693 break; 7694 case OP_ACOS: { 7695 switch(bits) { 7696 case 64: *name_ptr = "vector_float64_acos"; *addr_ptr = StubRoutines::vector_float64_acos(); break; 7697 case 128: *name_ptr = "vector_float128_acos"; *addr_ptr = StubRoutines::vector_float128_acos(); break; 7698 case 256: *name_ptr = "vector_float256_acos"; *addr_ptr = StubRoutines::vector_float256_acos(); break; 7699 case 512: *name_ptr = "vector_float512_acos"; *addr_ptr = StubRoutines::vector_float512_acos(); break; 7700 default: Unimplemented(); break; 7701 } 7702 } 7703 break; 7704 case OP_ATAN: { 7705 switch(bits) { 7706 case 64: *name_ptr = "vector_float64_atan"; *addr_ptr = StubRoutines::vector_float64_atan(); break; 7707 case 128: *name_ptr = "vector_float128_atan"; *addr_ptr = StubRoutines::vector_float128_atan(); break; 7708 case 256: *name_ptr = "vector_float256_atan"; *addr_ptr = StubRoutines::vector_float256_atan(); break; 7709 case 512: *name_ptr = "vector_float512_atan"; *addr_ptr = StubRoutines::vector_float512_atan(); break; 7710 default: Unimplemented(); break; 7711 } 7712 } 7713 break; 7714 case OP_CBRT: { 7715 switch(bits) { 7716 case 64: *name_ptr = "vector_float64_cbrt"; *addr_ptr = StubRoutines::vector_float64_cbrt(); break; 7717 case 128: *name_ptr = "vector_float128_cbrt"; *addr_ptr = StubRoutines::vector_float128_cbrt(); break; 7718 case 256: *name_ptr = "vector_float256_cbrt"; *addr_ptr = StubRoutines::vector_float256_cbrt(); break; 7719 case 512: *name_ptr = "vector_float512_cbrt"; *addr_ptr = StubRoutines::vector_float512_cbrt(); break; 7720 default: Unimplemented(); break; 7721 } 7722 } 7723 break; 7724 case OP_HYPOT: { 7725 switch(bits) { 7726 case 64: *name_ptr = "vector_float64_hypot"; *addr_ptr = StubRoutines::vector_float64_hypot(); break; 7727 case 128: *name_ptr = "vector_float128_hypot"; *addr_ptr = StubRoutines::vector_float128_hypot(); break; 7728 case 256: *name_ptr = "vector_float256_hypot"; *addr_ptr = StubRoutines::vector_float256_hypot(); break; 7729 case 512: *name_ptr = "vector_float512_hypot"; *addr_ptr = StubRoutines::vector_float512_hypot(); break; 7730 default: Unimplemented(); break; 7731 } 7732 } 7733 break; 7734 case OP_POW: { 7735 switch(bits) { 7736 case 64: *name_ptr = "vector_float64_pow"; *addr_ptr = StubRoutines::vector_float64_pow(); break; 7737 case 128: *name_ptr = "vector_float128_pow"; *addr_ptr = StubRoutines::vector_float128_pow(); break; 7738 case 256: *name_ptr = "vector_float256_pow"; *addr_ptr = StubRoutines::vector_float256_pow(); break; 7739 case 512: *name_ptr = "vector_float512_pow"; *addr_ptr = StubRoutines::vector_float512_pow(); break; 7740 default: Unimplemented(); break; 7741 } 7742 } 7743 break; 7744 case OP_ATAN2: { 7745 switch(bits) { 7746 case 64: *name_ptr = "vector_float64_atan2"; *addr_ptr = StubRoutines::vector_float64_atan2(); break; 7747 case 128: *name_ptr = "vector_float128_atan2"; *addr_ptr = StubRoutines::vector_float128_atan2(); break; 7748 case 256: *name_ptr = "vector_float256_atan2"; *addr_ptr = StubRoutines::vector_float256_atan2(); break; 7749 case 512: *name_ptr = "vector_float512_atan2"; *addr_ptr = StubRoutines::vector_float512_atan2(); break; 7750 default: Unimplemented(); break; 7751 } 7752 } 7753 break; 7754 default: 7755 *name_ptr = "invalid"; 7756 *addr_ptr = NULL; 7757 break; 7758 } 7759 } else { 7760 assert(bt == T_DOUBLE, "must be FP type only"); 7761 switch(op) { 7762 case OP_EXP: { 7763 switch(bits) { 7764 case 64: *name_ptr = "vector_double64_exp"; *addr_ptr = StubRoutines::vector_double64_exp(); break; 7765 case 128: *name_ptr = "vector_double128_exp"; *addr_ptr = StubRoutines::vector_double128_exp(); break; 7766 case 256: *name_ptr = "vector_double256_exp"; *addr_ptr = StubRoutines::vector_double256_exp(); break; 7767 case 512: *name_ptr = "vector_double512_exp"; *addr_ptr = StubRoutines::vector_double512_exp(); break; 7768 default: Unimplemented(); break; 7769 } 7770 } 7771 break; 7772 case OP_LOG1P: { 7773 switch(bits) { 7774 case 64: *name_ptr = "vector_double64_log1p"; *addr_ptr = StubRoutines::vector_double64_log1p(); break; 7775 case 128: *name_ptr = "vector_double128_log1p"; *addr_ptr = StubRoutines::vector_double128_log1p(); break; 7776 case 256: *name_ptr = "vector_double256_log1p"; *addr_ptr = StubRoutines::vector_double256_log1p(); break; 7777 case 512: *name_ptr = "vector_double512_log1p"; *addr_ptr = StubRoutines::vector_double512_log1p(); break; 7778 default: Unimplemented(); break; 7779 } 7780 } 7781 break; 7782 case OP_LOG: { 7783 switch(bits) { 7784 case 64: *name_ptr = "vector_double64_log"; *addr_ptr = StubRoutines::vector_double64_log(); break; 7785 case 128: *name_ptr = "vector_double128_log"; *addr_ptr = StubRoutines::vector_double128_log(); break; 7786 case 256: *name_ptr = "vector_double256_log"; *addr_ptr = StubRoutines::vector_double256_log(); break; 7787 case 512: *name_ptr = "vector_double512_log"; *addr_ptr = StubRoutines::vector_double512_log(); break; 7788 default: Unimplemented(); break; 7789 } 7790 } 7791 break; 7792 case OP_LOG10: { 7793 switch(bits) { 7794 case 64: *name_ptr = "vector_double64_log10"; *addr_ptr = StubRoutines::vector_double64_log10(); break; 7795 case 128: *name_ptr = "vector_double128_log10"; *addr_ptr = StubRoutines::vector_double128_log10(); break; 7796 case 256: *name_ptr = "vector_double256_log10"; *addr_ptr = StubRoutines::vector_double256_log10(); break; 7797 case 512: *name_ptr = "vector_double512_log10"; *addr_ptr = StubRoutines::vector_double512_log10(); break; 7798 default: Unimplemented(); break; 7799 } 7800 } 7801 break; 7802 case OP_EXPM1: { 7803 switch(bits) { 7804 case 64: *name_ptr = "vector_double64_expm1"; *addr_ptr = StubRoutines::vector_double64_expm1(); break; 7805 case 128: *name_ptr = "vector_double128_expm1"; *addr_ptr = StubRoutines::vector_double128_expm1(); break; 7806 case 256: *name_ptr = "vector_double256_expm1"; *addr_ptr = StubRoutines::vector_double256_expm1(); break; 7807 case 512: *name_ptr = "vector_double512_expm1"; *addr_ptr = StubRoutines::vector_double512_expm1(); break; 7808 default: Unimplemented(); break; 7809 } 7810 } 7811 break; 7812 case OP_SIN: { 7813 switch(bits) { 7814 case 64: *name_ptr = "vector_double64_sin"; *addr_ptr = StubRoutines::vector_double64_sin(); break; 7815 case 128: *name_ptr = "vector_double128_sin"; *addr_ptr = StubRoutines::vector_double128_sin(); break; 7816 case 256: *name_ptr = "vector_double256_sin"; *addr_ptr = StubRoutines::vector_double256_sin(); break; 7817 case 512: *name_ptr = "vector_double512_sin"; *addr_ptr = StubRoutines::vector_double512_sin(); break; 7818 default: Unimplemented(); break; 7819 } 7820 } 7821 break; 7822 case OP_COS: { 7823 switch(bits) { 7824 case 64: *name_ptr = "vector_double64_cos"; *addr_ptr = StubRoutines::vector_double64_cos(); break; 7825 case 128: *name_ptr = "vector_double128_cos"; *addr_ptr = StubRoutines::vector_double128_cos(); break; 7826 case 256: *name_ptr = "vector_double256_cos"; *addr_ptr = StubRoutines::vector_double256_cos(); break; 7827 case 512: *name_ptr = "vector_double512_cos"; *addr_ptr = StubRoutines::vector_double512_cos(); break; 7828 default: Unimplemented(); break; 7829 } 7830 } 7831 break; 7832 case OP_TAN: { 7833 switch(bits) { 7834 case 64: *name_ptr = "vector_double64_tan"; *addr_ptr = StubRoutines::vector_double64_tan(); break; 7835 case 128: *name_ptr = "vector_double128_tan"; *addr_ptr = StubRoutines::vector_double128_tan(); break; 7836 case 256: *name_ptr = "vector_double256_tan"; *addr_ptr = StubRoutines::vector_double256_tan(); break; 7837 case 512: *name_ptr = "vector_double512_tan"; *addr_ptr = StubRoutines::vector_double512_tan(); break; 7838 default: Unimplemented(); break; 7839 } 7840 } 7841 break; 7842 case OP_SINH: { 7843 switch(bits) { 7844 case 64: *name_ptr = "vector_double64_sinh"; *addr_ptr = StubRoutines::vector_double64_sinh(); break; 7845 case 128: *name_ptr = "vector_double128_sinh"; *addr_ptr = StubRoutines::vector_double128_sinh(); break; 7846 case 256: *name_ptr = "vector_double256_sinh"; *addr_ptr = StubRoutines::vector_double256_sinh(); break; 7847 case 512: *name_ptr = "vector_double512_sinh"; *addr_ptr = StubRoutines::vector_double512_sinh(); break; 7848 default: Unimplemented(); break; 7849 } 7850 } 7851 break; 7852 case OP_COSH: { 7853 switch(bits) { 7854 case 64: *name_ptr = "vector_double64_cosh"; *addr_ptr = StubRoutines::vector_double64_cosh(); break; 7855 case 128: *name_ptr = "vector_double128_cosh"; *addr_ptr = StubRoutines::vector_double128_cosh(); break; 7856 case 256: *name_ptr = "vector_double256_cosh"; *addr_ptr = StubRoutines::vector_double256_cosh(); break; 7857 case 512: *name_ptr = "vector_double512_cosh"; *addr_ptr = StubRoutines::vector_double512_cosh(); break; 7858 default: Unimplemented(); break; 7859 } 7860 } 7861 break; 7862 case OP_TANH: { 7863 switch(bits) { 7864 case 64: *name_ptr = "vector_double64_tanh"; *addr_ptr = StubRoutines::vector_double64_tanh(); break; 7865 case 128: *name_ptr = "vector_double128_tanh"; *addr_ptr = StubRoutines::vector_double128_tanh(); break; 7866 case 256: *name_ptr = "vector_double256_tanh"; *addr_ptr = StubRoutines::vector_double256_tanh(); break; 7867 case 512: *name_ptr = "vector_double512_tanh"; *addr_ptr = StubRoutines::vector_double512_tanh(); break; 7868 default: Unimplemented(); break; 7869 } 7870 } 7871 break; 7872 case OP_ASIN: { 7873 switch(bits) { 7874 case 64: *name_ptr = "vector_double64_asin"; *addr_ptr = StubRoutines::vector_double64_asin(); break; 7875 case 128: *name_ptr = "vector_double128_asin"; *addr_ptr = StubRoutines::vector_double128_asin(); break; 7876 case 256: *name_ptr = "vector_double256_asin"; *addr_ptr = StubRoutines::vector_double256_asin(); break; 7877 case 512: *name_ptr = "vector_double512_asin"; *addr_ptr = StubRoutines::vector_double512_asin(); break; 7878 default: Unimplemented(); break; 7879 } 7880 } 7881 break; 7882 case OP_ACOS: { 7883 switch(bits) { 7884 case 64: *name_ptr = "vector_double64_acos"; *addr_ptr = StubRoutines::vector_double64_acos(); break; 7885 case 128: *name_ptr = "vector_double128_acos"; *addr_ptr = StubRoutines::vector_double128_acos(); break; 7886 case 256: *name_ptr = "vector_double256_acos"; *addr_ptr = StubRoutines::vector_double256_acos(); break; 7887 case 512: *name_ptr = "vector_double512_acos"; *addr_ptr = StubRoutines::vector_double512_acos(); break; 7888 default: Unimplemented(); break; 7889 } 7890 } 7891 break; 7892 case OP_ATAN: { 7893 switch(bits) { 7894 case 64: *name_ptr = "vector_double64_atan"; *addr_ptr = StubRoutines::vector_double64_atan(); break; 7895 case 128: *name_ptr = "vector_double128_atan"; *addr_ptr = StubRoutines::vector_double128_atan(); break; 7896 case 256: *name_ptr = "vector_double256_atan"; *addr_ptr = StubRoutines::vector_double256_atan(); break; 7897 case 512: *name_ptr = "vector_double512_atan"; *addr_ptr = StubRoutines::vector_double512_atan(); break; 7898 default: Unimplemented(); break; 7899 } 7900 } 7901 break; 7902 case OP_CBRT: { 7903 switch(bits) { 7904 case 64: *name_ptr = "vector_double64_cbrt"; *addr_ptr = StubRoutines::vector_double64_cbrt(); break; 7905 case 128: *name_ptr = "vector_double128_cbrt"; *addr_ptr = StubRoutines::vector_double128_cbrt(); break; 7906 case 256: *name_ptr = "vector_double256_cbrt"; *addr_ptr = StubRoutines::vector_double256_cbrt(); break; 7907 case 512: *name_ptr = "vector_double512_cbrt"; *addr_ptr = StubRoutines::vector_double512_cbrt(); break; 7908 default: Unimplemented(); break; 7909 } 7910 } 7911 break; 7912 case OP_HYPOT: { 7913 switch(bits) { 7914 case 64: *name_ptr = "vector_double64_hypot"; *addr_ptr = StubRoutines::vector_double64_hypot(); break; 7915 case 128: *name_ptr = "vector_double128_hypot"; *addr_ptr = StubRoutines::vector_double128_hypot(); break; 7916 case 256: *name_ptr = "vector_double256_hypot"; *addr_ptr = StubRoutines::vector_double256_hypot(); break; 7917 case 512: *name_ptr = "vector_double512_hypot"; *addr_ptr = StubRoutines::vector_double512_hypot(); break; 7918 default: Unimplemented(); break; 7919 } 7920 } 7921 break; 7922 case OP_POW: { 7923 switch(bits) { 7924 case 64: *name_ptr = "vector_double64_pow"; *addr_ptr = StubRoutines::vector_double64_pow(); break; 7925 case 128: *name_ptr = "vector_double128_pow"; *addr_ptr = StubRoutines::vector_double128_pow(); break; 7926 case 256: *name_ptr = "vector_double256_pow"; *addr_ptr = StubRoutines::vector_double256_pow(); break; 7927 case 512: *name_ptr = "vector_double512_pow"; *addr_ptr = StubRoutines::vector_double512_pow(); break; 7928 default: Unimplemented(); break; 7929 } 7930 } 7931 break; 7932 case OP_ATAN2: { 7933 switch(bits) { 7934 case 64: *name_ptr = "vector_double64_atan2"; *addr_ptr = StubRoutines::vector_double64_atan2(); break; 7935 case 128: *name_ptr = "vector_double128_atan2"; *addr_ptr = StubRoutines::vector_double128_atan2(); break; 7936 case 256: *name_ptr = "vector_double256_atan2"; *addr_ptr = StubRoutines::vector_double256_atan2(); break; 7937 case 512: *name_ptr = "vector_double512_atan2"; *addr_ptr = StubRoutines::vector_double512_atan2(); break; 7938 default: Unimplemented(); break; 7939 } 7940 } 7941 break; 7942 7943 default: 7944 *name_ptr = "invalid"; 7945 *addr_ptr = NULL; 7946 break; 7947 } 7948 } 7949 } 7950 7951 Node* LibraryCallKit::gen_call_to_svml(int vector_api_op_id, BasicType bt, int num_elem, Node* opd1, Node* opd2) { 7952 assert(vector_api_op_id >= OP_SVML_START && vector_api_op_id <= OP_SVML_END, "need valid op id"); 7953 assert(opd1 != NULL, "must not be null"); 7954 const TypeVect* vt = TypeVect::make(bt, num_elem); 7955 const TypeFunc* call_type = OptoRuntime::Math_Vector_Vector_Type(opd2 != NULL ? 2 : 1, vt, vt); 7956 const char* name = NULL; 7957 address addr = NULL; 7958 7959 // Get address for svml method. 7960 get_svml_address(vector_api_op_id, vt->length_in_bytes() * BitsPerByte, bt, &name, &addr); 7961 7962 if (addr == NULL) { 7963 return NULL; 7964 } 7965 7966 assert(name != NULL, "name must not be null"); 7967 Node* operation = make_runtime_call(RC_VECTOR, 7968 call_type, 7969 addr, 7970 name, 7971 TypePtr::BOTTOM, 7972 opd1, 7973 opd2); 7974 return _gvn.transform(new ProjNode(_gvn.transform(operation), TypeFunc::Parms)); 7975 } 7976 7977 // static 7978 // <V extends Vector<?,?>> 7979 // V broadcastInt(int opr, Class<V> vectorClass, Class<?> elementType, int vlen, 7980 // V v, int i, 7981 // VectorBroadcastIntOp<V> defaultImpl) { 7982 // 7983 bool LibraryCallKit::inline_vector_broadcast_int() { 7984 const TypeInt* opr = gvn().type(argument(0))->is_int(); 7985 const TypeInstPtr* vector_klass = gvn().type(argument(1))->is_instptr(); 7986 const TypeInstPtr* elem_klass = gvn().type(argument(2))->is_instptr(); 7987 const TypeInt* vlen = gvn().type(argument(3))->is_int(); 7988 7989 if (!opr->is_con() || vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con()) { 7990 return false; // not enough info for intrinsification 7991 } 7992 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 7993 if (!elem_type->is_primitive_type()) { 7994 return false; // should be primitive type 7995 } 7996 BasicType elem_bt = elem_type->basic_type(); 7997 int num_elem = vlen->get_con(); 7998 int opc = get_opc(opr->get_con(), elem_bt); 7999 int sopc = get_sopc(opc, elem_bt); // get_node_id(opr->get_con(), elem_bt); 8000 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 8001 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 8002 8003 if (!arch_supports_vector(sopc, num_elem, elem_bt, VecMaskNotUsed)) { 8004 return false; // not supported 8005 } 8006 Node* opd1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); 8007 Node* opd2 = shift_count(argument(5), opc, elem_bt, num_elem); 8008 if (opd1 == NULL || opd2 == NULL) { 8009 return false; 8010 } 8011 Node* operation = _gvn.transform(VectorNode::make(opc, opd1, opd2, num_elem, elem_bt)); 8012 8013 Node* vbox = box_vector(operation, vbox_type, elem_bt, num_elem); 8014 set_vector_result(vbox); 8015 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 8016 return true; 8017 } 8018 8019 bool LibraryCallKit::inline_vector_cast_reinterpret(bool is_cast) { 8020 const TypeInstPtr* vector_klass_from = gvn().type(argument(0))->is_instptr(); 8021 const TypeInstPtr* elem_klass_from = gvn().type(argument(1))->is_instptr(); 8022 const TypeInt* vlen_from = gvn().type(argument(2))->is_int(); 8023 8024 const TypeInstPtr* vector_klass_to = gvn().type(argument(3))->is_instptr(); 8025 const TypeInstPtr* elem_klass_to = gvn().type(argument(4))->is_instptr(); 8026 const TypeInt* vlen_to = gvn().type(argument(5))->is_int(); 8027 8028 if (vector_klass_from->const_oop() == NULL || elem_klass_from->const_oop() == NULL || !vlen_from->is_con() || 8029 vector_klass_to->const_oop() == NULL || elem_klass_to->const_oop() == NULL || !vlen_to->is_con()) { 8030 return false; // not enough info for intrinsification 8031 } 8032 8033 ciKlass* vbox_klass_from = vector_klass_from->const_oop()->as_instance()->java_lang_Class_klass(); 8034 ciKlass* vbox_klass_to = vector_klass_to->const_oop()->as_instance()->java_lang_Class_klass(); 8035 if (!vbox_klass_from->is_vectorapi_vector() || !vbox_klass_to->is_vectorapi_vector()) { 8036 return false; // only vector & mask are supported 8037 } 8038 bool is_mask = vbox_klass_from->is_vectormask(); 8039 8040 ciType* elem_type_from = elem_klass_from->const_oop()->as_instance()->java_mirror_type(); 8041 if (!elem_type_from->is_primitive_type()) { 8042 return false; // should be primitive type 8043 } 8044 BasicType elem_bt_from = elem_type_from->basic_type(); 8045 ciType* elem_type_to = elem_klass_to->const_oop()->as_instance()->java_mirror_type(); 8046 if (!elem_type_to->is_primitive_type()) { 8047 return false; // should be primitive type 8048 } 8049 BasicType elem_bt_to = elem_type_to->basic_type(); 8050 if (is_mask && elem_bt_from != elem_bt_to) { 8051 return false; // type mismatch 8052 } 8053 int num_elem_from = vlen_from->get_con(); 8054 int num_elem_to = vlen_to->get_con(); 8055 8056 // Check whether we can unbox to appropriate size. Even with casting, checking for reinterpret is needed 8057 // since we may need to change size. 8058 if (!arch_supports_vector(Op_VectorReinterpret, 8059 num_elem_from, 8060 elem_bt_from, 8061 is_mask ? VecMaskUseAll : VecMaskNotUsed)) { 8062 return false; 8063 } 8064 8065 // Check whether we can support resizing/reinterpreting to the new size. 8066 if (!arch_supports_vector(Op_VectorReinterpret, 8067 num_elem_to, 8068 elem_bt_to, 8069 is_mask ? VecMaskUseAll : VecMaskNotUsed)) { 8070 return false; 8071 } 8072 8073 // At this point, we know that both input and output vector registers are supported 8074 // by the architecture. Next check if the casted type is simply to same type - which means 8075 // that it is actually a resize and not a cast. 8076 if (is_cast && elem_bt_from == elem_bt_to) { 8077 is_cast = false; 8078 } 8079 8080 const TypeInstPtr* vbox_type_from = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass_from); 8081 8082 Node* opd1 = unbox_vector(argument(6), vbox_type_from, elem_bt_from, num_elem_from); 8083 if (opd1 == NULL) { 8084 return false; 8085 } 8086 8087 const TypeVect* src_type = TypeVect::make(elem_bt_from, num_elem_from); 8088 const TypeVect* dst_type = TypeVect::make(elem_bt_to, num_elem_to); 8089 8090 Node* op = opd1; 8091 if (is_cast) { 8092 assert(!is_mask, "masks cannot be casted"); 8093 int cast_vopc = VectorCastNode::opcode(elem_bt_from); 8094 // Make sure that cast is implemented to particular type/size combination. 8095 if (!arch_supports_vector(cast_vopc, num_elem_to, elem_bt_to, VecMaskNotUsed)) { 8096 return false; 8097 } 8098 8099 if (num_elem_from < num_elem_to) { 8100 // Since input and output number of elements are not consistent, we need to make sure we 8101 // properly size. Thus, first make a cast that retains the number of elements from source. 8102 // In case the size exceeds the arch size, we do the minimum. 8103 int num_elem_for_cast = MIN2(num_elem_from, Matcher::max_vector_size(elem_bt_to)); 8104 8105 // It is possible that arch does not support this intermediate vector size 8106 // TODO More complex logic required here to handle this corner case for the sizes. 8107 if (!arch_supports_vector(cast_vopc, num_elem_for_cast, elem_bt_to, VecMaskNotUsed)) { 8108 return false; 8109 } 8110 8111 op = _gvn.transform(VectorCastNode::make(cast_vopc, op, elem_bt_to, num_elem_for_cast)); 8112 // Now ensure that the destination gets properly resized to needed size. 8113 op = _gvn.transform(new VectorReinterpretNode(op, op->bottom_type()->is_vect(), dst_type)); 8114 } else if (num_elem_from > num_elem_to) { 8115 // Since number elements from input is larger than output, simply reduce size of input (we are supposed to 8116 // drop top elements anyway). 8117 int num_elem_for_resize = MAX2(num_elem_to, Matcher::min_vector_size(elem_bt_to)); 8118 8119 // It is possible that arch does not support this intermediate vector size 8120 // TODO More complex logic required here to handle this corner case for the sizes. 8121 if (!arch_supports_vector(Op_VectorReinterpret, 8122 num_elem_for_resize, 8123 elem_bt_from, 8124 VecMaskNotUsed)) { 8125 return false; 8126 } 8127 8128 op = _gvn.transform(new VectorReinterpretNode(op, 8129 src_type, 8130 TypeVect::make(elem_bt_from, 8131 num_elem_for_resize))); 8132 op = _gvn.transform(VectorCastNode::make(cast_vopc, op, elem_bt_to, num_elem_to)); 8133 } else { 8134 // Since input and output number of elements match, and since we know this vector size is 8135 // supported, simply do a cast with no resize needed. 8136 op = _gvn.transform(VectorCastNode::make(cast_vopc, op, elem_bt_to, num_elem_to)); 8137 } 8138 } else if (Type::cmp(src_type, dst_type) != 0) { 8139 assert(!is_cast, "must be reinterpret"); 8140 op = _gvn.transform(new VectorReinterpretNode(op, src_type, dst_type)); 8141 } 8142 8143 const TypeInstPtr* vbox_type_to = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass_to); 8144 Node* vbox = box_vector(op, vbox_type_to, elem_bt_to, num_elem_to); 8145 set_vector_result(vbox); 8146 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem_to * type2aelembytes(elem_bt_to)))); 8147 return true; 8148 } 8149 8150 bool LibraryCallKit::inline_vector_insert() { 8151 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 8152 const TypeInstPtr* elem_klass = gvn().type(argument(1))->is_instptr(); 8153 const TypeInt* vlen = gvn().type(argument(2))->is_int(); 8154 const TypeInt* idx = gvn().type(argument(4))->is_int(); 8155 8156 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con() || !idx->is_con()) { 8157 return false; // not enough info for intrinsification 8158 } 8159 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 8160 if (!elem_type->is_primitive_type()) { 8161 return false; // should be primitive type 8162 } 8163 BasicType elem_bt = elem_type->basic_type(); 8164 int num_elem = vlen->get_con(); 8165 if (!arch_supports_vector(Op_VectorInsert, num_elem, elem_bt, VecMaskNotUsed)) { 8166 return false; // not supported 8167 } 8168 8169 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 8170 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 8171 8172 Node* opd = unbox_vector(argument(3), vbox_type, elem_bt, num_elem); 8173 if (opd == NULL) { 8174 return false; 8175 } 8176 8177 Node* insert_val = argument(5); 8178 assert(gvn().type(insert_val)->isa_long() != NULL, "expected to be long"); 8179 8180 // Convert insert value back to its appropriate type. 8181 switch (elem_bt) { 8182 case T_BYTE: 8183 insert_val = gvn().transform(new ConvL2INode(insert_val)); 8184 insert_val = gvn().transform(new CastIINode(insert_val, TypeInt::BYTE)); 8185 break; 8186 case T_SHORT: 8187 insert_val = gvn().transform(new ConvL2INode(insert_val)); 8188 insert_val = gvn().transform(new CastIINode(insert_val, TypeInt::SHORT)); 8189 break; 8190 case T_INT: 8191 insert_val = gvn().transform(new ConvL2INode(insert_val)); 8192 break; 8193 case T_FLOAT: 8194 insert_val = gvn().transform(new ConvL2INode(insert_val)); 8195 insert_val = gvn().transform(new MoveI2FNode(insert_val)); 8196 break; 8197 case T_DOUBLE: 8198 insert_val = gvn().transform(new MoveL2DNode(insert_val)); 8199 break; 8200 case T_LONG: 8201 // no conversion needed 8202 break; 8203 default: fatal("%s", type2name(elem_bt)); break; 8204 } 8205 8206 Node* operation = _gvn.transform(VectorInsertNode::make(opd, insert_val, idx->get_con())); 8207 operation = box_vector(operation, vbox_type, elem_bt, num_elem); 8208 set_vector_result(operation); 8209 8210 C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); 8211 return true; 8212 } 8213 8214 bool LibraryCallKit::inline_vector_extract() { 8215 const TypeInstPtr* vector_klass = gvn().type(argument(0))->is_instptr(); 8216 const TypeInstPtr* elem_klass = gvn().type(argument(1))->is_instptr(); 8217 const TypeInt* vlen = gvn().type(argument(2))->is_int(); 8218 const TypeInt* idx = gvn().type(argument(4))->is_int(); 8219 8220 if (vector_klass->const_oop() == NULL || elem_klass->const_oop() == NULL || !vlen->is_con() || !idx->is_con()) { 8221 return false; // not enough info for intrinsification 8222 } 8223 ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); 8224 if (!elem_type->is_primitive_type()) { 8225 return false; // should be primitive type 8226 } 8227 BasicType elem_bt = elem_type->basic_type(); 8228 int num_elem = vlen->get_con(); 8229 int vopc = ExtractNode::opcode(elem_bt); 8230 if (!arch_supports_vector(vopc, num_elem, elem_bt, VecMaskNotUsed)) { 8231 return false; // not supported 8232 } 8233 8234 ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); 8235 const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); 8236 8237 Node* opd = unbox_vector(argument(3), vbox_type, elem_bt, num_elem); 8238 if (opd == NULL) { 8239 return false; 8240 } 8241 8242 Node* operation = gvn().transform(ExtractNode::make(opd, idx->get_con(), elem_bt)); 8243 8244 Node* bits = NULL; 8245 switch (elem_bt) { 8246 case T_BYTE: 8247 case T_SHORT: 8248 case T_INT: { 8249 bits = gvn().transform(new ConvI2LNode(operation)); 8250 break; 8251 } 8252 case T_FLOAT: { 8253 bits = gvn().transform(new MoveF2INode(operation)); 8254 bits = gvn().transform(new ConvI2LNode(bits)); 8255 break; 8256 } 8257 case T_DOUBLE: { 8258 bits = gvn().transform(new MoveD2LNode(operation)); 8259 break; 8260 } 8261 case T_LONG: { 8262 bits = operation; // no conversion needed 8263 break; 8264 } 8265 default: fatal("%s", type2name(elem_bt)); 8266 } 8267 8268 set_vector_result(bits); 8269 return true; 8270 } 8271 8272 //------------------------------get_state_from_sha_object----------------------- 8273 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) { 8274 Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false); 8275 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2"); 8276 if (sha_state == NULL) return (Node *) NULL; 8277 8278 // now have the array, need to get the start address of the state array 8279 sha_state = access_resolve(sha_state, ACCESS_WRITE); 8280 Node* state = array_element_address(sha_state, intcon(0), T_INT); 8281 return state; 8282 } 8283 8284 //------------------------------get_state_from_sha5_object----------------------- 8285 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) { 8286 Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false); 8287 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5"); 8288 if (sha_state == NULL) return (Node *) NULL; 8289 8290 // now have the array, need to get the start address of the state array 8291 sha_state = access_resolve(sha_state, ACCESS_WRITE); 8292 Node* state = array_element_address(sha_state, intcon(0), T_LONG); 8293 return state; 8294 } 8295 8296 //----------------------------inline_digestBase_implCompressMB_predicate---------------------------- 8297 // Return node representing slow path of predicate check. 8298 // the pseudo code we want to emulate with this predicate is: 8299 // if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath 8300 // 8301 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) { 8302 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics, 8303 "need SHA1/SHA256/SHA512 instruction support"); 8304 assert((uint)predicate < 3, "sanity"); 8305 8306 // The receiver was checked for NULL already. 8307 Node* digestBaseObj = argument(0); 8308 8309 // get DigestBase klass for instanceOf check 8310 const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr(); 8311 assert(tinst != NULL, "digestBaseObj is null"); 8312 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded"); 8313 8314 const char* klass_SHA_name = NULL; 8315 switch (predicate) { 8316 case 0: 8317 if (UseSHA1Intrinsics) { 8318 // we want to do an instanceof comparison against the SHA class 8319 klass_SHA_name = "sun/security/provider/SHA"; 8320 } 8321 break; 8322 case 1: 8323 if (UseSHA256Intrinsics) { 8324 // we want to do an instanceof comparison against the SHA2 class 8325 klass_SHA_name = "sun/security/provider/SHA2"; 8326 } 8327 break; 8328 case 2: 8329 if (UseSHA512Intrinsics) { 8330 // we want to do an instanceof comparison against the SHA5 class 8331 klass_SHA_name = "sun/security/provider/SHA5"; 8332 } 8333 break; 8334 default: 8335 fatal("unknown SHA intrinsic predicate: %d", predicate); 8336 } 8337 8338 ciKlass* klass_SHA = NULL; 8339 if (klass_SHA_name != NULL) { 8340 klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name)); 8341 } 8342 if ((klass_SHA == NULL) || !klass_SHA->is_loaded()) { 8343 // if none of SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path 8344 Node* ctrl = control(); 8345 set_control(top()); // no intrinsic path 8346 return ctrl; 8347 } 8348 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass(); 8349 8350 Node* instofSHA = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass_SHA))); 8351 Node* cmp_instof = _gvn.transform(new CmpINode(instofSHA, intcon(1))); 8352 Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne)); 8353 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 8354 8355 return instof_false; // even if it is NULL 8356 } 8357 8358 //-------------inline_fma----------------------------------- 8359 bool LibraryCallKit::inline_fma(vmIntrinsics::ID id) { 8360 Node *a = NULL; 8361 Node *b = NULL; 8362 Node *c = NULL; 8363 Node* result = NULL; 8364 switch (id) { 8365 case vmIntrinsics::_fmaD: 8366 assert(callee()->signature()->size() == 6, "fma has 3 parameters of size 2 each."); 8367 // no receiver since it is static method 8368 a = round_double_node(argument(0)); 8369 b = round_double_node(argument(2)); 8370 c = round_double_node(argument(4)); 8371 result = _gvn.transform(new FmaDNode(control(), a, b, c)); 8372 break; 8373 case vmIntrinsics::_fmaF: 8374 assert(callee()->signature()->size() == 3, "fma has 3 parameters of size 1 each."); 8375 a = argument(0); 8376 b = argument(1); 8377 c = argument(2); 8378 result = _gvn.transform(new FmaFNode(control(), a, b, c)); 8379 break; 8380 default: 8381 fatal_unexpected_iid(id); break; 8382 } 8383 set_result(result); 8384 return true; 8385 } 8386 8387 bool LibraryCallKit::inline_character_compare(vmIntrinsics::ID id) { 8388 // argument(0) is receiver 8389 Node* codePoint = argument(1); 8390 Node* n = NULL; 8391 8392 switch (id) { 8393 case vmIntrinsics::_isDigit : 8394 n = new DigitNode(control(), codePoint); 8395 break; 8396 case vmIntrinsics::_isLowerCase : 8397 n = new LowerCaseNode(control(), codePoint); 8398 break; 8399 case vmIntrinsics::_isUpperCase : 8400 n = new UpperCaseNode(control(), codePoint); 8401 break; 8402 case vmIntrinsics::_isWhitespace : 8403 n = new WhitespaceNode(control(), codePoint); 8404 break; 8405 default: 8406 fatal_unexpected_iid(id); 8407 } 8408 8409 set_result(_gvn.transform(n)); 8410 return true; 8411 } 8412 8413 //------------------------------inline_fp_min_max------------------------------ 8414 bool LibraryCallKit::inline_fp_min_max(vmIntrinsics::ID id) { 8415 /* DISABLED BECAUSE METHOD DATA ISN'T COLLECTED PER CALL-SITE, SEE JDK-8015416. 8416 8417 // The intrinsic should be used only when the API branches aren't predictable, 8418 // the last one performing the most important comparison. The following heuristic 8419 // uses the branch statistics to eventually bail out if necessary. 8420 8421 ciMethodData *md = callee()->method_data(); 8422 8423 if ( md != NULL && md->is_mature() && md->invocation_count() > 0 ) { 8424 ciCallProfile cp = caller()->call_profile_at_bci(bci()); 8425 8426 if ( ((double)cp.count()) / ((double)md->invocation_count()) < 0.8 ) { 8427 // Bail out if the call-site didn't contribute enough to the statistics. 8428 return false; 8429 } 8430 8431 uint taken = 0, not_taken = 0; 8432 8433 for (ciProfileData *p = md->first_data(); md->is_valid(p); p = md->next_data(p)) { 8434 if (p->is_BranchData()) { 8435 taken = ((ciBranchData*)p)->taken(); 8436 not_taken = ((ciBranchData*)p)->not_taken(); 8437 } 8438 } 8439 8440 double balance = (((double)taken) - ((double)not_taken)) / ((double)md->invocation_count()); 8441 balance = balance < 0 ? -balance : balance; 8442 if ( balance > 0.2 ) { 8443 // Bail out if the most important branch is predictable enough. 8444 return false; 8445 } 8446 } 8447 */ 8448 8449 Node *a = NULL; 8450 Node *b = NULL; 8451 Node *n = NULL; 8452 switch (id) { 8453 case vmIntrinsics::_maxF: 8454 case vmIntrinsics::_minF: 8455 assert(callee()->signature()->size() == 2, "minF/maxF has 2 parameters of size 1 each."); 8456 a = argument(0); 8457 b = argument(1); 8458 break; 8459 case vmIntrinsics::_maxD: 8460 case vmIntrinsics::_minD: 8461 assert(callee()->signature()->size() == 4, "minD/maxD has 2 parameters of size 2 each."); 8462 a = round_double_node(argument(0)); 8463 b = round_double_node(argument(2)); 8464 break; 8465 default: 8466 fatal_unexpected_iid(id); 8467 break; 8468 } 8469 if (a->is_Con() || b->is_Con()) { 8470 return false; 8471 } 8472 switch (id) { 8473 case vmIntrinsics::_maxF: n = new MaxFNode(a, b); break; 8474 case vmIntrinsics::_minF: n = new MinFNode(a, b); break; 8475 case vmIntrinsics::_maxD: n = new MaxDNode(a, b); break; 8476 case vmIntrinsics::_minD: n = new MinDNode(a, b); break; 8477 default: fatal_unexpected_iid(id); break; 8478 } 8479 set_result(_gvn.transform(n)); 8480 return true; 8481 } 8482 8483 bool LibraryCallKit::inline_profileBoolean() { 8484 Node* counts = argument(1); 8485 const TypeAryPtr* ary = NULL; 8486 ciArray* aobj = NULL; 8487 if (counts->is_Con() 8488 && (ary = counts->bottom_type()->isa_aryptr()) != NULL 8489 && (aobj = ary->const_oop()->as_array()) != NULL 8490 && (aobj->length() == 2)) { 8491 // Profile is int[2] where [0] and [1] correspond to false and true value occurrences respectively. 8492 jint false_cnt = aobj->element_value(0).as_int(); 8493 jint true_cnt = aobj->element_value(1).as_int(); 8494 8495 if (C->log() != NULL) { 8496 C->log()->elem("observe source='profileBoolean' false='%d' true='%d'", 8497 false_cnt, true_cnt); 8498 } 8499 8500 if (false_cnt + true_cnt == 0) { 8501 // According to profile, never executed. 8502 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 8503 Deoptimization::Action_reinterpret); 8504 return true; 8505 } 8506 8507 // result is a boolean (0 or 1) and its profile (false_cnt & true_cnt) 8508 // is a number of each value occurrences. 8509 Node* result = argument(0); 8510 if (false_cnt == 0 || true_cnt == 0) { 8511 // According to profile, one value has been never seen. 8512 int expected_val = (false_cnt == 0) ? 1 : 0; 8513 8514 Node* cmp = _gvn.transform(new CmpINode(result, intcon(expected_val))); 8515 Node* test = _gvn.transform(new BoolNode(cmp, BoolTest::eq)); 8516 8517 IfNode* check = create_and_map_if(control(), test, PROB_ALWAYS, COUNT_UNKNOWN); 8518 Node* fast_path = _gvn.transform(new IfTrueNode(check)); 8519 Node* slow_path = _gvn.transform(new IfFalseNode(check)); 8520 8521 { // Slow path: uncommon trap for never seen value and then reexecute 8522 // MethodHandleImpl::profileBoolean() to bump the count, so JIT knows 8523 // the value has been seen at least once. 8524 PreserveJVMState pjvms(this); 8525 PreserveReexecuteState preexecs(this); 8526 jvms()->set_should_reexecute(true); 8527 8528 set_control(slow_path); 8529 set_i_o(i_o()); 8530 8531 uncommon_trap_exact(Deoptimization::Reason_intrinsic, 8532 Deoptimization::Action_reinterpret); 8533 } 8534 // The guard for never seen value enables sharpening of the result and 8535 // returning a constant. It allows to eliminate branches on the same value 8536 // later on. 8537 set_control(fast_path); 8538 result = intcon(expected_val); 8539 } 8540 // Stop profiling. 8541 // MethodHandleImpl::profileBoolean() has profiling logic in its bytecode. 8542 // By replacing method body with profile data (represented as ProfileBooleanNode 8543 // on IR level) we effectively disable profiling. 8544 // It enables full speed execution once optimized code is generated. 8545 Node* profile = _gvn.transform(new ProfileBooleanNode(result, false_cnt, true_cnt)); 8546 C->record_for_igvn(profile); 8547 set_result(profile); 8548 return true; 8549 } else { 8550 // Continue profiling. 8551 // Profile data isn't available at the moment. So, execute method's bytecode version. 8552 // Usually, when GWT LambdaForms are profiled it means that a stand-alone nmethod 8553 // is compiled and counters aren't available since corresponding MethodHandle 8554 // isn't a compile-time constant. 8555 return false; 8556 } 8557 } 8558 8559 bool LibraryCallKit::inline_isCompileConstant() { 8560 Node* n = argument(0); 8561 set_result(n->is_Con() ? intcon(1) : intcon(0)); 8562 return true; 8563 }