Skip to content

Commit 2ba5cc4

Browse files
committed
8284760: Correct type/array element offset in LibraryCallKit::get_state_from_digest_object()
Reviewed-by: roland, kvn
1 parent c3938ec commit 2ba5cc4

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/hotspot/share/opto/library_call.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6601,31 +6601,31 @@ bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
66016601
switch(id) {
66026602
case vmIntrinsics::_md5_implCompress:
66036603
assert(UseMD5Intrinsics, "need MD5 instruction support");
6604-
state = get_state_from_digest_object(digestBase_obj, "[I");
6604+
state = get_state_from_digest_object(digestBase_obj, T_INT);
66056605
stubAddr = StubRoutines::md5_implCompress();
66066606
stubName = "md5_implCompress";
66076607
break;
66086608
case vmIntrinsics::_sha_implCompress:
66096609
assert(UseSHA1Intrinsics, "need SHA1 instruction support");
6610-
state = get_state_from_digest_object(digestBase_obj, "[I");
6610+
state = get_state_from_digest_object(digestBase_obj, T_INT);
66116611
stubAddr = StubRoutines::sha1_implCompress();
66126612
stubName = "sha1_implCompress";
66136613
break;
66146614
case vmIntrinsics::_sha2_implCompress:
66156615
assert(UseSHA256Intrinsics, "need SHA256 instruction support");
6616-
state = get_state_from_digest_object(digestBase_obj, "[I");
6616+
state = get_state_from_digest_object(digestBase_obj, T_INT);
66176617
stubAddr = StubRoutines::sha256_implCompress();
66186618
stubName = "sha256_implCompress";
66196619
break;
66206620
case vmIntrinsics::_sha5_implCompress:
66216621
assert(UseSHA512Intrinsics, "need SHA512 instruction support");
6622-
state = get_state_from_digest_object(digestBase_obj, "[J");
6622+
state = get_state_from_digest_object(digestBase_obj, T_LONG);
66236623
stubAddr = StubRoutines::sha512_implCompress();
66246624
stubName = "sha512_implCompress";
66256625
break;
66266626
case vmIntrinsics::_sha3_implCompress:
66276627
assert(UseSHA3Intrinsics, "need SHA3 instruction support");
6628-
state = get_state_from_digest_object(digestBase_obj, "[B");
6628+
state = get_state_from_digest_object(digestBase_obj, T_BYTE);
66296629
stubAddr = StubRoutines::sha3_implCompress();
66306630
stubName = "sha3_implCompress";
66316631
digest_length = get_digest_length_from_digest_object(digestBase_obj);
@@ -6689,7 +6689,7 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
66896689
const char* klass_digestBase_name = NULL;
66906690
const char* stub_name = NULL;
66916691
address stub_addr = NULL;
6692-
const char* state_type = "[I";
6692+
BasicType elem_type = T_INT;
66936693

66946694
switch (predicate) {
66956695
case 0:
@@ -6718,15 +6718,15 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
67186718
klass_digestBase_name = "sun/security/provider/SHA5";
67196719
stub_name = "sha512_implCompressMB";
67206720
stub_addr = StubRoutines::sha512_implCompressMB();
6721-
state_type = "[J";
6721+
elem_type = T_LONG;
67226722
}
67236723
break;
67246724
case 4:
67256725
if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_sha3_implCompress)) {
67266726
klass_digestBase_name = "sun/security/provider/SHA3";
67276727
stub_name = "sha3_implCompressMB";
67286728
stub_addr = StubRoutines::sha3_implCompressMB();
6729-
state_type = "[B";
6729+
elem_type = T_BYTE;
67306730
}
67316731
break;
67326732
default:
@@ -6744,21 +6744,21 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
67446744
ciKlass* klass_digestBase = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
67456745
assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
67466746
ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
6747-
return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, state_type, stub_addr, stub_name, src_start, ofs, limit);
6747+
return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
67486748
}
67496749
return false;
67506750
}
67516751

67526752
//------------------------------inline_digestBase_implCompressMB-----------------------
67536753
bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
6754-
const char* state_type, address stubAddr, const char *stubName,
6754+
BasicType elem_type, address stubAddr, const char *stubName,
67556755
Node* src_start, Node* ofs, Node* limit) {
67566756
const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
67576757
const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
67586758
Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
67596759
digest_obj = _gvn.transform(digest_obj);
67606760

6761-
Node* state = get_state_from_digest_object(digest_obj, state_type);
6761+
Node* state = get_state_from_digest_object(digest_obj, elem_type);
67626762
if (state == NULL) return false;
67636763

67646764
Node* digest_length = NULL;
@@ -6918,13 +6918,20 @@ Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() {
69186918
}
69196919

69206920
//------------------------------get_state_from_digest_object-----------------------
6921-
Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, const char *state_type) {
6921+
Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) {
6922+
const char* state_type;
6923+
switch (elem_type) {
6924+
case T_BYTE: state_type = "[B"; break;
6925+
case T_INT: state_type = "[I"; break;
6926+
case T_LONG: state_type = "[J"; break;
6927+
default: ShouldNotReachHere();
6928+
}
69226929
Node* digest_state = load_field_from_object(digest_object, "state", state_type);
69236930
assert (digest_state != NULL, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3");
69246931
if (digest_state == NULL) return (Node *) NULL;
69256932

69266933
// now have the array, need to get the start address of the state array
6927-
Node* state = array_element_address(digest_state, intcon(0), T_INT);
6934+
Node* state = array_element_address(digest_state, intcon(0), elem_type);
69286935
return state;
69296936
}
69306937

src/hotspot/share/opto/library_call.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ class LibraryCallKit : public GraphKit {
282282
bool inline_digestBase_implCompress(vmIntrinsics::ID id);
283283
bool inline_digestBase_implCompressMB(int predicate);
284284
bool inline_digestBase_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass,
285-
const char* state_type, address stubAddr, const char *stubName,
285+
BasicType elem_type, address stubAddr, const char *stubName,
286286
Node* src_start, Node* ofs, Node* limit);
287-
Node* get_state_from_digest_object(Node *digestBase_object, const char* state_type);
287+
Node* get_state_from_digest_object(Node *digestBase_object, BasicType elem_type);
288288
Node* get_digest_length_from_digest_object(Node *digestBase_object);
289289
Node* inline_digestBase_implCompressMB_predicate(int predicate);
290290
bool inline_encodeISOArray(bool ascii);

0 commit comments

Comments
 (0)