Skip to content

Commit

Permalink
Fix fatal in OptConstantReplace::get_field_val
Browse files Browse the repository at this point in the history
--story=115043210
  • Loading branch information
946918940 authored and shiyuexw committed Jan 23, 2024
1 parent 729de6c commit 060bc4f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
20 changes: 10 additions & 10 deletions hotspot/src/share/vm/cr/codeReviveOptRecords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,7 @@ size_t OptConstantReplace::estimate_size_in_bytes() {
return 1 + 2 + 4 + 2 + 8;
}

jlong OptConstantReplace::get_field_val(ciConstant field_const) {
jlong field_val = 0;
bool OptConstantReplace::get_field_val(ciConstant field_const, jlong &field_val) {
jfloat f_val = 0;
jint i_val = 0;
jdouble d_val = 0;
Expand All @@ -672,14 +671,10 @@ jlong OptConstantReplace::get_field_val(ciConstant field_const) {
d_val = field_const.as_double();
field_val = *(jlong*)&d_val;
break;
case T_OBJECT:
case T_ARRAY:
ShouldNotReachHere();
break;
default:
fatal("illegal");
return false;
}
return field_val;
return true;
}

int OptConstantReplace::calc_opt_score() {
Expand All @@ -689,10 +684,15 @@ int OptConstantReplace::calc_opt_score() {
ciField* expected_fld = expected_kls->get_field_by_offset(_field_offset, true);
guarantee(expected_fld != NULL, "should be");
ciConstant expected_const = expected_fld->constant_value();

jlong field_val = get_field_val(expected_const);
jshort field_type = (jshort)expected_const.basic_type();

jlong field_val = 0;
bool field_status = get_field_val(expected_const, field_val);
if (field_status == false) {
CR_LOG(cr_restore, cr_fail, "Fail for get_field_val, illegal field_type: %d\n", field_type);
return max_jint;
}

int result = 0;
if (field_type == _field_type && field_val == _field_val) {
result = -1;
Expand Down
2 changes: 1 addition & 1 deletion hotspot/src/share/vm/cr/codeReviveOptRecords.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class OptConstantReplace : public OptRecord {
virtual size_t estimate_size_in_bytes();
virtual void write_to_stream(CompressedWriteStream* out);
virtual void read_from_stream(CompressedReadStream* in);
static jlong get_field_val(ciConstant field_const);
static bool get_field_val(ciConstant field_const, jlong &field_val);
virtual int calc_opt_score();
virtual bool equal(OptRecord* other);
virtual int compare_by_type_name(OptRecord* other);
Expand Down
8 changes: 7 additions & 1 deletion hotspot/src/share/vm/opto/parse3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ void Parse::do_get_xxx(Node* obj, ciField* field, bool is_field) {
// save for aot
ciKlass* klass = field->holder();
ciConstant field_const = field->constant_value();
env()->opt_records()->add_ConstantReplaceRecord(klass, field->offset(), (jshort)field_const.basic_type(), OptConstantReplace::get_field_val(field_const));
jlong field_val = 0;
bool field_status = OptConstantReplace::get_field_val(field_const, field_val);
if (field_status == false) {
CR_LOG(cr_save, cr_fail, "Fail for save klass %p, because of illegal field_type: %d\n", klass, (jshort)field_const.basic_type());
return;
}
env()->opt_records()->add_ConstantReplaceRecord(klass, field->offset(), (jshort)field_const.basic_type(), field_val);
return;
}
}
Expand Down

0 comments on commit 060bc4f

Please sign in to comment.