8284760: Correct type/array element offset in LibraryCallKit::get_state_from_digest_object()

Reviewed-by: roland, kvn
This commit is contained in:
Roman Kennke 2022-04-14 09:31:29 +00:00
parent c3938ec18b
commit 2ba5cc4163
2 changed files with 22 additions and 15 deletions

View File

@ -6601,31 +6601,31 @@ bool LibraryCallKit::inline_digestBase_implCompress(vmIntrinsics::ID id) {
switch(id) { switch(id) {
case vmIntrinsics::_md5_implCompress: case vmIntrinsics::_md5_implCompress:
assert(UseMD5Intrinsics, "need MD5 instruction support"); assert(UseMD5Intrinsics, "need MD5 instruction support");
state = get_state_from_digest_object(digestBase_obj, "[I"); state = get_state_from_digest_object(digestBase_obj, T_INT);
stubAddr = StubRoutines::md5_implCompress(); stubAddr = StubRoutines::md5_implCompress();
stubName = "md5_implCompress"; stubName = "md5_implCompress";
break; break;
case vmIntrinsics::_sha_implCompress: case vmIntrinsics::_sha_implCompress:
assert(UseSHA1Intrinsics, "need SHA1 instruction support"); assert(UseSHA1Intrinsics, "need SHA1 instruction support");
state = get_state_from_digest_object(digestBase_obj, "[I"); state = get_state_from_digest_object(digestBase_obj, T_INT);
stubAddr = StubRoutines::sha1_implCompress(); stubAddr = StubRoutines::sha1_implCompress();
stubName = "sha1_implCompress"; stubName = "sha1_implCompress";
break; break;
case vmIntrinsics::_sha2_implCompress: case vmIntrinsics::_sha2_implCompress:
assert(UseSHA256Intrinsics, "need SHA256 instruction support"); assert(UseSHA256Intrinsics, "need SHA256 instruction support");
state = get_state_from_digest_object(digestBase_obj, "[I"); state = get_state_from_digest_object(digestBase_obj, T_INT);
stubAddr = StubRoutines::sha256_implCompress(); stubAddr = StubRoutines::sha256_implCompress();
stubName = "sha256_implCompress"; stubName = "sha256_implCompress";
break; break;
case vmIntrinsics::_sha5_implCompress: case vmIntrinsics::_sha5_implCompress:
assert(UseSHA512Intrinsics, "need SHA512 instruction support"); assert(UseSHA512Intrinsics, "need SHA512 instruction support");
state = get_state_from_digest_object(digestBase_obj, "[J"); state = get_state_from_digest_object(digestBase_obj, T_LONG);
stubAddr = StubRoutines::sha512_implCompress(); stubAddr = StubRoutines::sha512_implCompress();
stubName = "sha512_implCompress"; stubName = "sha512_implCompress";
break; break;
case vmIntrinsics::_sha3_implCompress: case vmIntrinsics::_sha3_implCompress:
assert(UseSHA3Intrinsics, "need SHA3 instruction support"); assert(UseSHA3Intrinsics, "need SHA3 instruction support");
state = get_state_from_digest_object(digestBase_obj, "[B"); state = get_state_from_digest_object(digestBase_obj, T_BYTE);
stubAddr = StubRoutines::sha3_implCompress(); stubAddr = StubRoutines::sha3_implCompress();
stubName = "sha3_implCompress"; stubName = "sha3_implCompress";
digest_length = get_digest_length_from_digest_object(digestBase_obj); digest_length = get_digest_length_from_digest_object(digestBase_obj);
@ -6689,7 +6689,7 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
const char* klass_digestBase_name = NULL; const char* klass_digestBase_name = NULL;
const char* stub_name = NULL; const char* stub_name = NULL;
address stub_addr = NULL; address stub_addr = NULL;
const char* state_type = "[I"; BasicType elem_type = T_INT;
switch (predicate) { switch (predicate) {
case 0: case 0:
@ -6718,7 +6718,7 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
klass_digestBase_name = "sun/security/provider/SHA5"; klass_digestBase_name = "sun/security/provider/SHA5";
stub_name = "sha512_implCompressMB"; stub_name = "sha512_implCompressMB";
stub_addr = StubRoutines::sha512_implCompressMB(); stub_addr = StubRoutines::sha512_implCompressMB();
state_type = "[J"; elem_type = T_LONG;
} }
break; break;
case 4: case 4:
@ -6726,7 +6726,7 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
klass_digestBase_name = "sun/security/provider/SHA3"; klass_digestBase_name = "sun/security/provider/SHA3";
stub_name = "sha3_implCompressMB"; stub_name = "sha3_implCompressMB";
stub_addr = StubRoutines::sha3_implCompressMB(); stub_addr = StubRoutines::sha3_implCompressMB();
state_type = "[B"; elem_type = T_BYTE;
} }
break; break;
default: default:
@ -6744,21 +6744,21 @@ bool LibraryCallKit::inline_digestBase_implCompressMB(int predicate) {
ciKlass* klass_digestBase = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name)); ciKlass* klass_digestBase = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make(klass_digestBase_name));
assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded"); assert(klass_digestBase->is_loaded(), "predicate checks that this class is loaded");
ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass(); ciInstanceKlass* instklass_digestBase = klass_digestBase->as_instance_klass();
return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, state_type, stub_addr, stub_name, src_start, ofs, limit); return inline_digestBase_implCompressMB(digestBase_obj, instklass_digestBase, elem_type, stub_addr, stub_name, src_start, ofs, limit);
} }
return false; return false;
} }
//------------------------------inline_digestBase_implCompressMB----------------------- //------------------------------inline_digestBase_implCompressMB-----------------------
bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase, bool LibraryCallKit::inline_digestBase_implCompressMB(Node* digestBase_obj, ciInstanceKlass* instklass_digestBase,
const char* state_type, address stubAddr, const char *stubName, BasicType elem_type, address stubAddr, const char *stubName,
Node* src_start, Node* ofs, Node* limit) { Node* src_start, Node* ofs, Node* limit) {
const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase); const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_digestBase);
const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull); const TypeOopPtr* xtype = aklass->as_instance_type()->cast_to_ptr_type(TypePtr::NotNull);
Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype); Node* digest_obj = new CheckCastPPNode(control(), digestBase_obj, xtype);
digest_obj = _gvn.transform(digest_obj); digest_obj = _gvn.transform(digest_obj);
Node* state = get_state_from_digest_object(digest_obj, state_type); Node* state = get_state_from_digest_object(digest_obj, elem_type);
if (state == NULL) return false; if (state == NULL) return false;
Node* digest_length = NULL; Node* digest_length = NULL;
@ -6918,13 +6918,20 @@ Node* LibraryCallKit::inline_galoisCounterMode_AESCrypt_predicate() {
} }
//------------------------------get_state_from_digest_object----------------------- //------------------------------get_state_from_digest_object-----------------------
Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, const char *state_type) { Node * LibraryCallKit::get_state_from_digest_object(Node *digest_object, BasicType elem_type) {
const char* state_type;
switch (elem_type) {
case T_BYTE: state_type = "[B"; break;
case T_INT: state_type = "[I"; break;
case T_LONG: state_type = "[J"; break;
default: ShouldNotReachHere();
}
Node* digest_state = load_field_from_object(digest_object, "state", state_type); Node* digest_state = load_field_from_object(digest_object, "state", state_type);
assert (digest_state != NULL, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3"); assert (digest_state != NULL, "wrong version of sun.security.provider.MD5/SHA/SHA2/SHA5/SHA3");
if (digest_state == NULL) return (Node *) NULL; if (digest_state == NULL) return (Node *) NULL;
// now have the array, need to get the start address of the state array // now have the array, need to get the start address of the state array
Node* state = array_element_address(digest_state, intcon(0), T_INT); Node* state = array_element_address(digest_state, intcon(0), elem_type);
return state; return state;
} }

View File

@ -282,9 +282,9 @@ class LibraryCallKit : public GraphKit {
bool inline_digestBase_implCompress(vmIntrinsics::ID id); bool inline_digestBase_implCompress(vmIntrinsics::ID id);
bool inline_digestBase_implCompressMB(int predicate); bool inline_digestBase_implCompressMB(int predicate);
bool inline_digestBase_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass, bool inline_digestBase_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass,
const char* state_type, address stubAddr, const char *stubName, BasicType elem_type, address stubAddr, const char *stubName,
Node* src_start, Node* ofs, Node* limit); Node* src_start, Node* ofs, Node* limit);
Node* get_state_from_digest_object(Node *digestBase_object, const char* state_type); Node* get_state_from_digest_object(Node *digestBase_object, BasicType elem_type);
Node* get_digest_length_from_digest_object(Node *digestBase_object); Node* get_digest_length_from_digest_object(Node *digestBase_object);
Node* inline_digestBase_implCompressMB_predicate(int predicate); Node* inline_digestBase_implCompressMB_predicate(int predicate);
bool inline_encodeISOArray(bool ascii); bool inline_encodeISOArray(bool ascii);