comparison src/share/vm/opto/library_call.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 e7b3d177adda
children
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
44 class LibraryIntrinsic : public InlineCallGenerator { 44 class LibraryIntrinsic : public InlineCallGenerator {
45 // Extend the set of intrinsics known to the runtime: 45 // Extend the set of intrinsics known to the runtime:
46 public: 46 public:
47 private: 47 private:
48 bool _is_virtual; 48 bool _is_virtual;
49 bool _is_predicted;
50 bool _does_virtual_dispatch; 49 bool _does_virtual_dispatch;
50 int8_t _predicates_count; // Intrinsic is predicated by several conditions
51 int8_t _last_predicate; // Last generated predicate
51 vmIntrinsics::ID _intrinsic_id; 52 vmIntrinsics::ID _intrinsic_id;
52 53
53 public: 54 public:
54 LibraryIntrinsic(ciMethod* m, bool is_virtual, bool is_predicted, bool does_virtual_dispatch, vmIntrinsics::ID id) 55 LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
55 : InlineCallGenerator(m), 56 : InlineCallGenerator(m),
56 _is_virtual(is_virtual), 57 _is_virtual(is_virtual),
57 _is_predicted(is_predicted),
58 _does_virtual_dispatch(does_virtual_dispatch), 58 _does_virtual_dispatch(does_virtual_dispatch),
59 _predicates_count((int8_t)predicates_count),
60 _last_predicate((int8_t)-1),
59 _intrinsic_id(id) 61 _intrinsic_id(id)
60 { 62 {
61 } 63 }
62 virtual bool is_intrinsic() const { return true; } 64 virtual bool is_intrinsic() const { return true; }
63 virtual bool is_virtual() const { return _is_virtual; } 65 virtual bool is_virtual() const { return _is_virtual; }
64 virtual bool is_predicted() const { return _is_predicted; } 66 virtual bool is_predicated() const { return _predicates_count > 0; }
67 virtual int predicates_count() const { return _predicates_count; }
65 virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; } 68 virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; }
66 virtual JVMState* generate(JVMState* jvms, Parse* parent_parser); 69 virtual JVMState* generate(JVMState* jvms);
67 virtual Node* generate_predicate(JVMState* jvms); 70 virtual Node* generate_predicate(JVMState* jvms, int predicate);
68 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; } 71 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; }
69 }; 72 };
70 73
71 74
72 // Local helper class for LibraryIntrinsic: 75 // Local helper class for LibraryIntrinsic:
105 int bci() const { return jvms()->bci(); } 108 int bci() const { return jvms()->bci(); }
106 LibraryIntrinsic* intrinsic() const { return _intrinsic; } 109 LibraryIntrinsic* intrinsic() const { return _intrinsic; }
107 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); } 110 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); }
108 ciMethod* callee() const { return _intrinsic->method(); } 111 ciMethod* callee() const { return _intrinsic->method(); }
109 112
110 bool try_to_inline(); 113 bool try_to_inline(int predicate);
111 Node* try_to_predicate(); 114 Node* try_to_predicate(int predicate);
112 115
113 void push_result() { 116 void push_result() {
114 // Push the result onto the stack. 117 // Push the result onto the stack.
115 if (!stopped() && result() != NULL) { 118 if (!stopped() && result() != NULL) {
116 BasicType bt = result()->bottom_type()->basic_type(); 119 BasicType bt = result()->bottom_type()->basic_type();
305 bool inline_aescrypt_Block(vmIntrinsics::ID id); 308 bool inline_aescrypt_Block(vmIntrinsics::ID id);
306 bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id); 309 bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id);
307 Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting); 310 Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
308 Node* get_key_start_from_aescrypt_object(Node* aescrypt_object); 311 Node* get_key_start_from_aescrypt_object(Node* aescrypt_object);
309 Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object); 312 Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object);
313 bool inline_sha_implCompress(vmIntrinsics::ID id);
314 bool inline_digestBase_implCompressMB(int predicate);
315 bool inline_sha_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass_SHA,
316 bool long_state, address stubAddr, const char *stubName,
317 Node* src_start, Node* ofs, Node* limit);
318 Node* get_state_from_sha_object(Node *sha_object);
319 Node* get_state_from_sha5_object(Node *sha_object);
320 Node* inline_digestBase_implCompressMB_predicate(int predicate);
310 bool inline_encodeISOArray(); 321 bool inline_encodeISOArray();
311 bool inline_updateCRC32(); 322 bool inline_updateCRC32();
312 bool inline_updateBytesCRC32(); 323 bool inline_updateBytesCRC32();
313 bool inline_updateByteBufferCRC32(); 324 bool inline_updateByteBufferCRC32();
325 bool inline_multiplyToLen();
314 }; 326 };
315 327
316 328
317 //---------------------------make_vm_intrinsic---------------------------- 329 //---------------------------make_vm_intrinsic----------------------------
318 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 330 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
319 vmIntrinsics::ID id = m->intrinsic_id(); 331 vmIntrinsics::ID id = m->intrinsic_id();
320 assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 332 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
321 333
322 if (DisableIntrinsic[0] != '\0' 334 ccstr disable_intr = NULL;
323 && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) { 335
336 if ((DisableIntrinsic[0] != '\0'
337 && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) ||
338 (method_has_option_value("DisableIntrinsic", disable_intr)
339 && strstr(disable_intr, vmIntrinsics::name_at(id)) != NULL)) {
324 // disabled by a user request on the command line: 340 // disabled by a user request on the command line:
325 // example: -XX:DisableIntrinsic=_hashCode,_getClass 341 // example: -XX:DisableIntrinsic=_hashCode,_getClass
326 return NULL; 342 return NULL;
327 } 343 }
328 344
365 default: 381 default:
366 return NULL; 382 return NULL;
367 } 383 }
368 } 384 }
369 385
370 bool is_predicted = false; 386 int predicates = 0;
371 bool does_virtual_dispatch = false; 387 bool does_virtual_dispatch = false;
372 388
373 switch (id) { 389 switch (id) {
374 case vmIntrinsics::_compareTo: 390 case vmIntrinsics::_compareTo:
375 if (!SpecialStringCompareTo) return NULL; 391 if (!SpecialStringCompareTo) return NULL;
502 case vmIntrinsics::_aescrypt_encryptBlock: 518 case vmIntrinsics::_aescrypt_encryptBlock:
503 case vmIntrinsics::_aescrypt_decryptBlock: 519 case vmIntrinsics::_aescrypt_decryptBlock:
504 if (!UseAESIntrinsics) return NULL; 520 if (!UseAESIntrinsics) return NULL;
505 break; 521 break;
506 522
523 case vmIntrinsics::_multiplyToLen:
524 if (!UseMultiplyToLenIntrinsic) return NULL;
525 break;
526
507 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 527 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
508 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 528 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
509 if (!UseAESIntrinsics) return NULL; 529 if (!UseAESIntrinsics) return NULL;
510 // these two require the predicated logic 530 // these two require the predicated logic
511 is_predicted = true; 531 predicates = 1;
532 break;
533
534 case vmIntrinsics::_sha_implCompress:
535 if (!UseSHA1Intrinsics) return NULL;
536 break;
537
538 case vmIntrinsics::_sha2_implCompress:
539 if (!UseSHA256Intrinsics) return NULL;
540 break;
541
542 case vmIntrinsics::_sha5_implCompress:
543 if (!UseSHA512Intrinsics) return NULL;
544 break;
545
546 case vmIntrinsics::_digestBase_implCompressMB:
547 if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) return NULL;
548 predicates = 3;
512 break; 549 break;
513 550
514 case vmIntrinsics::_updateCRC32: 551 case vmIntrinsics::_updateCRC32:
515 case vmIntrinsics::_updateBytesCRC32: 552 case vmIntrinsics::_updateBytesCRC32:
516 case vmIntrinsics::_updateByteBufferCRC32: 553 case vmIntrinsics::_updateByteBufferCRC32:
575 // -XX:-InlineUnsafeOps disables natives from the Unsafe class. 612 // -XX:-InlineUnsafeOps disables natives from the Unsafe class.
576 if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) { 613 if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) {
577 if (!InlineUnsafeOps) return NULL; 614 if (!InlineUnsafeOps) return NULL;
578 } 615 }
579 616
580 return new LibraryIntrinsic(m, is_virtual, is_predicted, does_virtual_dispatch, (vmIntrinsics::ID) id); 617 return new LibraryIntrinsic(m, is_virtual, predicates, does_virtual_dispatch, (vmIntrinsics::ID) id);
581 } 618 }
582 619
583 //----------------------register_library_intrinsics----------------------- 620 //----------------------register_library_intrinsics-----------------------
584 // Initialize this file's data structures, for each Compile instance. 621 // Initialize this file's data structures, for each Compile instance.
585 void Compile::register_library_intrinsics() { 622 void Compile::register_library_intrinsics() {
586 // Nothing to do here. 623 // Nothing to do here.
587 } 624 }
588 625
589 JVMState* LibraryIntrinsic::generate(JVMState* jvms, Parse* parent_parser) { 626 JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
590 LibraryCallKit kit(jvms, this); 627 LibraryCallKit kit(jvms, this);
591 Compile* C = kit.C; 628 Compile* C = kit.C;
592 int nodes = C->unique(); 629 int nodes = C->unique();
593 #ifndef PRODUCT 630 #ifndef PRODUCT
594 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 631 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
599 #endif 636 #endif
600 ciMethod* callee = kit.callee(); 637 ciMethod* callee = kit.callee();
601 const int bci = kit.bci(); 638 const int bci = kit.bci();
602 639
603 // Try to inline the intrinsic. 640 // Try to inline the intrinsic.
604 if (kit.try_to_inline()) { 641 if (kit.try_to_inline(_last_predicate)) {
605 if (C->print_intrinsics() || C->print_inlining()) { 642 if (C->print_intrinsics() || C->print_inlining()) {
606 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 643 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
607 } 644 }
608 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 645 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
609 if (C->log()) { 646 if (C->log()) {
632 } 669 }
633 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 670 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
634 return NULL; 671 return NULL;
635 } 672 }
636 673
637 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms) { 674 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) {
638 LibraryCallKit kit(jvms, this); 675 LibraryCallKit kit(jvms, this);
639 Compile* C = kit.C; 676 Compile* C = kit.C;
640 int nodes = C->unique(); 677 int nodes = C->unique();
678 _last_predicate = predicate;
641 #ifndef PRODUCT 679 #ifndef PRODUCT
642 assert(is_predicted(), "sanity"); 680 assert(is_predicated() && predicate < predicates_count(), "sanity");
643 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 681 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
644 char buf[1000]; 682 char buf[1000];
645 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 683 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
646 tty->print_cr("Predicate for intrinsic %s", str); 684 tty->print_cr("Predicate for intrinsic %s", str);
647 } 685 }
648 #endif 686 #endif
649 ciMethod* callee = kit.callee(); 687 ciMethod* callee = kit.callee();
650 const int bci = kit.bci(); 688 const int bci = kit.bci();
651 689
652 Node* slow_ctl = kit.try_to_predicate(); 690 Node* slow_ctl = kit.try_to_predicate(predicate);
653 if (!kit.failing()) { 691 if (!kit.failing()) {
654 if (C->print_intrinsics() || C->print_inlining()) { 692 if (C->print_intrinsics() || C->print_inlining()) {
655 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 693 C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual, predicate)" : "(intrinsic, predicate)");
656 } 694 }
657 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 695 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
658 if (C->log()) { 696 if (C->log()) {
659 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 697 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'",
660 vmIntrinsics::name_at(intrinsic_id()), 698 vmIntrinsics::name_at(intrinsic_id()),
679 } 717 }
680 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 718 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
681 return NULL; 719 return NULL;
682 } 720 }
683 721
684 bool LibraryCallKit::try_to_inline() { 722 bool LibraryCallKit::try_to_inline(int predicate) {
685 // Handle symbolic names for otherwise undistinguished boolean switches: 723 // Handle symbolic names for otherwise undistinguished boolean switches:
686 const bool is_store = true; 724 const bool is_store = true;
687 const bool is_native_ptr = true; 725 const bool is_native_ptr = true;
688 const bool is_static = true; 726 const bool is_static = true;
689 const bool is_volatile = true; 727 const bool is_volatile = true;
873 911
874 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 912 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
875 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 913 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
876 return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 914 return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
877 915
916 case vmIntrinsics::_sha_implCompress:
917 case vmIntrinsics::_sha2_implCompress:
918 case vmIntrinsics::_sha5_implCompress:
919 return inline_sha_implCompress(intrinsic_id());
920
921 case vmIntrinsics::_digestBase_implCompressMB:
922 return inline_digestBase_implCompressMB(predicate);
923
924 case vmIntrinsics::_multiplyToLen:
925 return inline_multiplyToLen();
926
878 case vmIntrinsics::_encodeISOArray: 927 case vmIntrinsics::_encodeISOArray:
879 return inline_encodeISOArray(); 928 return inline_encodeISOArray();
880 929
881 case vmIntrinsics::_updateCRC32: 930 case vmIntrinsics::_updateCRC32:
882 return inline_updateCRC32(); 931 return inline_updateCRC32();
896 #endif 945 #endif
897 return false; 946 return false;
898 } 947 }
899 } 948 }
900 949
901 Node* LibraryCallKit::try_to_predicate() { 950 Node* LibraryCallKit::try_to_predicate(int predicate) {
902 if (!jvms()->has_method()) { 951 if (!jvms()->has_method()) {
903 // Root JVMState has a null method. 952 // Root JVMState has a null method.
904 assert(map()->memory()->Opcode() == Op_Parm, ""); 953 assert(map()->memory()->Opcode() == Op_Parm, "");
905 // Insert the memory aliasing node 954 // Insert the memory aliasing node
906 set_all_memory(reset_memory()); 955 set_all_memory(reset_memory());
910 switch (intrinsic_id()) { 959 switch (intrinsic_id()) {
911 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 960 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
912 return inline_cipherBlockChaining_AESCrypt_predicate(false); 961 return inline_cipherBlockChaining_AESCrypt_predicate(false);
913 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 962 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
914 return inline_cipherBlockChaining_AESCrypt_predicate(true); 963 return inline_cipherBlockChaining_AESCrypt_predicate(true);
964 case vmIntrinsics::_digestBase_implCompressMB:
965 return inline_digestBase_implCompressMB_predicate(predicate);
915 966
916 default: 967 default:
917 // If you get here, it may be that someone has added a new intrinsic 968 // If you get here, it may be that someone has added a new intrinsic
918 // to the list in vmSymbols.hpp without implementing it here. 969 // to the list in vmSymbols.hpp without implementing it here.
919 #ifndef PRODUCT 970 #ifndef PRODUCT
2609 // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar 2660 // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar
2610 // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl. 2661 // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl.
2611 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 2662 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
2612 2663
2613 if (!is_store) { 2664 if (!is_store) {
2614 Node* p = make_load(control(), adr, value_type, type, adr_type, MemNode::unordered, is_volatile); 2665 MemNode::MemOrd mo = is_volatile ? MemNode::acquire : MemNode::unordered;
2666 Node* p = make_load(control(), adr, value_type, type, adr_type, mo, is_volatile);
2615 // load value 2667 // load value
2616 switch (type) { 2668 switch (type) {
2617 case T_BOOLEAN: 2669 case T_BOOLEAN:
2618 case T_CHAR: 2670 case T_CHAR:
2619 case T_BYTE: 2671 case T_BYTE:
3344 int null_path, 3396 int null_path,
3345 int offset) { 3397 int offset) {
3346 if (region == NULL) never_see_null = true; 3398 if (region == NULL) never_see_null = true;
3347 Node* p = basic_plus_adr(mirror, offset); 3399 Node* p = basic_plus_adr(mirror, offset);
3348 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 3400 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3349 Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 3401 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type));
3350 Node* null_ctl = top(); 3402 Node* null_ctl = top();
3351 kls = null_check_oop(kls, &null_ctl, never_see_null); 3403 kls = null_check_oop(kls, &null_ctl, never_see_null);
3352 if (region != NULL) { 3404 if (region != NULL) {
3353 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 3405 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
3354 region->init_req(null_path, null_ctl); 3406 region->init_req(null_path, null_ctl);
3520 if (generate_array_guard(kls, region) != NULL) 3572 if (generate_array_guard(kls, region) != NULL)
3521 // A guard was added. If the guard is taken, it was an array. 3573 // A guard was added. If the guard is taken, it was an array.
3522 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 3574 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
3523 // If we fall through, it's a plain class. Get its _super. 3575 // If we fall through, it's a plain class. Get its _super.
3524 p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 3576 p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
3525 kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 3577 kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL));
3526 null_ctl = top(); 3578 null_ctl = top();
3527 kls = null_check_oop(kls, &null_ctl); 3579 kls = null_check_oop(kls, &null_ctl);
3528 if (null_ctl != top()) { 3580 if (null_ctl != top()) {
3529 // If the guard is taken, Object.superClass is null (both klass and mirror). 3581 // If the guard is taken, Object.superClass is null (both klass and mirror).
3530 region->add_req(null_ctl); 3582 region->add_req(null_ctl);
3602 arg = null_check(arg); 3654 arg = null_check(arg);
3603 if (stopped()) break; 3655 if (stopped()) break;
3604 args[which_arg] = arg; 3656 args[which_arg] = arg;
3605 3657
3606 Node* p = basic_plus_adr(arg, class_klass_offset); 3658 Node* p = basic_plus_adr(arg, class_klass_offset);
3607 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type); 3659 Node* kls = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, adr_type, kls_type);
3608 klasses[which_arg] = _gvn.transform(kls); 3660 klasses[which_arg] = _gvn.transform(kls);
3609 } 3661 }
3610 3662
3611 // Having loaded both klasses, test each for null. 3663 // Having loaded both klasses, test each for null.
3612 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 3664 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
5118 PreserveJVMState pjvms(this); 5170 PreserveJVMState pjvms(this);
5119 set_control(not_subtype_ctrl); 5171 set_control(not_subtype_ctrl);
5120 // (At this point we can assume disjoint_bases, since types differ.) 5172 // (At this point we can assume disjoint_bases, since types differ.)
5121 int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset()); 5173 int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset());
5122 Node* p1 = basic_plus_adr(dest_klass, ek_offset); 5174 Node* p1 = basic_plus_adr(dest_klass, ek_offset);
5123 Node* n1 = LoadKlassNode::make(_gvn, immutable_memory(), p1, TypeRawPtr::BOTTOM); 5175 Node* n1 = LoadKlassNode::make(_gvn, NULL, immutable_memory(), p1, TypeRawPtr::BOTTOM);
5124 Node* dest_elem_klass = _gvn.transform(n1); 5176 Node* dest_elem_klass = _gvn.transform(n1);
5125 Node* cv = generate_checkcast_arraycopy(adr_type, 5177 Node* cv = generate_checkcast_arraycopy(adr_type,
5126 dest_elem_klass, 5178 dest_elem_klass,
5127 src, src_offset, dest, dest_offset, 5179 src, src_offset, dest, dest_offset,
5128 ConvI2X(copy_length), dest_uninitialized); 5180 ConvI2X(copy_length), dest_uninitialized);
5693 set_memory(res_mem, mtype); 5745 set_memory(res_mem, mtype);
5694 set_result(enc); 5746 set_result(enc);
5695 return true; 5747 return true;
5696 } 5748 }
5697 5749
5750 //-------------inline_multiplyToLen-----------------------------------
5751 bool LibraryCallKit::inline_multiplyToLen() {
5752 assert(UseMultiplyToLenIntrinsic, "not implementated on this platform");
5753
5754 address stubAddr = StubRoutines::multiplyToLen();
5755 if (stubAddr == NULL) {
5756 return false; // Intrinsic's stub is not implemented on this platform
5757 }
5758 const char* stubName = "multiplyToLen";
5759
5760 assert(callee()->signature()->size() == 5, "multiplyToLen has 5 parameters");
5761
5762 Node* x = argument(1);
5763 Node* xlen = argument(2);
5764 Node* y = argument(3);
5765 Node* ylen = argument(4);
5766 Node* z = argument(5);
5767
5768 const Type* x_type = x->Value(&_gvn);
5769 const Type* y_type = y->Value(&_gvn);
5770 const TypeAryPtr* top_x = x_type->isa_aryptr();
5771 const TypeAryPtr* top_y = y_type->isa_aryptr();
5772 if (top_x == NULL || top_x->klass() == NULL ||
5773 top_y == NULL || top_y->klass() == NULL) {
5774 // failed array check
5775 return false;
5776 }
5777
5778 BasicType x_elem = x_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5779 BasicType y_elem = y_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
5780 if (x_elem != T_INT || y_elem != T_INT) {
5781 return false;
5782 }
5783
5784 // Set the original stack and the reexecute bit for the interpreter to reexecute
5785 // the bytecode that invokes BigInteger.multiplyToLen() if deoptimization happens
5786 // on the return from z array allocation in runtime.
5787 { PreserveReexecuteState preexecs(this);
5788 jvms()->set_should_reexecute(true);
5789
5790 Node* x_start = array_element_address(x, intcon(0), x_elem);
5791 Node* y_start = array_element_address(y, intcon(0), y_elem);
5792 // 'x_start' points to x array + scaled xlen
5793 // 'y_start' points to y array + scaled ylen
5794
5795 // Allocate the result array
5796 Node* zlen = _gvn.transform(new(C) AddINode(xlen, ylen));
5797 ciKlass* klass = ciTypeArrayKlass::make(T_INT);
5798 Node* klass_node = makecon(TypeKlassPtr::make(klass));
5799
5800 IdealKit ideal(this);
5801
5802 #define __ ideal.
5803 Node* one = __ ConI(1);
5804 Node* zero = __ ConI(0);
5805 IdealVariable need_alloc(ideal), z_alloc(ideal); __ declarations_done();
5806 __ set(need_alloc, zero);
5807 __ set(z_alloc, z);
5808 __ if_then(z, BoolTest::eq, null()); {
5809 __ increment (need_alloc, one);
5810 } __ else_(); {
5811 // Update graphKit memory and control from IdealKit.
5812 sync_kit(ideal);
5813 Node* zlen_arg = load_array_length(z);
5814 // Update IdealKit memory and control from graphKit.
5815 __ sync_kit(this);
5816 __ if_then(zlen_arg, BoolTest::lt, zlen); {
5817 __ increment (need_alloc, one);
5818 } __ end_if();
5819 } __ end_if();
5820
5821 __ if_then(__ value(need_alloc), BoolTest::ne, zero); {
5822 // Update graphKit memory and control from IdealKit.
5823 sync_kit(ideal);
5824 Node * narr = new_array(klass_node, zlen, 1);
5825 // Update IdealKit memory and control from graphKit.
5826 __ sync_kit(this);
5827 __ set(z_alloc, narr);
5828 } __ end_if();
5829
5830 sync_kit(ideal);
5831 z = __ value(z_alloc);
5832 // Can't use TypeAryPtr::INTS which uses Bottom offset.
5833 _gvn.set_type(z, TypeOopPtr::make_from_klass(klass));
5834 // Final sync IdealKit and GraphKit.
5835 final_sync(ideal);
5836 #undef __
5837
5838 Node* z_start = array_element_address(z, intcon(0), T_INT);
5839
5840 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
5841 OptoRuntime::multiplyToLen_Type(),
5842 stubAddr, stubName, TypePtr::BOTTOM,
5843 x_start, xlen, y_start, ylen, z_start, zlen);
5844 } // original reexecute is set back here
5845
5846 C->set_has_split_ifs(true); // Has chance for split-if optimization
5847 set_result(z);
5848 return true;
5849 }
5850
5851
5698 /** 5852 /**
5699 * Calculate CRC32 for byte. 5853 * Calculate CRC32 for byte.
5700 * int java.util.zip.CRC32.update(int crc, int b) 5854 * int java.util.zip.CRC32.update(int crc, int b)
5701 */ 5855 */
5702 bool LibraryCallKit::inline_updateCRC32() { 5856 bool LibraryCallKit::inline_updateCRC32() {
5864 const TypePtr* adr_type = C->alias_type(field)->adr_type(); 6018 const TypePtr* adr_type = C->alias_type(field)->adr_type();
5865 Node *adr = basic_plus_adr(fromObj, fromObj, offset); 6019 Node *adr = basic_plus_adr(fromObj, fromObj, offset);
5866 BasicType bt = field->layout_type(); 6020 BasicType bt = field->layout_type();
5867 6021
5868 // Build the resultant type of the load 6022 // Build the resultant type of the load
5869 const Type *type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 6023 const Type *type;
5870 6024 if (bt == T_OBJECT) {
6025 type = TypeOopPtr::make_from_klass(field_klass->as_klass());
6026 } else {
6027 type = Type::get_const_basic_type(bt);
6028 }
6029
6030 if (support_IRIW_for_not_multiple_copy_atomic_cpu && is_vol) {
6031 insert_mem_bar(Op_MemBarVolatile); // StoreLoad barrier
6032 }
5871 // Build the load. 6033 // Build the load.
5872 Node* loadedField = make_load(NULL, adr, type, bt, adr_type, MemNode::unordered, is_vol); 6034 MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered;
6035 Node* loadedField = make_load(NULL, adr, type, bt, adr_type, mo, is_vol);
6036 // If reference is volatile, prevent following memory ops from
6037 // floating up past the volatile read. Also prevents commoning
6038 // another volatile read.
6039 if (is_vol) {
6040 // Memory barrier includes bogus read of value to force load BEFORE membar
6041 insert_mem_bar(Op_MemBarAcquire, loadedField);
6042 }
5873 return loadedField; 6043 return loadedField;
5874 } 6044 }
5875 6045
5876 6046
5877 //------------------------------inline_aescrypt_Block----------------------- 6047 //------------------------------inline_aescrypt_Block-----------------------
5994 // cast it to what we know it will be at runtime 6164 // cast it to what we know it will be at runtime
5995 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 6165 const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr();
5996 assert(tinst != NULL, "CBC obj is null"); 6166 assert(tinst != NULL, "CBC obj is null");
5997 assert(tinst->klass()->is_loaded(), "CBC obj is not loaded"); 6167 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")); 6168 ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
5999 if (!klass_AESCrypt->is_loaded()) return false; 6169 assert(klass_AESCrypt->is_loaded(), "predicate checks that this class is loaded");
6000 6170
6001 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 6171 ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass();
6002 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 6172 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt);
6003 const TypeOopPtr* xtype = aklass->as_instance_type(); 6173 const TypeOopPtr* xtype = aklass->as_instance_type();
6004 Node* aescrypt_object = new(C) CheckCastPPNode(control(), embeddedCipherObj, xtype); 6174 Node* aescrypt_object = new(C) CheckCastPPNode(control(), embeddedCipherObj, xtype);
6069 // for decryption: 6239 // for decryption:
6070 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 6240 // if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
6071 // note cipher==plain is more conservative than the original java code but that's OK 6241 // note cipher==plain is more conservative than the original java code but that's OK
6072 // 6242 //
6073 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 6243 Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) {
6074 // First, check receiver for NULL since it is virtual method. 6244 // The receiver was checked for NULL already.
6075 Node* objCBC = argument(0); 6245 Node* objCBC = argument(0);
6076 objCBC = null_check(objCBC);
6077
6078 if (stopped()) return NULL; // Always NULL
6079 6246
6080 // Load embeddedCipher field of CipherBlockChaining object. 6247 // Load embeddedCipher field of CipherBlockChaining object.
6081 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 6248 Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
6082 6249
6083 // get AESCrypt klass for instanceOf check 6250 // get AESCrypt klass for instanceOf check
6120 region->init_req(2, src_dest_conjoint); 6287 region->init_req(2, src_dest_conjoint);
6121 6288
6122 record_for_igvn(region); 6289 record_for_igvn(region);
6123 return _gvn.transform(region); 6290 return _gvn.transform(region);
6124 } 6291 }
6292
6293 //------------------------------inline_sha_implCompress-----------------------
6294 //
6295 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
6296 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
6297 //
6298 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
6299 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
6300 //
6301 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array.
6302 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs)
6303 //
6304 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) {
6305 assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
6306
6307 Node* sha_obj = argument(0);
6308 Node* src = argument(1); // type oop
6309 Node* ofs = argument(2); // type int
6310
6311 const Type* src_type = src->Value(&_gvn);
6312 const TypeAryPtr* top_src = src_type->isa_aryptr();
6313 if (top_src == NULL || top_src->klass() == NULL) {
6314 // failed array check
6315 return false;
6316 }
6317 // Figure out the size and type of the elements we will be copying.
6318 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6319 if (src_elem != T_BYTE) {
6320 return false;
6321 }
6322 // 'src_start' points to src array + offset
6323 Node* src_start = array_element_address(src, ofs, src_elem);
6324 Node* state = NULL;
6325 address stubAddr;
6326 const char *stubName;
6327
6328 switch(id) {
6329 case vmIntrinsics::_sha_implCompress:
6330 assert(UseSHA1Intrinsics, "need SHA1 instruction support");
6331 state = get_state_from_sha_object(sha_obj);
6332 stubAddr = StubRoutines::sha1_implCompress();
6333 stubName = "sha1_implCompress";
6334 break;
6335 case vmIntrinsics::_sha2_implCompress:
6336 assert(UseSHA256Intrinsics, "need SHA256 instruction support");
6337 state = get_state_from_sha_object(sha_obj);
6338 stubAddr = StubRoutines::sha256_implCompress();
6339 stubName = "sha256_implCompress";
6340 break;
6341 case vmIntrinsics::_sha5_implCompress:
6342 assert(UseSHA512Intrinsics, "need SHA512 instruction support");
6343 state = get_state_from_sha5_object(sha_obj);
6344 stubAddr = StubRoutines::sha512_implCompress();
6345 stubName = "sha512_implCompress";
6346 break;
6347 default:
6348 fatal_unexpected_iid(id);
6349 return false;
6350 }
6351 if (state == NULL) return false;
6352
6353 // Call the stub.
6354 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::sha_implCompress_Type(),
6355 stubAddr, stubName, TypePtr::BOTTOM,
6356 src_start, state);
6357
6358 return true;
6359 }
6360
6361 //------------------------------inline_digestBase_implCompressMB-----------------------
6362 //
6363 // Calculate SHA/SHA2/SHA5 for multi-block byte[] array.
6364 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
6365 //
6366 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
6367 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6368 "need SHA1/SHA256/SHA512 instruction support");
6369 assert((uint)predicate < 3, "sanity");
6370 assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
6371
6372 Node* digestBase_obj = argument(0); // The receiver was checked for NULL already.
6373 Node* src = argument(1); // byte[] array
6374 Node* ofs = argument(2); // type int
6375 Node* limit = argument(3); // type int
6376
6377 const Type* src_type = src->Value(&_gvn);
6378 const TypeAryPtr* top_src = src_type->isa_aryptr();
6379 if (top_src == NULL || top_src->klass() == NULL) {
6380 // failed array check
6381 return false;
6382 }
6383 // Figure out the size and type of the elements we will be copying.
6384 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6385 if (src_elem != T_BYTE) {
6386 return false;
6387 }
6388 // 'src_start' points to src array + offset
6389 Node* src_start = array_element_address(src, ofs, src_elem);
6390
6391 const char* klass_SHA_name = NULL;
6392 const char* stub_name = NULL;
6393 address stub_addr = NULL;
6394 bool long_state = false;
6395
6396 switch (predicate) {
6397 case 0:
6398 if (UseSHA1Intrinsics) {
6399 klass_SHA_name = "sun/security/provider/SHA";
6400 stub_name = "sha1_implCompressMB";
6401 stub_addr = StubRoutines::sha1_implCompressMB();
6402 }
6403 break;
6404 case 1:
6405 if (UseSHA256Intrinsics) {
6406 klass_SHA_name = "sun/security/provider/SHA2";
6407 stub_name = "sha256_implCompressMB";
6408 stub_addr = StubRoutines::sha256_implCompressMB();
6409 }
6410 break;
6411 case 2:
6412 if (UseSHA512Intrinsics) {
6413 klass_SHA_name = "sun/security/provider/SHA5";
6414 stub_name = "sha512_implCompressMB";
6415 stub_addr = StubRoutines::sha512_implCompressMB();
6416 long_state = true;
6417 }
6418 break;
6419 default:
6420 fatal(err_msg_res("unknown SHA intrinsic predicate: %d", predicate));
6421 }
6422 if (klass_SHA_name != NULL) {
6423 // get DigestBase klass to lookup for SHA klass
6424 const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
6425 assert(tinst != NULL, "digestBase_obj is not instance???");
6426 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded");
6427
6428 ciKlass* klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name));
6429 assert(klass_SHA->is_loaded(), "predicate checks that this class is loaded");
6430 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass();
6431 return inline_sha_implCompressMB(digestBase_obj, instklass_SHA, long_state, stub_addr, stub_name, src_start, ofs, limit);
6432 }
6433 return false;
6434 }
6435 //------------------------------inline_sha_implCompressMB-----------------------
6436 bool LibraryCallKit::inline_sha_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_SHA,
6437 bool long_state, address stubAddr, const char *stubName,
6438 Node* src_start, Node* ofs, Node* limit) {
6439 const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_SHA);
6440 const TypeOopPtr* xtype = aklass->as_instance_type();
6441 Node* sha_obj = new (C) CheckCastPPNode(control(), digestBase_obj, xtype);
6442 sha_obj = _gvn.transform(sha_obj);
6443
6444 Node* state;
6445 if (long_state) {
6446 state = get_state_from_sha5_object(sha_obj);
6447 } else {
6448 state = get_state_from_sha_object(sha_obj);
6449 }
6450 if (state == NULL) return false;
6451
6452 // Call the stub.
6453 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
6454 OptoRuntime::digestBase_implCompressMB_Type(),
6455 stubAddr, stubName, TypePtr::BOTTOM,
6456 src_start, state, ofs, limit);
6457 // return ofs (int)
6458 Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms));
6459 set_result(result);
6460
6461 return true;
6462 }
6463
6464 //------------------------------get_state_from_sha_object-----------------------
6465 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) {
6466 Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false);
6467 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2");
6468 if (sha_state == NULL) return (Node *) NULL;
6469
6470 // now have the array, need to get the start address of the state array
6471 Node* state = array_element_address(sha_state, intcon(0), T_INT);
6472 return state;
6473 }
6474
6475 //------------------------------get_state_from_sha5_object-----------------------
6476 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) {
6477 Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false);
6478 assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5");
6479 if (sha_state == NULL) return (Node *) NULL;
6480
6481 // now have the array, need to get the start address of the state array
6482 Node* state = array_element_address(sha_state, intcon(0), T_LONG);
6483 return state;
6484 }
6485
6486 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
6487 // Return node representing slow path of predicate check.
6488 // the pseudo code we want to emulate with this predicate is:
6489 // if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath
6490 //
6491 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
6492 assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6493 "need SHA1/SHA256/SHA512 instruction support");
6494 assert((uint)predicate < 3, "sanity");
6495
6496 // The receiver was checked for NULL already.
6497 Node* digestBaseObj = argument(0);
6498
6499 // get DigestBase klass for instanceOf check
6500 const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr();
6501 assert(tinst != NULL, "digestBaseObj is null");
6502 assert(tinst->klass()->is_loaded(), "DigestBase is not loaded");
6503
6504 const char* klass_SHA_name = NULL;
6505 switch (predicate) {
6506 case 0:
6507 if (UseSHA1Intrinsics) {
6508 // we want to do an instanceof comparison against the SHA class
6509 klass_SHA_name = "sun/security/provider/SHA";
6510 }
6511 break;
6512 case 1:
6513 if (UseSHA256Intrinsics) {
6514 // we want to do an instanceof comparison against the SHA2 class
6515 klass_SHA_name = "sun/security/provider/SHA2";
6516 }
6517 break;
6518 case 2:
6519 if (UseSHA512Intrinsics) {
6520 // we want to do an instanceof comparison against the SHA5 class
6521 klass_SHA_name = "sun/security/provider/SHA5";
6522 }
6523 break;
6524 default:
6525 fatal(err_msg_res("unknown SHA intrinsic predicate: %d", predicate));
6526 }
6527
6528 ciKlass* klass_SHA = NULL;
6529 if (klass_SHA_name != NULL) {
6530 klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name));
6531 }
6532 if ((klass_SHA == NULL) || !klass_SHA->is_loaded()) {
6533 // if none of SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path
6534 Node* ctrl = control();
6535 set_control(top()); // no intrinsic path
6536 return ctrl;
6537 }
6538 ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass();
6539
6540 Node* instofSHA = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass_SHA)));
6541 Node* cmp_instof = _gvn.transform(new (C) CmpINode(instofSHA, intcon(1)));
6542 Node* bool_instof = _gvn.transform(new (C) BoolNode(cmp_instof, BoolTest::ne));
6543 Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6544
6545 return instof_false; // even if it is NULL
6546 }