src/share/vm/opto/library_call.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 8035968 Sdiff src/share/vm/opto

src/share/vm/opto/library_call.cpp

Print this page




 299                                    Node* dest, Node* dest_offset,
 300                                    Node* copy_length, bool dest_uninitialized);
 301   void generate_unchecked_arraycopy(const TypePtr* adr_type,
 302                                     BasicType basic_elem_type,
 303                                     bool disjoint_bases,
 304                                     Node* src,  Node* src_offset,
 305                                     Node* dest, Node* dest_offset,
 306                                     Node* copy_length, bool dest_uninitialized);
 307   typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind;
 308   bool inline_unsafe_load_store(BasicType type,  LoadStoreKind kind);
 309   bool inline_unsafe_ordered_store(BasicType type);
 310   bool inline_unsafe_fence(vmIntrinsics::ID id);
 311   bool inline_fp_conversions(vmIntrinsics::ID id);
 312   bool inline_number_methods(vmIntrinsics::ID id);
 313   bool inline_reference_get();
 314   bool inline_aescrypt_Block(vmIntrinsics::ID id);
 315   bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id);
 316   Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
 317   Node* get_key_start_from_aescrypt_object(Node* aescrypt_object);
 318   Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object);








 319   bool inline_encodeISOArray();
 320   bool inline_updateCRC32();
 321   bool inline_updateBytesCRC32();
 322   bool inline_updateByteBufferCRC32();
 323 };
 324 
 325 
 326 //---------------------------make_vm_intrinsic----------------------------
 327 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
 328   vmIntrinsics::ID id = m->intrinsic_id();
 329   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 330 
 331   if (DisableIntrinsic[0] != '\0'
 332       && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) {
 333     // disabled by a user request on the command line:
 334     // example: -XX:DisableIntrinsic=_hashCode,_getClass
 335     return NULL;
 336   }
 337 
 338   if (!m->is_loaded()) {


 502     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetP)) return NULL;
 503     if (UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetN)) return NULL;
 504     break;
 505 #else
 506     if (!Matcher::match_rule_supported(Op_GetAndSetP)) return NULL;
 507     break;
 508 #endif
 509 
 510   case vmIntrinsics::_aescrypt_encryptBlock:
 511   case vmIntrinsics::_aescrypt_decryptBlock:
 512     if (!UseAESIntrinsics) return NULL;
 513     break;
 514 
 515   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 516   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 517     if (!UseAESIntrinsics) return NULL;
 518     // these two require the predicated logic
 519     predicates = 1;
 520     break;
 521 

















 522   case vmIntrinsics::_updateCRC32:
 523   case vmIntrinsics::_updateBytesCRC32:
 524   case vmIntrinsics::_updateByteBufferCRC32:
 525     if (!UseCRC32Intrinsics) return NULL;
 526     break;
 527 
 528   case vmIntrinsics::_incrementExactI:
 529   case vmIntrinsics::_addExactI:
 530     if (!Matcher::match_rule_supported(Op_OverflowAddI) || !UseMathExactIntrinsics) return NULL;
 531     break;
 532   case vmIntrinsics::_incrementExactL:
 533   case vmIntrinsics::_addExactL:
 534     if (!Matcher::match_rule_supported(Op_OverflowAddL) || !UseMathExactIntrinsics) return NULL;
 535     break;
 536   case vmIntrinsics::_decrementExactI:
 537   case vmIntrinsics::_subtractExactI:
 538     if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL;
 539     break;
 540   case vmIntrinsics::_decrementExactL:
 541   case vmIntrinsics::_subtractExactL:


 869   case vmIntrinsics::_numberOfTrailingZeros_i:
 870   case vmIntrinsics::_numberOfTrailingZeros_l:
 871   case vmIntrinsics::_bitCount_i:
 872   case vmIntrinsics::_bitCount_l:
 873   case vmIntrinsics::_reverseBytes_i:
 874   case vmIntrinsics::_reverseBytes_l:
 875   case vmIntrinsics::_reverseBytes_s:
 876   case vmIntrinsics::_reverseBytes_c:           return inline_number_methods(intrinsic_id());
 877 
 878   case vmIntrinsics::_getCallerClass:           return inline_native_Reflection_getCallerClass();
 879 
 880   case vmIntrinsics::_Reference_get:            return inline_reference_get();
 881 
 882   case vmIntrinsics::_aescrypt_encryptBlock:
 883   case vmIntrinsics::_aescrypt_decryptBlock:    return inline_aescrypt_Block(intrinsic_id());
 884 
 885   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 886   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 887     return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
 888 








 889   case vmIntrinsics::_encodeISOArray:
 890     return inline_encodeISOArray();
 891 
 892   case vmIntrinsics::_updateCRC32:
 893     return inline_updateCRC32();
 894   case vmIntrinsics::_updateBytesCRC32:
 895     return inline_updateBytesCRC32();
 896   case vmIntrinsics::_updateByteBufferCRC32:
 897     return inline_updateByteBufferCRC32();
 898 
 899   default:
 900     // If you get here, it may be that someone has added a new intrinsic
 901     // to the list in vmSymbols.hpp without implementing it here.
 902 #ifndef PRODUCT
 903     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
 904       tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
 905                     vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
 906     }
 907 #endif
 908     return false;
 909   }
 910 }
 911 
 912 Node* LibraryCallKit::try_to_predicate(int predicate) {
 913   if (!jvms()->has_method()) {
 914     // Root JVMState has a null method.
 915     assert(map()->memory()->Opcode() == Op_Parm, "");
 916     // Insert the memory aliasing node
 917     set_all_memory(reset_memory());
 918   }
 919   assert(merged_memory(), "");
 920 
 921   switch (intrinsic_id()) {
 922   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 923     return inline_cipherBlockChaining_AESCrypt_predicate(false);
 924   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 925     return inline_cipherBlockChaining_AESCrypt_predicate(true);


 926 
 927   default:
 928     // If you get here, it may be that someone has added a new intrinsic
 929     // to the list in vmSymbols.hpp without implementing it here.
 930 #ifndef PRODUCT
 931     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
 932       tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)",
 933                     vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
 934     }
 935 #endif
 936     Node* slow_ctl = control();
 937     set_control(top()); // No fast path instrinsic
 938     return slow_ctl;
 939   }
 940 }
 941 
 942 //------------------------------set_result-------------------------------
 943 // Helper function for finishing intrinsics.
 944 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) {
 945   record_for_igvn(region);


6113 
6114   // for encryption, we are done
6115   if (!decrypting)
6116     return instof_false;  // even if it is NULL
6117 
6118   // for decryption, we need to add a further check to avoid
6119   // taking the intrinsic path when cipher and plain are the same
6120   // see the original java code for why.
6121   RegionNode* region = new RegionNode(3);
6122   region->init_req(1, instof_false);
6123   Node* src = argument(1);
6124   Node* dest = argument(4);
6125   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
6126   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
6127   Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN);
6128   region->init_req(2, src_dest_conjoint);
6129 
6130   record_for_igvn(region);
6131   return _gvn.transform(region);
6132 }

































































































































































































































































 299                                    Node* dest, Node* dest_offset,
 300                                    Node* copy_length, bool dest_uninitialized);
 301   void generate_unchecked_arraycopy(const TypePtr* adr_type,
 302                                     BasicType basic_elem_type,
 303                                     bool disjoint_bases,
 304                                     Node* src,  Node* src_offset,
 305                                     Node* dest, Node* dest_offset,
 306                                     Node* copy_length, bool dest_uninitialized);
 307   typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind;
 308   bool inline_unsafe_load_store(BasicType type,  LoadStoreKind kind);
 309   bool inline_unsafe_ordered_store(BasicType type);
 310   bool inline_unsafe_fence(vmIntrinsics::ID id);
 311   bool inline_fp_conversions(vmIntrinsics::ID id);
 312   bool inline_number_methods(vmIntrinsics::ID id);
 313   bool inline_reference_get();
 314   bool inline_aescrypt_Block(vmIntrinsics::ID id);
 315   bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id);
 316   Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
 317   Node* get_key_start_from_aescrypt_object(Node* aescrypt_object);
 318   Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object);
 319   bool inline_sha_implCompress(vmIntrinsics::ID id);
 320   bool inline_digestBase_implCompressMB(int predicate);
 321   bool inline_sha_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass_SHA,
 322                                  bool long_state, address stubAddr, const char *stubName,
 323                                  Node* src_start, Node* ofs, Node* limit);
 324   Node* get_state_from_sha_object(Node *sha_object);
 325   Node* get_state_from_sha5_object(Node *sha_object);
 326   Node* inline_digestBase_implCompressMB_predicate(int predicate);
 327   bool inline_encodeISOArray();
 328   bool inline_updateCRC32();
 329   bool inline_updateBytesCRC32();
 330   bool inline_updateByteBufferCRC32();
 331 };
 332 
 333 
 334 //---------------------------make_vm_intrinsic----------------------------
 335 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
 336   vmIntrinsics::ID id = m->intrinsic_id();
 337   assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
 338 
 339   if (DisableIntrinsic[0] != '\0'
 340       && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) {
 341     // disabled by a user request on the command line:
 342     // example: -XX:DisableIntrinsic=_hashCode,_getClass
 343     return NULL;
 344   }
 345 
 346   if (!m->is_loaded()) {


 510     if (!UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetP)) return NULL;
 511     if (UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetN)) return NULL;
 512     break;
 513 #else
 514     if (!Matcher::match_rule_supported(Op_GetAndSetP)) return NULL;
 515     break;
 516 #endif
 517 
 518   case vmIntrinsics::_aescrypt_encryptBlock:
 519   case vmIntrinsics::_aescrypt_decryptBlock:
 520     if (!UseAESIntrinsics) return NULL;
 521     break;
 522 
 523   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 524   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 525     if (!UseAESIntrinsics) return NULL;
 526     // these two require the predicated logic
 527     predicates = 1;
 528     break;
 529 
 530   case vmIntrinsics::_sha_implCompress:
 531     if (!UseSHA1Intrinsics) return NULL;
 532     break;
 533 
 534   case vmIntrinsics::_sha2_implCompress:
 535     if (!UseSHA256Intrinsics) return NULL;
 536     break;
 537 
 538   case vmIntrinsics::_sha5_implCompress:
 539     if (!UseSHA512Intrinsics) return NULL;
 540     break;
 541 
 542   case vmIntrinsics::_digestBase_implCompressMB:
 543     if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) return NULL;
 544     predicates = 3;
 545     break;
 546 
 547   case vmIntrinsics::_updateCRC32:
 548   case vmIntrinsics::_updateBytesCRC32:
 549   case vmIntrinsics::_updateByteBufferCRC32:
 550     if (!UseCRC32Intrinsics) return NULL;
 551     break;
 552 
 553   case vmIntrinsics::_incrementExactI:
 554   case vmIntrinsics::_addExactI:
 555     if (!Matcher::match_rule_supported(Op_OverflowAddI) || !UseMathExactIntrinsics) return NULL;
 556     break;
 557   case vmIntrinsics::_incrementExactL:
 558   case vmIntrinsics::_addExactL:
 559     if (!Matcher::match_rule_supported(Op_OverflowAddL) || !UseMathExactIntrinsics) return NULL;
 560     break;
 561   case vmIntrinsics::_decrementExactI:
 562   case vmIntrinsics::_subtractExactI:
 563     if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL;
 564     break;
 565   case vmIntrinsics::_decrementExactL:
 566   case vmIntrinsics::_subtractExactL:


 894   case vmIntrinsics::_numberOfTrailingZeros_i:
 895   case vmIntrinsics::_numberOfTrailingZeros_l:
 896   case vmIntrinsics::_bitCount_i:
 897   case vmIntrinsics::_bitCount_l:
 898   case vmIntrinsics::_reverseBytes_i:
 899   case vmIntrinsics::_reverseBytes_l:
 900   case vmIntrinsics::_reverseBytes_s:
 901   case vmIntrinsics::_reverseBytes_c:           return inline_number_methods(intrinsic_id());
 902 
 903   case vmIntrinsics::_getCallerClass:           return inline_native_Reflection_getCallerClass();
 904 
 905   case vmIntrinsics::_Reference_get:            return inline_reference_get();
 906 
 907   case vmIntrinsics::_aescrypt_encryptBlock:
 908   case vmIntrinsics::_aescrypt_decryptBlock:    return inline_aescrypt_Block(intrinsic_id());
 909 
 910   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 911   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 912     return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
 913 
 914   case vmIntrinsics::_sha_implCompress:
 915   case vmIntrinsics::_sha2_implCompress:
 916   case vmIntrinsics::_sha5_implCompress:
 917     return inline_sha_implCompress(intrinsic_id());
 918 
 919   case vmIntrinsics::_digestBase_implCompressMB:
 920     return inline_digestBase_implCompressMB(predicate);
 921 
 922   case vmIntrinsics::_encodeISOArray:
 923     return inline_encodeISOArray();
 924 
 925   case vmIntrinsics::_updateCRC32:
 926     return inline_updateCRC32();
 927   case vmIntrinsics::_updateBytesCRC32:
 928     return inline_updateBytesCRC32();
 929   case vmIntrinsics::_updateByteBufferCRC32:
 930     return inline_updateByteBufferCRC32();
 931 
 932   default:
 933     // If you get here, it may be that someone has added a new intrinsic
 934     // to the list in vmSymbols.hpp without implementing it here.
 935 #ifndef PRODUCT
 936     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
 937       tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
 938                     vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
 939     }
 940 #endif
 941     return false;
 942   }
 943 }
 944 
 945 Node* LibraryCallKit::try_to_predicate(int predicate) {
 946   if (!jvms()->has_method()) {
 947     // Root JVMState has a null method.
 948     assert(map()->memory()->Opcode() == Op_Parm, "");
 949     // Insert the memory aliasing node
 950     set_all_memory(reset_memory());
 951   }
 952   assert(merged_memory(), "");
 953 
 954   switch (intrinsic_id()) {
 955   case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
 956     return inline_cipherBlockChaining_AESCrypt_predicate(false);
 957   case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
 958     return inline_cipherBlockChaining_AESCrypt_predicate(true);
 959   case vmIntrinsics::_digestBase_implCompressMB:
 960     return inline_digestBase_implCompressMB_predicate(predicate);
 961 
 962   default:
 963     // If you get here, it may be that someone has added a new intrinsic
 964     // to the list in vmSymbols.hpp without implementing it here.
 965 #ifndef PRODUCT
 966     if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
 967       tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)",
 968                     vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
 969     }
 970 #endif
 971     Node* slow_ctl = control();
 972     set_control(top()); // No fast path instrinsic
 973     return slow_ctl;
 974   }
 975 }
 976 
 977 //------------------------------set_result-------------------------------
 978 // Helper function for finishing intrinsics.
 979 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) {
 980   record_for_igvn(region);


6148 
6149   // for encryption, we are done
6150   if (!decrypting)
6151     return instof_false;  // even if it is NULL
6152 
6153   // for decryption, we need to add a further check to avoid
6154   // taking the intrinsic path when cipher and plain are the same
6155   // see the original java code for why.
6156   RegionNode* region = new RegionNode(3);
6157   region->init_req(1, instof_false);
6158   Node* src = argument(1);
6159   Node* dest = argument(4);
6160   Node* cmp_src_dest = _gvn.transform(new CmpPNode(src, dest));
6161   Node* bool_src_dest = _gvn.transform(new BoolNode(cmp_src_dest, BoolTest::eq));
6162   Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN);
6163   region->init_req(2, src_dest_conjoint);
6164 
6165   record_for_igvn(region);
6166   return _gvn.transform(region);
6167 }
6168 
6169 //------------------------------inline_sha_implCompress-----------------------
6170 //
6171 // Calculate SHA (i.e., SHA-1) for single-block byte[] array.
6172 // void com.sun.security.provider.SHA.implCompress(byte[] buf, int ofs)
6173 //
6174 // Calculate SHA2 (i.e., SHA-244 or SHA-256) for single-block byte[] array.
6175 // void com.sun.security.provider.SHA2.implCompress(byte[] buf, int ofs)
6176 //
6177 // Calculate SHA5 (i.e., SHA-384 or SHA-512) for single-block byte[] array.
6178 // void com.sun.security.provider.SHA5.implCompress(byte[] buf, int ofs)
6179 //
6180 bool LibraryCallKit::inline_sha_implCompress(vmIntrinsics::ID id) {
6181   assert(callee()->signature()->size() == 2, "sha_implCompress has 2 parameters");
6182 
6183   Node* sha_obj = argument(0);
6184   Node* src     = argument(1); // type oop
6185   Node* ofs     = argument(2); // type int
6186 
6187   const Type* src_type = src->Value(&_gvn);
6188   const TypeAryPtr* top_src = src_type->isa_aryptr();
6189   if (top_src  == NULL || top_src->klass()  == NULL) {
6190     // failed array check
6191     return false;
6192   }
6193   // Figure out the size and type of the elements we will be copying.
6194   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6195   if (src_elem != T_BYTE) {
6196     return false;
6197   }
6198   // 'src_start' points to src array + offset
6199   Node* src_start = array_element_address(src, ofs, src_elem);
6200   Node* state = NULL;
6201   address stubAddr;
6202   const char *stubName;
6203 
6204   switch(id) {
6205   case vmIntrinsics::_sha_implCompress:
6206     assert(UseSHA1Intrinsics, "need SHA1 instruction support");
6207     state = get_state_from_sha_object(sha_obj);
6208     stubAddr = StubRoutines::sha1_implCompress();
6209     stubName = "sha1_implCompress";
6210     break;
6211   case vmIntrinsics::_sha2_implCompress:
6212     assert(UseSHA256Intrinsics, "need SHA256 instruction support");
6213     state = get_state_from_sha_object(sha_obj);
6214     stubAddr = StubRoutines::sha256_implCompress();
6215     stubName = "sha256_implCompress";
6216     break;
6217   case vmIntrinsics::_sha5_implCompress:
6218     assert(UseSHA512Intrinsics, "need SHA512 instruction support");
6219     state = get_state_from_sha5_object(sha_obj);
6220     stubAddr = StubRoutines::sha512_implCompress();
6221     stubName = "sha512_implCompress";
6222     break;
6223   default:
6224     fatal_unexpected_iid(id);
6225     return false;
6226   }
6227   if (state == NULL) return false;
6228 
6229   // Call the stub.
6230   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::sha_implCompress_Type(),
6231                                  stubAddr, stubName, TypePtr::BOTTOM,
6232                                  src_start, state);
6233 
6234   return true;
6235 }
6236 
6237 //------------------------------inline_digestBase_implCompressMB-----------------------
6238 //
6239 // Calculate SHA/SHA2/SHA5 for multi-block byte[] array.
6240 // int com.sun.security.provider.DigestBase.implCompressMultiBlock(byte[] b, int ofs, int limit)
6241 //
6242 bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
6243   assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6244          "need SHA1/SHA256/SHA512 instruction support");
6245   assert((uint)predicate < 3, "sanity");
6246   assert(callee()->signature()->size() == 3, "digestBase_implCompressMB has 3 parameters");
6247 
6248   Node* digestBase_obj = argument(0); // The receiver was checked for NULL already.
6249   Node* src            = argument(1); // byte[] array
6250   Node* ofs            = argument(2); // type int
6251   Node* limit          = argument(3); // type int
6252 
6253   const Type* src_type = src->Value(&_gvn);
6254   const TypeAryPtr* top_src = src_type->isa_aryptr();
6255   if (top_src  == NULL || top_src->klass()  == NULL) {
6256     // failed array check
6257     return false;
6258   }
6259   // Figure out the size and type of the elements we will be copying.
6260   BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
6261   if (src_elem != T_BYTE) {
6262     return false;
6263   }
6264   // 'src_start' points to src array + offset
6265   Node* src_start = array_element_address(src, ofs, src_elem);
6266 
6267   const char* klass_SHA_name = NULL;
6268   const char* stub_name = NULL;
6269   address     stub_addr = NULL;
6270   bool        long_state = false;
6271 
6272   switch (predicate) {
6273   case 0:
6274     if (UseSHA1Intrinsics) {
6275       klass_SHA_name = "sun/security/provider/SHA";
6276       stub_name = "sha1_implCompressMB";
6277       stub_addr = StubRoutines::sha1_implCompressMB();
6278     }
6279     break;
6280   case 1:
6281     if (UseSHA256Intrinsics) {
6282       klass_SHA_name = "sun/security/provider/SHA2";
6283       stub_name = "sha256_implCompressMB";
6284       stub_addr = StubRoutines::sha256_implCompressMB();
6285     }
6286     break;
6287   case 2:
6288     if (UseSHA512Intrinsics) {
6289       klass_SHA_name = "sun/security/provider/SHA5";
6290       stub_name = "sha512_implCompressMB";
6291       stub_addr = StubRoutines::sha512_implCompressMB();
6292       long_state = true;
6293     }
6294     break;
6295   default:
6296     fatal(err_msg_res("unknown SHA intrinsic predicate: %d", predicate));
6297   }
6298   if (klass_SHA_name != NULL) {
6299     // get DigestBase klass to lookup for SHA klass
6300     const TypeInstPtr* tinst = _gvn.type(digestBase_obj)->isa_instptr();
6301     assert(tinst != NULL, "digestBase_obj is not instance???");
6302     assert(tinst->klass()->is_loaded(), "DigestBase is not loaded");
6303 
6304     ciKlass* klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name));
6305     assert(klass_SHA->is_loaded(), "predicate checks that this class is loaded");
6306     ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass();
6307     return inline_sha_implCompressMB(digestBase_obj, instklass_SHA, long_state, stub_addr, stub_name, src_start, ofs, limit);
6308   }
6309   return false;
6310 }
6311 //------------------------------inline_sha_implCompressMB-----------------------
6312 bool LibraryCallKit::inline_sha_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_SHA,
6313                                                bool long_state, address stubAddr, const char *stubName,
6314                                                Node* src_start, Node* ofs, Node* limit) {
6315   const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_SHA);
6316   const TypeOopPtr* xtype = aklass->as_instance_type();
6317   Node* sha_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
6318   sha_obj = _gvn.transform(sha_obj);
6319 
6320   Node* state;
6321   if (long_state) {
6322     state = get_state_from_sha5_object(sha_obj);
6323   } else {
6324     state = get_state_from_sha_object(sha_obj);
6325   }
6326   if (state == NULL) return false;
6327 
6328   // Call the stub.
6329   Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
6330          OptoRuntime::digestBase_implCompressMB_Type(),
6331                                  stubAddr, stubName, TypePtr::BOTTOM,
6332                                  src_start, state, ofs, limit);
6333   // return ofs (int)
6334   Node* result = _gvn.transform(new ProjNode(call, TypeFunc::Parms));
6335   set_result(result);
6336 
6337   return true;
6338 }
6339 
6340 //------------------------------get_state_from_sha_object-----------------------
6341 Node * LibraryCallKit::get_state_from_sha_object(Node *sha_object) {
6342   Node* sha_state = load_field_from_object(sha_object, "state", "[I", /*is_exact*/ false);
6343   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA/SHA2");
6344   if (sha_state == NULL) return (Node *) NULL;
6345 
6346   // now have the array, need to get the start address of the state array
6347   Node* state = array_element_address(sha_state, intcon(0), T_INT);
6348   return state;
6349 }
6350 
6351 //------------------------------get_state_from_sha5_object-----------------------
6352 Node * LibraryCallKit::get_state_from_sha5_object(Node *sha_object) {
6353   Node* sha_state = load_field_from_object(sha_object, "state", "[J", /*is_exact*/ false);
6354   assert (sha_state != NULL, "wrong version of sun.security.provider.SHA5");
6355   if (sha_state == NULL) return (Node *) NULL;
6356 
6357   // now have the array, need to get the start address of the state array
6358   Node* state = array_element_address(sha_state, intcon(0), T_LONG);
6359   return state;
6360 }
6361 
6362 //----------------------------inline_digestBase_implCompressMB_predicate----------------------------
6363 // Return node representing slow path of predicate check.
6364 // the pseudo code we want to emulate with this predicate is:
6365 //    if (digestBaseObj instanceof SHA/SHA2/SHA5) do_intrinsic, else do_javapath
6366 //
6367 Node* LibraryCallKit::inline_digestBase_implCompressMB_predicate(int predicate) {
6368   assert(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics,
6369          "need SHA1/SHA256/SHA512 instruction support");
6370   assert((uint)predicate < 3, "sanity");
6371 
6372   // The receiver was checked for NULL already.
6373   Node* digestBaseObj = argument(0);
6374 
6375   // get DigestBase klass for instanceOf check
6376   const TypeInstPtr* tinst = _gvn.type(digestBaseObj)->isa_instptr();
6377   assert(tinst != NULL, "digestBaseObj is null");
6378   assert(tinst->klass()->is_loaded(), "DigestBase is not loaded");
6379 
6380   const char* klass_SHA_name = NULL;
6381   switch (predicate) {
6382   case 0:
6383     if (UseSHA1Intrinsics) {
6384       // we want to do an instanceof comparison against the SHA class
6385       klass_SHA_name = "sun/security/provider/SHA";
6386     }
6387     break;
6388   case 1:
6389     if (UseSHA256Intrinsics) {
6390       // we want to do an instanceof comparison against the SHA2 class
6391       klass_SHA_name = "sun/security/provider/SHA2";
6392     }
6393     break;
6394   case 2:
6395     if (UseSHA512Intrinsics) {
6396       // we want to do an instanceof comparison against the SHA5 class
6397       klass_SHA_name = "sun/security/provider/SHA5";
6398     }
6399     break;
6400   default:
6401     fatal(err_msg_res("unknown SHA intrinsic predicate: %d", predicate));
6402   }
6403 
6404   ciKlass* klass_SHA = NULL;
6405   if (klass_SHA_name != NULL) {
6406     klass_SHA = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_SHA_name));
6407   }
6408   if ((klass_SHA == NULL) || !klass_SHA->is_loaded()) {
6409     // if none of SHA/SHA2/SHA5 is loaded, we never take the intrinsic fast path
6410     Node* ctrl = control();
6411     set_control(top()); // no intrinsic path
6412     return ctrl;
6413   }
6414   ciInstanceKlass* instklass_SHA = klass_SHA->as_instance_klass();
6415 
6416   Node* instofSHA = gen_instanceof(digestBaseObj, makecon(TypeKlassPtr::make(instklass_SHA)));
6417   Node* cmp_instof = _gvn.transform(new CmpINode(instofSHA, intcon(1)));
6418   Node* bool_instof = _gvn.transform(new BoolNode(cmp_instof, BoolTest::ne));
6419   Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN);
6420 
6421   return instof_false;  // even if it is NULL
6422 }
src/share/vm/opto/library_call.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File